List of usage examples for org.objectweb.asm Opcodes INVOKEVIRTUAL
int INVOKEVIRTUAL
To view the source code for org.objectweb.asm Opcodes INVOKEVIRTUAL.
Click Source Link
From source file:com.nginious.http.serialize.JsonSerializerCreator.java
License:Apache License
/** * Creates bytecode for serializing a bean property which is in itself a serializable bean as defined in the class description. * /* w w w.j a v a 2s . c o m*/ * @param visitor method visitor used for creating bytecode * @param returnMethodName binary name of get method in bean that returns serializable bean * @param returnType class of serializable bean * @param intBeanClazzName binary class name of bean */ private void createBeanSerializationCode(MethodVisitor visitor, String returnMethodName, String propertyName, Class<?> returnType, String intBeanClazzName) { String intReturnClazzName = Serialization.createInternalClassName(returnType); visitor.visitVarInsn(Opcodes.ALOAD, 0); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/nginious/http/serialize/JsonSerializer", "getSerializerFactory", "()Lcom/nginious/http/serialize/SerializerFactoryImpl;"); visitor.visitLdcInsn(returnType.getName()); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;"); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/nginious/http/serialize/SerializerFactoryImpl", "createJsonSerializer", "(Ljava/lang/Class;)Lcom/nginious/http/serialize/JsonSerializer;"); visitor.visitVarInsn(Opcodes.ASTORE, 4); visitor.visitVarInsn(Opcodes.ALOAD, 4); visitor.visitVarInsn(Opcodes.ALOAD, 3); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, intBeanClazzName, returnMethodName, "()L" + intReturnClazzName + ";"); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/nginious/http/serialize/JsonSerializer", "serialize", "(Ljava/lang/Object;)Lorg/json/JSONObject;"); visitor.visitVarInsn(Opcodes.ASTORE, 4); visitor.visitVarInsn(Opcodes.ALOAD, 1); visitor.visitLdcInsn(propertyName); visitor.visitVarInsn(Opcodes.ALOAD, 4); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/json/JSONObject", "put", "(Ljava/lang/String;Ljava/lang/Object;)Lorg/json/JSONObject;"); }
From source file:com.nginious.http.serialize.JsonSerializerCreator.java
License:Apache License
/** * Creates bytecode for serializing property matching the specified bean method name. The generated bytecode calls the * appropriate serialization method in the class {@link JsonSerializer} depending on the specified method type. * //ww w . ja v a 2 s .co m * @param visitor method visitor for generating bytecode * @param clazzName binary name of serializer class being generated * @param methodName binary name of method in class {@link JsonSerializer} used for serializing property * @param methodType binary type for method in class {@link JsonSerializer} used for serializing property * @param beanType binary return type of get method in bean * @param beanClazzName binary name of bean class * @param beanMethodName binary name of get method in bean for getting method */ private void createPropertySerializationCode(MethodVisitor visitor, String clazzName, String methodName, String methodType, String beanType, String beanClazzName, String beanMethodName, String propertyName) { visitor.visitVarInsn(Opcodes.ALOAD, 0); visitor.visitVarInsn(Opcodes.ALOAD, 1); visitor.visitLdcInsn(propertyName); visitor.visitVarInsn(Opcodes.ALOAD, 3); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, beanClazzName, beanMethodName, "()" + beanType); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, clazzName, methodName, "(Lorg/json/JSONObject;Ljava/lang/String;" + methodType + ")V"); }
From source file:com.nginious.http.serialize.QueryDeserializerCreator.java
License:Apache License
/** * Creates bytecode for deserializing property matching the specified bean method name. The generated bytecode calls the * appropriate deserialization method in the class {@link QueryDeserializer} depending on the specified method type. * Then generated bytecode that calls the corresponding get method in the bean class. * //from w w w . ja v a2 s . co m * @param visitor method visitor for writing bytecode * @param clazzName binary name of class being generated * @param methodName binary name of method in class {@link QueryDeserializer} used for deserializing property * @param methodType binary type of value returned by called deserialization method in {@link QueryDeserializer} * @param beanType binary type for argument in bean method for setting property * @param beanClazzName binary class name of bean for which the deserializer class is being generated * @param beanMethodName binary name of method in bean class for setting property */ private void createPropertyDeserializationCode(MethodVisitor visitor, String clazzName, String methodName, String methodType, String beanType, String beanClazzName, String beanMethodName) { String propertyName = createParameterNameFromMethodName(beanMethodName); visitor.visitVarInsn(Opcodes.ALOAD, 3); visitor.visitVarInsn(Opcodes.ALOAD, 0); visitor.visitVarInsn(Opcodes.ALOAD, 1); visitor.visitLdcInsn(propertyName); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, clazzName, methodName, "(Lcom/nginious/http/HttpRequest;Ljava/lang/String;)" + methodType); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, beanClazzName, beanMethodName, "(" + beanType + ")V"); }
From source file:com.nginious.http.serialize.XmlDeserializerCreator.java
License:Apache License
/** * Creates bytecode for deserializing property matching the specified bean method name. The generated bytecode calls the * appropriate deserialization method in the class {@link XmlDeserializer} depending on the specified method type. * Then generated bytecode that calls the corresponding set method in the bean class. * /*from w w w .ja v a 2 s . c o m*/ * @param visitor method visitor for writing bytecode * @param clazzName binary name of class being generated * @param methodName binary name of method in class {@link XmlDeserializer} used for deserializing property * @param methodType binary type of value returned by called deserialization method in {@link XmlDeserializer} * @param beanType binary type for argument in bean method for setting property * @param beanClazzName binary class name of bean for which the deserializer class is being generated * @param beanMethodName binary name of method in bean class for setting property */ private void createPropertyDeserializationCode(MethodVisitor visitor, String clazzName, String methodName, String methodType, String beanType, String beanClazzName, String beanMethodName) { String propertyName = convertToXmlName(beanMethodName); visitor.visitVarInsn(Opcodes.ALOAD, 3); visitor.visitVarInsn(Opcodes.ALOAD, 0); visitor.visitVarInsn(Opcodes.ALOAD, 1); visitor.visitLdcInsn(propertyName); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, clazzName, methodName, "(Ljava/util/HashMap;Ljava/lang/String;)" + methodType); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, beanClazzName, beanMethodName, "(" + beanType + ")V"); }
From source file:com.nginious.http.serialize.XmlSerializerCreator.java
License:Apache License
/** * Creates bytecode for serializing a bean property which returns a collection of opaque objects. * //from w w w. ja v a 2s .c om * @param visitor method visitor used for creating bytecode * @param intBeanClazzName binary name of bean * @param methodName binary name of get method in bean * @param returnType return type of get method in bean */ private void createObjectCollectionSerializationCode(MethodVisitor visitor, String intBeanClazzName, String methodName, String propertyName, Class<?> returnType) { visitor.visitTypeInsn(Opcodes.NEW, "com/nginious/http/serialize/XmlObjectCollectionSerializer"); visitor.visitInsn(Opcodes.DUP); visitor.visitLdcInsn(propertyName); visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/nginious/http/serialize/XmlObjectCollectionSerializer", "<init>", "(Ljava/lang/String;)V"); visitor.visitVarInsn(Opcodes.ASTORE, 4); visitor.visitVarInsn(Opcodes.ALOAD, 4); visitor.visitVarInsn(Opcodes.ALOAD, 1); String intReturnClazzName = returnType.getName().replace('.', '/'); visitor.visitVarInsn(Opcodes.ALOAD, 3); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, intBeanClazzName, methodName, "()L" + intReturnClazzName + ";"); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/nginious/http/serialize/XmlObjectCollectionSerializer", "serialize", "(Ljavax/xml/transform/sax/TransformerHandler;Ljava/util/Collection;)V"); }
From source file:com.nginious.http.serialize.XmlSerializerCreator.java
License:Apache License
/** * Creates bytecode for serializing a bean property which returns a collection of beans that are serializable. Bean serializability * is determined as described in the class description. * /*from ww w .j a v a2 s . c o m*/ * @param visitor method visitor used for creating bytecode * @param intBeanClazzName binary class name of bean * @param methodName binary name of get method in bean returning collection * @param returnType return type of get method in bean * @param collectionBeanType class of serializable bean found in collection */ private void createBeanCollectionSerializationCode(MethodVisitor visitor, String intBeanClazzName, String methodName, String propertyName, Class<?> returnType, Class<?> collectionBeanType) { visitor.visitVarInsn(Opcodes.ALOAD, 0); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/nginious/http/serialize/XmlSerializer", "getSerializerFactory", "()Lcom/nginious/http/serialize/SerializerFactoryImpl;"); visitor.visitLdcInsn(collectionBeanType.getName()); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;"); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/nginious/http/serialize/SerializerFactoryImpl", "createXmlSerializer", "(Ljava/lang/Class;)Lcom/nginious/http/serialize/XmlSerializer;"); visitor.visitVarInsn(Opcodes.ASTORE, 4); visitor.visitTypeInsn(Opcodes.NEW, "com/nginious/http/serialize/XmlBeanCollectionSerializer"); visitor.visitInsn(Opcodes.DUP); visitor.visitLdcInsn(propertyName); visitor.visitVarInsn(Opcodes.ALOAD, 4); visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/nginious/http/serialize/XmlBeanCollectionSerializer", "<init>", "(Ljava/lang/String;Lcom/nginious/http/serialize/XmlSerializer;)V"); visitor.visitVarInsn(Opcodes.ASTORE, 5); visitor.visitVarInsn(Opcodes.ALOAD, 5); visitor.visitVarInsn(Opcodes.ALOAD, 1); String intReturnClazzName = returnType.getName().replace('.', '/'); visitor.visitVarInsn(Opcodes.ALOAD, 3); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, intBeanClazzName, methodName, "()L" + intReturnClazzName + ";"); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/nginious/http/serialize/XmlBeanCollectionSerializer", "serialize", "(Ljavax/xml/transform/sax/TransformerHandler;Ljava/util/Collection;)V"); }
From source file:com.nginious.http.serialize.XmlSerializerCreator.java
License:Apache License
/** * Creates bytecode for serializing a bean property which is in itself a serializable bean as defined in the class description. * /*from w w w. j a v a 2s .c o m*/ * @param visitor method visitor used for creating bytecode * @param returnMethodName binary name of get method in bean that returns serializable bean * @param returnType class of serializable bean * @param intBeanClazzName binary class name of bean */ private void createBeanSerializationCode(MethodVisitor visitor, String returnMethodName, String propertyName, Class<?> returnType, String intBeanClazzName) { String intReturnClazzName = Serialization.createInternalClassName(returnType); visitor.visitVarInsn(Opcodes.ALOAD, 0); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/nginious/http/serialize/XmlSerializer", "getSerializerFactory", "()Lcom/nginious/http/serialize/SerializerFactoryImpl;"); visitor.visitLdcInsn(returnType.getName()); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;"); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/nginious/http/serialize/SerializerFactoryImpl", "createXmlSerializer", "(Ljava/lang/Class;)Lcom/nginious/http/serialize/XmlSerializer;"); visitor.visitVarInsn(Opcodes.ASTORE, 4); visitor.visitVarInsn(Opcodes.ALOAD, 4); visitor.visitVarInsn(Opcodes.ALOAD, 1); visitor.visitLdcInsn(convertToXmlName(propertyName)); visitor.visitVarInsn(Opcodes.ALOAD, 3); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, intBeanClazzName, returnMethodName, "()L" + intReturnClazzName + ";"); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/nginious/http/serialize/XmlSerializer", "serialize", "(Ljavax/xml/transform/sax/TransformerHandler;Ljava/lang/String;Ljava/lang/Object;)V"); visitor.visitVarInsn(Opcodes.ASTORE, 4); }
From source file:com.nginious.http.serialize.XmlSerializerCreator.java
License:Apache License
/** * Creates bytecode for serializing property matching the specified bean method name. The generated bytecode calls the * appropriate serialization method in the class {@link XmlSerializer} depending on the specified method type. * /* w w w . j a va 2 s . com*/ * @param visitor method visitor for generating bytecode * @param clazzName binary name of serializer class being generated * @param methodName binary name of method in class {@link XmlSerializer} used for serializing property * @param propertyName name of XML element * @param methodType binary type for method in class {@link XmlSerializer} used for serializing property * @param beanType binary return type of get method in bean * @param beanClazzName binary name of bean class * @param beanMethodName binary name of get method in bean for getting method */ private void createPropertySerializationCode(MethodVisitor visitor, String clazzName, String methodName, String methodType, String beanType, String beanClazzName, String beanMethodName, String propertyName) { visitor.visitVarInsn(Opcodes.ALOAD, 0); visitor.visitVarInsn(Opcodes.ALOAD, 1); visitor.visitLdcInsn(propertyName); visitor.visitVarInsn(Opcodes.ALOAD, 3); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, beanClazzName, beanMethodName, "()" + beanType); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, clazzName, methodName, "(Ljavax/xml/transform/sax/TransformerHandler;Ljava/lang/String;" + methodType + ")V"); }
From source file:com.nginious.http.xsp.DocumentPart.java
License:Apache License
/** * Creates bytecode for this document tag part using the specified class writer and method visitor. * // ww w .j a va 2 s . c o m * @param intClassName the binary class name of the class being created * @param writer the class writer * @param visitor the method visitor * @throws XspException if unable to create bytecode */ void compile(String intClassName, ClassWriter writer, MethodVisitor visitor) throws XspException { // 0 = this, 1 = HttpRequest, 2 = HttpResponse, 3 = StringBuffer // StringBuffer buffer = new StringBuffer(); visitor.visitTypeInsn(Opcodes.NEW, "java/lang/StringBuffer"); visitor.visitInsn(Opcodes.DUP); visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/StringBuffer", "<init>", "()V"); visitor.visitVarInsn(Opcodes.ASTORE, 3); for (XspPart part : contentParts) { part.compile(intClassName, writer, visitor); } // response.setContentLength(buffer.length()); visitor.visitVarInsn(Opcodes.ALOAD, 2); visitor.visitVarInsn(Opcodes.ALOAD, 3); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuffer", "length", "()I"); visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "com/nginious/http/HttpResponse", "setContentLength", "(I)V"); // response.addHeader(contentType); String contentType = getMetaContent("Content-Type"); if (contentType == null) { contentType = "application/unknown"; } visitor.visitVarInsn(Opcodes.ALOAD, 2); visitor.visitLdcInsn("Content-Type"); visitor.visitLdcInsn(contentType); visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "com/nginious/http/HttpResponse", "addHeader", "(Ljava/lang/String;Ljava/lang/String;)V"); // PrintWriter writer = response.getWriter(); // writer.print(buffer.toString()); visitor.visitVarInsn(Opcodes.ALOAD, 2); visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "com/nginious/http/HttpResponse", "getWriter", "()Ljava/io/PrintWriter;"); visitor.visitVarInsn(Opcodes.ALOAD, 3); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuffer", "toString", "()Ljava/lang/String;"); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintWriter", "print", "(Ljava/lang/String;)V"); }
From source file:com.nginious.http.xsp.expr.AttributeValue.java
License:Apache License
/** * Creates bytecode for evaluating this attribute value. The bytecode is created using the * specified method visitor and creates a result of specified type. * //from ww w. j av a 2 s.co m * @param visitor the method visitor * @param type the type */ void compile(MethodVisitor visitor, Type type) { visitor.visitLdcInsn(this.name); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "com/nginious/http/xsp/expr/Expression", "getVariable", "(Ljava/lang/String;)Ljava/lang/Object;"); if (type != Type.ANY) { visitor.visitInsn(Opcodes.DUP); } if (type == Type.STRING) { Label nullLabel = new Label(); Label notNullLabel = new Label(); visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;"); visitor.visitJumpInsn(Opcodes.GOTO, notNullLabel); visitor.visitLabel(nullLabel); visitor.visitInsn(Opcodes.POP); visitor.visitInsn(Opcodes.ACONST_NULL); visitor.visitLabel(notNullLabel); } else if (type == Type.INT) { Label nullLabel = new Label(); Label notNullLabel = new Label(); visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;"); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "parseInt", "(Ljava/lang/String;)I"); visitor.visitJumpInsn(Opcodes.GOTO, notNullLabel); visitor.visitLabel(nullLabel); visitor.visitInsn(Opcodes.POP); visitor.visitLdcInsn(0); visitor.visitLabel(notNullLabel); } else if (type == Type.DOUBLE) { Label nullLabel = new Label(); Label notNullLabel = new Label(); visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;"); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "parseDouble", "(Ljava/lang/String;)D"); visitor.visitJumpInsn(Opcodes.GOTO, notNullLabel); visitor.visitLabel(nullLabel); visitor.visitInsn(Opcodes.POP); visitor.visitLdcInsn(0.0d); visitor.visitLabel(notNullLabel); } }