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 RevpropTable.cpp
24
* @brief Implementation of the class RevpropTable
27
#include "RevpropTable.h"
29
#include "JNIStringHolder.h"
31
#include <apr_tables.h>
32
#include <apr_strings.h>
35
#include "svn_props.h"
38
RevpropTable::~RevpropTable()
40
if (m_revpropTable != NULL)
41
JNIUtil::getEnv()->DeleteLocalRef(m_revpropTable);
44
const apr_hash_t *RevpropTable::hash(const SVN::Pool &pool)
46
if (m_revprops.size() == 0)
49
apr_hash_t *revprop_table = apr_hash_make(pool.getPool());
51
std::map<std::string, std::string>::const_iterator it;
52
for (it = m_revprops.begin(); it != m_revprops.end(); ++it)
54
const char *propname = apr_pstrdup(pool.getPool(), it->first.c_str());
55
if (!svn_prop_name_is_valid(propname))
57
const char *msg = apr_psprintf(pool.getPool(),
58
"Invalid property name: '%s'",
60
JNIUtil::throwNativeException(JAVA_PACKAGE "/ClientException", msg,
61
NULL, SVN_ERR_CLIENT_PROPERTY_NAME);
65
svn_string_t *propval = svn_string_create(it->second.c_str(),
68
apr_hash_set(revprop_table, propname, APR_HASH_KEY_STRING, propval);
74
RevpropTable::RevpropTable(jobject jrevpropTable)
76
m_revpropTable = jrevpropTable;
78
if (jrevpropTable != NULL)
80
static jmethodID keySet = 0, get = 0;
81
JNIEnv *env = JNIUtil::getEnv();
83
jclass mapClazz = env->FindClass("java/util/Map");
87
keySet = env->GetMethodID(mapClazz, "keySet",
89
if (JNIUtil::isExceptionThrown())
93
jobject jkeySet = env->CallObjectMethod(jrevpropTable, keySet);
94
if (JNIUtil::isExceptionThrown())
99
get = env->GetMethodID(mapClazz, "get",
100
"(Ljava/lang/Object;)Ljava/lang/Object;");
101
if (JNIUtil::isExceptionThrown())
105
Array keyArray(jkeySet);
106
std::vector<jobject> keys = keyArray.vector();
108
for (std::vector<jobject>::const_iterator it = keys.begin();
109
it < keys.end(); ++it)
111
JNIStringHolder propname((jstring)*it);
112
if (JNIUtil::isExceptionThrown())
115
jobject jpropval = env->CallObjectMethod(jrevpropTable, get, *it);
116
if (JNIUtil::isExceptionThrown())
119
JNIStringHolder propval((jstring)jpropval);
120
if (JNIUtil::isExceptionThrown())
123
m_revprops[std::string(static_cast<const char *>(propname))]
124
= std::string(static_cast<const char *>(propval));
126
JNIUtil::getEnv()->DeleteLocalRef(jpropval);
129
JNIUtil::getEnv()->DeleteLocalRef(jkeySet);