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
* ====================================================================
24
#ifndef SVN_JAVAHL_JNIWRAPPER_OBJECT_HPP
25
#define SVN_JAVAHL_JNIWRAPPER_OBJECT_HPP
27
#include "jni_env.hpp"
28
#include "jni_globalref.hpp"
33
* An abstract wrapper for a @c java.lang.Object instance.
35
* This is the base class for all concrete object wrapper classes. It
36
* is self-contained in the sense that it heeps its own JVM
37
* environment, class and object reference; Java object methods are
38
* expected to be exposed as methods of derived classes.
40
* The associated JNI class reference is stored for the lifetime of
41
* the JVM in the global class cache.
49
* Returns the wrapped JNI object reference.
57
* Returns the wrapped JNI class reference.
59
jclass get_class() const
61
return m_impl->get_class();
65
* Returns the wrapped enviromnment reference.
73
* This object's implementation details.
78
jclass get_class() const
86
explicit ClassImpl(Env env, jclass cls)
91
friend class ClassCacheImpl;
93
GlobalClass m_class; ///< Class reference for this object wrapper
96
ClassImpl(const ClassImpl&);
97
ClassImpl& operator=(const ClassImpl&);
102
* constructs an object wrapper given the class @a impl and an
103
* object reference @a jthis.
105
Object(Env env, const ClassImpl* impl, jobject jthis = NULL)
111
const Env m_env; ///< JVM environment wrapper
112
const ClassImpl* const m_impl; ///< Class implementation details
113
const jobject m_jthis; ///< @c this object reference
116
* Certain subclasses need a fully constructed base Object before
117
* they can create the wrapped JNI object. They can use this
118
* function to oveerride the constness of @c m_jthis, but only if
119
* they're changing a @c NULL @c m_jthis to a concrete value.
121
void set_this(jobject jthis)
123
if (!m_jthis && jthis)
124
*const_cast<jobject*>(&m_jthis) = jthis;
128
friend class ClassCacheImpl;
129
static const char* const m_class_name;
132
// Forward declaration
133
class ClassCacheImpl;
136
* A singleton cache for global class references.
138
* The instance is created when the native library is loaded by the
139
* JVM, and destroyed when it is unloaded. It creates global
140
* references for a number of classes and calls said classes'
141
* single-threded static initializers, which usually find and store
142
* method and field IDs (which are usually only valid until the
143
* associated class is garbage-collected).
145
* Be aware that as long as the global references exist, these classes
146
* cannot be garbage-collected. The number of classes stored in this
147
* cache should therefore be kept to a reasonable minimum.
153
// Cannot create instances of this type.
157
static ClassCacheImpl* m_impl;
160
/* This static initializer must only be called by JNI_OnLoad */
161
static void create();
163
/* This static finalizer must only be called by JNI_OnUnload */
164
static void destroy();
166
#define JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(M) \
167
static const Object::ClassImpl* get_##M(Env env);
169
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(object);
170
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(classtype);
171
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(throwable);
172
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(string);
174
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(exc_index_out_of_bounds);
175
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(exc_no_such_element);
177
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(list);
178
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(array_list);
180
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(map);
181
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(set);
182
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(iterator);
183
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(map_entry);
184
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(hash_map);
186
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(input_stream);
187
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(output_stream);
189
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(byte_buffer);
191
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(subversion_exception);
193
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(authn_cb);
194
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(authn_result);
195
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(authn_ssl_server_cert_failures);
196
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(authn_ssl_server_cert_info);
197
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(user_passwd_cb);
199
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(credential);
200
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(credential_kind);
202
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(external_item);
204
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(editor_provide_base_cb);
205
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(editor_provide_base_cb_ret);
206
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(editor_provide_props_cb);
207
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(editor_provide_props_cb_ret);
208
JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(editor_get_kind_cb);
209
#undef JNIWRAPPER_DECLARE_CACHED_CLASS
214
* Object wrapper for @c java.lang.Class.
216
* The associated JNI class reference is stored for the lifetime of
217
* the JVM in the global class cache.
225
* Constructs class instance wrapper for @a obj.
227
explicit Class(Env env, jobject obj);
230
* Constructs class instance wrapper for @a obj.
232
explicit Class(const Object& obj);
235
* Wrapper for the Java @c getName() method.
237
jstring get_name() const;
240
* Returns the wrapped class instance.
248
* Returns the wrapped enviromnment reference.
257
* This object's implementation details.
259
class ClassImpl : public Object::ClassImpl
261
friend class ClassCacheImpl;
264
explicit ClassImpl(Env env, jclass cls)
265
: Object::ClassImpl(env, cls)
269
virtual ~ClassImpl();
272
const Env m_env; ///< JVM environment wrapper
273
const jobject m_jthis; ///< Class instance
275
friend class ClassCacheImpl;
276
static const char* const m_class_name;
277
static void static_init(Env env, jclass class_type);
279
static MethodID m_mid_get_class;
280
static MethodID m_mid_get_name;
285
#endif // SVN_JAVAHL_JNIWRAPPER_OBJECT_HPP