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 org_apache_subversion_javahl_util_ConfigImpl_Category.cpp
24
* @brief Implementation of the native methods in the Java class
25
* util.ConfigImpl.Category.
31
#include "../include/org_apache_subversion_javahl_util_ConfigImpl_Category.h"
33
#include "JNIStackElement.h"
34
#include "JNIStringHolder.h"
35
#include "OperationContext.h"
37
#include "EnumMapper.h"
39
#include "svn_config.h"
41
#include "svn_private_config.h"
46
ImplContext(JNIEnv* env, jobject jthis,
47
jstring jcategory, jlong jcontext,
48
jstring jsection, jstring joption) : m_config(NULL)
50
OperationContext* const context(
51
reinterpret_cast<OperationContext*>(jcontext));
52
CPPADDR_NULL_PTR(context,);
54
JNIStringHolder category(jcategory);
55
if (JNIUtil::isJavaExceptionThrown())
59
apr_hash_t* cfgdata = context->getConfigData();
61
m_config = static_cast<svn_config_t*>(
62
svn_hash_gets(cfgdata, category.c_str()));
64
JNIUtil::throwNullPointerException("getConfigData");
67
JNIUtil::throwNullPointerException("category");
69
JNIStringHolder section(jsection);
70
if (JNIUtil::isJavaExceptionThrown())
73
m_section = section.c_str();
75
JNIStringHolder option(joption);
76
if (JNIUtil::isJavaExceptionThrown())
79
m_option = option.c_str();
82
svn_config_t* m_config;
83
std::string m_section;
86
} // anonymous namespace
90
JNIEXPORT jstring JNICALL
91
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_get_1str(
92
JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
93
jstring jsection, jstring joption, jstring jdefault_value)
95
JNIEntry(ConfigImpl$Category, get_str);
96
const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
98
JNIStringHolder default_value(jdefault_value);
99
if (JNIUtil::isJavaExceptionThrown())
103
svn_config_get(ctx.m_config, &value,
104
ctx.m_section.c_str(), ctx.m_option.c_str(),
105
default_value.c_str());
106
return JNIUtil::makeJString(value);
109
JNIEXPORT jboolean JNICALL
110
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_get_1bool(
111
JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
112
jstring jsection, jstring joption, jboolean jdefault_value)
114
JNIEntry(ConfigImpl$Category, get_bool);
115
const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
118
SVN_JNI_ERR(svn_config_get_bool(ctx.m_config, &value,
119
ctx.m_section.c_str(), ctx.m_option.c_str(),
120
bool(jdefault_value)),
122
return jboolean(value);
125
JNIEXPORT jlong JNICALL
126
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_get_1long(
127
JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
128
jstring jsection, jstring joption, jlong jdefault_value)
130
JNIEntry(ConfigImpl$Category, get_long);
131
const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
134
SVN_JNI_ERR(svn_config_get_int64(ctx.m_config, &value,
135
ctx.m_section.c_str(), ctx.m_option.c_str(),
136
apr_int64_t(jdefault_value)),
141
JNIEXPORT jobject JNICALL
142
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_get_1tri(
143
JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
144
jstring jsection, jstring joption,
145
jstring junknown, jobject jdefault_value)
147
JNIEntry(ConfigImpl$Category, get_tri);
148
const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
150
JNIStringHolder unknown(junknown);
151
if (JNIUtil::isJavaExceptionThrown())
154
svn_tristate_t value;
155
SVN_JNI_ERR(svn_config_get_tristate(ctx.m_config, &value,
156
ctx.m_section.c_str(),
157
ctx.m_option.c_str(),
159
EnumMapper::toTristate(jdefault_value)),
161
return EnumMapper::mapTristate(value);
164
JNIEXPORT jstring JNICALL
165
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_get_1yna(
166
JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
167
jstring jsection, jstring joption, jstring jdefault_value)
169
JNIEntry(ConfigImpl$Category, get_yna);
170
const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
172
JNIStringHolder default_value(jdefault_value);
173
if (JNIUtil::isJavaExceptionThrown())
177
SVN_JNI_ERR(svn_config_get_yes_no_ask(
178
ctx.m_config, &value,
179
ctx.m_section.c_str(), ctx.m_option.c_str(),
180
default_value.c_str()),
182
return JNIUtil::makeJString(value);
185
JNIEXPORT void JNICALL
186
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_set_1str(
187
JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
188
jstring jsection, jstring joption, jstring jvalue)
190
JNIEntry(ConfigImpl$Category, set_str);
191
const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
193
JNIStringHolder value(jvalue);
194
if (JNIUtil::isJavaExceptionThrown())
197
svn_config_set(ctx.m_config,
198
ctx.m_section.c_str(), ctx.m_option.c_str(),
202
JNIEXPORT void JNICALL
203
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_set_1bool(
204
JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
205
jstring jsection, jstring joption, jboolean jvalue)
207
JNIEntry(ConfigImpl$Category, set_bool);
208
const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
210
svn_config_set_bool(ctx.m_config,
211
ctx.m_section.c_str(), ctx.m_option.c_str(),
215
JNIEXPORT void JNICALL
216
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_set_1long(
217
JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
218
jstring jsection, jstring joption, jlong jvalue)
220
JNIEntry(ConfigImpl$Category, set_long);
221
const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
223
svn_config_set_int64(ctx.m_config,
224
ctx.m_section.c_str(), ctx.m_option.c_str(),
225
apr_int64_t(jvalue));
228
JNIEXPORT jobject JNICALL
229
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_sections(
230
JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext)
232
JNIEntry(ConfigImpl$Category, sections);
233
const ImplContext ctx(env, jthis, jcategory, jcontext, NULL, NULL);
237
static svn_boolean_t process(const char* name, void* baton,
240
jstring jname = JNIUtil::makeJString(name);
241
if (JNIUtil::isJavaExceptionThrown())
243
static_cast<enumerator_t*>(baton)
244
->m_sections.push_back(jobject(jname));
247
std::vector<jobject> m_sections;
250
SVN::Pool requestPool;
251
svn_config_enumerate_sections2(ctx.m_config, enumerator.process, &enumerator,
252
requestPool.getPool());
253
if (JNIUtil::isJavaExceptionThrown())
255
return CreateJ::Set(enumerator.m_sections);
258
JNIEXPORT void JNICALL
259
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_enumerate(
260
JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
261
jstring jsection, jobject jhandler)
263
JNIEntry(ConfigImpl$Category, sections);
264
const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, NULL);
268
static svn_boolean_t process(const char* name, const char* value,
269
void* baton, apr_pool_t *pool)
271
enumerator_t* enmr = static_cast<enumerator_t*>(baton);
272
JNIEnv* const e = enmr->m_env;
273
const jobject jh = enmr->m_jhandler;;
275
static jmethodID mid = 0;
278
jclass cls = e->FindClass(JAVAHL_CLASS("/ISVNConfig$Enumerator"));
279
if (JNIUtil::isJavaExceptionThrown())
281
mid = e->GetMethodID(cls, "option",
282
"(Ljava/lang/String;Ljava/lang/String;)V");
283
if (JNIUtil::isJavaExceptionThrown())
287
jstring jname = JNIUtil::makeJString(name);
288
if (JNIUtil::isJavaExceptionThrown())
290
jstring jvalue = JNIUtil::makeJString(value);
291
if (JNIUtil::isJavaExceptionThrown())
294
e->CallVoidMethod(jh, mid, jname, jvalue);
295
if (JNIUtil::isJavaExceptionThrown())
298
e->DeleteLocalRef(jname);
299
e->DeleteLocalRef(jvalue);
307
enumerator.m_env = env;
308
enumerator.m_jhandler = jhandler;
310
SVN::Pool requestPool;
311
svn_config_enumerate2(ctx.m_config, ctx.m_section.c_str(),
312
enumerator.process, &enumerator,
313
requestPool.getPool());