felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r530141 [2/2] - in /incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides: ./ manipulation/
Date Wed, 18 Apr 2007 19:47:58 GMT
Added: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/POJOWriter.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/POJOWriter.java?view=auto&rev=530141
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/POJOWriter.java
(added)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/POJOWriter.java
Wed Apr 18 12:47:57 2007
@@ -0,0 +1,405 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.composite.service.provides.manipulation;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
+
+import org.apache.felix.ipojo.composite.service.provides.FieldMetadata;
+import org.apache.felix.ipojo.composite.service.provides.MethodMetadata;
+import org.apache.felix.ipojo.composite.service.provides.SpecificationMetadata;
+import org.apache.felix.ipojo.handlers.dependency.nullable.MethodSignature;
+import org.apache.felix.ipojo.handlers.dependency.nullable.MethodSignatureVisitor;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+
+/**
+ * Create the proxy class.
+ * 
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class POJOWriter implements Opcodes {
+
+    /**
+     * Create a class.
+     * @param cw : class writer
+     * @param className : class name
+     * @param spec : implemented specification
+     */
+    private static void createClass(ClassWriter cw, String className, String spec) {
+        // Create the class
+        cw.visit(V1_2, ACC_PUBLIC + ACC_SUPER, className, null, "java/lang/Object", new String[]
{ spec.replace('.', '/') });
+    }
+
+    /**
+     * Inject field in the current class.
+     * @param cw : class writer.
+     * @param fields : list of field to inject.
+     */
+    private static void injectFields(ClassWriter cw, List fields) {
+        // Inject fields
+        for (int i = 0; i < fields.size(); i++) {
+            FieldMetadata field = (FieldMetadata) fields.get(i);
+            if (field.isUseful()) {
+                SpecificationMetadata spec = field.getSpecification();
+                String fieldName = field.getName();
+                String desc = "";
+                if (field.isAggregate()) {
+                    desc = "[L" + spec.getName().replace('.', '/') + ";";
+                } else {
+                    desc = "L" + spec.getName().replace('.', '/') + ";";
+                }
+
+                cw.visitField(Opcodes.ACC_PRIVATE, fieldName, desc, null, null);
+            }
+        }
+    }
+
+    /**
+     * Return the proxy classname for the contract contractname by delegating on available
service.
+     * @param url URL of the needed contract
+     * @param contractName : The interface to implement
+     * @param className : The class name to create
+     * @param fields : the list of fields on which delegate
+     * @param methods : the list of method on which delegate
+     * @return byte[] : the build class
+     */
+    public static byte[] dump(URL url, String contractName, String className, List fields,
List methods) {
+
+        ClassReader cr = null;
+        InputStream is = null;
+        byte[] b = null;
+        try {
+            is = url.openStream();
+            cr = new ClassReader(is);
+            MethodSignatureVisitor msv = new MethodSignatureVisitor();
+            cr.accept(msv, true);
+            is.close();
+
+            MethodSignature[] methodsSign = msv.getMethods();
+
+            ClassWriter cw = new ClassWriter(true);
+
+            // Create the class
+            className = className.replace('.', '/');
+            createClass(cw, className, contractName);
+
+            // Inject fields inside the POJO
+            injectFields(cw, fields);
+
+            // Inject a constructor <INIT>()V
+            MethodVisitor cst = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+            cst.visitVarInsn(ALOAD, 0);
+            cst.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
+            cst.visitInsn(RETURN);
+            cst.visitMaxs(0, 0);
+            cst.visitEnd();
+
+            for (int i = 0; i < methodsSign.length; ++i) {
+                MethodSignature method = methodsSign[i];
+
+                // Get the field for this method
+                // 1) find the MethodMetadata
+                FieldMetadata delegator = null; // field to delegate
+                MethodMetadata methodDelegator = null; // field to delegate
+                for (int j = 0; j < methods.size(); j++) {
+                    MethodMetadata methodMeta = (MethodMetadata) methods.get(j);
+                    if (methodMeta.equals(method)) {
+                        delegator = methodMeta.getDelegation();
+                        methodDelegator = methodMeta;
+                    }
+                }
+
+                generateOneMethod(cw, className, methodDelegator, method, delegator);
+
+            }
+
+            // End process
+            cw.visitEnd();
+            b = cw.toByteArray();
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        // Write the class :
+//        try {
+//            FileOutputStream fos = new FileOutputStream(
+//                    "F:\\dev\\workspaces\\iPOJO_dev\\Test_Manipulator\\manipulated\\org\\apache\\felix\\ipojo\\test\\scenarios\\component\\"
+//                            + className.replace('/', '.') + ".class");
+//
+//            fos.write(b);
+//
+//            fos.close();
+//        } catch (Exception e) {
+//            System.err.println("Exception : " + e.getMessage());
+//        }
+
+        return b;
+    }
+
+    /**
+     * Generate on method.
+     * @param cw : class writer
+     * @param className : the current class name
+     * @param method : the method to generate
+     * @param sign : method signature to generate
+     * @param delegator : the field on which delegate
+     */
+    private static void generateOneMethod(ClassWriter cw, String className, MethodMetadata
method, MethodSignature sign, FieldMetadata delegator) {
+        String desc = sign.getDesc();
+        String name = sign.getName();
+        String signa = sign.getSignature();
+        String[] exc = sign.getException();
+
+        MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, name, desc, signa, exc);
+
+        if (delegator.isOptional()) {
+            if (!delegator.isAggregate()) {
+                generateOptionalCase(mv, delegator, className);
+            }
+            if (delegator.isAggregate() /*&& method.getPolicy() == MethodMetadata.ONE_POLICY*/)
{
+                generateOptionalAggregateCase(mv, delegator, className);
+            }
+        }
+
+        if (!delegator.isAggregate()) {
+            mv.visitVarInsn(ALOAD, 0);
+            mv.visitFieldInsn(GETFIELD, className, delegator.getName(), "L" + delegator.getSpecification().getName().replace('.',
'/') + ";");
+
+            // Loads args
+            Type[] args = Type.getArgumentTypes(desc);
+            for (int i = 0; i < args.length; i++) {
+                writeLoad(args[i], i + 1, mv);
+            }
+
+            // Invoke
+            mv.visitMethodInsn(INVOKEINTERFACE, delegator.getSpecification().getName().replace('.',
'/'), name, desc);
+
+            // Return
+            writeReturn(Type.getReturnType(desc), mv);
+        } else {
+            if (method.getPolicy() == MethodMetadata.ONE_POLICY) {
+                // Aggregate and One Policy
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, className, delegator.getName(), "[L" + delegator.getSpecification().getName().replace('.',
'/') + ";");
+                mv.visitInsn(ICONST_0); // Take the first one
+                mv.visitInsn(AALOAD);
+
+                // Loads args
+                Type[] args = Type.getArgumentTypes(desc);
+                for (int i = 0; i < args.length; i++) {
+                    writeLoad(args[i], i + 1, mv);
+                }
+
+                // Invoke
+                mv.visitMethodInsn(INVOKEINTERFACE, delegator.getSpecification().getName().replace('.',
'/'), name, desc);
+
+                // Return
+                writeReturn(Type.getReturnType(desc), mv);
+            } else { // All policy
+                if (Type.getReturnType(desc).getSort() != Type.VOID) {
+                    System.err.println("All policy cannot be used on method which does not
return void");
+                }
+
+                Type[] args = Type.getArgumentTypes(desc);
+                int index = args.length + 1;
+
+                // Init
+                mv.visitInsn(ICONST_0);
+                mv.visitVarInsn(ISTORE, index);
+                Label l1b = new Label();
+                mv.visitLabel(l1b);
+                Label l2b = new Label();
+                mv.visitJumpInsn(GOTO, l2b);
+
+                // Loop
+                Label l3b = new Label();
+                mv.visitLabel(l3b);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, className, delegator.getName(), "[L" + delegator.getSpecification().getName().replace('.',
'/') + ";");
+                mv.visitVarInsn(ILOAD, index);
+                mv.visitInsn(AALOAD);
+
+                // Loads args
+                for (int i = 0; i < args.length; i++) {
+                    writeLoad(args[i], i + 1, mv);
+                }
+
+                mv.visitMethodInsn(INVOKEINTERFACE, delegator.getSpecification().getName().replace('.',
'/'), name, desc);
+
+                Label l4b = new Label();
+                mv.visitLabel(l4b);
+                mv.visitIincInsn(index, 1); // i++;
+
+                // Condition
+                mv.visitLabel(l2b);
+                mv.visitVarInsn(ILOAD, index);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, className, delegator.getName(), "[L" + delegator.getSpecification().getName().replace('.',
'/') + ";");
+                mv.visitInsn(ARRAYLENGTH);
+                mv.visitJumpInsn(IF_ICMPLT, l3b);
+
+                Label l5b = new Label();
+                mv.visitLabel(l5b);
+                mv.visitInsn(RETURN);
+            }
+        }
+
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+
+    /**
+     * Generate Optional Case for aggregate field.
+     * @param mv : method visitor
+     * @param delegator : Field on which delegate
+     * @param className : current class name
+     */
+    private static void generateOptionalAggregateCase(MethodVisitor mv, FieldMetadata delegator,
String className) {
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, className, delegator.getName(), "[L" + delegator.getSpecification().getName().replace('.',
'/') + ";");
+        mv.visitInsn(ARRAYLENGTH);
+        Label l1a = new Label();
+        mv.visitJumpInsn(IFNE, l1a);
+        Label l2a = new Label();
+        mv.visitLabel(l2a);
+        mv.visitTypeInsn(NEW, "java/lang/UnsupportedOperationException");
+        mv.visitInsn(DUP);
+        mv.visitLdcInsn("Operation not supported");
+        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>",
"(Ljava/lang/String;)V");
+        mv.visitInsn(ATHROW);
+        mv.visitLabel(l1a);
+    }
+
+    /**
+     * Generate Optional case for non aggregate fields.
+     * 
+     * @param mv : the method visitor
+     * @param delegator : the field on which delegate.
+     * @param className : the name of the current class.
+     */
+    private static void generateOptionalCase(MethodVisitor mv, FieldMetadata delegator, String
className) {
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, className, delegator.getName(), "L" + delegator.getSpecification().getName().replace('.',
'/') + ";");
+        mv.visitTypeInsn(INSTANCEOF, "org/apache/felix/ipojo/Nullable");
+        Label end = new Label();
+        mv.visitJumpInsn(IFEQ, end);
+        Label begin = new Label();
+        mv.visitLabel(begin);
+        mv.visitTypeInsn(NEW, "java/lang/UnsupportedOperationException");
+        mv.visitInsn(DUP);
+        mv.visitLdcInsn("Operation not supported");
+        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>",
"(Ljava/lang/String;)V");
+        mv.visitInsn(ATHROW);
+        mv.visitLabel(end);
+    }
+
+    /**
+     * Write a return instruction according to the given type.
+     * @param t : the type
+     * @param mv : the method visitor
+     */
+    private static void writeReturn(Type t, MethodVisitor mv) {
+        switch (t.getSort()) {
+            case Type.BOOLEAN:
+            case Type.INT:
+            case Type.BYTE:
+            case Type.CHAR:
+            case Type.SHORT:
+                // Integer or Boolean : return 0 ( false)
+                mv.visitInsn(IRETURN);
+                break;
+            case Type.LONG:
+                // mv.visitInsn(LCONST_0);
+                mv.visitInsn(LRETURN);
+                break;
+            case Type.DOUBLE:
+                // Double : return 0.0
+                // mv.visitInsn(DCONST_0);
+                mv.visitInsn(DRETURN);
+                break;
+            case Type.FLOAT:
+                // Double : return 0.0
+                // mv.visitInsn(DCONST_0);
+                mv.visitInsn(FRETURN);
+                break;
+            case Type.ARRAY:
+            case Type.OBJECT:
+                // Return always null for array and object
+                // mv.visitInsn(ACONST_NULL);
+                mv.visitInsn(ARETURN);
+                break;
+            case Type.VOID:
+                mv.visitInsn(RETURN);
+                break;
+            default:
+                System.err.println("Type not yet managed : " + t);
+                break;
+        }
+    }
+
+    /**
+     * Write a load instruction according to the given type.
+     * @param t : the type
+     * @param mv : the method visitor
+     * @param index : variable name (index)
+     */
+    private static void writeLoad(Type t, int index, MethodVisitor mv) {
+        switch (t.getSort()) {
+            case Type.BOOLEAN:
+            case Type.INT:
+            case Type.BYTE:
+            case Type.CHAR:
+            case Type.SHORT:
+                // Integer or Boolean : return 0 ( false)
+                mv.visitVarInsn(ILOAD, index);
+                break;
+            case Type.LONG:
+                // mv.visitInsn(LCONST_0);
+                mv.visitVarInsn(LLOAD, index);
+                break;
+            case Type.FLOAT:
+                // mv.visitInsn(LCONST_0);
+                mv.visitVarInsn(FLOAD, index);
+                break;
+            case Type.DOUBLE:
+                // Double : return 0.0
+                // mv.visitInsn(DCONST_0);
+                mv.visitVarInsn(DLOAD, index);
+                break;
+            case Type.ARRAY:
+            case Type.OBJECT:
+                // Return always null for array and object
+                // mv.visitInsn(ACONST_NULL);
+                mv.visitVarInsn(ALOAD, index);
+                break;
+            default:
+                System.err.println("Type not yet managed : " + t);
+                break;
+        }
+    }
+
+}

