|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 2 of 4
The nine primitive classes act as the wrappers for the nine primitive JNI values. You use these classes as arguments and return values from other C++ proxy classes:
/* Retrieve the hashcode for the java.lang.String, "A String" */ JInt hashCode = String( "A String" ).hashCode();
You also use these classes as template parameters to JArray:
/* Create a byte buffer of size 512 */ JArray<JByte> buffer( 512 );
JValue is the base class for all the proxy classes. It represents the total set of Java primitive and reference types. Therefore,
each JValue has a JClass instance that represents the corresponding jclass for the jvalue. You can only construct a JValue by providing it with a JNI jvalue type. JValue then acts as a holder for that jvalue. Most developers don't need to interact with JValues directly.
JClass represents the JNI type jclass. JClass provides methods to retrieve its jclass and the strings that represent that jclass in different JNI calls (for example, java/lang/Object and Ljava/lang/Object;). The framework uses JClass instances to provide the information necessary to make JNI calls, like GetMethodID(), GetFieldID(), and NewObjectArray(). Most developers don't need to interact with JClasses directly.
The JObject class, which represents the JNI type jobject, serves as the base class for all reference types. In addition to overriding JValue::getJavaValue(), JObject also provides getJavaObject(). These two methods are functionally equivalent, except that getJavaObject() unwraps the jvalue and places it into a jobject.
Things become interesting with JObject, because Java reference types have some features that Java primitive types don't:
JObject subclasses in two ways. First, you can construct them as a reference to an existing Java object. You can do this by using
the constructor that takes a jobject (or a jvalue containing a jobject) or by using the C++ copy constructor.When you instantiate a JObject subclass, the subclass instance refers itself to the jobject reference provided as the argument. (The instance creates a new global reference to the jobject using NewGlobalRef()):
using jace::java::net::URL;
/**
* @param jurl - A java.net.URL
*/
JNIEXPORT void JNICALL Java_foo_Bar_someMethod( JNIEnv *env, jobject jURL ) {
/* You create a reference to jURL; not a new URL
*/
URL url( jurl );
/* Now that you've instantiated this C++ proxy object, you can call methods
* on jURL with ease—like toString()
*/
std::string urlString = url.toString();
}
Second, you can construct a JObject subclass by creating a new Java object. You can create a new object by calling any other subclass constructor. When that
happens, the subclass calls the appropriate Java constructor using JNI. After constructing the Java object, the subclass creates
a new global reference to it:
/* Creates a new FileOutputStream on foo.txt. */ jace::java::io::FileOutputStream output( "foo.txt" );
Regardless of how you create a JObject subclass, the subclass's only action upon leaving scope is to call DeleteGlobalRef() on the global reference it created at construction.