felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r602120 [2/2] - in /felix/sandbox/clement/ipojo: ./ annotations/ ant/ arch/ core/ core/src/main/java/org/apache/felix/ipojo/ core/src/main/java/org/apache/felix/ipojo/composite/architecture/ core/src/main/java/org/apache/felix/ipojo/composi...
Date Fri, 07 Dec 2007 15:18:40 GMT
Modified: felix/sandbox/clement/ipojo/event.admin.handler/src/main/java/org/apache/felix/ipojo/handler/event/EventAdminSubscriberHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/event.admin.handler/src/main/java/org/apache/felix/ipojo/handler/event/EventAdminSubscriberHandler.java?rev=602120&r1=602119&r2=602120&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/event.admin.handler/src/main/java/org/apache/felix/ipojo/handler/event/EventAdminSubscriberHandler.java (original)
+++ felix/sandbox/clement/ipojo/event.admin.handler/src/main/java/org/apache/felix/ipojo/handler/event/EventAdminSubscriberHandler.java Fri Dec  7 07:18:37 2007
@@ -33,7 +33,6 @@
 import org.apache.felix.ipojo.parser.ManipulationMetadata;
 import org.apache.felix.ipojo.parser.MethodMetadata;
 import org.apache.felix.ipojo.util.Callback;
-import org.apache.felix.ipojo.util.Logger;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventHandler;
@@ -109,25 +108,24 @@
                         Callback cb = new Callback(methodMetadata, m_manager);
                         eventAdminSubscriberMetadata.setCallback(cb);
                     } else {
-                        log(Logger.WARNING, " EVENT HANDLER SUBSCRIBERS : malformed subscriber : the method " + eventAdminSubscriberMetadata.getCallbackStr() + "(Event myEvent) is not present in the component");
+                        warn(" EVENT HANDLER SUBSCRIBERS : malformed subscriber : the method " + eventAdminSubscriberMetadata.getCallbackStr() + "(Event myEvent) is not present in the component");
                         throw new ConfigurationException("EVENT HANDLER SUBSCRIBERS : malformed subscriber : the method " + eventAdminSubscriberMetadata.getCallbackStr() + "(Event myEvent) is not present in the component");
                     }
                     m_subEvent.add(eventAdminSubscriberMetadata);
                 } else {
-                    log(Logger.WARNING, " EVENT HANDLER SUBSCRIBERS : malformed subscriber !");
+                    warn(" EVENT HANDLER SUBSCRIBERS : malformed subscriber !");
                     throw new ConfigurationException("EVENT HANDLER SUBSCRIBERS : malformed subscriber !");
                 }
             }
-            log(Logger.INFO, " EVENT HANDLER SUBSCRIBERS : Suscribers detected !");
         } else {
-            log(Logger.ERROR, " EVENT HANDLER SUBSCRIBERS : no Suscribers detected !");
+            error(" EVENT HANDLER SUBSCRIBERS : no Suscribers detected !");
             throw new ConfigurationException(" EVENT HANDLER SUBSCRIBERS : no Suscribers detected !");
         }
 
         // if well formed publishers or subscribers found
         if (!m_subEvent.isEmpty()) {
             // register the handler
-            log(Logger.INFO, " EVENT HANDLER SUBSCRIBERS has been configured !");
+            info(" EVENT HANDLER SUBSCRIBERS has been configured !");
         } else {
             return;
         }
@@ -178,8 +176,6 @@
      * @see org.apache.felix.ipojo.Handler#start()
      */
     public void start() {
-        log(Logger.INFO, " EVENT HANDLER SUBSCRIBERS STARTING!!!");
-
         if (!m_subEvent.isEmpty()) {
             // build the topic to listen
             // Topics is a merge of all required topics by subscribers
@@ -199,8 +195,6 @@
 
             // Put the m_topics properties to the good value
             m_topics = topics.split(",");
-
-            log(Logger.INFO, " EVENT HANDLER SUBSCRIBERS : EventHandler registered object: " + this);
         }
     }
 
@@ -249,7 +243,7 @@
                             c.call(new Object[] { event });
                         }
                     } catch (Exception e) {
-                        log(Logger.ERROR, "EVENT HANDLER SUBSCRIBERS CALLBACK error : " + eventSubscriberData.getCallbackStr() + " exception :" + e + " Cause : " + e.getCause());
+                        error("EVENT HANDLER SUBSCRIBERS CALLBACK error : " + eventSubscriberData.getCallbackStr() + " exception :" + e.getMessage());
                         // stop the component :
                         m_manager.setState(InstanceManager.INVALID);
                     }

Modified: felix/sandbox/clement/ipojo/jmx.handler/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/jmx.handler/pom.xml?rev=602120&r1=602119&r2=602120&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/jmx.handler/pom.xml (original)
+++ felix/sandbox/clement/ipojo/jmx.handler/pom.xml Fri Dec  7 07:18:37 2007
@@ -3,7 +3,7 @@
 	<packaging>bundle</packaging>
 	<groupId>org.apache.felix</groupId>
 	<artifactId>org.apache.felix.ipojo.handler.jmx</artifactId>
-	<version>0.7.5-SNAPSHOT</version>
+	<version>0.7.6-SNAPSHOT</version>
 	<name>iPOJO JMX Handler</name>
 
 	<dependencies>
@@ -20,12 +20,12 @@
 		<dependency>
 			<groupId>org.apache.felix</groupId>
 			<artifactId>org.apache.felix.ipojo.metadata</artifactId>
-			<version>0.7.5-SNAPSHOT</version>
+			<version>0.7.6-SNAPSHOT</version>
 		</dependency>
 		<dependency>
 			<groupId>org.apache.felix</groupId>
 			<artifactId>org.apache.felix.ipojo</artifactId>
-			<version>0.7.5-SNAPSHOT</version>
+			<version>0.7.6-SNAPSHOT</version>
 		</dependency>
 	</dependencies>
 

