3
* ====================================================================
4
* Licensed to the Apache Software Foundation (ASF) under one
5
* or more contributor license agreements. See the NOTICE file
6
* distributed with this work for additional information
7
* regarding copyright ownership. The ASF licenses this file
8
* to you under the Apache License, Version 2.0 (the
9
* "License"); you may not use this file except in compliance
10
* with the License. You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing,
15
* software distributed under the License is distributed on an
16
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
* KIND, either express or implied. See the License for the
18
* specific language governing permissions and limitations
20
* ====================================================================
23
* @file RevisionRangeList.cpp
24
* @brief Implementat of the class RevisionRangeList
29
#include "RevisionRange.h"
30
#include "RevisionRangeList.h"
32
RevisionRangeList::RevisionRangeList(jobject jrangelist, SVN::Pool &pool)
38
Iterator iter(jrangelist);
39
if (JNIUtil::isJavaExceptionThrown())
42
m_rangelist = apr_array_make(pool.getPool(), 0, sizeof(svn_merge_range_t*));
43
while (iter.hasNext())
45
svn_merge_range_t* range = RevisionRange(iter.next()).toMergeRange(pool);
46
if (JNIUtil::isExceptionThrown())
48
APR_ARRAY_PUSH(m_rangelist, svn_merge_range_t*) = range;
52
RevisionRangeList RevisionRangeList::create(jobject jthis, SVN::Pool &pool)
54
jobject jrangelist = NULL;
58
JNIEnv *env = JNIUtil::getEnv();
63
jclass cls = env->FindClass(JAVAHL_CLASS("/types/RevisionRangeList"));
64
if (JNIUtil::isJavaExceptionThrown())
65
return RevisionRangeList(NULL, pool);
67
mid = env->GetMethodID(cls, "getRanges", "()Ljava/util/List;");
68
if (JNIUtil::isJavaExceptionThrown())
69
return RevisionRangeList(NULL, pool);
72
jrangelist = env->CallObjectMethod(jthis, mid);
73
if (JNIUtil::isJavaExceptionThrown())
74
return RevisionRangeList(NULL, pool);
76
return RevisionRangeList(jrangelist, pool);
79
jobject RevisionRangeList::toList() const
81
JNIEnv *env = JNIUtil::getEnv();
83
// Create a local frame for our references
84
env->PushLocalFrame(LOCAL_FRAME_SIZE);
85
if (JNIUtil::isJavaExceptionThrown())
88
jclass clazz = env->FindClass("java/util/ArrayList");
89
if (JNIUtil::isJavaExceptionThrown())
92
static jmethodID init_mid = 0;
95
init_mid = env->GetMethodID(clazz, "<init>", "()V");
96
if (JNIUtil::isJavaExceptionThrown())
100
static jmethodID add_mid = 0;
103
add_mid = env->GetMethodID(clazz, "add", "(Ljava/lang/Object;)Z");
104
if (JNIUtil::isJavaExceptionThrown())
108
jobject jranges = env->NewObject(clazz, init_mid);
110
for (int i = 0; i < m_rangelist->nelts; ++i)
112
// Convert svn_merge_range_t *'s to Java RevisionRange objects.
113
svn_merge_range_t *range =
114
APR_ARRAY_IDX(m_rangelist, i, svn_merge_range_t *);
116
jobject jrange = RevisionRange::makeJRevisionRange(range);
117
if (JNIUtil::isJavaExceptionThrown())
120
env->CallBooleanMethod(jranges, add_mid, jrange);
121
if (JNIUtil::isJavaExceptionThrown())
124
env->DeleteLocalRef(jrange);
127
return env->PopLocalFrame(jranges);