~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/bindings/java/javahl/native/MessageReceiver.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @copyright
 
3
 * ====================================================================
 
4
 * Copyright (c) 2003 CollabNet.  All rights reserved.
 
5
 *
 
6
 * This software is licensed as described in the file COPYING, which
 
7
 * you should have received as part of this distribution.  The terms
 
8
 * are also available at http://subversion.tigris.org/license-1.html.
 
9
 * If newer versions of this license are posted there, you may use a
 
10
 * newer version instead, at your option.
 
11
 *
 
12
 * This software consists of voluntary contributions made by many
 
13
 * individuals.  For exact contribution history, see the revision
 
14
 * history and logs, available at http://subversion.tigris.org/.
 
15
 * ====================================================================
 
16
 * @endcopyright
 
17
 *
 
18
 * @file MessageReceiver.cpp
 
19
 * @brief Implementation of the class MessageReceiver
 
20
 */
 
21
 
 
22
#include "MessageReceiver.h"
 
23
#include "JNIUtil.h"
 
24
/**
 
25
 * create a new object and store the local reference to the java object
 
26
 */
 
27
MessageReceiver::MessageReceiver(jobject jthis)
 
28
{
 
29
    m_jthis = jthis;
 
30
}
 
31
/**
 
32
 * destroy the object
 
33
 */
 
34
MessageReceiver::~MessageReceiver()
 
35
{
 
36
    // the m_callback does not need to be destroyed, because it is the passed 
 
37
    // in parameter to the java method.
 
38
}
 
39
/**
 
40
 * send a message to the java object
 
41
 * @param message   the message to be send
 
42
 */
 
43
void MessageReceiver::receiveMessage(const char *message)
 
44
{
 
45
    JNIEnv *env = JNIUtil::getEnv();
 
46
    static jmethodID mid = 0; // the method id will not change during
 
47
                              // the time this library is loaded, so
 
48
                              // it can be cached. 
 
49
    if(mid == 0)
 
50
    {
 
51
        jclass clazz = env->FindClass(JAVA_PACKAGE"/SVNAdmin$MessageReceiver");
 
52
        if(JNIUtil::isJavaExceptionThrown())
 
53
        {
 
54
            return;
 
55
        }
 
56
        mid = env->GetMethodID(clazz, "receiveMessageLine", 
 
57
            "(Ljava/lang/String;)V");
 
58
        if(JNIUtil::isJavaExceptionThrown() || mid == 0)
 
59
        {
 
60
            return;
 
61
        }
 
62
        env->DeleteLocalRef(clazz);
 
63
        if(JNIUtil::isJavaExceptionThrown())
 
64
        {
 
65
            return;
 
66
        }
 
67
    }
 
68
    // convert the message to a java string
 
69
    jstring jmsg = JNIUtil::makeJString(message);
 
70
    if(JNIUtil::isJavaExceptionThrown())
 
71
    {
 
72
        return;
 
73
    }
 
74
    
 
75
    // call the java method
 
76
    env->CallVoidMethod(m_jthis, mid);
 
77
    if(JNIUtil::isJavaExceptionThrown())
 
78
    {
 
79
        return;
 
80
    }
 
81
 
 
82
    // delete the java string
 
83
    env->DeleteLocalRef(jmsg);
 
84
    if(JNIUtil::isJavaExceptionThrown())
 
85
    {
 
86
        return;
 
87
    }
 
88
}