Modified: felix/sandbox/clement/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java?rev=602120&r1=602119&r2=602120&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java (original)
+++ felix/sandbox/clement/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java Fri Dec  7 07:18:37 2007
@@ -208,7 +208,7 @@
         
         if (value == null) {
             try {
-                m_instanceManager.setterCallback(propertyField.getField(), null);
+                m_instanceManager.onSet(null, propertyField.getField(), null);
             } catch (Exception e) {
                 throw new InvalidAttributeValueException(
                         "Cannot set attribute " + name + " to null");
@@ -217,7 +217,7 @@
             if (true /* TODO type.class.isAssignableFrom(value.getClass())*/) {
                 //propertyField.setValue(value);
                 // setValue(attributeField.getField(),null);
-                m_instanceManager.setterCallback(propertyField.getField(), value);
+                m_instanceManager.onSet(null, propertyField.getField(), value);
             } else {
                 throw new InvalidAttributeValueException(
                         "Cannot set attribute " + name + " to a "
@@ -264,7 +264,7 @@
         return resultList;
     }
     /** 
-     * buildMBeanInfo : buil the MBean information on initilisation.
+     * buildMBeanInfo : build the MBean information on initialization.
      * this value don't change after
      */
     private void buildMBeanInfo() {

Modified: felix/sandbox/clement/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java?rev=602120&r1=602119&r2=602120&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java (original)
+++ felix/sandbox/clement/ipojo/jmx.handler/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java Fri Dec  7 07:18:37 2007
@@ -146,8 +146,7 @@
      * start : register the Dynamic Mbean.
      */
     public void start() {
-        
-//      create the corresponding MBean
+        // create the corresponding MBean
         m_MBean = new DynamicMBeanImpl(m_jmxConfigFieldMap, m_instanceManager);
         if (m_serviceRegistration != null) { m_serviceRegistration.unregister(); }
 
@@ -163,7 +162,7 @@
     }
 
     /** 
-     * stop : deregister the Dynamic Mbean.
+     * stop : unregister the Dynamic Mbean.
      */
     public void stop() {
         if (m_serviceRegistration != null) { m_serviceRegistration.unregister(); }
@@ -177,7 +176,7 @@
      * @param fieldName : name of the modified field 
      * @param value     : new value of the field
      */
-    public void setterCallback(String fieldName, Object value) {
+    public void onSet(Object pojo, String fieldName, Object value) {
         // Check if the field is a configurable property
 
         PropertyField propertyField = (PropertyField) m_jmxConfigFieldMap.getPropertyFromField(fieldName);
@@ -197,16 +196,15 @@
      * @param value     : old value of the field
      * @return          : new value of the field
      */
-    public Object getterCallback(String fieldName, Object value) {
-        
+    public Object onGet(Object pojo, String fieldName, Object value) {
         
         // Check if the field is a configurable property
         PropertyField propertyField = (PropertyField) m_jmxConfigFieldMap.getPropertyFromField(fieldName);
         if (propertyField != null) { 
-            m_instanceManager.setterCallback(fieldName, propertyField.getValue());
+            m_instanceManager.onSet(pojo, fieldName, propertyField.getValue());
             return propertyField.getValue();
         }
-        m_instanceManager.setterCallback(fieldName, value);
+        m_instanceManager.onSet(pojo, fieldName, value);
         return value;
     }
     

Modified: felix/sandbox/clement/ipojo/manipulator/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/manipulator/pom.xml?rev=602120&r1=602119&r2=602120&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/manipulator/pom.xml (original)
+++ felix/sandbox/clement/ipojo/manipulator/pom.xml Fri Dec  7 07:18:37 2007
@@ -9,14 +9,14 @@
   <modelVersion>4.0.0</modelVersion>
   <packaging>bundle</packaging>
   <artifactId>org.apache.felix.ipojo.manipulator</artifactId>
-  <version>0.7.5-SNAPSHOT</version>
+  <version>0.7.6-SNAPSHOT</version>
   <name>Apache Felix iPOJO Manipulator</name>
   
   
   <dependencies>
     <dependency>
       <groupId>asm</groupId>
-      <artifactId>asm</artifactId>
+      <artifactId>asm-all</artifactId>
       <version>3.0</version>
     </dependency>
     <dependency>
@@ -33,7 +33,7 @@
     <dependency>
       <groupId>${pom.groupId}</groupId>
       <artifactId>org.apache.felix.ipojo.metadata</artifactId>
-      <version>0.7.5-SNAPSHOT</version>
+      <version>0.7.6-SNAPSHOT</version>
     </dependency>
   </dependencies>
   <build>

Modified: felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java?rev=602120&r1=602119&r2=602120&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java (original)
+++ felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java Fri Dec  7 07:18:37 2007
@@ -23,7 +23,6 @@
 import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
-import org.objectweb.asm.Type;
 import org.objectweb.asm.commons.GeneratorAdapter;
 
 
@@ -48,11 +47,6 @@
      * Set of contained fields.
      */
     private Set m_fields;
-    
-    /**
-     * Constructor description.
-     */
-    private String m_desc;
 
     /** 
      * PropertyCodeAdapter constructor.
@@ -69,7 +63,6 @@
         m_owner = owner;
         m_superDetected = false;
         m_fields = fields;
-        m_desc = desc;
     }
 
 
@@ -89,12 +82,12 @@
         if (m_fields.contains(name) && m_owner.equals(owner)) {
             if (opcode == GETFIELD) {
                 String gDesc = "()" + desc;
-                visitMethodInsn(INVOKEVIRTUAL, owner, "_get" + name, gDesc);
+                visitMethodInsn(INVOKEVIRTUAL, owner, "__get" + name, gDesc);
                 return;
             } else
                 if (opcode == PUTFIELD) {
                     String sDesc = "(" + desc + ")V";
-                    visitMethodInsn(INVOKESPECIAL, owner, "_set" + name, sDesc);
+                    visitMethodInsn(INVOKESPECIAL, owner, "__set" + name, sDesc);
                     return;
                 }
         }
@@ -126,10 +119,6 @@
             // 3) Initialize the field 
             mv.visitMethodInsn(INVOKESPECIAL, m_owner, "_setComponentManager", "(Lorg/apache/felix/ipojo/InstanceManager;)V");
             
-            // Add the entry callback call.
-            methodEntry();
-            
-            // insertion finished   
         } else { 
             mv.visitMethodInsn(opcode, owner, name, desc); 
         }
@@ -197,101 +186,6 @@
     public void visitMaxs(int maxStack, int maxLocals) {
         mv.visitMaxs(maxStack + 1, maxLocals + 2);
     }
-    
-    /**
-     * Visit zero argument instruction.
-     * This allow to catch RETURN instruction in order to insert the invocation to exit callback.
-     * @param opcode : instruction code
-     * @see org.objectweb.asm.MethodAdapter#visitInsn(int)
-     */
-    public void visitInsn(int opcode) {
-        switch(opcode) {
-            case RETURN:
-                onMethodExit(opcode);
-                break;
-            default :
-                break;
-        }
-        super.visitInsn(opcode);
-    }
-    
-    /**
-     * Method injecting call at the entry of each method.
-     */
-    private void methodEntry() {
-        Type[] args = Type.getArgumentTypes(m_desc);
-        String name = "$init";
-        
-        for (int i = 0; i < args.length; i++) {
-            String cn = args[i].getClassName();
-            if (cn.endsWith("[]")) {
-                cn = cn.replace('[', '$');
-                cn = cn.substring(0, cn.length() - 1);
-            }
-            cn = cn.replace('.', '_');
-            name += cn;
-        }
-
-        String flag = "_M" + name;
-
-        Label l0 = new Label();
-        mv.visitLabel(l0);
-        mv.visitVarInsn(ALOAD, 0);
-        mv.visitFieldInsn(GETFIELD, m_owner, flag, "Z");
-        Label l1 = new Label();
-        mv.visitJumpInsn(IFEQ, l1);
-        mv.visitVarInsn(ALOAD, 0);
-        mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
-        mv.visitLdcInsn(name);
-        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "entryCallback", "(Ljava/lang/String;)V");
-        mv.visitLabel(l1);
-    }
-
-    /**
-     * Method injecting call at the exit of each method.
-     * @param opcode : returned opcode (ARETURN, IRETURN, ATHROW ...)
-     * @see org.objectweb.asm.commons.AdviceAdapter#onMethodExit(int)
-     */
-    protected void onMethodExit(int opcode) {        
-        Type[] args = Type.getArgumentTypes(m_desc);
-        String name = "$init";
-       
-        for (int i = 0; i < args.length; i++) {
-            String cn = args[i].getClassName();
-            if (cn.endsWith("[]")) {
-                cn = cn.replace('[', '$');
-                cn = cn.substring(0, cn.length() - 1);
-            }
-            cn = cn.replace('.', '_');
-            name += cn;
-        }
-
-        String flag = "_M" + name;
-
-        int local = newLocal(Type.getType(Object.class));
-        local++;
-        visitInsn(ACONST_NULL);
-        
-        mv.visitVarInsn(ASTORE, local);
-        mv.visitVarInsn(ALOAD, 0);
-        mv.visitFieldInsn(GETFIELD, m_owner, flag, "Z");
-        Label l5 = new Label();
-        mv.visitJumpInsn(IFEQ, l5);
-        mv.visitVarInsn(ALOAD, 0);
-        mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
-        mv.visitLdcInsn(name);
-        mv.visitVarInsn(ALOAD, local);
-        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "exitCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
-
-        mv.visitLabel(l5);
-    }
-
-
-    /**
-     * Do nothing.
-     * @see org.objectweb.asm.commons.AdviceAdapter#onMethodEnter()
-     */
-    protected void onMethodEnter() { }
 
 }
 

Modified: felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java?rev=602120&r1=602119&r2=602120&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java (original)
+++ felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java Fri Dec  7 07:18:37 2007
@@ -32,6 +32,7 @@
 import org.apache.felix.ipojo.metadata.Element;
 import org.objectweb.asm.ClassReader;
 import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.util.CheckClassAdapter;
 
 /**
  * iPOJO Byte code Manipulator.
@@ -106,8 +107,9 @@
             InputStream is2 = url.openStream();
             ClassReader cr0 = new ClassReader(is2);
             ClassWriter cw0 = new ClassWriter(ClassWriter.COMPUTE_MAXS);
-            PojoAdapter preprocess = new PojoAdapter(cw0, m_fields);
-            cr0.accept(preprocess, ClassReader.SKIP_FRAMES);
+            MethodCreator preprocess = new MethodCreator(cw0, m_fields);
+            CheckClassAdapter ch = new CheckClassAdapter(preprocess);
+            cr0.accept(ch, ClassReader.SKIP_FRAMES);
             is2.close();
 
             try {
@@ -158,7 +160,8 @@
             InputStream is2 = new ByteArrayInputStream(origin);
             ClassReader cr0 = new ClassReader(is2);
             ClassWriter cw0 = new ClassWriter(ClassWriter.COMPUTE_MAXS);
-            PojoAdapter preprocess = new PojoAdapter(cw0, m_fields);
+            CheckClassAdapter ch = new CheckClassAdapter(cw0);
+            MethodCreator preprocess = new MethodCreator(ch, m_fields);
             cr0.accept(preprocess, ClassReader.SKIP_FRAMES);
             is2.close();
             finalWriter = cw0;

Modified: felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java?rev=602120&r1=602119&r2=602120&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java (original)
+++ felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCodeAdapter.java Fri Dec  7 07:18:37 2007
@@ -20,28 +20,21 @@
 
 import java.util.Set;
 
-import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
-import org.objectweb.asm.Type;
-import org.objectweb.asm.commons.AdviceAdapter;
+import org.objectweb.asm.commons.GeneratorAdapter;
 
 /**
  * Insert code calling callbacks at the entry and before the exit of a method.
  * Moreover it replaces all GETFIELD and SETFIELD by getter and setter invocation.
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public class MethodCodeAdapter extends AdviceAdapter implements Opcodes {
+public class MethodCodeAdapter extends GeneratorAdapter implements Opcodes {
 
     /**
      * The owner class of the field. m_owner : String
      */
     private String m_owner;
-
-    /**
-     * Name of the method.
-     */
-    private String m_name;
     
     /**
      * Contained fields.
@@ -60,7 +53,6 @@
     public MethodCodeAdapter(final MethodVisitor mv, final String owner, int access, String name, String desc, Set fields) {
         super(mv, access, name, desc);
         m_owner = owner;
-        m_name = name;
         m_fields = fields;
     }
 
@@ -76,106 +68,15 @@
         if (owner.equals(m_owner) && m_fields.contains(name)) {
             if (opcode == GETFIELD) {
                 String gDesc = "()" + desc;
-                visitMethodInsn(INVOKEVIRTUAL, owner, "_get" + name, gDesc);
+                visitMethodInsn(INVOKEVIRTUAL, owner, "__get" + name, gDesc);
                 return;
             } else if (opcode == PUTFIELD) {
                 String sDesc = "(" + desc + ")V";
-                visitMethodInsn(INVOKESPECIAL, owner, "_set" + name, sDesc);
+                visitMethodInsn(INVOKESPECIAL, owner, "__set" + name, sDesc);
                 return;
             }
         }
         super.visitFieldInsn(opcode, owner, name, desc);
-    }
-
-    /**
-     * Method injecting call at the entry of each method.
-     * @see org.objectweb.asm.commons.AdviceAdapter#onMethodEnter()
-     */
-    protected void onMethodEnter() {
-        Type[] args = Type.getArgumentTypes(methodDesc);
-        String name = m_name;
-        
-        for (int i = 0; i < args.length; i++) {
-            String cn = args[i].getClassName();
-            if (cn.endsWith("[]")) {
-                cn = cn.replace('[', '$');
-                cn = cn.substring(0, cn.length() - 1);
-            }
-            cn = cn.replace('.', '_');
-            name += cn;
-        }
-
-        String flag = "_M" + name;
-
-        Label l0 = new Label();
-        mv.visitLabel(l0);
-        mv.visitVarInsn(ALOAD, 0);
-        mv.visitFieldInsn(GETFIELD, m_owner, flag, "Z");
-        Label l1 = new Label();
-        mv.visitJumpInsn(IFEQ, l1);
-        mv.visitVarInsn(ALOAD, 0);
-        mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
-        mv.visitLdcInsn(name);
-        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "entryCallback", "(Ljava/lang/String;)V");
-        mv.visitLabel(l1);
-    }
-
-    /**
-     * Method injecting call at the exit of each method.
-     * @param opcode : returned opcode (ARETURN, IRETURN, ATHROW ...)
-     * @see org.objectweb.asm.commons.AdviceAdapter#onMethodExit(int)
-     */
-    protected void onMethodExit(int opcode) {
-        Type[] args = Type.getArgumentTypes(methodDesc);
-        String name = m_name;
-       
-        for (int i = 0; i < args.length; i++) {
-            String cn = args[i].getClassName();
-            if (cn.endsWith("[]")) {
-                cn = cn.replace('[', '$');
-                cn = cn.substring(0, cn.length() - 1);
-            }
-            cn = cn.replace('.', '_');
-            name += cn;
-        }
-
-        String flag = "_M" + name;
-
-        int local = newLocal(Type.getType(Object.class));
-        if (opcode == RETURN) {
-            visitInsn(ACONST_NULL);
-        } else if (opcode != ARETURN && opcode != ATHROW) {
-            box(Type.getReturnType(this.methodDesc));
-        }
-        
-        mv.visitVarInsn(ASTORE, local);
-        mv.visitVarInsn(ALOAD, 0);
-        mv.visitFieldInsn(GETFIELD, m_owner, flag, "Z");
-        Label l5 = new Label();
-        mv.visitJumpInsn(IFEQ, l5);
-        mv.visitVarInsn(ALOAD, 0);
-        mv.visitFieldInsn(GETFIELD, m_owner, "_cm", "Lorg/apache/felix/ipojo/InstanceManager;");
-        mv.visitLdcInsn(name);
-        mv.visitVarInsn(ALOAD, local);
-        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "exitCallback", "(Ljava/lang/String;Ljava/lang/Object;)V");
-
-        mv.visitLabel(l5);
-        if (opcode == ARETURN || opcode == ATHROW) {
-            mv.visitVarInsn(ALOAD, local);
-        } else if (opcode != RETURN) {
-            mv.visitVarInsn(ALOAD, local);
-            unbox(Type.getReturnType(this.methodDesc));
-        }
-    }
-
-    /**
-     * Compute max local and max stack size.
-     * @param maxStack : new stack size.
-     * @param maxLocals : max local (do not modified, super will update it automatically).
-     * @see org.objectweb.asm.commons.LocalVariablesSorter#visitMaxs(int, int)
-     */
-    public void visitMaxs(int maxStack, int maxLocals) {
-        super.visitMaxs(maxStack + 1, maxLocals);
     }
 
 }

Added: felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java?rev=602120&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java (added)
+++ felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java Fri Dec  7 07:18:37 2007
@@ -0,0 +1,864 @@
+package org.apache.felix.ipojo.manipulation;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+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;
+import org.objectweb.asm.commons.GeneratorAdapter;
+
+public class MethodCreator extends ClassAdapter implements Opcodes {
+    
+    private final static String PREFIX = "__";
+
+    private final static String POJO = "org/apache/felix/ipojo/Pojo";
+    
+    private final static String CONSTRUCTOR = "__create";
+    
+    public final static String FIELD_FLAG_PREFIX = "__F";
+    
+    public final static String METHOD_FLAG_PREFIX = "__M";
+    
+    public final static String IM_FIELD = "__IM";
+    
+    private final static String ENTRY = "onEntry";
+    
+    private final static String EXIT = "onExit";
+    
+    private final static String ERROR = "onError";
+    
+    private final static String GET = "onGet";
+    
+    private final static String SET = "onSet";
+    
+    private String m_owner;
+    
+    private Set m_fields;
+    
+    private List m_methods = new ArrayList(); // Contains method id.
+
+    public MethodCreator(ClassVisitor arg0, Map fields) {
+        super(arg0);
+        m_fields = fields.keySet();
+    }
+    
+    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
+        m_owner = name;
+        addPOJOInterface(version, access, name, signature, superName, interfaces);
+        addCMField();
+    }
+    
+    public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
+        // Avoid manipulating special methods
+        if (name.equals("<clinit>") || name.equals("class$")) { return super.visitMethod(access, name, desc, signature, exceptions); }
+        // The constructor is manipulated separately
+        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;
+                        
+            Type[] args = Type.getArgumentTypes(desc);
+            if (args.length == 0) {
+                generateEmptyConstructor();
+            } else {
+                generateBCConstructor(access, name, desc, signature, exceptions);
+            }
+            
+            // Insert the new constructor
+            MethodVisitor mv = super.visitMethod(access, "<init>", newDesc, signature, exceptions);
+            return new ConstructorCodeAdapter(mv, m_owner, m_fields, access, name, newDesc);
+        }
+        
+        if ((access & ACC_STATIC) == ACC_STATIC) { return super.visitMethod(access, name, desc, signature, exceptions); }
+        
+        generateVoidMethod(access, name, desc, signature, exceptions);
+        FieldVisitor flagField = cv.visitField(Opcodes.ACC_PRIVATE, generateMethodFlag(name, desc), "Z", null, null);
+        flagField.visitEnd();
+
+        MethodVisitor mv = super.visitMethod(access, PREFIX + name, desc, signature, exceptions);
+        return new MethodCodeAdapter(mv, m_owner, access, PREFIX + name, desc, m_fields);
+    }
+    
+    /**
+     * Visit a Field.
+     * Inject the getter and the setter method for this field.
+     * @see org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)
+     * @param access : access 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 : null
+     */
+    public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) {
+        if ((access & ACC_STATIC) == 0) {
+            FieldVisitor flag = cv.visitField(Opcodes.ACC_PRIVATE, FIELD_FLAG_PREFIX + name, "Z", null, null);
+            flag.visitEnd();
+            
+            Type type = Type.getType(desc);
+
+            if (type.getSort() == Type.ARRAY) {
+                String gDesc = "()" + desc;
+                createArrayGetter(name, gDesc, type);
+
+                // Generates setter method
+                String sDesc = "(" + desc + ")V";
+                createArraySetter(name, sDesc, type);
+
+            } else {
+                // Generate the getter method
+                String gDesc = "()" + desc;
+                createSimpleGetter(name, gDesc, type);
+
+                // Generates setter method
+                String sDesc = "(" + desc + ")V";
+                createSimpleSetter(name, sDesc, type);
+            }
+
+        }
+        return cv.visitField(access, name, desc, signature, value);
+    }
+    
+    private void generateEmptyConstructor() {
+        MethodVisitor mv = cv.visitMethod(ACC_PUBLIC + ACC_STATIC, CONSTRUCTOR, "(Lorg/apache/felix/ipojo/InstanceManager;)Ljava/lang/Object;", null, new String[] {"java/lang/Throwable"});
+        mv.visitCode();
+        Label l0 = new Label();
+        Label l1 = new Label();
+        Label l2 = new Label();
+        
+        mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Throwable");
+        
+        mv.visitInsn(ACONST_NULL);
+        mv.visitVarInsn(ASTORE, 1);
+        mv.visitLabel(l0);
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitInsn(ACONST_NULL);
+        mv.visitLdcInsn(generateMethodId("<init>", "()V"));
+        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", ENTRY, "(Ljava/lang/Object;Ljava/lang/String;)V");
+        mv.visitTypeInsn(NEW, m_owner);
+        mv.visitInsn(DUP);
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitMethodInsn(INVOKESPECIAL, m_owner, "<init>", "(Lorg/apache/felix/ipojo/InstanceManager;)V");
+        mv.visitVarInsn(ASTORE, 1);
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitInsn(ACONST_NULL);
+        mv.visitLdcInsn(generateMethodId("<init>", "()V"));
+        mv.visitVarInsn(ALOAD, 1);
+        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", EXIT, "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V");
+        mv.visitLabel(l1);
+        Label l6 = new Label();
+        mv.visitJumpInsn(GOTO, l6);
+        mv.visitLabel(l2);
+
+        mv.visitFrame(Opcodes.F_FULL, 2, new Object[] {"org/apache/felix/ipojo/InstanceManager", "java/lang/Object"}, 1, new Object[] {"java/lang/Throwable"});
+        mv.visitVarInsn(ASTORE, 2);
+  
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitInsn(ACONST_NULL);
+        mv.visitLdcInsn(generateMethodId("<init>", "()V"));
+        mv.visitVarInsn(ALOAD, 2);
+        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", ERROR, "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Throwable;)V");
+       
+        mv.visitVarInsn(ALOAD, 2);
+        mv.visitInsn(ATHROW);
+        mv.visitLabel(l6);
+
+        mv.visitVarInsn(ALOAD, 1);
+        mv.visitInsn(ARETURN);
+        
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+    
+    private void generateBCConstructor(int access, String name, String desc, String signature, String[] exceptions) {
+        MethodVisitor mv = cv.visitMethod(ACC_PUBLIC + ACC_STATIC, CONSTRUCTOR, "(Lorg/apache/felix/ipojo/InstanceManager;Lorg/osgi/framework/BundleContext;)Ljava/lang/Object;", signature, exceptions);
+        mv.visitCode();
+        
+        Label l0 = new Label();
+        Label l1 = new Label();
+        Label l2 = new Label();
+        
+        mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Throwable");
+        
+        mv.visitInsn(ACONST_NULL);
+        mv.visitVarInsn(ASTORE, 2);
+        
+        mv.visitLabel(l0);
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitInsn(ACONST_NULL);
+        mv.visitLdcInsn(generateMethodId("<init>", "()V"));
+        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", ENTRY, "(Ljava/lang/Object;Ljava/lang/String;)V");
+        
+        mv.visitTypeInsn(NEW, m_owner);
+        mv.visitInsn(DUP);
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitVarInsn(ALOAD, 1);
+        mv.visitMethodInsn(INVOKESPECIAL, m_owner, "<init>", "(Lorg/apache/felix/ipojo/InstanceManager;Lorg/osgi/framework/BundleContext;)V");
+        mv.visitVarInsn(ASTORE, 2);
+        
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitInsn(ACONST_NULL);
+        mv.visitLdcInsn(generateMethodId("<init>", "()V"));
+        mv.visitVarInsn(ALOAD, 2);
+        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", EXIT, "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V");
+        mv.visitLabel(l1);
+        Label l6 = new Label();
+        mv.visitJumpInsn(GOTO, l6);
+        mv.visitLabel(l2);
+
+        mv.visitVarInsn(ASTORE, 3);
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitInsn(ACONST_NULL);
+        mv.visitLdcInsn(generateMethodId("<init>", "()V"));
+        mv.visitVarInsn(ALOAD, 3);
+        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", ERROR, "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Throwable;)V");
+        mv.visitVarInsn(ALOAD, 3);
+        mv.visitInsn(ATHROW);
+        
+        mv.visitLabel(l6);
+        mv.visitVarInsn(ALOAD, 2);
+        mv.visitInsn(ARETURN);
+        
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+    
+    private void generateVoidMethod(int access, String name, String desc, String signature, String[] exceptions) {
+        MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
+        mv.visitCode();
+        Type returnType = Type.getReturnType(desc);
+        Type[] args = Type.getArgumentTypes(desc);
+        int result = -1;
+        int exception = args.length + 1 ;
+        
+        if(returnType.getSort() != Type.VOID) {
+            result = args.length + 1;
+            exception = args.length + 2;
+        }
+        
+        Label l0 = new Label();
+        Label l1 = new Label();
+        Label l2 = new Label();
+        
+        mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Throwable");
+        
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, m_owner, generateMethodFlag(name, desc), "Z");
+        mv.visitJumpInsn(IFNE, l0);
+
+        mv.visitVarInsn(ALOAD, 0);
+        for(int i = 0; i < args.length; i++) {
+            mv.visitVarInsn(args[i].getOpcode(ILOAD), i+1);
+        }
+        mv.visitMethodInsn(INVOKEVIRTUAL, m_owner, PREFIX+name, desc);
+        mv.visitInsn(returnType.getOpcode(IRETURN));
+        
+        mv.visitLabel(l0);
+        
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitLdcInsn(generateMethodId(name, desc));
+        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", ENTRY, "(Ljava/lang/Object;Ljava/lang/String;)V");
+        
+        mv.visitVarInsn(ALOAD, 0);
+        for(int i = 0; i < args.length; i++) {
+            mv.visitVarInsn(args[i].getOpcode(ILOAD), i+1);
+        }
+        mv.visitMethodInsn(INVOKEVIRTUAL, m_owner, PREFIX+name, desc);
+        
+        
+        if(returnType.getSort() != Type.VOID) {
+            mv.visitVarInsn(returnType.getOpcode(ISTORE), result);
+        }
+        
+            mv.visitVarInsn(ALOAD, 0);
+            mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+            mv.visitVarInsn(ALOAD, 0);
+            mv.visitLdcInsn(generateMethodId(name, desc));
+            if(returnType.getSort() != Type.VOID) {
+                GeneratorAdapter gen = new GeneratorAdapter(mv,access, name, desc);
+                mv.visitVarInsn(returnType.getOpcode(ILOAD), result);
+                gen.box(returnType);
+            } else {
+                mv.visitInsn(ACONST_NULL);
+            }
+            mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", EXIT, "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V");
+            
+            mv.visitLabel(l1);
+            Label l7 = new Label();
+            mv.visitJumpInsn(GOTO, l7);
+            mv.visitLabel(l2);
+            
+            mv.visitVarInsn(ASTORE, exception);
+            mv.visitVarInsn(ALOAD, 0);
+            mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+            mv.visitVarInsn(ALOAD, 0);
+            mv.visitLdcInsn(generateMethodId(name, desc));
+            mv.visitVarInsn(ALOAD, exception);
+            mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", ERROR, "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Throwable;)V");
+            mv.visitVarInsn(ALOAD, exception);
+            mv.visitInsn(ATHROW);
+        
+        mv.visitLabel(l7);
+        if(returnType.getSort() != Type.VOID) {
+            mv.visitVarInsn(returnType.getOpcode(ILOAD), result);
+        }
+        mv.visitInsn(returnType.getOpcode(IRETURN));
+        
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+
+    private String generateMethodFlag(String name, String desc) {
+       return METHOD_FLAG_PREFIX + generateMethodId(name, desc);
+    }
+    
+    private String generateMethodId(String name, String desc) {
+       String id = name;
+       Type[] args = Type.getArgumentTypes(desc);
+       for (int i =0; i < args.length; i++) {
+           String arg = args[i].getClassName();
+           if (arg.endsWith("[]")) {
+               arg = arg.substring(0, arg.length() - 2);
+               id+= "$" + arg.replace('.', '_') + "__";
+           } else {
+               id+= "$" + arg.replace('.', '_');
+           }
+       }
+       if (! m_methods.contains(id)) { m_methods.add(id); }
+       return id;
+    }
+    
+    /**
+     * Add the instance manager field (__im).
+     */
+    private void addCMField() {
+        FieldVisitor fv = super.visitField(ACC_PRIVATE, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;", null, null);
+        fv.visitEnd();
+    }
+    
+    /**
+     * Add the POJO interface to the visited class.
+     * @param version : class version
+     * @param access : class access
+     * @param name : class name
+     * @param signature : class signature
+     * @param superName : super class
+     * @param interfaces : implemented interfaces.
+     */
+    private void addPOJOInterface(int version, int access, String name, String signature, String superName, String[] interfaces) {
+
+        // Add the POJO interface to the interface list
+        // Check that the POJO interface is not already in the list
+        boolean found = false;
+        for (int i = 0; i < interfaces.length; i++) {
+            if (interfaces[i].equals(POJO)) {
+                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;
+        } else {
+            itfs = interfaces;
+        }
+
+        String str = "";
+        for (int i = 0; i < itfs.length; i++) {
+            str += itfs[i] + " ";
+        }
+
+        cv.visit(version, access, name, signature, superName, itfs);
+    }
+    
+    /**
+     * Visit end.
+     * Create helper methods.
+     * @see org.objectweb.asm.ClassAdapter#visitEnd()
+     */
+    public void visitEnd() {
+        // Create the component manager setter method
+        createComponentManagerSetter();
+
+        // Add the getComponentInstance
+        createGetComponentInstanceMethod();
+
+        m_methods.clear();
+
+        cv.visitEnd();
+    }
+    
+    /**
+     * 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.visitCode();
+        
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitVarInsn(ALOAD, 1);
+        mv.visitFieldInsn(PUTFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "getRegistredFields", "()Ljava/util/Set;");
+        mv.visitVarInsn(ASTORE, 2);
+
+        mv.visitVarInsn(ALOAD, 2);
+        Label endif = new Label();
+        mv.visitJumpInsn(IFNULL, endif);
+        Iterator it = m_fields.iterator();
+        while (it.hasNext()) {
+            String field = (String) it.next();
+            mv.visitVarInsn(ALOAD, 2);
+            mv.visitLdcInsn(field);
+            mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Set", "contains", "(Ljava/lang/Object;)Z");
+            Label l3 = new Label();
+            mv.visitJumpInsn(IFEQ, l3);
+            mv.visitVarInsn(ALOAD, 0);
+            mv.visitInsn(ICONST_1);
+            mv.visitFieldInsn(PUTFIELD, m_owner, FIELD_FLAG_PREFIX + field, "Z");
+            mv.visitLabel(l3);
+        }
+        mv.visitLabel(endif);
+        
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", "getRegistredMethods", "()Ljava/util/Set;");
+        mv.visitVarInsn(ASTORE, 2);
+        
+        mv.visitVarInsn(ALOAD, 2);
+        Label endif2 = new Label();
+        mv.visitJumpInsn(IFNULL, endif2);
+
+        for (int i = 0; i < m_methods.size(); i++) {
+            String methodId = (String) m_methods.get(i);
+            if(! methodId.equals("<init>")) {
+                mv.visitVarInsn(ALOAD, 2);
+                mv.visitLdcInsn(methodId);
+                mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Set", "contains", "(Ljava/lang/Object;)Z");
+                Label l3 = new Label();
+                mv.visitJumpInsn(IFEQ, l3);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitInsn(ICONST_1);
+                mv.visitFieldInsn(PUTFIELD, m_owner, METHOD_FLAG_PREFIX + methodId, "Z");
+                mv.visitLabel(l3);
+            }
+        }
+        
+        mv.visitLabel(endif2);
+
+        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.visitCode();
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+        mv.visitInsn(ARETURN);
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+    
+    /**
+     * Create a getter method for an array.
+     * @param name : field name
+     * @param desc : method description
+     * @param type : contained type (inside the array)
+     */
+    private void createArraySetter(String name, String desc, Type type) {
+        MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, "__set" + name, desc, null, null);
+        mv.visitCode();
+        
+        String internalType = desc.substring(1);
+        internalType = internalType.substring(0, internalType.length() - 2);
+
+        
+        Label l1 = new Label();
+        mv.visitLabel(l1);
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
+        Label l2 = new Label();
+        mv.visitJumpInsn(IFNE, l2);
+
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitVarInsn(ALOAD, 1);
+        mv.visitFieldInsn(PUTFIELD, m_owner, name, internalType);
+        mv.visitInsn(RETURN);
+        mv.visitLabel(l2);
+
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitLdcInsn(name);
+        mv.visitVarInsn(ALOAD, 1);
+        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", SET, "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V");
+
+        mv.visitInsn(RETURN);
+
+        // End
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+
+    /**
+     * Create a setter method for an array.
+     * @param name : field name
+     * @param desc : method description
+     * @param type : contained type (inside the array)
+     */
+    private void createArrayGetter(String name, String desc, Type type) {
+        String methodName = "__get" + name;
+        MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, methodName, desc, null, null);
+        mv.visitCode();
+        
+        String internalType = desc.substring(2);
+
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
+        Label l1 = new Label();
+        mv.visitJumpInsn(IFNE, l1);
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, m_owner, name, internalType);
+        mv.visitInsn(ARETURN);
+        mv.visitLabel(l1);
+
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitLdcInsn(name);
+        mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", GET, "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;");
+        mv.visitTypeInsn(CHECKCAST, internalType);
+        mv.visitInsn(ARETURN);
+
+        // End
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+
+    /**
+     * Create the getter for a field.
+     * @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);
+        mv.visitCode();
+        
+        switch (type.getSort()) {
+            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];
+
+                Label l0 = new Label();
+                mv.visitLabel(l0);
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
+                Label l1 = new Label();
+                mv.visitJumpInsn(IFNE, l1);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, name, internalName);
+                mv.visitInsn(IRETURN);
+
+                mv.visitLabel(l1);
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitLdcInsn(name);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", GET, "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;");
+                mv.visitVarInsn(ASTORE, 1);
+
+                mv.visitVarInsn(ALOAD, 1);
+                mv.visitTypeInsn(CHECKCAST, boxingType);
+                mv.visitVarInsn(ASTORE, 2);
+
+                mv.visitVarInsn(ALOAD, 2);
+                mv.visitMethodInsn(INVOKEVIRTUAL, boxingType, unboxingMethod, "()" + internalName);
+                mv.visitInsn(type.getOpcode(IRETURN));
+                break;
+
+            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];
+
+                l0 = new Label();
+                mv.visitLabel(l0);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
+                l1 = new Label();
+                mv.visitJumpInsn(IFNE, l1);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, name, internalName);
+                mv.visitInsn(LRETURN);
+                mv.visitLabel(l1);
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitLdcInsn(name);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", GET, "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;");
+                mv.visitVarInsn(ASTORE, 1);
+
+                mv.visitVarInsn(ALOAD, 1);
+                mv.visitTypeInsn(CHECKCAST, boxingType);
+                mv.visitVarInsn(ASTORE, 2);
+
+                mv.visitVarInsn(ALOAD, 2);
+                mv.visitMethodInsn(INVOKEVIRTUAL, boxingType, unboxingMethod, "()" + internalName);
+                mv.visitInsn(LRETURN);
+
+                break;
+
+            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];
+
+                l0 = new Label();
+                mv.visitLabel(l0);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
+                l1 = new Label();
+                mv.visitJumpInsn(IFNE, l1);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, name, internalName);
+                mv.visitInsn(DRETURN);
+                mv.visitLabel(l1);
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitLdcInsn(name);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", GET, "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;");
+                mv.visitVarInsn(ASTORE, 1);
+
+                mv.visitVarInsn(ALOAD, 1);
+                mv.visitTypeInsn(CHECKCAST, boxingType);
+                mv.visitVarInsn(ASTORE, 2);
+
+                mv.visitVarInsn(ALOAD, 2);
+                mv.visitMethodInsn(INVOKEVIRTUAL, boxingType, unboxingMethod, "()" + internalName);
+                mv.visitInsn(DRETURN);
+
+                break;
+
+            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];
+
+                l0 = new Label();
+                mv.visitLabel(l0);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
+                l1 = new Label();
+                mv.visitJumpInsn(IFNE, l1);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, name, internalName);
+                mv.visitInsn(FRETURN);
+                mv.visitLabel(l1);
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitLdcInsn(name);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", GET, "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;");
+                mv.visitVarInsn(ASTORE, 1);
+
+                mv.visitVarInsn(ALOAD, 1);
+                mv.visitTypeInsn(CHECKCAST, boxingType);
+                mv.visitVarInsn(ASTORE, 2);
+
+                mv.visitVarInsn(ALOAD, 2);
+                mv.visitMethodInsn(INVOKEVIRTUAL, boxingType, unboxingMethod, "()" + internalName);
+                mv.visitInsn(FRETURN);
+
+                break;
+
+            case Type.OBJECT:
+                l0 = new Label();
+                mv.visitLabel(l0);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
+                l1 = new Label();
+                mv.visitJumpInsn(IFNE, l1);
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, name, "L" + type.getInternalName() + ";");
+                mv.visitInsn(ARETURN);
+                mv.visitLabel(l1);
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitLdcInsn(name);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", GET, "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;");
+                mv.visitTypeInsn(CHECKCAST, type.getInternalName());
+                mv.visitInsn(ARETURN);
+
+                break;
+
+            default:
+                ManipulationProperty.getLogger().log(ManipulationProperty.SEVERE, "Manipulation problem in " + m_owner + " : a type is not implemented : " + type);
+                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);
+        mv.visitCode();
+        
+        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];
+
+                Label l1 = new Label();
+                mv.visitLabel(l1);
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
+                Label l22 = new Label();
+                mv.visitJumpInsn(IFNE, l22);
+                
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitVarInsn(type.getOpcode(ILOAD), 1);
+                mv.visitFieldInsn(PUTFIELD, m_owner, name, internalName);
+                mv.visitInsn(RETURN);
+                mv.visitLabel(l22);
+
+                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, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitLdcInsn(name);
+                mv.visitVarInsn(ALOAD, 2);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", SET, "(Ljava/lang/Object;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];
+
+                l1 = new Label();
+                mv.visitLabel(l1);
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
+                Label l23 = new Label();
+                mv.visitJumpInsn(IFNE, l23);
+           
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitVarInsn(type.getOpcode(ILOAD), 1);
+                mv.visitFieldInsn(PUTFIELD, m_owner, name, internalName);
+                mv.visitInsn(RETURN);
+                mv.visitLabel(l23);
+
+                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, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitLdcInsn(name);
+                mv.visitVarInsn(ALOAD, 3);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", SET, "(Ljava/lang/Object;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.visitFieldInsn(GETFIELD, m_owner, FIELD_FLAG_PREFIX + name, "Z");
+                Label l24 = new Label();
+                mv.visitJumpInsn(IFNE, l24);
+           
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitVarInsn(ALOAD, 1);
+                mv.visitFieldInsn(PUTFIELD, m_owner, name, "L" + type.getInternalName() + ";");
+                mv.visitInsn(RETURN);
+                mv.visitLabel(l24);
+
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitFieldInsn(GETFIELD, m_owner, IM_FIELD, "Lorg/apache/felix/ipojo/InstanceManager;");
+                mv.visitVarInsn(ALOAD, 0);
+                mv.visitLdcInsn(name);
+                mv.visitVarInsn(ALOAD, 1);
+                mv.visitMethodInsn(INVOKEVIRTUAL, "org/apache/felix/ipojo/InstanceManager", SET, "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V");
+
+                mv.visitInsn(RETURN);
+                break;
+            default:
+                ManipulationProperty.getLogger().log(ManipulationProperty.SEVERE, "Manipulation Error : Cannot create the setter method for the field : " + name + " (" + type + ")");
+                break;
+        }
+
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+
+
+}

Modified: felix/sandbox/clement/ipojo/metadata/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/metadata/pom.xml?rev=602120&r1=602119&r2=602120&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/metadata/pom.xml (original)
+++ felix/sandbox/clement/ipojo/metadata/pom.xml Fri Dec  7 07:18:37 2007
@@ -8,7 +8,7 @@
   <modelVersion>4.0.0</modelVersion>
   <artifactId>org.apache.felix.ipojo.metadata</artifactId>
   <packaging>bundle</packaging>
-  <version>0.7.5-SNAPSHOT</version>
+  <version>0.7.6-SNAPSHOT</version>
   <name>Apache Felix iPOJO Metadata</name>
   <build>
   <plugins>

Modified: felix/sandbox/clement/ipojo/plugin/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/plugin/pom.xml?rev=602120&r1=602119&r2=602120&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/plugin/pom.xml (original)
+++ felix/sandbox/clement/ipojo/plugin/pom.xml Fri Dec  7 07:18:37 2007
@@ -7,7 +7,7 @@
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>maven-ipojo-plugin</artifactId>
-  <version>0.7.5-SNAPSHOT</version>
+  <version>0.7.6-SNAPSHOT</version>
   <name>Apache Felix iPOJO Maven Plugin</name>
   <packaging>maven-plugin</packaging>
   <dependencies>
@@ -39,12 +39,12 @@
     <dependency>
       <groupId>${pom.groupId}</groupId>
       <artifactId>org.apache.felix.ipojo.metadata</artifactId>
-      <version>0.7.5-SNAPSHOT</version>
+      <version>0.7.6-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>${pom.groupId}</groupId>
       <artifactId>org.apache.felix.ipojo.manipulator</artifactId>
-      <version>0.7.5-SNAPSHOT</version>
+      <version>0.7.6-SNAPSHOT</version>
     </dependency>
   </dependencies>
 </project>

Modified: felix/sandbox/clement/ipojo/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/pom.xml?rev=602120&r1=602119&r2=602120&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/pom.xml (original)
+++ felix/sandbox/clement/ipojo/pom.xml Fri Dec  7 07:18:37 2007
@@ -9,7 +9,7 @@
   <modelVersion>4.0.0</modelVersion>
   <artifactId>ipojo</artifactId>
   <name>Apache Felix iPOJO</name>
-  <version>0.7.5-SNAPSHOT</version>
+  <version>0.7.6-SNAPSHOT</version>
   <packaging>pom</packaging>
   <modules>
 	<module>metadata</module>



Mime
View raw message