String qualifiedInternalClassName = qualifiedClassName.replace('.', '/');
Type componentType = Type.getType("L" + componentClass.getRawName().replace('.', '/') + ";");
ClassWriter cw = new ClassWriter(false);
CodeVisitor cv;
cw.visit(Constants.V1_5, Constants.ACC_PUBLIC + Constants.ACC_SUPER, qualifiedInternalClassName, "org/eclipse/persistence/internal/jaxb/many/PrimitiveArrayValue", null, className.replace(".", "/") + ".java");
// FIELD ATTRIBUTES
RuntimeVisibleAnnotations fieldAttrs1 = new RuntimeVisibleAnnotations();
if(typeMappingInfo != null){
java.lang.annotation.Annotation[] annotations = getAnnotations(typeMappingInfo);
if(annotations != null){
for(int i=0; i<annotations.length; i++){
java.lang.annotation.Annotation nextAnnotation = annotations[i];
if (nextAnnotation != null && !(nextAnnotation instanceof XmlElement) && !(nextAnnotation instanceof XmlJavaTypeAdapter)) {
String annotationClassName = nextAnnotation.getClass().getName();
Annotation fieldAttrs1ann0 = new Annotation("L"+annotationClassName+";");
fieldAttrs1.annotations.add(fieldAttrs1ann0);
for(Method next:nextAnnotation.annotationType().getDeclaredMethods()) {
try {
Object nextValue = next.invoke(nextAnnotation, new Object[]{});
if(nextValue instanceof Class) {
Type nextType = Type.getType("L" + ((Class)nextValue).getName().replace('.', '/') + ";");
nextValue = nextType;
}
fieldAttrs1ann0.add(next.getName(), nextValue);
} catch(InvocationTargetException ex) {
//ignore the invocation target exception here.
} catch(IllegalAccessException ex) {
}
}
}
}
}
}
SignatureAttribute fieldAttrs2 = new SignatureAttribute("Ljava/util/Collection<L" + componentType.getInternalName() + ";>;");
fieldAttrs1.next = fieldAttrs2;
cw.visitField(Constants.ACC_PUBLIC, "item", "Ljava/util/Collection;", null, fieldAttrs1);
cv = cw.visitMethod(Constants.ACC_PUBLIC, "<init>", "()V", null, null);
cv.visitVarInsn(Constants.ALOAD, 0);
cv.visitMethodInsn(Constants.INVOKESPECIAL, "org/eclipse/persistence/internal/jaxb/many/PrimitiveArrayValue", "<init>", "()V");
cv.visitInsn(Constants.RETURN);
cv.visitMaxs(1, 1);
// METHOD ATTRIBUTES
RuntimeVisibleAnnotations methodAttrs1 = new RuntimeVisibleAnnotations();
Annotation methodAttrs1ann0 = new Annotation("Ljavax/xml/bind/annotation/XmlTransient;");
methodAttrs1.annotations.add(methodAttrs1ann0);
cv = cw.visitMethod(Constants.ACC_PUBLIC, "getItem", "()Ljava/lang/Object;", null, methodAttrs1);
cv.visitVarInsn(Constants.ALOAD, 0);
cv.visitFieldInsn(Constants.GETFIELD, qualifiedInternalClassName, "item", "Ljava/util/Collection;");
cv.visitMethodInsn(Constants.INVOKEINTERFACE, "java/util/Collection", "iterator", "()Ljava/util/Iterator;");
cv.visitVarInsn(Constants.ASTORE, 1);
Label l0 = new Label();
cv.visitLabel(l0);
cv.visitVarInsn(Constants.ALOAD, 0);
cv.visitFieldInsn(Constants.GETFIELD, qualifiedInternalClassName, "item", "Ljava/util/Collection;");
cv.visitMethodInsn(Constants.INVOKEINTERFACE, "java/util/Collection", "size", "()I");
cv.visitIntInsn(Constants.NEWARRAY, getNewArrayConstantForPrimitive(primitiveClassName));
cv.visitVarInsn(Constants.ASTORE, 2);
cv.visitInsn(Constants.ICONST_0);
cv.visitVarInsn(Constants.ISTORE, 3);
Label l1 = new Label();
cv.visitJumpInsn(Constants.GOTO, l1);
Label l2 = new Label();
cv.visitLabel(l2);
cv.visitVarInsn(Constants.ALOAD, 2);
cv.visitVarInsn(Constants.ILOAD, 3);
cv.visitVarInsn(Constants.ALOAD, 1);
cv.visitMethodInsn(Constants.INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;");
cv.visitTypeInsn(Constants.CHECKCAST, componentType.getInternalName());
cv.visitMethodInsn(Constants.INVOKEVIRTUAL, componentType.getInternalName(), getToPrimitiveStringForObjectClass(primitiveClassName), getReturnTypeFor(primitiveClass));
int iaStoreOpcode = Type.getType(primitiveClass).getOpcode(Constants.IASTORE);
cv.visitInsn(iaStoreOpcode);
cv.visitIincInsn(3, 1);
cv.visitLabel(l1);
cv.visitVarInsn(Constants.ILOAD, 3);
cv.visitVarInsn(Constants.ALOAD, 2);
cv.visitInsn(Constants.ARRAYLENGTH);
cv.visitJumpInsn(Constants.IF_ICMPLT, l2);
cv.visitVarInsn(Constants.ALOAD, 2);
cv.visitInsn(Constants.ARETURN);
Label l3 = new Label();
cv.visitLabel(l3);
// CODE ATTRIBUTE
LocalVariableTypeTableAttribute cvAttr = new LocalVariableTypeTableAttribute();
cv.visitAttribute(cvAttr);
cv.visitMaxs(3, 4);
// METHOD ATTRIBUTES
methodAttrs1 = new RuntimeVisibleAnnotations();
methodAttrs1ann0 = new Annotation("Ljavax/xml/bind/annotation/XmlTransient;");
methodAttrs1.annotations.add(methodAttrs1ann0);
cv = cw.visitMethod(Constants.ACC_PUBLIC, "setItem", "(Ljava/lang/Object;)V", null, methodAttrs1);
cv.visitTypeInsn(Constants.NEW, "java/util/ArrayList");
cv.visitInsn(Constants.DUP);
cv.visitMethodInsn(Constants.INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V");
cv.visitVarInsn(Constants.ASTORE, 2);
l0 = new Label();
cv.visitLabel(l0);
cv.visitVarInsn(Constants.ALOAD, 1);
cv.visitTypeInsn(Constants.CHECKCAST, getCastTypeFor(primitiveClass));
cv.visitVarInsn(Constants.ASTORE, 3);
cv.visitInsn(Constants.ICONST_0);
cv.visitVarInsn(Constants.ISTORE, 4);
l1 = new Label();
cv.visitJumpInsn(Constants.GOTO, l1);
l2 = new Label();
cv.visitLabel(l2);
cv.visitVarInsn(Constants.ALOAD, 3);
cv.visitVarInsn(Constants.ILOAD, 4);
int iaLoadOpcode = Type.getType(primitiveClass).getOpcode(Constants.IALOAD);
cv.visitInsn(iaLoadOpcode);
cv.visitVarInsn(Constants.ISTORE, 5);
cv.visitVarInsn(Constants.ALOAD, 2);
cv.visitTypeInsn(Constants.NEW, componentType.getInternalName());
cv.visitInsn(Constants.DUP);
cv.visitVarInsn(Constants.ILOAD, 5);
cv.visitMethodInsn(Constants.INVOKESPECIAL, componentType.getInternalName(), "<init>", "(" + getShortNameForPrimitive(primitiveClass) + ")V");
cv.visitMethodInsn(Constants.INVOKEVIRTUAL, "java/util/ArrayList", "add", "(Ljava/lang/Object;)Z");
cv.visitInsn(Constants.POP);
cv.visitIincInsn(4, 1);
cv.visitLabel(l1);
cv.visitVarInsn(Constants.ILOAD, 4);
cv.visitVarInsn(Constants.ALOAD, 3);
cv.visitInsn(Constants.ARRAYLENGTH);
cv.visitJumpInsn(Constants.IF_ICMPLT, l2);
cv.visitVarInsn(Constants.ALOAD, 0);
cv.visitVarInsn(Constants.ALOAD, 2);
cv.visitFieldInsn(Constants.PUTFIELD, qualifiedInternalClassName, "item", "Ljava/util/Collection;");
cv.visitInsn(Constants.RETURN);
l3 = new Label();
cv.visitLabel(l3);
// CODE ATTRIBUTE
cv.visitAttribute(cvAttr);
cv.visitMaxs(4, 6);
cw.visitEnd();
byte[] classBytes = cw.toByteArray();