fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Common Development and Distribution License, Version 1.0 only
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (the "License"). You may not use this file except in compliance
fa9e4066f08beec538e775443c5be79dd423fcabahrens * with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrens#pragma ident "%Z%%M% %I% %E% SMI"
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Package-private functions
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*PRINTFLIKE2*/
fa9e4066f08beec538e775443c5be79dd423fcabahrenszjni_throw_exception(JNIEnv *env, const char *fmt, ...)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->FindClass(env, "java/lang/UnsupportedOperationException");
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->ThrowNew(env, class_UnsupportedOperationException, error);
fa9e4066f08beec538e775443c5be79dd423fcabahrenszjni_get_matched_string(JNIEnv *env, char *name, regmatch_t *match)
fa9e4066f08beec538e775443c5be79dd423fcabahrens stringUTF = (*env)->NewStringUTF(env, name + match->rm_so);
fa9e4066f08beec538e775443c5be79dd423fcabahrenszjni_get_dataset_from_snapshot(const char *snapshot, char *dataset,
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Convert a zjni_Collection to a (Java) array */
fa9e4066f08beec538e775443c5be79dd423fcabahrenszjni_Collection_to_array(JNIEnv *env, zjni_Collection_t *list, char *class)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Get size of zjni_Collection */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Create array to hold elements of list */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Copy list elements to array */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (*env)->CallObjectMethod(env, ((zjni_Object_t *)list)->object,
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create a zjni_Collection */
fa9e4066f08beec538e775443c5be79dd423fcabahrensnew_Collection(JNIEnv *env, zjni_Collection_t *collection)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "size", "()I");
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create an zjni_ArrayList */
fa9e4066f08beec538e775443c5be79dd423fcabahrenszjni_new_ArrayList(JNIEnv *env, zjni_ArrayList_t *list)
fa9e4066f08beec538e775443c5be79dd423fcabahrens object->class = (*env)->FindClass(env, "java/util/ArrayList");
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "<init>", "()V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* Create an zjni_DatasetSet */
fa9e4066f08beec538e775443c5be79dd423fcabahrenszjni_new_DatasetSet(JNIEnv *env, zjni_DatasetSet_t *list)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (*env)->GetMethodID(env, object->class, "<init>", "()V");
fa9e4066f08beec538e775443c5be79dd423fcabahrens jfieldID id = (*env)->GetStaticFieldID(env, class_Boolean,
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (*env)->GetStaticObjectField(env, class_Boolean, id);
fbfd10ff571cfd0139aa5127460f1b8a53dac971talleyzjni_int_to_enum(JNIEnv *env, int value, char *class_name,
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley char *default_field_name, zjni_field_mapping_t *mapping)
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley (void) snprintf(signature, sizeof (signature), "L%s;",
fbfd10ff571cfd0139aa5127460f1b8a53dac971talley field_value = (*env)->GetStaticObjectField(env, class, id);
fa9e4066f08beec538e775443c5be79dd423fcabahrens jclass class_Long = (*env)->FindClass(env, "java/lang/Long");
fa9e4066f08beec538e775443c5be79dd423fcabahrens jmethodID method_valueOf = (*env)->GetStaticMethodID(env,
fa9e4066f08beec538e775443c5be79dd423fcabahrens class_Long, "valueOf", "(Ljava/lang/String;)Ljava/lang/Long;");
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* May throw a NumberFormatException */
fa9e4066f08beec538e775443c5be79dd423fcabahrens jclass class_Long = (*env)->FindClass(env, "java/lang/Long");
fa9e4066f08beec538e775443c5be79dd423fcabahrens jclass class_Long = (*env)->FindClass(env, "java/lang/Long");
fa9e4066f08beec538e775443c5be79dd423fcabahrens jmethodID method_parseLong = (*env)->GetStaticMethodID(env,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* May throw a NumberFormatException */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Date constructor takes epoch milliseconds */
c8e9ed14d97e244b9753db14caf8481f181f5750talleyzjni_c_string_array_to_java(JNIEnv *env, char **array, int n)
fa9e4066f08beec538e775443c5be79dd423fcabahrens jclass class_String = (*env)->FindClass(env, "java/lang/String");
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < n; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens jstring elementUTF = (*env)->NewStringUTF(env, array[i]);
c8e9ed14d97e244b9753db14caf8481f181f5750talley * Converts the non-null elements of the given Java String array into
c8e9ed14d97e244b9753db14caf8481f181f5750talley * a NULL-terminated char* array. When done, each element and then
c8e9ed14d97e244b9753db14caf8481f181f5750talley * the array itself must be free()d. Returns NULL if memory could not
c8e9ed14d97e244b9753db14caf8481f181f5750talley * be allocated.
c8e9ed14d97e244b9753db14caf8481f181f5750talleyzjni_java_string_array_to_c(JNIEnv *env, jobjectArray array)
c8e9ed14d97e244b9753db14caf8481f181f5750talley char **result = (char **)calloc(length + 1, sizeof (char *));
c8e9ed14d97e244b9753db14caf8481f181f5750talley for (i = 0, n = 0; i < length; i++) {
c8e9ed14d97e244b9753db14caf8481f181f5750talley /* Retrive String from array */
c8e9ed14d97e244b9753db14caf8481f181f5750talley /* Convert to char* */
c8e9ed14d97e244b9753db14caf8481f181f5750talley /* Free chars in Java space */
c8e9ed14d97e244b9753db14caf8481f181f5750talley /* strdup failed */
c8e9ed14d97e244b9753db14caf8481f181f5750talley /* Terminate array */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Counts the number of elements in the given NULL-terminated array.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Does not include the terminating NULL in the count.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (i);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Get a handle to the next nvpair with the specified name and data
fa9e4066f08beec538e775443c5be79dd423fcabahrens * type in the list following the given nvpair.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This function is needed because the nvlist_lookup_* routines can
fa9e4066f08beec538e775443c5be79dd423fcabahrens * only be used with nvlists allocated with NV_UNIQUE_NAME or
fa9e4066f08beec538e775443c5be79dd423fcabahrens * NV_UNIQUE_NAME_TYPE, ie. lists of unique name/value pairs.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Some variation of this function will likely appear in the libnvpair
fa9e4066f08beec538e775443c5be79dd423fcabahrens * library per 4981923.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @param nvl
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the nvlist_t to search
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @param name
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the string key for the pair to find in the list, or
fa9e4066f08beec538e775443c5be79dd423fcabahrens * NULL to match any name
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @param type
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the data type for the pair to find in the list, or
fa9e4066f08beec538e775443c5be79dd423fcabahrens * DATA_TYPE_UNKNOWN to match any type
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @param nvp
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the pair to search from in the list, or NULL to search
fa9e4066f08beec538e775443c5be79dd423fcabahrens * from the beginning of the list
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @return the next nvpair in the list matching the given
fa9e4066f08beec538e775443c5be79dd423fcabahrens * criteria, or NULL if no matching nvpair is found
fa9e4066f08beec538e775443c5be79dd423fcabahrenszjni_nvlist_walk_nvpair(nvlist_t *nvl, const char *name, data_type_t type,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* For each nvpair in the list following nvp... */
fa9e4066f08beec538e775443c5be79dd423fcabahrens while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Does this pair's name match the given name? */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((name == NULL || strcmp(nvpair_name(nvp), name) == 0) &&
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Does this pair's type match the given type? */