Search in sources :

Example 16 with OpcodesProxy

use of org.apache.cxf.common.util.OpcodesProxy in project cxf by apache.

the class NamespaceClassGenerator method createNamespaceWrapperInternal.

private byte[] createNamespaceWrapperInternal(String postFix) {
    String superName = "com/sun/xml/" + ("RI".equals(postFix) ? "" : "internal/") + "bind/marshaller/NamespacePrefixMapper";
    String postFixedName = "org/apache/cxf/jaxb/NamespaceMapper" + postFix;
    ASMHelper.ClassWriter cw = helper.createClassWriter();
    if (cw == null) {
        return null;
    }
    ASMHelper.FieldVisitor fv;
    ASMHelper.MethodVisitor mv;
    OpcodesProxy opcodes = helper.getOpCodes();
    cw.visit(opcodes.V1_6, opcodes.ACC_PUBLIC + opcodes.ACC_FINAL + opcodes.ACC_SUPER, postFixedName, null, superName, null);
    cw.visitSource("NamespaceMapper.java", null);
    fv = cw.visitField(opcodes.ACC_PRIVATE + opcodes.ACC_FINAL, "nspref", "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;", null);
    fv.visitEnd();
    fv = cw.visitField(opcodes.ACC_PRIVATE, "nsctxt", "[Ljava/lang/String;", null, null);
    fv.visitEnd();
    fv = cw.visitField(opcodes.ACC_PRIVATE + opcodes.ACC_FINAL + opcodes.ACC_STATIC, "EMPTY_STRING", "[Ljava/lang/String;", null, null);
    fv.visitEnd();
    mv = cw.visitMethod(opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
    mv.visitCode();
    ASMHelper.Label l0 = helper.createLabel();
    mv.visitLabel(l0);
    mv.visitLineNumber(30, l0);
    mv.visitInsn(opcodes.ICONST_0);
    mv.visitTypeInsn(opcodes.ANEWARRAY, "java/lang/String");
    mv.visitFieldInsn(opcodes.PUTSTATIC, postFixedName, "EMPTY_STRING", "[Ljava/lang/String;");
    mv.visitInsn(opcodes.RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    mv = cw.visitMethod(opcodes.ACC_PUBLIC, "<init>", "(Ljava/util/Map;)V", "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;)V", null);
    mv.visitCode();
    l0 = helper.createLabel();
    mv.visitLabel(l0);
    mv.visitLineNumber(32, l0);
    mv.visitVarInsn(opcodes.ALOAD, 0);
    mv.visitMethodInsn(opcodes.INVOKESPECIAL, superName, "<init>", "()V", false);
    ASMHelper.Label l1 = helper.createLabel();
    mv.visitLabel(l1);
    mv.visitLineNumber(29, l1);
    mv.visitVarInsn(opcodes.ALOAD, 0);
    mv.visitFieldInsn(opcodes.GETSTATIC, postFixedName, "EMPTY_STRING", "[Ljava/lang/String;");
    mv.visitFieldInsn(opcodes.PUTFIELD, postFixedName, "nsctxt", "[Ljava/lang/String;");
    ASMHelper.Label l2 = helper.createLabel();
    mv.visitLabel(l2);
    mv.visitLineNumber(33, l2);
    mv.visitVarInsn(opcodes.ALOAD, 0);
    mv.visitVarInsn(opcodes.ALOAD, 1);
    mv.visitFieldInsn(opcodes.PUTFIELD, postFixedName, "nspref", "Ljava/util/Map;");
    ASMHelper.Label l3 = helper.createLabel();
    mv.visitLabel(l3);
    mv.visitLineNumber(34, l3);
    mv.visitInsn(opcodes.RETURN);
    ASMHelper.Label l4 = helper.createLabel();
    mv.visitLabel(l4);
    mv.visitLocalVariable("this", "L" + postFixedName + ";", null, l0, l4, 0);
    mv.visitLocalVariable("nspref", "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;", l0, l4, 1);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    mv = cw.visitMethod(opcodes.ACC_PUBLIC, "getPreferredPrefix", "(Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;", null, null);
    mv.visitCode();
    l0 = helper.createLabel();
    mv.visitLabel(l0);
    mv.visitLineNumber(39, l0);
    mv.visitVarInsn(opcodes.ALOAD, 0);
    mv.visitFieldInsn(opcodes.GETFIELD, postFixedName, "nspref", "Ljava/util/Map;");
    mv.visitVarInsn(opcodes.ALOAD, 1);
    mv.visitMethodInsn(opcodes.INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", true);
    mv.visitTypeInsn(opcodes.CHECKCAST, "java/lang/String");
    mv.visitVarInsn(opcodes.ASTORE, 4);
    l1 = helper.createLabel();
    mv.visitLabel(l1);
    mv.visitLineNumber(40, l1);
    mv.visitVarInsn(opcodes.ALOAD, 4);
    l2 = helper.createLabel();
    mv.visitJumpInsn(opcodes.IFNULL, l2);
    l3 = helper.createLabel();
    mv.visitLabel(l3);
    mv.visitLineNumber(41, l3);
    mv.visitVarInsn(opcodes.ALOAD, 4);
    mv.visitInsn(opcodes.ARETURN);
    mv.visitLabel(l2);
    mv.visitLineNumber(43, l2);
    mv.visitFrame(opcodes.F_APPEND, 1, new Object[] { "java/lang/String" }, 0, null);
    mv.visitVarInsn(opcodes.ALOAD, 2);
    mv.visitInsn(opcodes.ARETURN);
    l4 = helper.createLabel();
    mv.visitLabel(l4);
    mv.visitLocalVariable("this", "L" + postFixedName + ";", null, l0, l4, 0);
    mv.visitLocalVariable("namespaceUri", "Ljava/lang/String;", null, l0, l4, 1);
    mv.visitLocalVariable("suggestion", "Ljava/lang/String;", null, l0, l4, 2);
    mv.visitLocalVariable("requirePrefix", "Z", null, l0, l4, 3);
    mv.visitLocalVariable("prefix", "Ljava/lang/String;", null, l1, l4, 4);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    mv = cw.visitMethod(opcodes.ACC_PUBLIC, "setContextualNamespaceDecls", "([Ljava/lang/String;)V", null, null);
    mv.visitCode();
    l0 = helper.createLabel();
    mv.visitLabel(l0);
    mv.visitLineNumber(47, l0);
    mv.visitVarInsn(opcodes.ALOAD, 0);
    mv.visitVarInsn(opcodes.ALOAD, 1);
    mv.visitFieldInsn(opcodes.PUTFIELD, postFixedName, "nsctxt", "[Ljava/lang/String;");
    l1 = helper.createLabel();
    mv.visitLabel(l1);
    mv.visitLineNumber(48, l1);
    mv.visitInsn(opcodes.RETURN);
    l2 = helper.createLabel();
    mv.visitLabel(l2);
    mv.visitLocalVariable("this", "L" + postFixedName + ";", null, l0, l2, 0);
    mv.visitLocalVariable("contextualNamespaceDecls", "[Ljava/lang/String;", null, l0, l2, 1);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    mv = cw.visitMethod(opcodes.ACC_PUBLIC, "getContextualNamespaceDecls", "()[Ljava/lang/String;", null, null);
    mv.visitCode();
    l0 = helper.createLabel();
    mv.visitLabel(l0);
    mv.visitLineNumber(51, l0);
    mv.visitVarInsn(opcodes.ALOAD, 0);
    mv.visitFieldInsn(opcodes.GETFIELD, postFixedName, "nsctxt", "[Ljava/lang/String;");
    mv.visitInsn(opcodes.ARETURN);
    l1 = helper.createLabel();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", "L" + postFixedName + ";", null, l0, l1, 0);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    cw.visitEnd();
    return cw.toByteArray();
}
Also used : OpcodesProxy(org.apache.cxf.common.util.OpcodesProxy) ASMHelper(org.apache.cxf.common.util.ASMHelper)

Example 17 with OpcodesProxy

use of org.apache.cxf.common.util.OpcodesProxy in project cxf by apache.

the class WrapperHelperClassGenerator method addGetWrapperParts.

private boolean addGetWrapperParts(String newClassName, Class<?> wrapperClass, Method[] getMethods, Field[] fields, ASMHelper asmhelper, ASMHelper.ClassWriter cw) {
    OpcodesProxy opCodes = asmhelper.getOpCodes();
    ASMHelper.MethodVisitor mv = cw.visitMethod(opCodes.ACC_PUBLIC, "getWrapperParts", "(Ljava/lang/Object;)Ljava/util/List;", "(Ljava/lang/Object;)Ljava/util/List<Ljava/lang/Object;>;", new String[] { "org/apache/cxf/interceptor/Fault" });
    mv.visitCode();
    ASMHelper.Label lBegin = asmhelper.createLabel();
    mv.visitLabel(lBegin);
    mv.visitLineNumber(108, lBegin);
    // the ret List
    mv.visitTypeInsn(opCodes.NEW, "java/util/ArrayList");
    mv.visitInsn(opCodes.DUP);
    mv.visitMethodInsn(opCodes.INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false);
    mv.visitVarInsn(opCodes.ASTORE, 2);
    // cast the Object to the wrapperType type
    mv.visitVarInsn(opCodes.ALOAD, 1);
    mv.visitTypeInsn(opCodes.CHECKCAST, StringUtils.periodToSlashes(wrapperClass.getName()));
    mv.visitVarInsn(opCodes.ASTORE, 3);
    for (int x = 0; x < getMethods.length; x++) {
        Method method = getMethods[x];
        if (method == null && fields[x] != null) {
            // fallback to reflection mode
            return false;
        }
        if (method == null) {
            ASMHelper.Label l3 = asmhelper.createLabel();
            mv.visitLabel(l3);
            mv.visitLineNumber(200 + x, l3);
            mv.visitVarInsn(opCodes.ALOAD, 2);
            mv.visitInsn(opCodes.ACONST_NULL);
            mv.visitMethodInsn(opCodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
            mv.visitInsn(opCodes.POP);
        } else {
            ASMHelper.Label l3 = asmhelper.createLabel();
            mv.visitLabel(l3);
            mv.visitLineNumber(250 + x, l3);
            mv.visitVarInsn(opCodes.ALOAD, 2);
            mv.visitVarInsn(opCodes.ALOAD, 3);
            mv.visitMethodInsn(opCodes.INVOKEVIRTUAL, StringUtils.periodToSlashes(wrapperClass.getName()), method.getName(), asmhelper.getMethodSignature(method), false);
            if (method.getReturnType().isPrimitive()) {
                // wrap into Object type
                createObjectWrapper(mv, method.getReturnType(), asmhelper);
            }
            if (JAXBElement.class.isAssignableFrom(method.getReturnType())) {
                ASMHelper.Label jumpOverLabel = asmhelper.createLabel();
                mv.visitInsn(opCodes.DUP);
                mv.visitJumpInsn(opCodes.IFNULL, jumpOverLabel);
                mv.visitMethodInsn(opCodes.INVOKEVIRTUAL, "javax/xml/bind/JAXBElement", "getValue", "()Ljava/lang/Object;", false);
                mv.visitLabel(jumpOverLabel);
            }
            mv.visitMethodInsn(opCodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
            mv.visitInsn(opCodes.POP);
        }
    }
    // return the list
    ASMHelper.Label l2 = asmhelper.createLabel();
    mv.visitLabel(l2);
    mv.visitLineNumber(108, l2);
    mv.visitVarInsn(opCodes.ALOAD, 2);
    mv.visitInsn(opCodes.ARETURN);
    ASMHelper.Label lEnd = asmhelper.createLabel();
    mv.visitLabel(lEnd);
    mv.visitLocalVariable("this", "L" + newClassName + ";", null, lBegin, lEnd, 0);
    mv.visitLocalVariable("o", "Ljava/lang/Object;", null, lBegin, lEnd, 1);
    mv.visitLocalVariable("ret", "Ljava/util/List;", "Ljava/util/List<Ljava/lang/Object;>;", lBegin, lEnd, 2);
    mv.visitLocalVariable("ok", "L" + StringUtils.periodToSlashes(wrapperClass.getName()) + ";", null, lBegin, lEnd, 3);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
    return true;
}
Also used : OpcodesProxy(org.apache.cxf.common.util.OpcodesProxy) ASMHelper(org.apache.cxf.common.util.ASMHelper) Method(java.lang.reflect.Method)

Example 18 with OpcodesProxy

use of org.apache.cxf.common.util.OpcodesProxy in project cxf by apache.

the class WrapperHelperClassGenerator method doCollection.

// CHECKSTYLE:ON
private void doCollection(ASMHelper.MethodVisitor mv, int x, Class<?> wrapperType, Method[] setMethods, Method[] getMethods, ASMHelper asmhelper) {
    // List aVal = obj.getA();
    // List newA = (List)lst.get(99);
    // if (aVal == null) {
    // obj.setA(newA);
    // } else if (newA != null) {
    // aVal.addAll(newA);
    // }
    OpcodesProxy opCodes = asmhelper.getOpCodes();
    ASMHelper.Label l3 = asmhelper.createLabel();
    mv.visitLabel(l3);
    mv.visitLineNumber(114, l3);
    mv.visitMethodInsn(opCodes.INVOKEVIRTUAL, StringUtils.periodToSlashes(wrapperType.getName()), getMethods[x].getName(), asmhelper.getMethodSignature(getMethods[x]), false);
    mv.visitVarInsn(opCodes.ASTORE, 3);
    mv.visitVarInsn(opCodes.ALOAD, 1);
    mv.visitIntInsn(opCodes.SIPUSH, x);
    mv.visitMethodInsn(opCodes.INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;", true);
    mv.visitTypeInsn(opCodes.CHECKCAST, "java/util/List");
    mv.visitVarInsn(opCodes.ASTORE, 4);
    mv.visitVarInsn(opCodes.ALOAD, 3);
    ASMHelper.Label nonNullLabel = asmhelper.createLabel();
    mv.visitJumpInsn(opCodes.IFNONNULL, nonNullLabel);
    if (setMethods[x] == null) {
        mv.visitTypeInsn(opCodes.NEW, "java/lang/RuntimeException");
        mv.visitInsn(opCodes.DUP);
        mv.visitLdcInsn(getMethods[x].getName() + " returned null and there isn't a set method.");
        mv.visitMethodInsn(opCodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V", false);
        mv.visitInsn(opCodes.ATHROW);
    } else {
        mv.visitVarInsn(opCodes.ALOAD, 2);
        mv.visitVarInsn(opCodes.ALOAD, 4);
        mv.visitTypeInsn(opCodes.CHECKCAST, getMethods[x].getReturnType().getName().replace('.', '/'));
        mv.visitMethodInsn(opCodes.INVOKEVIRTUAL, StringUtils.periodToSlashes(wrapperType.getName()), setMethods[x].getName(), asmhelper.getMethodSignature(setMethods[x]), false);
    }
    ASMHelper.Label jumpOverLabel = asmhelper.createLabel();
    mv.visitJumpInsn(opCodes.GOTO, jumpOverLabel);
    mv.visitLabel(nonNullLabel);
    mv.visitLineNumber(106, nonNullLabel);
    mv.visitVarInsn(opCodes.ALOAD, 4);
    mv.visitJumpInsn(opCodes.IFNULL, jumpOverLabel);
    mv.visitVarInsn(opCodes.ALOAD, 3);
    mv.visitVarInsn(opCodes.ALOAD, 4);
    mv.visitMethodInsn(opCodes.INVOKEINTERFACE, "java/util/List", "addAll", "(Ljava/util/Collection;)Z", true);
    mv.visitInsn(opCodes.POP);
    mv.visitLabel(jumpOverLabel);
    mv.visitLineNumber(107, jumpOverLabel);
}
Also used : OpcodesProxy(org.apache.cxf.common.util.OpcodesProxy) ASMHelper(org.apache.cxf.common.util.ASMHelper)

Example 19 with OpcodesProxy

use of org.apache.cxf.common.util.OpcodesProxy in project cxf by apache.

the class CorbaFixedAnyImplGenerator method addExtractOverride.

private void addExtractOverride(ASMHelper helper, ASMHelper.ClassWriter cw) {
    OpcodesProxy opCodes = helper.getOpCodes();
    ASMHelper.MethodVisitor mv = cw.visitMethod(opCodes.ACC_PUBLIC, "extract_Streamable", "()Lorg/omg/CORBA/portable/Streamable;", null, null);
    mv.visitCode();
    ASMHelper.Label l0 = helper.createLabel();
    mv.visitLabel(l0);
    mv.visitLineNumber(47, l0);
    mv.visitVarInsn(opCodes.ALOAD, 0);
    mv.visitFieldInsn(opCodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj", "Lorg/omg/CORBA/portable/Streamable;");
    ASMHelper.Label l1 = helper.createLabel();
    mv.visitJumpInsn(opCodes.IFNULL, l1);
    ASMHelper.Label l2 = helper.createLabel();
    mv.visitLabel(l2);
    mv.visitLineNumber(48, l2);
    mv.visitVarInsn(opCodes.ALOAD, 0);
    mv.visitFieldInsn(opCodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj", "Lorg/omg/CORBA/portable/Streamable;");
    mv.visitInsn(opCodes.ARETURN);
    mv.visitLabel(l1);
    mv.visitLineNumber(50, l1);
    mv.visitVarInsn(opCodes.ALOAD, 0);
    mv.visitMethodInsn(opCodes.INVOKESPECIAL, "com/sun/corba/se/impl/corba/AnyImpl", "extract_Streamable", "()Lorg/omg/CORBA/portable/Streamable;", false);
    mv.visitInsn(opCodes.ARETURN);
    ASMHelper.Label l3 = helper.createLabel();
    mv.visitLabel(l3);
    mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l3, 0);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
Also used : OpcodesProxy(org.apache.cxf.common.util.OpcodesProxy) ASMHelper(org.apache.cxf.common.util.ASMHelper)

Example 20 with OpcodesProxy

use of org.apache.cxf.common.util.OpcodesProxy in project cxf by apache.

the class CorbaFixedAnyImplGenerator method addReadOverride.

private void addReadOverride(ASMHelper helper, ASMHelper.ClassWriter cw) {
    OpcodesProxy opCodes = helper.getOpCodes();
    ASMHelper.MethodVisitor mv = cw.visitMethod(opCodes.ACC_PUBLIC, "read_value", "(Lorg/omg/CORBA/portable/InputStream;Lorg/omg/CORBA/TypeCode;)V", null, null);
    mv.visitCode();
    ASMHelper.Label l0 = helper.createLabel();
    mv.visitLabel(l0);
    mv.visitLineNumber(54, l0);
    mv.visitVarInsn(opCodes.ALOAD, 0);
    mv.visitFieldInsn(opCodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj", "Lorg/omg/CORBA/portable/Streamable;");
    ASMHelper.Label l1 = helper.createLabel();
    mv.visitJumpInsn(opCodes.IFNULL, l1);
    ASMHelper.Label l2 = helper.createLabel();
    mv.visitLabel(l2);
    mv.visitLineNumber(55, l2);
    mv.visitVarInsn(opCodes.ALOAD, 0);
    mv.visitFieldInsn(opCodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj", "Lorg/omg/CORBA/portable/Streamable;");
    mv.visitVarInsn(opCodes.ALOAD, 1);
    mv.visitMethodInsn(opCodes.INVOKEINTERFACE, "org/omg/CORBA/portable/Streamable", "_read", "(Lorg/omg/CORBA/portable/InputStream;)V", true);
    ASMHelper.Label l3 = helper.createLabel();
    mv.visitJumpInsn(opCodes.GOTO, l3);
    mv.visitLabel(l1);
    mv.visitLineNumber(57, l1);
    mv.visitVarInsn(opCodes.ALOAD, 0);
    mv.visitVarInsn(opCodes.ALOAD, 1);
    mv.visitVarInsn(opCodes.ALOAD, 2);
    mv.visitMethodInsn(opCodes.INVOKESPECIAL, "com/sun/corba/se/impl/corba/AnyImpl", "read_value", "(Lorg/omg/CORBA/portable/InputStream;Lorg/omg/CORBA/TypeCode;)V", false);
    mv.visitLabel(l3);
    mv.visitLineNumber(59, l3);
    mv.visitInsn(opCodes.RETURN);
    ASMHelper.Label l4 = helper.createLabel();
    mv.visitLabel(l4);
    mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l4, 0);
    mv.visitLocalVariable("is", "Lorg/omg/CORBA/portable/InputStream;", null, l0, l4, 1);
    mv.visitLocalVariable("t", "Lorg/omg/CORBA/TypeCode;", null, l0, l4, 2);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
Also used : OpcodesProxy(org.apache.cxf.common.util.OpcodesProxy) ASMHelper(org.apache.cxf.common.util.ASMHelper)

Aggregations

OpcodesProxy (org.apache.cxf.common.util.OpcodesProxy)24 ASMHelper (org.apache.cxf.common.util.ASMHelper)23 Annotation (java.lang.annotation.Annotation)2 Method (java.lang.reflect.Method)2 GenericArrayType (java.lang.reflect.GenericArrayType)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Collection (java.util.Collection)1 Map (java.util.Map)1 JAXBElement (javax.xml.bind.JAXBElement)1 XmlMimeType (javax.xml.bind.annotation.XmlMimeType)1 XmlNsForm (javax.xml.bind.annotation.XmlNsForm)1 XmlJavaTypeAdapter (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter)1 XmlJavaTypeAdapters (javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters)1 QName (javax.xml.namespace.QName)1 Holder (javax.xml.ws.Holder)1 WrapperHelper (org.apache.cxf.databinding.WrapperHelper)1 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)1 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)1