Пример #1
0
CLASS getClass(const char *name) {
  GUARANTEE(_in_kvm_native_method, "sanity");

  OopDesc *mirror_obj = NULL;
  KNI_FindClass(name, (jclass)&mirror_obj);
  return mirror_obj;
}
Пример #2
0
void JSR239_getWindowContents(JSR239_Pixmap *dst,
                              jobject srcGraphicsHandle, 
                              jint srcWidth, jint srcHeight,
                              jint deltaHeight) {

    QPixmap* pixmap;
    void* src;

    KNI_StartHandles(1);
    KNI_DeclareHandle(GraphicsClassHandle);

#ifdef DEBUG
    printf("JSR239_getWindowContents >>\n");
#endif

    KNI_FindClass("javax/microedition/lcdui/Graphics", GraphicsClassHandle);

    if (!KNI_IsInstanceOf(graphicsHandle, GraphicsClassHandle)) {
#ifdef DEBUG
        printf("JSR239_getWindowContents only implemented for graphicsHandle "
                "instanceof Graphics!\n");
#endif
    } else {
        pixmap = getGraphicsBuffer(graphicsHandle);

#ifdef DEBUG
        printf("JSR239_getWindowContents: pixmap=%p\n", pixmap);
        printf("  pixmap Bpp = %d\n", pixmap->depth()/8);
        printf("  pixmap width  = %d\n", pixmap->width());
        printf("  pixmap height = %d\n", pixmap->height());
        printf("  dst Bpp = %d\n", dst->pixelBytes);
        printf("  dst width  = %d\n", dst->width);
        printf("  dst height = %d\n", dst->height);
#endif

        src = (void*)pixmap->scanLine(0);

        /* IMPL_NOTE: get clip sizes into account. */
        copyFromScreenBuffer(dst,
                             src, srcWidth, srcHeight,
                             deltaHeight);
    }

#ifdef DEBUG
    printf("JSR239_getWindowContents <<\n");
#endif

    KNI_EndHandles();
}
Пример #3
0
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_INT
    Java_com_sun_j2me_location_PlatformLocationProvider_getStateImpl() {

    jsr179_state state = JSR179_OUT_OF_SERVICE;
    jint provider = KNI_GetParameterAsInt(1);
    jint ret=0; /* out of service */
    
    if (stateValue.filled == KNI_FALSE) {

        KNI_StartHandles(1);
        KNI_DeclareHandle(clazz);
    
        KNI_FindClass("javax/microedition/location/LocationProvider", clazz);
        if(!KNI_IsNullHandle(clazz)) {
            stateValue.available = KNI_GetStaticIntField(clazz, 
                KNI_GetStaticFieldID(clazz, "AVAILABLE", "I"));
            stateValue.temporarilyUnavailable = KNI_GetStaticIntField(clazz, 
                KNI_GetStaticFieldID(clazz, "TEMPORARILY_UNAVAILABLE", "I"));
            stateValue.outOfService = KNI_GetStaticIntField(clazz, 
                KNI_GetStaticFieldID(clazz, "OUT_OF_SERVICE", "I"));
            stateValue.filled = KNI_TRUE;
        }
        KNI_EndHandles();

    }        

    if (stateValue.filled == KNI_TRUE) {
        jsr179_provider_state((jsr179_handle)provider, &state);
        switch(state) {
            case JSR179_AVAILABLE:
                ret = stateValue.available;
                break;
            case JSR179_TEMPORARILY_UNAVAILABLE:
                ret = stateValue.temporarilyUnavailable;
                break;
            case JSR179_OUT_OF_SERVICE:
            default:
                ret = stateValue.outOfService;
                break;
        }
    }

    KNI_ReturnInt(ret);
}
Пример #4
0
/* Copy engine buffer back to MIDP */
void
JSR239_putWindowContents(jobject graphicsHandle,
                         jint delta_height,
                         JSR239_Pixmap *src, jint flipY) {

    void* s;
    void* d;

    KNI_StartHandles(1);
    KNI_DeclareHandle(GraphicsClassHandle);

#ifdef DEBUG
    printf("JSR239_putWindowContents >>\n");
#endif

    KNI_FindClass("javax/microedition/lcdui/Graphics", GraphicsClassHandle);
    if (!KNI_IsInstanceOf(graphicsHandle, GraphicsClassHandle)) {
#ifdef DEBUG
        printf("JSR239_putWindowContents only implemented for graphicsHandle "
               "instanceof Graphics!\n");
#endif
    } else {
        gxj_screen_buffer sbuf;
        gxj_screen_buffer* gimg;

        // Obtain the dimensions of the destination.
        jint dest_width = lcdlf_get_screen_width();
        jint dest_height = lcdlf_get_screen_height();

        jint min_height = 0;
        
        gimg = GXJ_GET_GRAPHICS_SCREEN_BUFFER(graphicsHandle, &sbuf);
        if (gimg != NULL) {
            dest_width = gimg->width;
            dest_height= gimg->height;
        }

#ifdef DEBUG
        printf("JSR239_putWindowContents:\n"); 
        printf("  src Bpp    = %d\n", src->pixelBytes);
        printf("  src width  = %d\n", src->width);
        printf("  src height = %d\n", src->height);
        printf("  min height = %d\n", min_height);
#endif

        /* IMPL_NOTE: get clip sizes into account. */
        copyToScreenBuffer(src, delta_height, flipY);

        /* src->screen_buffer is an output of copyToScreenBuffer function. */
        s = (void*)src->screen_buffer;
        d = (void*)getGraphicsBuffer(graphicsHandle);

        min_height = (dest_height > src->height) ? src->height : dest_height;

        if ((src->width  != dest_width) ||
            (sizeof(gxj_pixel_type) != 2)) {
#ifdef DEBUG
        printf("JSR239: offscreen buffer data is incorrect.\n");
#endif
        } else {
            /* Source data must be in 16bit 565 format. */
            JSR239_memcpy(d, s,
                dest_width * min_height * sizeof(gxj_pixel_type));
        }
    }

#ifdef DEBUG
    printf("JSR239_putWindowContents <<\n");
#endif

    KNI_EndHandles();
}
Пример #5
0
void
JSR239_putWindowContents(jobject graphicsHandle,
                         jint delta_height,
                         JSR239_Pixmap *src, 
                         jint clipX, jint clipY, jint clipWidth, jint clipHeight,
                         jint flipY) {

    void* s;
    void* d;
    QPixmap* pixmap;

    KNI_StartHandles(1);
    KNI_DeclareHandle(GraphicsClassHandle);

#ifdef DEBUG
    printf("JSR239_putWindowContents >>\n");
#endif

    KNI_FindClass("javax/microedition/lcdui/Graphics", GraphicsClassHandle);
    if (!KNI_IsInstanceOf(graphicsHandle, GraphicsClassHandle)) {
#ifdef DEBUG
        printf("JSR239_putWindowContents only implemented for graphicsHandle "
               "instanceof Graphics!\n");
#endif
    } else {
        const jint bytes_for_depth = 2;
        const jint bits_per_byte = 8;
        jint min_height;

        pixmap = getGraphicsBuffer(graphicsHandle);

        min_height = (pixmap->height() > src->height) ? src->height :
            pixmap->height();

#ifdef DEBUG
        printf("JSR239_putWindowContent: pixmap=%p\n", pixmap);
        printf("  pixmap Bpp = %d\n",  pixmap->depth()/bits_per_byte);
        printf("  pixmap width  = %d\n", pixmap->width());
        printf("  pixmap height = %d\n", pixmap->height());
        printf("  src Bpp = %d\n", src->pixelBytes);
        printf("  src width = %d\n", src->width);
        printf("  src height = %d\n", src->height);
        printf("  min height = %d\n", min_height);
#endif

        /* IMPL_NOTE: get clip sizes into account. */
        copyToScreenBuffer(src, delta_height, 
                           clipX, clipY, 
                           clipWidth, clipHeight, 
                           clipWidth, clipHeight,
                           flipY);

        /* src->screen_buffer is an output of copyToScreenBuffer function. */
        s = (void*)src->screen_buffer;
        d = (void*)pixmap->scanLine(0);

        if ((pixmap->width() != src->width) ||
            (pixmap->depth() != bits_per_byte * bytes_for_depth)) {
#ifdef DEBUG
            printf("JSR239: offscreen buffer data is incorrect.\n");
#endif
        } else {
            /* Source data must be in 16bit 565 format. */
            JSR239_memcpy(
                d, s, pixmap->width() * min_height * bytes_for_depth);
        }
    }

#ifdef DEBUG
    printf("JSR239_putWindowContents <<\n");
#endif

    KNI_EndHandles();
}
Пример #6
0
/**
 * Copies the contents of fromMsg to the contents of toMsg. Both must be
 * instances of LinkMessage. The toLink object must be an instance of Link.
 * It's filled in if the contents of fromMsg are a Link.  Returns KNI_TRUE if
 * successful, otherwise KNI_FALSE.
 */
