~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/bindings/java/javahl/native/BlameCallback.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-2004 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 BlameCall.cpp
 
19
 * @brief Implementation of the class BlameCallback
 
20
 */
 
21
 
 
22
#include "BlameCallback.h"
 
23
#include "JNIUtil.h"
 
24
#include <svn_time.h>
 
25
/**
 
26
 * Create a BlameCallback object
 
27
 * @param jcallback the java callback object.
 
28
 */
 
29
BlameCallback::BlameCallback(jobject jcallback)
 
30
{
 
31
    m_callback = jcallback;
 
32
}
 
33
/**
 
34
 * Destroy a BlameCallback object
 
35
 */
 
36
BlameCallback::~BlameCallback()
 
37
{
 
38
    // the m_callback does not need to be destroyed, because it is the passed 
 
39
    // in parameter to the java SVNClient.blame method.
 
40
}
 
41
/**
 
42
 * Callback called for a single line in the file, for which the blame 
 
43
 * information was requested
 
44
 * @param revision  the revision number, when the line was last changed
 
45
 *                  or -1, if not changed during the request revision
 
46
 *                  interval
 
47
 *
 
48
 * @param author    the author, who performed the last change of the line
 
49
 * @param date      the date of the last change of the line
 
50
 * @param line      the content of the line
 
51
 * @param pool      memory pool for the use of this function
 
52
 */
 
53
void BlameCallback::callback(svn_revnum_t revision, const char *author, 
 
54
                             const char *date, const char *line, 
 
55
                             apr_pool_t *pool)
 
56
{
 
57
    JNIEnv *env = JNIUtil::getEnv();
 
58
 
 
59
    static jmethodID mid = 0; // the method id will not change during
 
60
                              // the time this library is loaded, so
 
61
                              // it can be cached. 
 
62
    if(mid == 0)
 
63
    {
 
64
        jclass clazz = env->FindClass(JAVA_PACKAGE"/BlameCallback");
 
65
        if(JNIUtil::isJavaExceptionThrown())
 
66
        {
 
67
            return;
 
68
        }
 
69
        mid = env->GetMethodID(clazz, "singleLine", 
 
70
            "(Ljava/util/Date;JLjava/lang/String;Ljava/lang/String;)V");
 
71
        if(JNIUtil::isJavaExceptionThrown() || mid == 0)
 
72
        {
 
73
            return;
 
74
        }
 
75
        env->DeleteLocalRef(clazz);
 
76
        if(JNIUtil::isJavaExceptionThrown())
 
77
        {
 
78
            return;
 
79
        }
 
80
    }
 
81
 
 
82
    // convert the parameters to their java relatives
 
83
    jstring jauthor = JNIUtil::makeJString(author);
 
84
    if(JNIUtil::isJavaExceptionThrown())
 
85
    {
 
86
        return;
 
87
    }
 
88
    jobject jdate = NULL;
 
89
    if(date != NULL && *date != '\0')
 
90
    {
 
91
        apr_time_t timeTemp;
 
92
        svn_time_from_cstring (&timeTemp, date, pool);
 
93
 
 
94
        jdate = JNIUtil::createDate(timeTemp);
 
95
        if(JNIUtil::isJavaExceptionThrown())
 
96
        {
 
97
            return;
 
98
        }
 
99
    }
 
100
    jstring jline = JNIUtil::makeJString(line);
 
101
    if(JNIUtil::isJavaExceptionThrown())
 
102
    {
 
103
        return;
 
104
    }
 
105
 
 
106
    // call the java method
 
107
    env->CallVoidMethod(m_callback, mid, jdate, (jlong)revision, jauthor, 
 
108
        jline);
 
109
    if(JNIUtil::isJavaExceptionThrown())
 
110
    {
 
111
        return;
 
112
    }
 
113
 
 
114
    // cleanup the temporary java objects
 
115
    env->DeleteLocalRef(jline);
 
116
    if(JNIUtil::isJavaExceptionThrown())
 
117
    {
 
118
        return;
 
119
    }
 
120
    env->DeleteLocalRef(jauthor);
 
121
    if(JNIUtil::isJavaExceptionThrown())
 
122
    {
 
123
        return;
 
124
    }
 
125
    env->DeleteLocalRef(jdate);
 
126
    if(JNIUtil::isJavaExceptionThrown())
 
127
    {
 
128
        return;
 
129
    }
 
130
}