Propchange: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/POJOWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/PreprocessClassAdapter.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/PreprocessClassAdapter.java?view=auto&rev=530141
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/PreprocessClassAdapter.java
(added)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/PreprocessClassAdapter.java
Wed Apr 18 12:47:57 2007
@@ -0,0 +1,661 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.composite.service.provides.manipulation;
+
+import org.objectweb.asm.ClassAdapter;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+
+/**
+ * Manipulate the class. - Add a component manager field (_cm) - Create getter
+ * and setter for each fields - Store information about field - Store
+ * information about implemented interfaces - Change GETFIELD and PUTFIELD to
+ * called the getter and setter method
+ * 
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ * 
+ */
+public class PreprocessClassAdapter extends ClassAdapter implements Opcodes {
+
+    /**
+     * Constant : POJO interface.
+     */
+    private static final String POJO_INTERFACE = "org/apache/felix/ipojo/Pojo";
+
+    /**
+     * The owner. m_owner : String
+     */
+    private String m_owner;
+
+    /**
+     * Constructor.
+     * 
+     * @param cv : Class visitor
+     */
+    public PreprocessClassAdapter(final ClassVisitor cv) {
+        super(cv);
+    }
+
+    /**
+     * The visit method. - Insert the _cm field - Create the _initialize method -
+     * Create the _cm setter method
+     * 
+     * @see org.objectweb.asm.ClassVisitor#visit(int, int, String, String,
+     * String, String[])
+     * @param version : Version
+     * @param access : Access modifier
+     * @param name : name of the visited element
+     * @param signature : singature of the visited element
+     * @param superName : superclasses (extend clause)
+     * @param interfaces : implement clause
+     */
+    public void visit(final int version, final int access, final String name, final String
signature, final String superName, final String[] interfaces) {
+
+        m_owner = name;
+
+        // Insert _cm field
+        FieldVisitor fv = super.visitField(ACC_PRIVATE, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;",
null, null);
+        fv.visitEnd();
+
+        // Create the _cmSetter(ComponentManager cm) method
+        createComponentManagerSetter();
+
+        // Add the getComponentInstance
+        createGetComponentInstanceMethod();
+
+        // Add the POJO interface to the interface list
+        // Check that the POJO interface isnot already in the list
+        boolean found = false;
+        for (int i = 0; i < interfaces.length; i++) {
+            if (interfaces[i].equals(POJO_INTERFACE)) {
+                found = true;
+            }
+        }
+        String[] itfs;
+        if (!found) {
+            itfs = new String[interfaces.length + 1];
+            for (int i = 0; i < interfaces.length; i++) {
+                itfs[i] = interfaces[i];
+            }
+            itfs[interfaces.length] = POJO_INTERFACE;
+        } else {
+            itfs = interfaces;
+        }
+
+        String str = "";
+        for (int i = 0; i < itfs.length; i++) {
+            str += itfs[i] + " ";
+        }
+
+        super.visit(version, access, name, signature, superName, itfs);
+    }
+
+    /**
+     * visit method method :-).
+     * 
+     * @see org.objectweb.asm.ClassVisitor#visitMethod(int, java.lang.String,
+     * java.lang.String, java.lang.String, java.lang.String[])
+     * @param access : access modifier
+     * @param name : name of the method
+     * @param desc : descriptor of the method
+     * @param signature : signature of the method
+     * @param exceptions : exception launched by the method
+     * @return MethodVisitor
+     */
+    public MethodVisitor visitMethod(final int access, final String name, final String desc,
final String signature, final String[] exceptions) {
+        // The method is a constructor, adapt the constructor to add a
+        // ComponentManager argument
+        if (name.equals("<init>")) {
+            // 1) change the constructor descriptor (add a component manager arg
+            // as first argument)
+            String newDesc = desc.substring(1);
+            newDesc = "(Lorg/apache/felix/ipojo/InstanceManager;" + newDesc;
+
+            // Insert the new constructor
+            MethodVisitor mv = super.visitMethod(ACC_PUBLIC, "<init>", newDesc, null,
null);
+
+            if (mv == null) {
+                return null;
+            } else {
+                return new ConstructorCodeAdapter(mv, m_owner);
+            }
+
+        } else {
+            MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
+            if (mv == null) {
+                return null;
+            } else {
+                return new PreprocessCodeAdapter(mv, m_owner);
+            }
+        }
+
+    }
+
+    /**
+     * Create the setter method for the _cm field.
+     */
+    private void createComponentManagerSetter() {
+        MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, "_setComponentManager", "(Lorg/apache/felix/ipojo/InstanceManager;)V",
null, null);
+
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitVarInsn(ALOAD, 1);
+        mv.visitFieldInsn(PUTFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
+
+        mv.visitInsn(RETURN);
+
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+
+    /**
+     * Create the getComponentInstance method.
+     */
+    private void createGetComponentInstanceMethod() {
+        MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "getComponentInstance", "()Lorg/apache/felix/ipojo/ComponentInstance;",
null, null);
+
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
+        mv.visitInsn(ARETURN);
+
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+
+    /**
+     * visit Field method.
+     * 
+     * @see org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String,
+     * java.lang.String, java.lang.String, java.lang.Object)
+     * @param access : acces modifier
+     * @param name : name of the field
+     * @param desc : description of the field
+     * @param signature : signature of the field
+     * @param value : value of the field
+     * @return FieldVisitor
+     */
+    public FieldVisitor visitField(final int access, final String name, final String desc,
final String signature, final Object value) {
+        if ((access & ACC_STATIC) == 0) {
+            Type type = Type.getType(desc);
+
+            // Keep the field in the code
+            FieldVisitor fv = cv.visitField(access, name, desc, signature, value);
+
+            if (type.getSort() == Type.ARRAY) {
+
+                String gDesc = "()" + desc;
+                createArrayGetter(name, gDesc);
+
+                // Generates setter method
+                String sDesc = "(" + desc + ")V";
+                createArraySetter(name, sDesc);
+
+            } else {
+
+                // Generate the getter method
+                String gDesc = "()" + desc;
+                createSimpleGetter(name, gDesc, type);
+
+                // Generates setter method
+                String sDesc = "(" + desc + ")V";
+                createSimpleSetter(name, sDesc, type);
+            }
+
+            return fv;
+
+        }
+        return super.visitField(access, name, desc, signature, value);
+    }
+
+    /**
+     * Generate a setter method for an array field.
+     * @param name : name of the field.
+     * @param desc : description of the method
+     */
+    private void createArraySetter(String name, String desc) {
+        MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, "_set" + name, desc, null, null);
+
+        String internalType = desc.substring(1);
+        internalType = internalType.substring(0, internalType.length() - 2);
+
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitVarInsn(ALOAD, 1);
+        mv.visitFieldInsn(PUTFIELD, m_owner, name, internalType);
+
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
+        mv.visitLdcInsn(name);
+        mv.visitVarInsn(ALOAD, 1);
+        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "setterCallback",
"(Ljava/lang/String;Ljava/lang/Object;)V");
+
+        mv.visitInsn(RETURN);
+
+        // End
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+
+    /**
+     * Generate a getter method for an array field.
+     * @param name : name of the field.
+     * @param desc : description of the method
+     */
+    private void createArrayGetter(String name, String desc) {
+
+        String methodName = "_get" + name;
+        MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, methodName, desc, null, null);
+
+        String internalType = desc.substring(2);
+
+        mv.visitVarInsn(ALOAD, 0);
+        // mv.visitFieldInsn(GETFIELD, m_owner, name,
+        // "["+type.getInternalName()+";");
+        mv.visitFieldInsn(GETFIELD, m_owner, name, internalType);
+        mv.visitVarInsn(ASTORE, 1);
+
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
+        mv.visitLdcInsn(name);
+        mv.visitVarInsn(ALOAD, 1);
+        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "getterCallback",
+                "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+        mv.visitVarInsn(ASTORE, 2);
+
+        mv.visitVarInsn(ALOAD, 2);
+        mv.visitTypeInsn(CHECKCAST, internalType);
+        mv.visitVarInsn(ASTORE, 3);
+
+        Label l3a = new Label();
+        mv.visitLabel(l3a);
+
+        mv.visitVarInsn(ALOAD, 1);
+        Label l4a = new Label();
+        mv.visitJumpInsn(IFNULL, l4a);
+        mv.visitVarInsn(ALOAD, 1);
+        mv.visitVarInsn(ALOAD, 3);
+        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z");
+
+        Label l5a = new Label();
+        mv.visitJumpInsn(IFNE, l5a);
+        mv.visitLabel(l4a);
+
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitVarInsn(ALOAD, 3);
+        mv.visitMethodInsn(INVOKEVIRTUAL, m_owner, "_set" + name, "(" + internalType + ")V");
+        mv.visitLabel(l5a);
+
+        mv.visitVarInsn(ALOAD, 3);
+        mv.visitInsn(ARETURN);
+
+        // End
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+
+    /**
+     * Create the getter for service dependency.
+     * 
+     * @param name : field of the dependency
+     * @param desc : description of the getter method
+     * @param type : type to return
+     */
+    private void createSimpleGetter(String name, String desc, Type type) {
+
+        String methodName = "_get" + name;
+        MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, methodName, desc, null, null);
+
+        switch (type.getSort()) {
+            // Generate the getter method for boolean, char, byte shot as for int.
+            case Type.BOOLEAN:
+            case Type.CHAR:
+            case Type.BYTE:
+            case Type.SHORT:
+            case Type.INT:
+                String internalName = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][0];
+                String boxingType = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][1];
+                String unboxingMethod = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][2];
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, name, internalName);
+                mv.visitVarInsn(type.getOpcode(ISTORE), 1);
+                mv.visitTypeInsn(NEW, boxingType);
+                mv.visitInsn(DUP);
+                mv.visitVarInsn(type.getOpcode(ILOAD), 1);
+                mv.visitMethodInsn(INVOKESPECIAL, boxingType, "<init>", "(" + internalName
+ ")V");
+                mv.visitVarInsn(ASTORE, 2);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitLdcInsn(name);
+                mv.visitVarInsn(ALOAD, 2);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager",
"getterCallback",
+                        "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+                mv.visitVarInsn(ASTORE, 3);
+                mv.visitVarInsn(ALOAD, 3);
+                mv.visitTypeInsn(CHECKCAST, boxingType);
+                mv.visitVarInsn(ASTORE, 4);
+                mv.visitVarInsn(ALOAD, 4);
+                mv.visitMethodInsn(INVOKEVIRTUAL, boxingType, unboxingMethod, "()" + internalName);
+                mv.visitVarInsn(type.getOpcode(ISTORE), 5);
+                Label l5 = new Label();
+                mv.visitLabel(l5);
+                mv.visitVarInsn(type.getOpcode(ILOAD), 1);
+                mv.visitVarInsn(type.getOpcode(ILOAD), 5);
+                Label l6 = new Label();
+                mv.visitJumpInsn(type.getOpcode(IF_ICMPEQ), l6);
+                Label l7 = new Label();
+                mv.visitLabel(l7);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitVarInsn(type.getOpcode(ILOAD), 5);
+                mv.visitMethodInsn(INVOKEVIRTUAL, m_owner, "_set" + name, "(" + internalName
+ ")V");
+                mv.visitLabel(l6);
+                mv.visitVarInsn(type.getOpcode(ILOAD), 5);
+                mv.visitInsn(type.getOpcode(IRETURN));
+                break;
+
+            // Generate the getter for long
+            case Type.LONG:
+                internalName = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][0];
+                boxingType = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][1];
+                unboxingMethod = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][2];
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, name, internalName);
+                mv.visitVarInsn(LSTORE, 1);
+                mv.visitTypeInsn(NEW, boxingType);
+                mv.visitInsn(DUP);
+                mv.visitVarInsn(LLOAD, 1);
+                mv.visitMethodInsn(INVOKESPECIAL, boxingType, "<init>", "(" + internalName
+ ")V");
+                mv.visitVarInsn(ASTORE, 3); // Double Space
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitLdcInsn(name);
+                mv.visitVarInsn(ALOAD, 3);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager",
"getterCallback",
+                        "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+                mv.visitVarInsn(ASTORE, 4);
+                mv.visitVarInsn(ALOAD, 4);
+                mv.visitTypeInsn(CHECKCAST, boxingType);
+                mv.visitVarInsn(ASTORE, 5);
+                mv.visitVarInsn(ALOAD, 5);
+                mv.visitMethodInsn(INVOKEVIRTUAL, boxingType, unboxingMethod, "()" + internalName);
+                mv.visitVarInsn(LSTORE, 6);
+                l5 = new Label();
+                mv.visitLabel(l5);
+                mv.visitVarInsn(LLOAD, 1);
+                mv.visitVarInsn(LLOAD, 6);
+                mv.visitInsn(LCMP);
+                l6 = new Label();
+                mv.visitJumpInsn(IFEQ, l6);
+                l7 = new Label();
+                mv.visitLabel(l7);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitVarInsn(LLOAD, 6);
+                mv.visitMethodInsn(INVOKEVIRTUAL, m_owner, "_set" + name, "(" + internalName
+ ")V");
+                mv.visitLabel(l6);
+                mv.visitVarInsn(LLOAD, 6);
+                mv.visitInsn(LRETURN);
+                break;
+
+            // Generate the getter for double
+            case Type.DOUBLE:
+                internalName = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][0];
+                boxingType = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][1];
+                unboxingMethod = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][2];
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, name, internalName);
+                mv.visitVarInsn(DSTORE, 1);
+                mv.visitTypeInsn(NEW, boxingType);
+                mv.visitInsn(DUP);
+                mv.visitVarInsn(DLOAD, 1);
+                mv.visitMethodInsn(INVOKESPECIAL, boxingType, "<init>", "(" + internalName
+ ")V");
+                mv.visitVarInsn(ASTORE, 3); // Double Space
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitLdcInsn(name);
+                mv.visitVarInsn(ALOAD, 3);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager",
"getterCallback",
+                        "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+                mv.visitVarInsn(ASTORE, 4);
+                mv.visitVarInsn(ALOAD, 4);
+                mv.visitTypeInsn(CHECKCAST, boxingType);
+                mv.visitVarInsn(ASTORE, 5);
+                mv.visitVarInsn(ALOAD, 5);
+                mv.visitMethodInsn(INVOKEVIRTUAL, boxingType, unboxingMethod, "()" + internalName);
+                mv.visitVarInsn(DSTORE, 6);
+                l5 = new Label();
+                mv.visitLabel(l5);
+                mv.visitVarInsn(DLOAD, 1);
+                mv.visitVarInsn(DLOAD, 6);
+                mv.visitInsn(DCMPL);
+                l6 = new Label();
+                mv.visitJumpInsn(IFEQ, l6);
+                l7 = new Label();
+                mv.visitLabel(l7);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitVarInsn(DLOAD, 6);
+                mv.visitMethodInsn(INVOKEVIRTUAL, m_owner, "_set" + name, "(" + internalName
+ ")V");
+                mv.visitLabel(l6);
+                mv.visitVarInsn(DLOAD, 6);
+                mv.visitInsn(DRETURN);
+                break;
+
+            // Generate for float.
+            case Type.FLOAT:
+                internalName = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][0];
+                boxingType = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][1];
+                unboxingMethod = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][2];
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, name, internalName);
+                mv.visitVarInsn(FSTORE, 1);
+
+                mv.visitTypeInsn(NEW, boxingType);
+                mv.visitInsn(DUP);
+                mv.visitVarInsn(FLOAD, 1);
+                mv.visitMethodInsn(INVOKESPECIAL, boxingType, "<init>", "(" + internalName
+ ")V");
+                mv.visitVarInsn(ASTORE, 2); // One Space
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitLdcInsn(name);
+                mv.visitVarInsn(ALOAD, 2);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager",
"getterCallback",
+                        "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+                mv.visitVarInsn(ASTORE, 3);
+
+                mv.visitVarInsn(ALOAD, 3);
+                mv.visitTypeInsn(CHECKCAST, boxingType);
+                mv.visitVarInsn(ASTORE, 4);
+
+                mv.visitVarInsn(ALOAD, 4);
+                mv.visitMethodInsn(INVOKEVIRTUAL, boxingType, unboxingMethod, "()" + internalName);
+                mv.visitVarInsn(FSTORE, 5);
+
+                l5 = new Label();
+                mv.visitLabel(l5);
+                
+                mv.visitVarInsn(FLOAD, 1);
+                mv.visitVarInsn(FLOAD, 5);
+                mv.visitInsn(FCMPL);
+                l6 = new Label();
+                mv.visitJumpInsn(IFEQ, l6);
+
+                l7 = new Label();
+                mv.visitLabel(l7);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitVarInsn(FLOAD, 5);
+                mv.visitMethodInsn(INVOKEVIRTUAL, m_owner, "_set" + name, "(" + internalName
+ ")V");
+                mv.visitLabel(l6);
+
+                mv.visitVarInsn(FLOAD, 5);
+                mv.visitInsn(FRETURN);
+
+                break;
+
+            //Generate for array.
+            case Type.OBJECT:
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, name, "L" + type.getInternalName() +
";");
+                mv.visitVarInsn(ASTORE, 1);
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitLdcInsn(name);
+                mv.visitVarInsn(ALOAD, 1);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager",
"getterCallback",
+                        "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
+                mv.visitVarInsn(ASTORE, 2);
+
+                mv.visitVarInsn(ALOAD, 2);
+                mv.visitTypeInsn(CHECKCAST, type.getInternalName());
+                mv.visitVarInsn(ASTORE, 3);
+
+                Label l3b = new Label();
+                mv.visitLabel(l3b);
+
+                mv.visitVarInsn(ALOAD, 1);
+                Label l4b = new Label();
+                mv.visitJumpInsn(IFNULL, l4b);
+                mv.visitVarInsn(ALOAD, 1);
+                mv.visitVarInsn(ALOAD, 3);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z");
+
+                Label l5b = new Label();
+                mv.visitJumpInsn(IFNE, l5b);
+                mv.visitLabel(l4b);
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitVarInsn(ALOAD, 3);
+                mv.visitMethodInsn(INVOKEVIRTUAL, m_owner, "_set" + name, "(L" + type.getInternalName()
+ ";)V");
+                mv.visitLabel(l5b);
+
+                mv.visitVarInsn(ALOAD, 3);
+                mv.visitInsn(ARETURN);
+
+                break;
+
+            default:
+                break;
+        }
+
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+
+    /**
+     * Create the setter method for one property. The name of the method is
+     * _set+name of the field
+     * 
+     * @param name : name of the field representing a property
+     * @param desc : description of the setter method
+     * @param type : type of the property
+     */
+    private void createSimpleSetter(String name, String desc, Type type) {
+        MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, "_set" + name, desc, null, null);
+
+        switch (type.getSort()) {
+            case Type.BOOLEAN:
+            case Type.CHAR:
+            case Type.BYTE:
+            case Type.SHORT:
+            case Type.INT:
+            case Type.FLOAT:
+                String internalName = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][0];
+                String boxingType = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][1];
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitVarInsn(type.getOpcode(ILOAD), 1);
+                mv.visitFieldInsn(PUTFIELD, m_owner, name, internalName);
+                Label l1 = new Label();
+                mv.visitLabel(l1);
+
+                mv.visitTypeInsn(NEW, boxingType);
+                mv.visitInsn(DUP);
+                mv.visitVarInsn(type.getOpcode(ILOAD), 1);
+                mv.visitMethodInsn(INVOKESPECIAL, boxingType, "<init>", "(" + internalName
+ ")V");
+                mv.visitVarInsn(ASTORE, 2);
+
+                Label l2 = new Label();
+                mv.visitLabel(l2);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitLdcInsn(name);
+                mv.visitVarInsn(ALOAD, 2);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager",
"setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
+
+                Label l3 = new Label();
+                mv.visitLabel(l3);
+                mv.visitInsn(RETURN);
+                break;
+
+            case Type.LONG:
+            case Type.DOUBLE:
+                internalName = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][0];
+                boxingType = ManipulationProperty.PRIMITIVE_BOXING_INFORMATION[type.getSort()][1];
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitVarInsn(type.getOpcode(ILOAD), 1);
+                mv.visitFieldInsn(PUTFIELD, m_owner, name, internalName);
+                l1 = new Label();
+                mv.visitLabel(l1);
+
+                mv.visitTypeInsn(NEW, boxingType);
+                mv.visitInsn(DUP);
+                mv.visitVarInsn(type.getOpcode(ILOAD), 1);
+                mv.visitMethodInsn(INVOKESPECIAL, boxingType, "<init>", "(" + internalName
+ ")V");
+                mv.visitVarInsn(ASTORE, 3); // Double space
+
+                l2 = new Label();
+                mv.visitLabel(l2);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitLdcInsn(name);
+                mv.visitVarInsn(ALOAD, 3);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager",
"setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
+
+                l3 = new Label();
+                mv.visitLabel(l3);
+                mv.visitInsn(RETURN);
+                break;
+
+            case Type.OBJECT:
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitVarInsn(ALOAD, 1);
+                mv.visitFieldInsn(PUTFIELD, m_owner, name, "L" + type.getInternalName() +
";");
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitLdcInsn(name);
+                mv.visitVarInsn(ALOAD, 1);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager",
"setterCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
+
+                mv.visitInsn(RETURN);
+                break;
+            default:
+                break;
+        }
+
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+}

