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 LockTokenTable.cpp
24
* @brief Implementation of the class LockTokenTable
27
#include "LockTokenTable.h"
29
#include "JNIStringHolder.h"
33
LockTokenTable::~LockTokenTable()
36
JNIUtil::getEnv()->DeleteLocalRef(m_jlock_tokens);
40
LockTokenTable::hash(const SVN::Pool &pool, bool null_if_empty)
42
if (m_lock_tokens.size() == 0 && null_if_empty)
45
apr_pool_t* result_pool = pool.getPool();
46
apr_hash_t* lock_table = apr_hash_make(result_pool);
48
for (lock_tokens_t::const_iterator it = m_lock_tokens.begin();
49
it != m_lock_tokens.end(); ++it)
51
const char *path = apr_pstrdup(result_pool, it->first.c_str());
52
const char *token = apr_pstrdup(result_pool, it->second.c_str());
53
apr_hash_set(lock_table, path, APR_HASH_KEY_STRING, token);
59
LockTokenTable::LockTokenTable(jobject jlock_tokens)
60
: m_jlock_tokens(jlock_tokens)
63
if (jlock_tokens != NULL)
65
JNIEnv *env = JNIUtil::getEnv();
67
jclass lock_cls = env->FindClass(JAVAHL_CLASS("/types/Lock"));
68
if (JNIUtil::isExceptionThrown())
71
static jmethodID getPath_mid = 0;
74
getPath_mid = env->GetMethodID(lock_cls, "getPath",
75
"()Ljava/lang/String;");
76
if (JNIUtil::isExceptionThrown())
80
static jmethodID getToken_mid = 0;
81
if (0 == getToken_mid)
83
getToken_mid = env->GetMethodID(lock_cls, "getToken",
84
"()Ljava/lang/String;");
85
if (JNIUtil::isExceptionThrown())
89
std::vector<jobject> locks = Array(jlock_tokens).vector();
90
for (std::vector<jobject>::const_iterator it = locks.begin();
91
it != locks.end(); ++it)
93
jobject jpath = env->CallObjectMethod(*it, getPath_mid);
94
if (JNIUtil::isExceptionThrown())
96
jobject jtoken = env->CallObjectMethod(*it, getToken_mid);
97
if (JNIUtil::isExceptionThrown())
100
JNIStringHolder path((jstring)jpath);
101
if (JNIUtil::isExceptionThrown())
103
JNIStringHolder token((jstring)jtoken);
104
if (JNIUtil::isExceptionThrown())
107
m_lock_tokens[std::string(static_cast<const char *>(path))] =
108
std::string(static_cast<const char *>(token));
110
env->DeleteLocalRef(jpath);
111
env->DeleteLocalRef(jtoken);