static jboolean
copy(jobject fromMsg, jobject toMsg, jobject toLink) {
    jboolean retval;

    KNI_StartHandles(6);
    KNI_DeclareHandle(byteArrayClass);
    KNI_DeclareHandle(stringClass);
    KNI_DeclareHandle(linkClass);
    KNI_DeclareHandle(fromContents);
    KNI_DeclareHandle(newString);
    KNI_DeclareHandle(newByteArray);

    KNI_FindClass("[B", byteArrayClass);
    KNI_FindClass("java/lang/String", stringClass);
    KNI_FindClass("com/sun/midp/links/Link", linkClass);
    getContents(fromMsg, fromContents);
    
    if (KNI_IsInstanceOf(fromContents, byteArrayClass)) {
        /* do a byte array copy */
        jint fromOffset;
        jint fromLength;

        getRange(fromMsg, &fromOffset, &fromLength);

        SNI_NewArray(SNI_BYTE_ARRAY, fromLength, newByteArray);
        if (KNI_IsNullHandle(newByteArray)) {
            retval = KNI_FALSE;
        } else {
            KNI_GetRawArrayRegion(fromContents, fromOffset, fromLength,
                SNI_GetRawArrayPointer(newByteArray));
            setContents(toMsg, newByteArray);
            setRange(toMsg, 0, fromLength);
            retval = KNI_TRUE;
        }
    } else if (KNI_IsInstanceOf(fromContents, stringClass)) {
        /* do a string copy */
        jchar *buf;
        jsize slen = KNI_GetStringLength(fromContents);

        SNI_NewArray(SNI_BYTE_ARRAY, slen*sizeof(jchar), newByteArray);

        if (KNI_IsNullHandle(newByteArray)) {
            retval = KNI_FALSE;
        } else {
            buf = SNI_GetRawArrayPointer(newByteArray);
            KNI_GetStringRegion(fromContents, 0, slen, buf);
            KNI_NewString(buf, slen, newString);
            setContents(toMsg, newString);
            retval = KNI_TRUE;
        }
    } else if (KNI_IsInstanceOf(fromContents, linkClass)) {
        /* copy the link */
        rendezvous *rp = getNativePointer(fromContents);
        setNativePointer(toLink, rp);
        rp_incref(rp);
        setContents(toMsg, toLink);
        retval = KNI_TRUE;
    } else {
        retval = KNI_FALSE;
    }

    KNI_EndHandles();
    return retval;
}
Пример #7
0
/**
 * KNI function that creates native resource for the current StringItem.
 *
 * Class: javax.microedition.lcdui.StringItemLFImpl
 *
 * Java prototype:
 * private native int createNativeResource0(int ownerId,
 *	    		String label, int layout, String text, int maxSize,
 *			int constraints, String initialInputMode)
 *
 * INTERFACE (operand stack manipulation):
 *   parameters:  ownerId            id of the owner's native resource
 *                label              StringItem's label
 *                layout             StringItem's layout
 *                text               StringItem's text
 *                appearanceMode     the appearanceMode of StringItem
 *                font               font to paint text
 *   returns:     id of the created platform widget
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_lcdui_StringItemLFImpl_createNativeResource0() {
    MidpError err = KNI_OK;
    MidpDisplayable  *ownerPtr;
    MidpItem *itemPtr = NULL;
    pcsl_string label, text;
    pcsl_string_status rc1 = PCSL_STRING_OK, rc2 = PCSL_STRING_OK;
    PlatformFontPtr fontPtr = NULL;
    int appearanceMode, layout;

    KNI_StartHandles(4);

    KNI_DeclareHandle(labelJString);
    KNI_DeclareHandle(textJString);
    KNI_DeclareHandle(fontJFont);
    KNI_DeclareHandle(fontHandle);

    ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1);
    KNI_GetParameterAsObject(2, labelJString);
    layout = KNI_GetParameterAsInt(3);
    KNI_GetParameterAsObject(4, textJString);
    appearanceMode = KNI_GetParameterAsInt(5);
    KNI_GetParameterAsObject(6, fontJFont);

    if (KNI_IsNullHandle(fontJFont) != KNI_TRUE) {
        int face, style, size;

        KNI_FindClass("javax/microedition/lcdui/Font", fontHandle);

        face  = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "face",
                                "I", _f_face_cache));
        style = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "style",
                                "I", _f_style_cache));
        size  = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "size",
                                "I", _f_size_cache));

        err = lfpport_get_font(&fontPtr, face, style, size);
    }

    if (err == KNI_OK) {
        rc1 = midp_kjstring_to_pcsl_string(labelJString, &label);
        rc2 = midp_kjstring_to_pcsl_string(textJString, &text);
    }

    KNI_EndHandles();

    if (err != KNI_OK || PCSL_STRING_OK != rc1 || PCSL_STRING_OK != rc2) {
        err = KNI_ENOMEM;
        goto cleanup;
    }


    itemPtr = MidpNewItem(ownerPtr, MIDP_PLAIN_STRING_ITEM_TYPE+appearanceMode);
    if (itemPtr == NULL) {
        err = KNI_ENOMEM;
        goto cleanup;
    }

    err = lfpport_stringitem_create(itemPtr, ownerPtr, &label, layout,
                                    &text, fontPtr, appearanceMode);

cleanup:
    pcsl_string_free(&text);
    pcsl_string_free(&label);

    if (err != KNI_OK) {
        MidpDeleteItem(itemPtr);
        KNI_ThrowNew(midpOutOfMemoryError, NULL);
    }

    KNI_ReturnInt(itemPtr);
}
Пример #8
0
/* Copy engine buffer back to MIDP */
void
JSR239_putWindowContents(jobject graphicsHandle,
                         jint delta_height,
                         JSR239_Pixmap *src, 
                         jint clipX, jint clipY, 
                         jint clipWidth, jint clipHeight,
                         jint flipY) {

    void* s;
    void* d;

    KNI_StartHandles(1);
    KNI_DeclareHandle(GraphicsClassHandle);

#ifdef DEBUG
    printf("JSR239_putWindowContents >>\n");
#endif

    KNI_FindClass("javax/microedition/lcdui/Graphics", GraphicsClassHandle);
    if (!KNI_IsInstanceOf(graphicsHandle, GraphicsClassHandle)) {
#ifdef DEBUG
        printf("JSR239_putWindowContents only implemented for graphicsHandle "
               "instanceof Graphics!\n");
#endif
    } else {
        gxj_screen_buffer sbuf;
        gxj_screen_buffer* gimg;

        // Obtain the dimensions of the destination.
        // Revisit: multiple displays support. Obtain Id of display render surfane is
        // bound to. Consider recalculations when display got changed.
        int displayId    = lcdlf_get_current_hardwareId();
        jint dest_width  = lcdlf_get_screen_width(displayId);
        jint dest_height = lcdlf_get_screen_height(displayId);
        jint min_height  = 0;
        gxj_pixel_type* srcPtr;
        gxj_pixel_type* dstPtr;
        
        gimg = GXJ_GET_GRAPHICS_SCREEN_BUFFER(graphicsHandle, &sbuf);
        if (gimg != NULL) {
            dest_width = gimg->width;
            dest_height= gimg->height;
        }                

        /* src->screen_buffer is an output of copyToScreenBuffer function. */
        s = (void*)src->screen_buffer;
        d = (void*)getGraphicsBuffer(graphicsHandle);

        min_height = (dest_height > src->height) ? src->height : dest_height;

#ifdef DEBUG
        printf("JSR239_putWindowContents:\n"); 
        printf("  src        = %d\n", src->pixels);
        printf("  src Bpp    = %d\n", src->pixelBytes);
        printf("  src width  = %d\n", src->width);
        printf("  src height = %d\n", src->height);
        printf("  min height = %d\n", min_height);
        printf("  dst        = %d\n", d);     
        printf("  dst width  = %d\n", clipWidth);
        printf("  dst height = %d\n", clipHeight);
#endif

        srcPtr = (gxj_pixel_type *)s;
        dstPtr = (gxj_pixel_type *)d;

        if ((dest_width * min_height <= src->width * src->height) && 
            (sizeof(gxj_pixel_type) == 2)) {
            /* Source data must be in 16bit 565 format. */
           JSR239_memcpy(s, d,
               dest_width * min_height * sizeof(gxj_pixel_type));

           /* IMPL_NOTE: get clip sizes into account. */
           copyToScreenBuffer(src, delta_height, 
                              clipX, clipY, clipWidth, clipHeight,
                              dest_width, dest_height,
                              flipY);

            /* Source data must be in 16bit 565 format. */
           JSR239_memcpy(d, s,
               dest_width * min_height * sizeof(gxj_pixel_type));        
        } else {
#ifdef DEBUG
        printf("JSR239: offscreen buffer data is incorrect.\n");
#endif
        }
    }

#ifdef DEBUG
    printf("JSR239_putWindowContents <<\n");
#endif

    KNI_EndHandles();
}
Пример #9
0
/**
 * Retrieves fields IDs for classes:
 * <BR> <code>com.sun.midp.content.ContentHandlerImpl</code> and
 * <BR> <code>javax.microedition.content.ActionNameMap</code>
 * @return KNI_OK - if successfully get all fields, KNI_ERR - otherwise
 */