Propchange: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/PreprocessClassAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/PreprocessCodeAdapter.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/PreprocessCodeAdapter.java?view=auto&rev=530141
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/PreprocessCodeAdapter.java
(added)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/PreprocessCodeAdapter.java
Wed Apr 18 12:47:57 2007
@@ -0,0 +1,73 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.composite.service.provides.manipulation;
+
+import org.objectweb.asm.MethodAdapter;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+/**
+ * Manipulate a method to change all getter and setter on field by invocations on getter
and setter callbacks.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+public class PreprocessCodeAdapter extends MethodAdapter implements Opcodes {
+
+    /**
+     * The owner class of the field. m_owner : String
+     */
+    private String m_owner;
+
+    /**
+     * PropertyCodeAdapter constructor. A new FieldCodeAdapter should be create
+     * for each method visit.
+     * 
+     * @param mv MethodVisitor
+     * @param owner Name of the class
+     */
+    public PreprocessCodeAdapter(final MethodVisitor mv, final String owner) {
+        super(mv);
+        m_owner = owner;
+    }
+
+    /**
+     * Visit Method for Filed instance (GETFIELD).
+     * 
+     * @see org.objectweb.asm.MethodVisitor#visitFieldInsn(int, String, String,
+     * String)
+     * @param opcode : visited operation code
+     * @param owner : owner of the field
+     * @param name : name of the field
+     * @param desc : decriptor of the field
+     */
+    public void visitFieldInsn(final int opcode, final String owner, final String name, final
String desc) {
+        if (owner.equals(m_owner)) {
+            if (opcode == GETFIELD) {
+                String gDesc = "()" + desc;
+                visitMethodInsn(INVOKEVIRTUAL, owner, "_get" + name, gDesc);
+                return;
+            } else if (opcode == PUTFIELD) {
+                String sDesc = "(" + desc + ")V";
+                visitMethodInsn(INVOKESPECIAL, owner, "_set" + name, sDesc);
+                return;
+            }
+        }
+        super.visitFieldInsn(opcode, owner, name, desc);
+    }
+
+}

Propchange: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/composite/service/provides/manipulation/PreprocessCodeAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message