List of usage examples for org.objectweb.asm Opcodes ACC_PUBLIC
int ACC_PUBLIC
To view the source code for org.objectweb.asm Opcodes ACC_PUBLIC.
Click Source Link
From source file:org.apache.cxf.binding.corba.utils.CorbaAnyHelper.java
License:Apache License
private static void addExtractOverride(ClassWriter cw) { // TODO Auto-generated method stub MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "extract_Streamable", "()Lorg/omg/CORBA/portable/Streamable;", null, null); mv.visitCode();//from ww w . j a v a2 s . c o m Label l0 = new Label(); 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;"); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l1); Label l2 = new Label(); 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;"); mv.visitInsn(Opcodes.ARETURN); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l3, 0); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:org.apache.cxf.binding.corba.utils.CorbaAnyHelper.java
License:Apache License
private static void addInsertOverride(ClassWriter cw) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "insert_Streamable", "(Lorg/omg/CORBA/portable/Streamable;)V", null, null); mv.visitCode();/*from ww w .j a v a 2 s . co m*/ Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(43, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/corba/se/impl/corba/AnyImpl", "insert_Streamable", "(Lorg/omg/CORBA/portable/Streamable;)V"); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(44, l1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitFieldInsn(Opcodes.PUTFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj", "Lorg/omg/CORBA/portable/Streamable;"); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLineNumber(45, l2); mv.visitInsn(Opcodes.RETURN); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l3, 0); mv.visitLocalVariable("s", "Lorg/omg/CORBA/portable/Streamable;", null, l0, l3, 1); mv.visitMaxs(2, 2); mv.visitEnd(); }
From source file:org.apache.cxf.binding.corba.utils.CorbaAnyHelper.java
License:Apache License
private static void addFixedAnyConstructor(ClassWriter cw) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Lorg/omg/CORBA/ORB;)V", null, null); mv.visitCode();/*from www . j ava 2 s .c o m*/ Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(36, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitTypeInsn(Opcodes.CHECKCAST, "com/sun/corba/se/spi/orb/ORB"); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/corba/se/impl/corba/AnyImpl", "<init>", "(Lcom/sun/corba/se/spi/orb/ORB;)V"); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(37, l1); mv.visitInsn(Opcodes.RETURN); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l2, 0); mv.visitLocalVariable("orb", "Lorg/omg/CORBA/ORB;", null, l0, l2, 1); mv.visitMaxs(2, 2); mv.visitEnd(); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Lorg/omg/CORBA/ORB;Lorg/omg/CORBA/Any;)V", null, null); mv.visitCode(); l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(39, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitTypeInsn(Opcodes.CHECKCAST, "com/sun/corba/se/spi/orb/ORB"); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/corba/se/impl/corba/AnyImpl", "<init>", "(Lcom/sun/corba/se/spi/orb/ORB;Lorg/omg/CORBA/Any;)V"); l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(40, l1); mv.visitInsn(Opcodes.RETURN); l2 = new Label(); mv.visitLabel(l2); mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l2, 0); mv.visitLocalVariable("orb", "Lorg/omg/CORBA/ORB;", null, l0, l2, 1); mv.visitLocalVariable("any", "Lorg/omg/CORBA/Any;", null, l0, l2, 2); mv.visitMaxs(3, 3); mv.visitEnd(); }
From source file:org.apache.cxf.jaxb.JAXBUtils.java
License:Apache License
private static Class<?> createNamespaceWrapperInternal(ASMHelper helper, ClassWriter cw) { String className = "org.apache.cxf.jaxb.NamespaceMapperInternal"; FieldVisitor fv;/* w ww . ja v a2s . c om*/ MethodVisitor mv; cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, "org/apache/cxf/jaxb/NamespaceMapperInternal", null, "com/sun/xml/internal/bind/marshaller/NamespacePrefixMapper", 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(); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Ljava/util/Map;)V", "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;)V", null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(30, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/xml/internal/bind/marshaller/NamespacePrefixMapper", "<init>", "()V"); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(31, l1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitFieldInsn(Opcodes.PUTFIELD, "org/apache/cxf/jaxb/NamespaceMapperInternal", "nspref", "Ljava/util/Map;"); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLineNumber(32, l2); mv.visitInsn(Opcodes.RETURN); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLocalVariable("this", "Lorg/apache/cxf/jaxb/NamespaceMapperInternal;", null, l0, l3, 0); mv.visitLocalVariable("nspref", "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;", l0, l3, 1); mv.visitMaxs(2, 2); mv.visitEnd(); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getPreferredPrefix", "(Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;", null, null); mv.visitCode(); l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(38, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/jaxb/NamespaceMapperInternal", "nspref", "Ljava/util/Map;"); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/String"); mv.visitVarInsn(Opcodes.ASTORE, 4); l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(39, l1); mv.visitVarInsn(Opcodes.ALOAD, 4); l2 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l2); l3 = new Label(); mv.visitLabel(l3); mv.visitLineNumber(40, l3); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(l2); mv.visitLineNumber(42, l2); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitInsn(Opcodes.ARETURN); Label l4 = new Label(); mv.visitLabel(l4); mv.visitLocalVariable("this", "Lorg/apache/cxf/jaxb/NamespaceMapperInternal;", 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(2, 5); mv.visitEnd(); cw.visitEnd(); byte bts[] = cw.toByteArray(); return helper.loadClass(className, JAXBUtils.class, bts); }
From source file:org.apache.cxf.jaxb.WrapperHelperCompiler.java
License:Apache License
public WrapperHelper compile() { if (cw == null) { return null; }/*from ww w . j a v a 2 s .c o m*/ int count = 1; String newClassName = wrapperType.getName() + "_WrapperTypeHelper" + count; newClassName = newClassName.replaceAll("\\$", "."); newClassName = periodToSlashes(newClassName); Class<?> cls = super.findClass(newClassName.replace('/', '.'), wrapperType); while (cls != null) { try { WrapperHelper helper = WrapperHelper.class.cast(cls.newInstance()); if (!helper.getSignature().equals(computeSignature())) { count++; newClassName = wrapperType.getName() + "_WrapperTypeHelper" + count; newClassName = newClassName.replaceAll("\\$", "."); newClassName = periodToSlashes(newClassName); cls = super.findClass(newClassName.replace('/', '.'), wrapperType); } else { return helper; } } catch (Exception e) { return null; } } cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, newClassName, null, "java/lang/Object", new String[] { periodToSlashes(WrapperHelper.class.getName()) }); addConstructor(newClassName, cw, objectFactory == null ? null : objectFactory.getClass()); boolean b = addSignature(); if (b) { b = addCreateWrapperObject(newClassName, objectFactory == null ? null : objectFactory.getClass()); } if (b) { b = addGetWrapperParts(newClassName, wrapperType, getMethods, fields, cw); } try { if (b) { cw.visitEnd(); byte bt[] = cw.toByteArray(); Class<?> cl = loadClass(newClassName.replace('/', '.'), wrapperType, bt); Object o = cl.newInstance(); return WrapperHelper.class.cast(o); } } catch (Throwable e) { // ignore, we'll just fall down to reflection based } return null; }
From source file:org.apache.cxf.jaxb.WrapperHelperCompiler.java
License:Apache License
private boolean addSignature() { String sig = computeSignature(); if (sig == null) { return false; }/*from w ww .j a v a2 s .c o m*/ MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getSignature", "()Ljava/lang/String;", null, null); mv.visitCode(); mv.visitLdcInsn(sig); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(100, l0); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); return true; }
From source file:org.apache.cxf.jaxb.WrapperHelperCompiler.java
License:Apache License
private static void addConstructor(String newClassName, ClassWriter cw, Class<?> objectFactory) { if (objectFactory != null) { String ofName = "L" + periodToSlashes(objectFactory.getName()) + ";"; FieldVisitor fv = cw.visitField(0, "factory", ofName, null, null); fv.visitEnd();/* w ww.j av a 2 s.c om*/ } MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(102, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); if (objectFactory != null) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.NEW, periodToSlashes(objectFactory.getName())); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, periodToSlashes(objectFactory.getName()), "<init>", "()V"); mv.visitFieldInsn(Opcodes.PUTFIELD, periodToSlashes(newClassName), "factory", "L" + periodToSlashes(objectFactory.getName()) + ";"); } mv.visitInsn(Opcodes.RETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(103, l0); mv.visitLocalVariable("this", "L" + newClassName + ";", null, l0, l1, 0); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.apache.cxf.jaxb.WrapperHelperCompiler.java
License:Apache License
private boolean addCreateWrapperObject(String newClassName, Class<?> objectFactoryClass) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "createWrapperObject", "(Ljava/util/List;)Ljava/lang/Object;", "(Ljava/util/List<*>;)Ljava/lang/Object;", new String[] { "org/apache/cxf/interceptor/Fault" }); mv.visitCode();//w ww . jav a 2s .c om Label lBegin = new Label(); mv.visitLabel(lBegin); mv.visitLineNumber(104, lBegin); mv.visitTypeInsn(Opcodes.NEW, periodToSlashes(wrapperType.getName())); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, periodToSlashes(wrapperType.getName()), "<init>", "()V"); mv.visitVarInsn(Opcodes.ASTORE, 2); for (int x = 0; x < setMethods.length; x++) { if (getMethods[x] == null) { if (setMethods[x] == null && fields[x] == null) { // null placeholder continue; } else { return false; } } Class<?> tp = getMethods[x].getReturnType(); mv.visitVarInsn(Opcodes.ALOAD, 2); if (List.class.isAssignableFrom(tp)) { doCollection(mv, x); } else { if (JAXBElement.class.isAssignableFrom(tp)) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, periodToSlashes(newClassName), "factory", "L" + periodToSlashes(objectFactoryClass.getName()) + ";"); } mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitIntInsn(Opcodes.BIPUSH, x); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;"); if (tp.isPrimitive()) { mv.visitTypeInsn(Opcodes.CHECKCAST, NONPRIMITIVE_MAP.get(tp)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, NONPRIMITIVE_MAP.get(tp), tp.getName() + "Value", "()" + PRIMITIVE_MAP.get(tp)); } else if (JAXBElement.class.isAssignableFrom(tp)) { mv.visitTypeInsn(Opcodes.CHECKCAST, periodToSlashes(jaxbMethods[x].getParameterTypes()[0].getName())); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, periodToSlashes(objectFactoryClass.getName()), jaxbMethods[x].getName(), getMethodSignature(jaxbMethods[x])); } else if (tp.isArray()) { mv.visitTypeInsn(Opcodes.CHECKCAST, getClassCode(tp)); } else { mv.visitTypeInsn(Opcodes.CHECKCAST, periodToSlashes(tp.getName())); } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, periodToSlashes(wrapperType.getName()), setMethods[x].getName(), "(" + getClassCode(tp) + ")V"); } } mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitInsn(Opcodes.ARETURN); Label lEnd = new Label(); mv.visitLabel(lEnd); mv.visitLocalVariable("this", "L" + newClassName + ";", null, lBegin, lEnd, 0); mv.visitLocalVariable("lst", "Ljava/util/List;", "Ljava/util/List<*>;", lBegin, lEnd, 1); mv.visitLocalVariable("ok", "L" + periodToSlashes(wrapperType.getName()) + ";", null, lBegin, lEnd, 2); mv.visitMaxs(0, 0); mv.visitEnd(); return true; }
From source file:org.apache.cxf.jaxb.WrapperHelperCompiler.java
License:Apache License
private static boolean addGetWrapperParts(String newClassName, Class<?> wrapperClass, Method getMethods[], Field fields[], ClassWriter cw) { 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();//from www .j a v a 2 s. c o m Label lBegin = new Label(); 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"); mv.visitVarInsn(Opcodes.ASTORE, 2); // cast the Object to the wrapperType type mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitTypeInsn(Opcodes.CHECKCAST, 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) { Label l3 = new Label(); 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"); mv.visitInsn(Opcodes.POP); } else { Label l3 = new Label(); mv.visitLabel(l3); mv.visitLineNumber(250 + x, l3); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, periodToSlashes(wrapperClass.getName()), method.getName(), getMethodSignature(method)); if (method.getReturnType().isPrimitive()) { // wrap into Object type createObjectWrapper(mv, method.getReturnType()); } if (JAXBElement.class.isAssignableFrom(method.getReturnType())) { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "javax/xml/bind/JAXBElement", "getValue", "()Ljava/lang/Object;"); } mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z"); mv.visitInsn(Opcodes.POP); } } // return the list Label l2 = new Label(); mv.visitLabel(l2); mv.visitLineNumber(108, l2); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitInsn(Opcodes.ARETURN); Label lEnd = new Label(); 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" + periodToSlashes(wrapperClass.getName()) + ";", null, lBegin, lEnd, 3); mv.visitMaxs(0, 0); mv.visitEnd(); return true; }