static int initializeFields() {
    static const char* STRING_TYPE = "Ljava/lang/String;";
    static const char* S_ARRAY_TYPE = "[Ljava/lang/String;";
    static const char* ANM_ARRAY_TYPE = 
                            "[Ljavax/microedition/content/ActionNameMap;";
    static const char* ANM_CLASS_NAME = 
                            "javax/microedition/content/ActionNameMap";
    int ret;    // returned result code
    KNI_StartHandles(1);
    KNI_DeclareHandle(clObj);   // clazz object

    do {
        // 1. initialize ContentHandlerImpl fields
        KNI_FindClass("com/sun/midp/content/ContentHandlerImpl", clObj);
        chImplId =          KNI_GetFieldID(clObj,  "ID", STRING_TYPE);
        chImplSuiteId =     KNI_GetFieldID(clObj,  "storageId", "I");
        chImplClassname =   KNI_GetFieldID(clObj,  "classname", STRING_TYPE);
        chImplregMethod =   KNI_GetFieldID(clObj,  "registrationMethod", "I");
        chImplTypes =       KNI_GetFieldID(clObj,  "types", S_ARRAY_TYPE);
        chImplSuffixes =    KNI_GetFieldID(clObj,  "suffixes", S_ARRAY_TYPE);
        chImplActions =     KNI_GetFieldID(clObj,  "actions", S_ARRAY_TYPE);
        chImplActionnames = KNI_GetFieldID(clObj,  "actionnames", 
                                                            ANM_ARRAY_TYPE);
        chImplAccesses =    KNI_GetFieldID(clObj,  "accessRestricted", 
                                                            S_ARRAY_TYPE);
    
        if (chImplId == 0 || chImplSuiteId == 0 || chImplClassname == 0 || 
            chImplregMethod == 0 || chImplTypes == 0 || 
            chImplSuffixes == 0 || chImplActions == 0 || 
            chImplActionnames == 0 || chImplAccesses == 0) {
    
#if REPORT_LEVEL <= LOG_CRITICAL
    REPORT_CRIT(LC_NONE,
            "regstore.c: can't initialize ContentHandlerImpl fields!");
#endif
    
            ret = KNI_ERR;
            break;
        }
    
        // 2. initialize ActionName fields
        KNI_FindClass(ANM_CLASS_NAME, clObj);  // clObj = ActionNameMap class
        if (KNI_IsNullHandle(clObj)) {
#if REPORT_LEVEL <= LOG_CRITICAL
    REPORT_CRIT(LC_NONE,
            "regstore.c: can't find ActionNameMap class!");
#endif
            ret = KNI_ERR;
            break;
        }
    
        anMapLocale =       KNI_GetFieldID(clObj,  "locale", STRING_TYPE);
        anMapActionnames =  KNI_GetFieldID(clObj,  "actionnames", S_ARRAY_TYPE);
    
        if (anMapLocale == 0 || anMapActionnames == 0) {
    
#if REPORT_LEVEL <= LOG_CRITICAL
    REPORT_CRIT(LC_NONE,
            "regstore.c: can't initialize ActionNameMap fields!");
#endif
            ret = KNI_ERR;
            break;
        }
        
        ret = KNI_OK;   // that's all right.
    } while (0);

    KNI_EndHandles();
    return ret;
}
Пример #10
0
/**
 * KNI function that creates native resource for the current StringItem.
 * <p>
 * Java declaration:
 * <pre>
 *     createNativeResource0(ISIII[OII)I
 * </pre>
 *
 * @param ownerId Owner screen's native resource id (MidpDisplayable *)
 * @param label - label to be used for this ChoiceGroup
 * @param layout layout directive associated with this ChoiceGroup
 * @param choiceType - should be EXCLUSIVE, MULTIPLE, IMPLICIT, POPUP
 * @param fitPolicy  - to be used to display created ChoiceGroup
 * @param cgElements - elements array with string, image, font, selected state
 *                     information per element
 * @param numChoices - number of elements in the ChoiceGroup
 * @param selectedIndex - currently selected index (for EXCLUSIVE, IMPLICIT, and
 *                        POPUP)
 * @return native resource id (MidpItem *) of this StringItem
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_lcdui_ChoiceGroupLFImpl_createNativeResource0() {
  MidpError err = KNI_OK;
  MidpDisplayable  *ownerPtr = NULL;
  MidpItem *cgPtr = NULL;
  pcsl_string label_str;
  MidpChoiceGroupElement *cgChoices = NULL;
  int choiceType, layout;
  int fitPolicy;
  int numChoices = 0;
  int selectedIndex;
  int i = 0;
  pcsl_string_status perr;

  ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1);
  layout = KNI_GetParameterAsInt(3);
  choiceType = KNI_GetParameterAsInt(4);
  fitPolicy  = KNI_GetParameterAsInt(5);
  numChoices = KNI_GetParameterAsInt(7);
  selectedIndex  = KNI_GetParameterAsInt(8);

  KNI_StartHandles(8);
  
  KNI_DeclareHandle(labelJString);
  KNI_DeclareHandle(cgElementsJObject);
  KNI_DeclareHandle(cgElement);
  KNI_DeclareHandle(strJString);
  KNI_DeclareHandle(imgJImage);
  KNI_DeclareHandle(fontJFont);
  KNI_DeclareHandle(cgElementHandle);
  KNI_DeclareHandle(fontHandle);

  KNI_GetParameterAsObject(2, labelJString);
  KNI_GetParameterAsObject(6, cgElementsJObject);
 
  if (numChoices > 0) {
    jobjectArray cgElementsArray;
    KNI_FindClass("javax/microedition/lcdui/ChoiceGroup$CGElement", 
		  cgElementHandle);

    KNI_FindClass("javax/microedition/lcdui/Font", fontHandle);
	  
    cgElementsArray = (jobjectArray)cgElementsJObject;

    cgChoices = (MidpChoiceGroupElement *)
		midpMalloc(sizeof(MidpChoiceGroupElement) * numChoices);
    if (cgChoices == NULL) {
      err = KNI_ENOMEM;
    }

    for (i = 0; err == KNI_OK && i < numChoices; i++) {

      KNI_GetObjectArrayElement(cgElementsArray, i, cgElement);

      KNI_GetObjectField(cgElement, 
			 _CACHE_FIELDID(cgElementHandle, "stringEl", 
					"Ljava/lang/String;", 
					_cgEl_stringEl_cache), strJString);

      perr = midp_jstring_to_pcsl_string(strJString, &cgChoices[i].string);
      if (PCSL_STRING_OK != perr) {
        err = KNI_ENOMEM;
      } else {

	KNI_GetObjectField(cgElement, 
			   _CACHE_FIELDID(cgElementHandle, "imageDataEl", 
					  "Ljavax/microedition/lcdui/ImageData;", 
					  _cgEl_imageDataEl_cache), imgJImage);

	if (KNI_IsNullHandle(imgJImage) == KNI_TRUE) {
	  cgChoices[i].image = NULL;
	} else {
	  cgChoices[i].image = gxp_get_imagedata(imgJImage);
	}

	cgChoices[i].selected = 
	  KNI_GetBooleanField(cgElement, _CACHE_FIELDID(cgElementHandle, 
							"selected", "Z",
							_cgEl_selected_cache));
	
	KNI_GetObjectField(cgElement,
			   _CACHE_FIELDID(cgElementHandle, "fontEl",
					  "Ljavax/microedition/lcdui/Font;", 
					  _cgEl_font_cache), fontJFont); 
	
	if (KNI_IsNullHandle(fontJFont) == KNI_TRUE) {
	  cgChoices[i].font = NULL;
	} else {
	  
	  int face, style, size; /* usually only few fonts are set */

	  face = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "face", 
                             "I", _f_face_cache));
	  style = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, 
                             "style",
                             "I", _f_style_cache));
      size = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "size",
                             "I", _f_size_cache));

            if ((err = lfpport_get_font(&(cgChoices[i].font), face, style, size))
                != KNI_OK) {
                  err = KNI_ENOMEM;
                  i++;
                  break;
            }
        }
      }
    }
  }
 
  if (err == KNI_OK) {
    if(PCSL_STRING_OK
        != midp_jstring_to_pcsl_string(labelJString, &label_str)) {
      err = KNI_ENOMEM;
    }
  }

  KNI_EndHandles();

  if (err == KNI_OK) {
    cgPtr = MidpNewItem(ownerPtr, 
			MIDP_EXCLUSIVE_CHOICE_GROUP_TYPE + choiceType - 1);
    
    if (cgPtr == NULL) {
      err = KNI_ENOMEM;
    } else {
      err = lfpport_choicegroup_create(cgPtr, ownerPtr, &label_str, layout,
				    choiceType, cgChoices, numChoices,
				    selectedIndex, fitPolicy);
    }
  }

  // do clean up
  pcsl_string_free(&label_str);
  for (i--; i >= 0; i--) {
    pcsl_string_free(&cgChoices[i].string);
  }
  midpFree(cgChoices);
  
  if (err != KNI_OK) {
    MidpDeleteItem(cgPtr);
    KNI_ThrowNew(midpOutOfMemoryError, NULL);
  }

  KNI_ReturnInt(cgPtr);
}