List of usage examples for org.objectweb.asm Opcodes ASTORE
int ASTORE
To view the source code for org.objectweb.asm Opcodes ASTORE.
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. * // ww w . ja va2 s . co 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 which implements the {@link JsonSerializer#serializeProperties(org.json.JSONObject, Object)} * method for the serializer class being created. * /*w ww . j a va 2s. c o m*/ * @param writer class byte code writer * @param intBeanClazzName binary name of serializer class being generated * @return a method visitor for writing bytecode inside the generated method */ private MethodVisitor createSerializeMethod(ClassWriter writer, String intBeanClazzName) { String[] exceptions = { "com/nginious/serialize/SerializerException" }; MethodVisitor visitor = writer.visitMethod(Opcodes.ACC_PUBLIC, "serializeProperties", "(Lorg/json/JSONObject;Ljava/lang/Object;)V", null, exceptions); visitor.visitCode(); Label label = new Label(); visitor.visitVarInsn(Opcodes.ALOAD, 2); visitor.visitJumpInsn(Opcodes.IFNONNULL, label); visitor.visitInsn(Opcodes.RETURN); visitor.visitLabel(label); visitor.visitVarInsn(Opcodes.ALOAD, 2); visitor.visitTypeInsn(Opcodes.CHECKCAST, intBeanClazzName); visitor.visitIntInsn(Opcodes.ASTORE, 3); return visitor; }
From source file:com.nginious.http.serialize.QueryDeserializerCreator.java
License:Apache License
/** * Creates bytecode which implements the {@link QueryDeserializer#deserialize(se.netdigital.http.HttpRequest)} method for * the deserializer class being created. * //from www . ja v a 2 s. c om * @param writer class byte code writer * @param intBeanClazzName name of deserializer class being generated * @return a method visitor for writing bytecode inside the generated method */ private MethodVisitor createDeserializeMethod(ClassWriter writer, String intBeanClazzName) { String[] exceptions = { "com/nginious/serialize/SerializerException" }; MethodVisitor visitor = writer.visitMethod(Opcodes.ACC_PUBLIC, "deserialize", "(Lcom/nginious/http/HttpRequest;)Ljava/lang/Object;", null, exceptions); visitor.visitCode(); visitor.visitTypeInsn(Opcodes.NEW, intBeanClazzName); visitor.visitInsn(Opcodes.DUP); visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, intBeanClazzName, "<init>", "()V"); visitor.visitVarInsn(Opcodes.ASTORE, 3); return visitor; }
From source file:com.nginious.http.serialize.XmlDeserializerCreator.java
License:Apache License
/** * Creates bytecode which implements the {@link XmlDeserializer#deserialize(java.util.HashMap)} method for * the deserializer class being created. * /* w w w .j av a2 s . co m*/ * @param writer class byte code writer * @param intBeanClazzName name of deserializer class being generated * @return a method visitor for writing bytecode inside the generated method */ private MethodVisitor createDeserializeMethod(ClassWriter writer, String intBeanClazzName) { String[] exceptions = { "com/nginious/http/serialize/SerializerException" }; MethodVisitor visitor = writer.visitMethod(Opcodes.ACC_PUBLIC, "deserialize", "(Ljava/util/HashMap;)Ljava/lang/Object;", null, exceptions); visitor.visitCode(); visitor.visitTypeInsn(Opcodes.NEW, intBeanClazzName); visitor.visitInsn(Opcodes.DUP); visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, intBeanClazzName, "<init>", "()V"); visitor.visitVarInsn(Opcodes.ASTORE, 3); return visitor; }
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. * //www .j a v a2 s. 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. * //www . j ava 2s. co 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 www . j av a 2 s . co 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 which implements the {@link XmlSerializer#serializeProperties(javax.xml.transform.sax.TransformerHandler, Object)} * method for the serializer class being created. * //from w w w . ja va 2s . c o m * @param writer class byte code writer * @param intBeanClazzName binary name of serializer class being generated * @return a method visitor for writing bytecode inside the generated method */ private MethodVisitor createSerializeMethod(ClassWriter writer, String intBeanClazzName) { String[] exceptions = { "com/nginious/serialize/SerializerException" }; MethodVisitor visitor = writer.visitMethod(Opcodes.ACC_PUBLIC, "serializeProperties", "(Ljavax/xml/transform/sax/TransformerHandler;Ljava/lang/Object;)V", null, exceptions); visitor.visitCode(); Label label = new Label(); visitor.visitVarInsn(Opcodes.ALOAD, 2); visitor.visitJumpInsn(Opcodes.IFNONNULL, label); visitor.visitInsn(Opcodes.RETURN); visitor.visitLabel(label); visitor.visitVarInsn(Opcodes.ALOAD, 0); visitor.visitVarInsn(Opcodes.ALOAD, 2); visitor.visitTypeInsn(Opcodes.CHECKCAST, intBeanClazzName); visitor.visitIntInsn(Opcodes.ASTORE, 3); return visitor; }
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. * //from w w w .ja v a 2 s .c om * @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.EqualsOperator.java
License:Apache License
/** * Compiles bytecode for evaluating this equals operator producing * a string as result. The specified method visitor is used for generating * bytecode./*from w w w .j av a 2 s .c om*/ * * @param visitor the method visitor */ private void compileString(MethodVisitor visitor) { value1.compile(visitor, Type.STRING); visitor.visitVarInsn(Opcodes.ASTORE, 1); value2.compile(visitor, Type.STRING); visitor.visitVarInsn(Opcodes.ASTORE, 2); Label nullLabel = new Label(); Label notNullLabel = new Label(); visitor.visitVarInsn(Opcodes.ALOAD, 1); visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel); visitor.visitVarInsn(Opcodes.ALOAD, 2); visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel); visitor.visitVarInsn(Opcodes.ALOAD, 1); visitor.visitVarInsn(Opcodes.ALOAD, 2); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z"); visitor.visitJumpInsn(Opcodes.GOTO, notNullLabel); visitor.visitLabel(nullLabel); visitor.visitLdcInsn(false); visitor.visitLabel(notNullLabel); }