felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r633138 [6/7] - in /felix/sandbox/clement/ipojo: composite/ composite/src/main/java/org/apache/felix/ipojo/composite/ composite/src/main/java/org/apache/felix/ipojo/composite/architecture/ composite/src/main/java/org/apache/felix/ipojo/comp...
Date Mon, 03 Mar 2008 15:46:43 GMT
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java Mon Mar  3 07:46:27 2008
@@ -43,6 +43,7 @@
 import org.apache.felix.ipojo.parser.ParseException;
 import org.apache.felix.ipojo.parser.ParseUtils;
 import org.apache.felix.ipojo.parser.PojoMetadata;
+import org.apache.felix.ipojo.util.Property;
 import org.osgi.framework.Bundle;
 
 /**
@@ -60,21 +61,21 @@
     /**
      * Add a provided service to the list .
      * 
-     * @param ps : the provided service to add
+     * @param svc : the provided service to add
      */
-    private void addProvidedService(ProvidedService ps) {
+    private void addProvidedService(ProvidedService svc) {
         // Verify that the provided service is not already in the array.
         for (int i = 0; (m_providedServices != null) && (i < m_providedServices.length); i++) {
-            if (m_providedServices[i] == ps) { return; }
+            if (m_providedServices[i] == svc) { return; }
         }
 
         if (m_providedServices.length > 0) {
             ProvidedService[] newPS = new ProvidedService[m_providedServices.length + 1];
             System.arraycopy(m_providedServices, 0, newPS, 0, m_providedServices.length);
-            newPS[m_providedServices.length] = ps;
+            newPS[m_providedServices.length] = svc;
             m_providedServices = newPS;
         } else {
-            m_providedServices = new ProvidedService[] { ps };
+            m_providedServices = new ProvidedService[] { svc };
         }
     }
 
@@ -112,10 +113,11 @@
             }
 
             // Then create the provided service
-            ProvidedService ps = new ProvidedService(this, serviceSpecifications, factory);
+            ProvidedService svc = new ProvidedService(this, serviceSpecifications, factory);
 
             Element[] props = providedServices[i].getElements("Property");
             if (props != null) {
+                //Property[] properties = new Property[props.length];
                 Property[] properties = new Property[props.length];
                 for (int j = 0; j < props.length; j++) {
                     String name = props[j].getAttribute("name");
@@ -123,45 +125,31 @@
                     String type = props[j].getAttribute("type");
                     String field = props[j].getAttribute("field");
 
-                    if (name != null && configuration.get(name) != null && configuration.get(name) instanceof String) {
-                        value = (String) configuration.get(name);
-                    } else {
-                        if (field != null && configuration.get(field) != null && configuration.get(field) instanceof String) {
-                            value = (String) configuration.get(field);
-                        }
-                    }
-
-                    Property prop = new Property(ps, name, field, type, value);
+                    Property prop = new Property(name, field, null, value, type, getInstanceManager(), this);
                     properties[j] = prop;
 
-                    // Check if the instance configuration has a value for this property
-                    Object o = configuration.get(prop.getName());
-                    if (o != null && !(o instanceof String)) {
-                        prop.set(o);
-                    } else {
-                        if (field != null) {
-                            o = configuration.get(field);
-                            if (o != null && !(o instanceof String)) {
-                                prop.set(configuration.get(field));
-                            }
-                        }
+                    // Check if the instance configuration has a value for this property                    
+                    Object object = configuration.get(prop.getName());
+                    if (object != null) {
+                        prop.setValue(object);
                     }
-
+                    
                     if (field != null) {
                         fields.add(new FieldMetadata(field, type));
                     }
                 }
 
                 // Attach to properties to the provided service
-                ps.setProperties(properties);
+                svc.setProperties(properties);
             }
 
-            if (checkProvidedService(ps)) {
-                addProvidedService(ps);
+            if (checkProvidedService(svc)) {
+                addProvidedService(svc);
             } else {
-                String itfs = "";
+                StringBuffer itfs = new StringBuffer();
                 for (int j = 0; j < serviceSpecifications.length; j++) {
-                    itfs = itfs + " " + serviceSpecifications[j];
+                    itfs.append(' ');
+                    itfs.append(serviceSpecifications[j]);
                 }
                 throw new ConfigurationException("[" + getInstanceManager().getInstanceName() + "] The provided service" + itfs + " is not valid");                
             }
@@ -190,8 +178,8 @@
 
         // Look for parent class.
         if (parent != null) {
-            Class cl = bundle.loadClass(parent);
-            collectInterfacesFromClass(cl, result, bundle);
+            Class clazz = bundle.loadClass(parent);
+            collectInterfacesFromClass(clazz, result, bundle);
         }
 
         return result;
@@ -200,78 +188,78 @@
     /**
      * Look for inherited interfaces.
      * @param clazz : interface name to explore (class object)
-     * @param l : set (accumulator)
-     * @param b : bundle
+     * @param acc : set (accumulator)
+     * @param bundle : bundle
      * @throws ClassNotFoundException : occurs when an interface cannot be loaded.
      */
-    private void collectInterfaces(Class clazz, Set l, Bundle b) throws ClassNotFoundException {
+    private void collectInterfaces(Class clazz, Set acc, Bundle bundle) throws ClassNotFoundException {
         Class[] clazzes = clazz.getInterfaces();
         for (int i = 0; i < clazzes.length; i++) {
-            l.add(clazzes[i].getName());
-            collectInterfaces(clazzes[i], l, b);
+            acc.add(clazzes[i].getName());
+            collectInterfaces(clazzes[i], acc, bundle);
         }
     }
     
     /**
      * Collect interfaces for the given class.
      * This method explores super class to.
-     * @param cl : class object.
-     * @param l : set of implemented interface (accumulator)
-     * @param b : bundle.
+     * @param clazz : class object.
+     * @param acc : set of implemented interface (accumulator)
+     * @param bundle : bundle.
      * @throws ClassNotFoundException : occurs if an interface cannot be load.
      */
-    private void collectInterfacesFromClass(Class cl, Set l, Bundle b) throws ClassNotFoundException {
-        Class[] clazzes = cl.getInterfaces();
+    private void collectInterfacesFromClass(Class clazz, Set acc, Bundle bundle) throws ClassNotFoundException {
+        Class[] clazzes = clazz.getInterfaces();
         for (int i = 0; i < clazzes.length; i++) {
-            l.add(clazzes[i].getName());
-            collectInterfaces(clazzes[i], l, b);
+            acc.add(clazzes[i].getName());
+            collectInterfaces(clazzes[i], acc, bundle);
         }
         // Iterate on parent classes
-        Class sup = cl.getSuperclass();
+        Class sup = clazz.getSuperclass();
         if (sup != null) {
-            collectInterfacesFromClass(sup, l, b);
+            collectInterfacesFromClass(sup, acc, bundle);
         }
     }
 
     /**
      * Check the provided service given in argument in the sense that the metadata are consistent.
-     * @param ps : the provided service to check.
+     * @param svc : the provided service to check.
      * @return true if the provided service is correct
      * @throws ConfigurationException : the checked provided service is not correct.
      */
-    private boolean checkProvidedService(ProvidedService ps) throws ConfigurationException {        
-        for (int i = 0; i < ps.getServiceSpecification().length; i++) {
-            String specName = ps.getServiceSpecification()[i];
+    private boolean checkProvidedService(ProvidedService svc) throws ConfigurationException {        
+        for (int i = 0; i < svc.getServiceSpecification().length; i++) {
+            String specName = svc.getServiceSpecification()[i];
             
             // Check service level dependencies
             try {
                 Class spec = getInstanceManager().getFactory().loadClass(specName);
                 Field specField = spec.getField("specification");
-                Object o = specField.get(null);
-                if (o instanceof String) {
-                    Element specification = ManifestMetadataParser.parse((String) o);
+                Object specif = specField.get(null);
+                if (specif instanceof String) {
+                    Element specification = ManifestMetadataParser.parse((String) specif);
                     Element[] deps = specification.getElements("requires");
                     for (int j = 0; deps != null && j < deps.length; j++) {
-                        Dependency d = getAttachedDependency(deps[j]);
-                        if (d != null) {
+                        Dependency dep = getAttachedDependency(deps[j]);
+                        if (dep != null) {
                             // Fix service-level dependency flag
-                            d.setServiceLevelDependency();
+                            dep.setServiceLevelDependency();
                         }
-                        isDependencyCorrect(d, deps[j]);
+                        isDependencyCorrect(dep, deps[j]);
                     }
                 } else {
-                    throw new ConfigurationException("Provides  : The specification field of the service specification " + ps.getServiceSpecification()[i] + " need to be a String");
+                    throw new ConfigurationException("Provides  : The specification field of the service specification " + svc.getServiceSpecification()[i] + " need to be a String");
                 }
             } catch (NoSuchFieldException e) {
                 return true; // No specification field
             } catch (ClassNotFoundException e) {
-                throw new ConfigurationException("Provides  : The service specification " + ps.getServiceSpecification()[i] + " cannot be load");
+                throw new ConfigurationException("Provides  : The service specification " + svc.getServiceSpecification()[i] + " cannot be load");
             } catch (IllegalArgumentException e) {
-                throw new ConfigurationException("Provides  : The field 'specification' of the service specification " + ps.getServiceSpecification()[i] + " is not accessible : " + e.getMessage());
+                throw new ConfigurationException("Provides  : The field 'specification' of the service specification " + svc.getServiceSpecification()[i] + " is not accessible : " + e.getMessage());
             } catch (IllegalAccessException e) {
-                throw new ConfigurationException("Provides  : The field 'specification' of the service specification " + ps.getServiceSpecification()[i] + " is not accessible : " + e.getMessage());
+                throw new ConfigurationException("Provides  : The field 'specification' of the service specification " + svc.getServiceSpecification()[i] + " is not accessible : " + e.getMessage());
             } catch (ParseException e) {
-                throw new ConfigurationException("Provides  :  The field 'specification' of the service specification " + ps.getServiceSpecification()[i] + " does not contain a valid String : " + e.getMessage());
+                throw new ConfigurationException("Provides  :  The field 'specification' of the service specification " + svc.getServiceSpecification()[i] + " does not contain a valid String : " + e.getMessage());
             }
         }
 
@@ -284,20 +272,20 @@
      * @return the Dependency object, null if not found or if the DependencyHandler is not plugged to the instance
      */
     private Dependency getAttachedDependency(Element element) {
-        DependencyHandler dh = (DependencyHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":requires");
-        if (dh == null) { return null; }
+        DependencyHandler handler = (DependencyHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":requires");
+        if (handler == null) { return null; }
 
-        String id = element.getAttribute("id");
-        if (id != null) {
+        String identity = element.getAttribute("id");
+        if (identity != null) {
             // Look for dependency Id
-            for (int i = 0; i < dh.getDependencies().length; i++) {
-                if (dh.getDependencies()[i].getId().equals(id)) { return dh.getDependencies()[i]; }
+            for (int i = 0; i < handler.getDependencies().length; i++) {
+                if (handler.getDependencies()[i].getId().equals(identity)) { return handler.getDependencies()[i]; }
             }
         }
         // If not found or no id, look for a dependency with the same specification
         String requirement = element.getAttribute("specification");
-        for (int i = 0; i < dh.getDependencies().length; i++) {
-            if (dh.getDependencies()[i].getSpecification().equals(requirement)) { return dh.getDependencies()[i]; }
+        for (int i = 0; i < handler.getDependencies().length; i++) {
+            if (handler.getDependencies()[i].getSpecification().equals(requirement)) { return handler.getDependencies()[i]; }
         }
 
         return null;
@@ -339,6 +327,7 @@
      * @see org.apache.felix.ipojo.Handler#stop()
      */
     public void stop() {
+        //Nothing to do.
     }
 
     /**
@@ -346,7 +335,9 @@
      * 
      * @see org.apache.felix.ipojo.Handler#start()
      */
-    public void start() { }
+    public void start() {
+        // Nothing to do.
+    }
 
     /**
      * Setter Callback Method.
@@ -360,18 +351,18 @@
     public void onSet(Object pojo, String fieldName, Object value) {
         // Verify that the field name correspond to a dependency
         for (int i = 0; i < m_providedServices.length; i++) {
-            ProvidedService ps = m_providedServices[i];
+            ProvidedService svc = m_providedServices[i];
             boolean update = false;
-            for (int j = 0; j < ps.getProperties().length; j++) {
-                Property prop = ps.getProperties()[j];
+            for (int j = 0; j < svc.getProperties().length; j++) {
+                Property prop = svc.getProperties()[j];
                 if (fieldName.equals(prop.getField()) && ! prop.getValue().equals(value)) {
                     // it is the associated property
-                    prop.set(value);
+                    prop.setValue(value);
                     update = true;
                 }
             }
             if (update) {
-                ps.update();
+                svc.update();
             }
         }
         // Else do nothing
@@ -389,12 +380,12 @@
      */
     public Object onGet(Object pojo, String fieldName, Object value) {
         for (int i = 0; i < m_providedServices.length; i++) {
-            ProvidedService ps = m_providedServices[i];
-            for (int j = 0; j < ps.getProperties().length; j++) {
-                Property prop = ps.getProperties()[j];
+            ProvidedService svc = m_providedServices[i];
+            for (int j = 0; j < svc.getProperties().length; j++) {
+                Property prop = svc.getProperties()[j];
                 if (fieldName.equals(prop.getField())) {
                     // it is the associated property
-                    return prop.get();
+                    return prop.getValue();
                 }
             }
         }
@@ -459,12 +450,12 @@
         ProvidedServiceHandlerDescription pshd = new ProvidedServiceHandlerDescription(this);
 
         for (int j = 0; j < getProvidedService().length; j++) {
-            ProvidedService ps = getProvidedService()[j];
-            ProvidedServiceDescription psd = new ProvidedServiceDescription(ps.getServiceSpecification(), ps.getState(), ps.getServiceReference());
+            ProvidedService svc = getProvidedService()[j];
+            ProvidedServiceDescription psd = new ProvidedServiceDescription(svc.getServiceSpecification(), svc.getState(), svc.getServiceReference());
 
             Properties props = new Properties();
-            for (int k = 0; k < ps.getProperties().length; k++) {
-                Property prop = ps.getProperties()[k];
+            for (int k = 0; k < svc.getProperties().length; k++) {
+                Property prop = svc.getProperties()[k];
                 if (prop.getValue() != null) {
                     props.put(prop.getName(), prop.getValue().toString());
                 }
@@ -482,33 +473,29 @@
      */
     public void reconfigure(Dictionary dict) {
         for (int j = 0; j < getProvidedService().length; j++) {
-            ProvidedService ps = getProvidedService()[j];
-            Property[] props = ps.getProperties();
+            ProvidedService svc = getProvidedService()[j];
+            Property[] props = svc.getProperties();
             boolean update = false;
             for (int k = 0; k < props.length; k++) {
                 if (dict.get(props[k].getName()) != null) {
                     update = true;
-                    if (dict.get(props[k].getName()) instanceof String) {
-                        props[k].set((String) dict.get(props[k].getName()));
-                    } else {
-                        props[k].set(dict.get(props[k].getName()));
-                    }
+                    props[k].setValue(dict.get(props[k].getName()));
                 }
             }
             if (update) {
-                ps.update();
+                svc.update();
             }
         }
     }
 
     /**
      * Initialize the component type.
-     * @param cd : component type description to populate.
+     * @param desc : component type description to populate.
      * @param metadata : component type metadata.
      * @throws ConfigurationException : occurs when the POJO does not implement any interfaces.
      * @see org.apache.felix.ipojo.Handler#initializeComponentFactory(org.apache.felix.ipojo.architecture.ComponentTypeDescription, org.apache.felix.ipojo.metadata.Element)
      */
-    public void initializeComponentFactory(ComponentTypeDescription cd, Element metadata) throws ConfigurationException {
+    public void initializeComponentFactory(ComponentTypeDescription desc, Element metadata) throws ConfigurationException {
         // Change ComponentInfo
         Element[] provides = metadata.getElements("provides");
         PojoMetadata manipulation = getFactory().getPojoMetadata();
@@ -519,7 +506,7 @@
             String parent = manipulation.getSuperClass();
             Set all = null;
             try {
-                all = computeInterfaces(serviceSpecification, parent, cd.getBundleContext().getBundle());
+                all = computeInterfaces(serviceSpecification, parent, desc.getBundleContext().getBundle());
             } catch (ClassNotFoundException e) {
                 throw new ConfigurationException("A interface cannot be loaded : " + e.getMessage());
             }
@@ -529,32 +516,34 @@
                 List itfs = ParseUtils.parseArraysAsList(serviceSpecificationStr);
                 for (int j = 0; j < itfs.size(); j++) {
                     if (! all.contains(itfs.get(j))) {
-                        throw new ConfigurationException("The specification " + itfs.get(j) + " is not implemented by " + cd.getClassName());
+                        throw new ConfigurationException("The specification " + itfs.get(j) + " is not implemented by " + desc.getClassName());
                     }
                 }
                 all = new HashSet(itfs);
             }
             
-            if (all.size() == 0) {
+            if (all.isEmpty()) {
                 throw new ConfigurationException("Provides  : Cannot instantiate a provided service : no specifications found (no interfaces implemented by the pojo)");
             }
 
-            String specs = null;
+            StringBuffer specs = null;
             Set set = new HashSet(all);
-            Iterator it = set.iterator(); 
-            while (it.hasNext()) {
-                String sp = (String) it.next();
-                cd.addProvidedServiceSpecification(sp);
+            Iterator iterator = set.iterator(); 
+            while (iterator.hasNext()) {
+                String spec = (String) iterator.next();
+                desc.addProvidedServiceSpecification(spec);
                 if (specs == null) {
-                    specs = "{" + sp;
+                    specs = new StringBuffer("{");
+                    specs.append(spec);
                 } else {
-                    specs += "," + sp;
+                    specs.append(',');
+                    specs.append(spec);
                 }
             }
             
-            specs += "}";
+            specs.append('}');
             
-            provides[i].addAttribute(new Attribute("interface", specs)); // Add interface attribute to avoid checking in the configure method
+            provides[i].addAttribute(new Attribute("interface", specs.toString())); // Add interface attribute to avoid checking in the configure method
 
             Element[] props = provides[i].getElements("property");
             for (int j = 0; props != null && j < props.length; j++) {
@@ -573,11 +562,11 @@
                     if (field == null) {
                         throw new ConfigurationException("The property " + name + " has neither type neither field.");
                     }
-                    FieldMetadata fm = manipulation.getField(field);
-                    if (fm == null) {
+                    FieldMetadata fieldMeta = manipulation.getField(field);
+                    if (fieldMeta == null) {
                         throw new ConfigurationException("A declared property was not found in the class : " + field);
                     }
-                    type = fm.getFieldType();
+                    type = fieldMeta.getFieldType();
                     props[j].addAttribute(new Attribute("type", type));
                 }
                 
@@ -588,7 +577,7 @@
                     immutable = true;
                 }
 
-                cd.addProperty(new PropertyDescription(name, type, value, immutable));
+                desc.addProperty(new PropertyDescription(name, type, value, immutable));
             }
         }
     }

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java Mon Mar  3 07:46:27 2008
@@ -40,10 +40,10 @@
 
     /**
      * Constructor.
-     * @param h : handler.
+     * @param handler : handler.
      */
-    public ProvidedServiceHandlerDescription(Handler h) {
-        super(h);
+    public ProvidedServiceHandlerDescription(Handler handler) {
+        super(handler);
     }
 
     /**
@@ -83,17 +83,18 @@
     public Element getHandlerInfo() {
         Element services = super.getHandlerInfo();
         for (int i = 0; i < m_providedServices.length; i++) {
-            Element service = new Element("provides", "");
-            String spec = "[";
+            Element service = new Element("provides", null);
+            StringBuffer spec = new StringBuffer("[");
             for (int j = 0; j < m_providedServices[i].getServiceSpecification().length; j++) {
                 if (j == 0) {
-                    spec += m_providedServices[i].getServiceSpecification()[j];
+                    spec.append(m_providedServices[i].getServiceSpecification()[j]);
                 } else {
-                    spec += ", " + m_providedServices[i].getServiceSpecification()[j];
+                    spec.append(',');
+                    spec.append(m_providedServices[i].getServiceSpecification()[j]);
                 }
             }
-            spec += "]";
-            service.addAttribute(new Attribute("specifications", spec));
+            spec.append(']');
+            service.addAttribute(new Attribute("specifications", spec.toString()));
 
             if (m_providedServices[i].getState() == ProvidedService.REGISTERED) {
                 service.addAttribute(new Attribute("state", "registered"));
@@ -102,12 +103,12 @@
                 service.addAttribute(new Attribute("state", "unregistered"));
             }
             
-            Iterator it = m_providedServices[i].getProperties().keySet().iterator();
-            while (it.hasNext()) {
-                Element prop = new Element("property", "");
-                String k = (String) it.next();
-                prop.addAttribute(new Attribute("name", k));
-                prop.addAttribute(new Attribute("value", m_providedServices[i].getProperties().getProperty(k).toString()));
+            Iterator iterator = m_providedServices[i].getProperties().keySet().iterator();
+            while (iterator.hasNext()) {
+                Element prop = new Element("property", null);
+                String name = (String) iterator.next();
+                prop.addAttribute(new Attribute("name", name));
+                prop.addAttribute(new Attribute("value", m_providedServices[i].getProperties().getProperty(name).toString()));
                 service.addElement(prop);
             }
             services.addElement(service);

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/FieldMetadata.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/FieldMetadata.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/FieldMetadata.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/FieldMetadata.java Mon Mar  3 07:46:27 2008
@@ -62,37 +62,24 @@
     public String getFieldType() { return m_type; }
     
     /**
-     * Get the 'reflective' type of the field.
+     * Get the 'reflective' type of the given type.
      * The reflective type is the type used by the Java Reflection API.
+     * @param type : the type to analyze to find the Java reflective type.
      * @return : the reflective type corresponding to this field.
      */
-    public String getReflectionType() {
+    public static String getReflectionType(String type) {
         // Primitive Array 
-        if (m_type.endsWith("[]") && m_type.indexOf(".") == -1) {
-            String arr = "";
-            for (int i = 0; i < m_type.length(); i++) {
-                if (m_type.charAt(i) == '[') { arr += '['; }
-            }
-            int index = m_type.indexOf('[');
-            String t = m_type.substring(0, index);
-            return arr + getInternalPrimitiveType(t);
+        if (type.endsWith("[]") && type.indexOf('.') == -1) {
+            int index = type.indexOf('[');
+            return '[' + getInternalPrimitiveType(type.substring(0, index));
         }
         // Non-Primitive Array 
-        if (m_type.endsWith("[]") && m_type.indexOf(".") != -1) {
-            String arr = "";
-            for (int i = 0; i < m_type.length(); i++) {
-                if (m_type.charAt(i) == '[') { arr += '['; }
-            }
-            int index = m_type.indexOf('[');
-            String t = m_type.substring(0, index);
-            return arr + "L" + t + ";";
-        }
-        // Simple type 
-        if (!m_type.endsWith("[]")) {
-            return m_type;
+        if (type.endsWith("[]") && type.indexOf('.') != -1) {
+            int index = type.indexOf('[');
+            return "[L" + type.substring(0, index) + ";";
         }
-        
-        return null;
+        // The type is not an array.
+        return type;
     }
     
     /**
@@ -125,7 +112,39 @@
         if (string.equalsIgnoreCase("double")) {
             return "D";
         }
-        System.err.println("No primitive type found for " + string);
+        return null;
+    }
+    
+    /**
+     * Get the iPOJO primitive type from the given primitive class.
+     * @param clazz : a primitive class
+     * @return the primitive type.
+     */
+    public static String getPrimitiveTypeByClass(Class clazz) {
+        if (clazz.equals(Boolean.TYPE)) {
+            return "boolean";
+        }
+        if (clazz.equals(Character.TYPE)) {
+            return "char";
+        }
+        if (clazz.equals(Byte.TYPE)) {
+            return "byte";
+        }
+        if (clazz.equals(Short.TYPE)) {
+            return "short";
+        }
+        if (clazz.equals(Integer.TYPE)) {
+            return "int";
+        }
+        if (clazz.equals(Float.TYPE)) {
+            return "float";
+        }
+        if (clazz.equals(Long.TYPE)) {
+            return "long";
+        }
+        if (clazz.equals(Double.TYPE)) {
+            return "double";
+        }
         return null;
     }
 

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java Mon Mar  3 07:46:27 2008
@@ -34,11 +34,6 @@
 public class ManifestMetadataParser {
 
     /**
-     * Manifest Headers.
-     */
-    private Dictionary m_headers;
-
-    /**
      * Element list.
      */
     private Element[] m_elements = new Element[0];
@@ -52,7 +47,7 @@
         Element[] elems = m_elements[0].getElements();
         List list = new ArrayList();
         for (int i = 0; i < elems.length; i++) {
-            if (! "instance".equals(elems[i].getName())) {
+            if (!"instance".equals(elems[i].getName())) {
                 list.add(elems[i]);
             }
         }
@@ -90,18 +85,18 @@
         if (name != null) {
             dict.put("name", instance.getAttribute("name"));
         }
-        
+
         if (comp == null) {
             throw new ParseException("An instance does not have the 'component' attribute");
         }
-        
+
         dict.put("component", comp);
         Element[] props = instance.getElements("property");
-        
+
         for (int i = 0; props != null && i < props.length; i++) {
             parseProperty(props[i], dict);
         }
-        
+
         return dict;
     }
 
@@ -118,10 +113,8 @@
         if (name == null) {
             throw new ParseException("A property does not have the 'name' attribute");
         }
-        // Final case : the property element has a 'value' attribute
-        if (value != null) {
-            dict.put(prop.getAttribute("name"), prop.getAttribute("value"));
-        } else {
+        //case : the property element has a 'value' attribute
+        if (value == null) {
             // Recursive case
             // Check if there is 'property' element
             Element[] subProps = prop.getElements("property");
@@ -133,6 +126,8 @@
                 parseProperty(subProps[i], dict2);
                 dict.put(name, dict2);
             }
+        } else {
+            dict.put(prop.getAttribute("name"), prop.getAttribute("value"));
         }
     }
 
@@ -142,13 +137,13 @@
      * @param elem : the element to add
      */
     private void addElement(Element elem) {
-        if (m_elements != null) {
+        if (m_elements == null) {
+            m_elements = new Element[] { elem };
+        } else {
             Element[] newElementsList = new Element[m_elements.length + 1];
             System.arraycopy(m_elements, 0, newElementsList, 0, m_elements.length);
             newElementsList[m_elements.length] = elem;
             m_elements = newElementsList;
-        } else {
-            m_elements = new Element[] { elem };
         }
     }
 
@@ -176,19 +171,18 @@
     }
 
     /**
-     * Parse the given dictionnary and create the instance managers.
+     * Parse the given dictionary and create the instance managers.
      * 
      * @param dict : the given headers of the manifest file
      * @throws ParseException : if any error occurs
      */
     public void parse(Dictionary dict) throws ParseException {
-        m_headers = dict;
-        String componentClassesStr = (String) m_headers.get("iPOJO-Components");
+        String componentClassesStr = (String) dict.get("iPOJO-Components");
         // Add the ipojo element inside the element list
         addElement(new Element("iPOJO", ""));
         parseElements(componentClassesStr.trim());
     }
-    
+
     /**
      * Parse the given header and create the instance managers.
      * 
@@ -220,55 +214,59 @@
     /**
      * Parse the given string.
      * 
-     * @param s : the string to parse
+     * @param elems : the string to parse
      */
-    private void parseElements(String s) {
-        char[] string = s.toCharArray();
+    private void parseElements(String elems) {
+        char[] string = elems.toCharArray();
 
         for (int i = 0; i < string.length; i++) {
-            char c = string[i];
+            char current = string[i];
 
-            switch (c) {
+            switch (current) { //NOPMD
                 // Beginning of an attribute.
                 case '$':
-                    String attName = "";
-                    String attValue = "";
-                    String attNs = "";
+                    StringBuffer attName = new StringBuffer();
+                    StringBuffer attValue = new StringBuffer();
+                    StringBuffer attNs = null;
                     i++;
-                    c = string[i];
-                    while (c != '=') {
-                        if (c == ':') {
+                    current = string[i]; // Increment and get the new current char.
+                    while (current != '=') {
+                        if (current == ':') {
                             attNs = attName;
-                            attName = "";
+                            attName = new StringBuffer();
                         } else {
-                            attName = attName + c;
+                            attName.append(current);
                         }
-                        i = i + 1;
-                        c = string[i];
+                        i++;
+                        current = string[i];
                     }
-                    i++; // skip =
-                    i++; // skip "
-                    c = string[i];
-                    while (c != '"') {
-                        attValue = attValue + c;
+                    i = i + 2; // skip ="
+                    current = string[i];
+                    while (current != '"') {
+                        attValue.append(current);
                         i++;
-                        c = string[i];
+                        current = string[i]; // Increment and get the new current char.
                     }
                     i++; // skip "
-                    c = string[i];
+                    current = string[i];
 
-                    Attribute att = new Attribute(attName, attNs, attValue);
+                    Attribute att = null;
+                    if (attNs == null) {
+                        att = new Attribute(attName.toString(), attValue.toString());
+                    } else {
+                        att = new Attribute(attName.toString(), attNs.toString(), attValue.toString());
+                    }
                     m_elements[m_elements.length - 1].addAttribute(att);
                     break;
 
                 // End of an element
                 case '}':
                     Element lastElement = removeLastElement();
-                    if (m_elements.length != 0) {
+                    if (m_elements.length == 0) {
+                        addElement(lastElement);
+                    } else {
                         Element newQueue = m_elements[m_elements.length - 1];
                         newQueue.addElement(lastElement);
-                    } else {
-                        addElement(lastElement);
                     }
                     break;
 
@@ -278,19 +276,19 @@
 
                 // Default case
                 default:
-                    String name = "";
-                    String ns = "";
-                    c = string[i];
-                    while (c != ' ') {
-                        if (c == ':') {
-                            ns = name;
-                            name = "";
+                    StringBuffer name = new StringBuffer();
+                    StringBuffer namespace = null;
+                    current = string[i];
+                    while (current != ' ') {
+                        if (current == ':') {
+                            namespace = name;
+                            name = new StringBuffer();
                             i++;
-                            c = string[i];
+                            current = string[i];
                         } else {
-                            name = name + c;
+                            name.append(current);
                             i++;
-                            c = string[i];
+                            current = string[i]; // Increment and get the new current char.
                         }
                     }
                     // Skip spaces
@@ -298,8 +296,15 @@
                         i = i + 1;
                     }
                     i = i + 1; // skip {
-                    Element elem = new Element(name, ns);
+                    
+                    Element elem = null;
+                    if (namespace == null) {
+                        elem = new Element(name.toString(), null);
+                    } else {
+                        elem = new Element(name.toString(), namespace.toString());
+                    }
                     addElement(elem);
+                    
                     break;
             }
         }

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java Mon Mar  3 07:46:27 2008
@@ -18,6 +18,8 @@
  */
 package org.apache.felix.ipojo.parser;
 
+import java.lang.reflect.Method;
+
 import org.apache.felix.ipojo.metadata.Element;
 
 /**
@@ -27,22 +29,22 @@
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class MethodMetadata {
-    
+
     /**
      * Name of the method.
      */
     private String m_name;
-    
+
     /**
      * Argument type array. 
      */
     private String[] m_arguments = new String[0];
-    
+
     /**
      * Returned type. 
      */
     private String m_return = "void";
-    
+
     /**
      * Constructor.
      * @param metadata : method manipulation element.
@@ -50,37 +52,77 @@
     MethodMetadata(Element metadata) {
         m_name = metadata.getAttribute("name");
         String arg = metadata.getAttribute("arguments");
-        String rt = metadata.getAttribute("return");
+        String result = metadata.getAttribute("return");
         if (arg != null) {
             m_arguments = ParseUtils.parseArrays(arg);
         }
-        if (rt != null) {
-            m_return = rt;
+        if (result != null) {
+            m_return = result;
         }
     }
-    
-    public String getMethodName() { return m_name; }
-    
-    public String[] getMethodArguments() { return m_arguments; }
-    
-    public String getMethodReturn() { return m_return; }
-    
+
+    public String getMethodName() {
+        return m_name;
+    }
+
+    public String[] getMethodArguments() {
+        return m_arguments;
+    }
+
+    public String getMethodReturn() {
+        return m_return;
+    }
+
     /**
      * Get the method unique identifier. For internal usage only.
      * @return the method identifier.
      */
     public String getMethodIdentifier() {
-        String id = m_name;
+        StringBuffer identifier = new StringBuffer(m_name);
         for (int i = 0; i < m_arguments.length; i++) {
             String arg = m_arguments[i];
+            identifier.append('$');
             if (arg.endsWith("[]")) {
                 arg = arg.substring(0, arg.length() - 2);
-                id += "$" + arg.replace('.', '_') + "__";
+                identifier.append(arg.replace('.', '_'));
+                identifier.append("__"); // Replace [] by __
+            } else {
+                identifier.append(arg.replace('.', '_'));
+            }
+        }
+        return identifier.toString();
+    }
+
+    /**
+     * Compute the method id for the given method. 
+     * @param method : Method object.
+     * @return the method id.
+     */
+    public static String computeMethodId(Method method) {
+        StringBuffer identifier = new StringBuffer(method.getName());
+        Class[] args = method.getParameterTypes();
+        for (int i = 0; i < args.length; i++) {
+            identifier.append('$'); // Argument separator.
+            if (args[i].isArray()) {
+                if (args[i].getComponentType().isPrimitive()) {
+                    // Primitive array
+                    identifier.append(FieldMetadata.getPrimitiveTypeByClass(args[i].getComponentType()));
+                } else {
+                    // Object array
+                    identifier.append(args[i].getComponentType().getName().replace('.', '_')); // Replace '.' by '_'
+                }
+                identifier.append("__"); // Add __ (array)
             } else {
-                id += "$" + arg.replace('.', '_');
+                if (args[i].isPrimitive()) {
+                    // Primitive type
+                    identifier.append(FieldMetadata.getPrimitiveTypeByClass(args[i]));
+                } else {
+                    // Object type
+                    identifier.append(args[i].getName().replace('.', '_')); // Replace '.' by '_'
+                }
             }
         }
-        return id;
+        return identifier.toString();
     }
 
 }

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ParseUtils.java Mon Mar  3 07:46:27 2008
@@ -27,7 +27,7 @@
  * 
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public class ParseUtils {
+public final class ParseUtils {
 
     /**
      * Parse the string form of an array as {a, b, c}.
@@ -37,18 +37,13 @@
      */
     public static String[] parseArrays(String str) {
         // Remove { and }
-        if (str.startsWith("{") && str.endsWith("}")) {
-            String m = str.substring(1, str.length() - 1);
+        if (str.charAt(0) == '{' && str.charAt(str.length() - 1) == '}') {
+            String internal = (str.substring(1, str.length() - 1)).trim();
             // Check empty array
-            m = m.trim();
-            if (m.length() == 0) {
+            if (internal.length() == 0) {
                 return new String[0];
             }
-            String[] values = split(m, ",");
-            for (int i = 0; i < values.length; i++) {
-                values[i] = values[i].trim();
-            }
-            return values;
+            return split(internal, ",");
         } else {
             return new String[] { str };
         }
@@ -67,17 +62,18 @@
     /**
      * Split method. 
      * This method is equivalent of the String.split in java 1.4
+     * The result array contains 'trimmed' String
      * @param toSplit : String to split
      * @param separator : separator
      * @return the token array 
      */
     public static String[] split(String toSplit, String separator) {
-        StringTokenizer st = new StringTokenizer(toSplit, separator);
-        String[] result = new String[st.countTokens()];
-        int i = 0;
-        while (st.hasMoreElements()) {
-            result[i] = st.nextToken();
-            i++;
+        StringTokenizer tokenizer = new StringTokenizer(toSplit, separator);
+        String[] result = new String[tokenizer.countTokens()];
+        int index = 0;
+        while (tokenizer.hasMoreElements()) {
+            result[index] = tokenizer.nextToken().trim();
+            index++;
         }
         return result;
     }

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/PojoMetadata.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/PojoMetadata.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/PojoMetadata.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/PojoMetadata.java Mon Mar  3 07:46:27 2008
@@ -60,13 +60,13 @@
         m_super = manip.getAttribute("super");
         Element[] fields = manip.getElements("field");
         for (int i = 0; fields != null && i < fields.length; i++) {
-            FieldMetadata fm = new FieldMetadata(fields[i]);
-            addField(fm);
+            FieldMetadata field = new FieldMetadata(fields[i]);
+            addField(field);
         }
         Element[] methods = manip.getElements("method");
         for (int i = 0; methods != null && i < methods.length; i++) {
-            MethodMetadata fm = new MethodMetadata(methods[i]);
-            addMethod(fm);
+            MethodMetadata method = new MethodMetadata(methods[i]);
+            addMethod(method);
         }
         Element[] itfs = manip.getElements("interface");
         for (int i = 0; itfs != null && i < itfs.length; i++) {
@@ -167,14 +167,13 @@
     public MethodMetadata getMethod(String name, String[] types) {
         for (int i = 0; i < m_methods.length; i++) {
             if (m_methods[i].getMethodName().equalsIgnoreCase(name) && m_methods[i].getMethodArguments().length == types.length) {
-                boolean ok = true;
-                for (int j = 0; j < types.length; j++) {
-                    if (! types[j].equals(m_methods[i].getMethodArguments()[j])) {
-                        ok = false;
+                int argIndex = 0;
+                for (; argIndex < types.length; argIndex++) {
+                    if (! types[argIndex].equals(m_methods[i].getMethodArguments()[argIndex])) {
                         break;
                     }
                 }
-                if (ok) { return m_methods[i]; }
+                if (argIndex == types.length) { return m_methods[i]; } // No mismatch detected.
             }
         }
         return null;
@@ -182,11 +181,11 @@
         
      /**
       * Add a method to the list.
-     * @param mm : Method Metadata to add.
+     * @param method : Method Metadata to add.
      */
-    private void addMethod(MethodMetadata mm) {
+    private void addMethod(MethodMetadata method) {
         for (int i = 0; (m_methods != null) && (i < m_methods.length); i++) {
-            if (m_methods[i] == mm) {
+            if (m_methods[i] == method) {
                 return;
             }
         }
@@ -194,20 +193,20 @@
         if (m_methods.length > 0) {
             MethodMetadata[] newInstances = new MethodMetadata[m_methods.length + 1];
             System.arraycopy(m_methods, 0, newInstances, 0, m_methods.length);
-            newInstances[m_methods.length] = mm;
+            newInstances[m_methods.length] = method;
             m_methods = newInstances;
         } else {
-            m_methods = new MethodMetadata[] { mm };
+            m_methods = new MethodMetadata[] { method };
         }
     }
         
      /**
       * Add a field to the list.
-     * @param mm : the Field Metadata to add.
+     * @param field : the Field Metadata to add.
      */
-    private void addField(FieldMetadata mm) {
+    private void addField(FieldMetadata field) {
         for (int i = 0; (m_fields != null) && (i < m_fields.length); i++) {
-            if (m_fields[i] == mm) {
+            if (m_fields[i] == field) {
                 return;
             }
         }
@@ -215,20 +214,20 @@
         if (m_fields.length > 0) {
             FieldMetadata[] newInstances = new FieldMetadata[m_fields.length + 1];
             System.arraycopy(m_fields, 0, newInstances, 0, m_fields.length);
-            newInstances[m_fields.length] = mm;
+            newInstances[m_fields.length] = field;
             m_fields = newInstances;
         } else {
-            m_fields = new FieldMetadata[] { mm };
+            m_fields = new FieldMetadata[] { field };
         }
     }
         
     /**
      * Add the interface to the list.
-     * @param mm : the interface name to add.
+     * @param itf : the interface name to add.
      */
-    private void addInterface(String mm) {
+    private void addInterface(String itf) {
         for (int i = 0; (m_interfaces != null) && (i < m_interfaces.length); i++) {
-            if (m_interfaces[i] == mm) {
+            if (m_interfaces[i] == itf) {
                 return;
             }
         }
@@ -236,10 +235,10 @@
         if (m_interfaces.length > 0) {
             String[] newInstances = new String[m_interfaces.length + 1];
             System.arraycopy(m_interfaces, 0, newInstances, 0, m_interfaces.length);
-            newInstances[m_interfaces.length] = mm;
+            newInstances[m_interfaces.length] = itf;
             m_interfaces = newInstances;
         } else {
-            m_interfaces = new String[] { mm };
+            m_interfaces = new String[] { itf };
         }
     }
 

Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java Mon Mar  3 07:46:27 2008
@@ -27,11 +27,10 @@
 
 /**
  * A callback allows calling a method on the component instances.
- * 
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class Callback {
-    
+
     /**
      * Method object.
      */
@@ -51,7 +50,7 @@
      * Reference on the instance manager.
      */
     private InstanceManager m_manager;
-    
+
     /**
      * Argument classes.
      */
@@ -59,52 +58,49 @@
 
     /**
      * Callback constructor.
-     * 
      * @param method : the name of the method to call
      * @param args : argument type name
      * @param isStatic : is the method a static method
-     * @param im : the instance manager of the component containing the method
+     * @param manager : the instance manager of the component containing the method
      */
-    public Callback(String method, String[] args, boolean isStatic, InstanceManager im) {
+    public Callback(String method, String[] args, boolean isStatic, InstanceManager manager) {
         m_method = method;
         m_isStatic = isStatic;
-        m_manager = im;
+        m_manager = manager;
         if (args != null) {
             computeArguments(args);
         }
     }
-    
+
     /**
      * Callback constructor.
-     * 
      * @param method : the name of the method to call
      * @param args : argument classes
      * @param isStatic : is the method a static method
-     * @param im : the instance manager of the component containing the method
+     * @param manager : the instance manager of the component containing the method
      */
-    public Callback(String method, Class[] args, boolean isStatic, InstanceManager im) {
+    public Callback(String method, Class[] args, boolean isStatic, InstanceManager manager) {
         m_method = method;
         m_isStatic = isStatic;
-        m_manager = im;
+        m_manager = manager;
         m_args = new String[args.length];
         for (int i = 0; i < args.length; i++) {
             m_args[i] = args[i].getName();
         }
     }
-    
+
     /**
      * Constructor.
-     * @param mm : Method Metadata obtain form manipulation metadata.
-     * @param im : instance manager.
+     * @param method : Method Metadata obtain form manipulation metadata.
+     * @param manager : instance manager.
      */
-    public Callback(MethodMetadata mm, InstanceManager im) {
+    public Callback(MethodMetadata method, InstanceManager manager) {
         m_isStatic = false;
-        m_method = mm.getMethodName();
-        m_manager = im;
-        String[] args = mm.getMethodArguments();
-        computeArguments(args);
+        m_method = method.getMethodName();
+        m_manager = manager;
+        computeArguments(method.getMethodArguments());
     }
-    
+
     /**
      * Compute arguments of the method.
      * @param args : arguments of the method.
@@ -112,84 +108,50 @@
     private void computeArguments(String[] args) {
         m_args = new String[args.length];
         for (int i = 0; i < args.length; i++) {
-            // Primitive Array 
-            if (args[i].endsWith("[]") && args[i].indexOf(".") == -1) {
-                String arr = "";
-                for (int j = 0; j < args[i].length(); j++) {
-                    if (args[i].charAt(j) == '[') { arr += '['; }
-                }
-                int index = args[i].indexOf('[');
-                m_args[i] = arr + FieldMetadata.getInternalPrimitiveType(args[i].substring(0, index));
-            }
-            // Non-Primitive Array 
-            if (args[i].endsWith("[]") && args[i].indexOf(".") != -1) {
-                String arr = "";
-                for (int j = 0; j < args[i].length(); j++) {
-                    if (args[i].charAt(j) == '[') { arr += '['; }
-                }
-                int index = args[i].indexOf('[');
-                m_args[i] = arr + "L" + args[i].substring(0, index) + ";";
-            }
-            // Simple type 
-            if (!args[i].endsWith("[]")) {
-                m_args[i] = args[i];
-            }
+            m_args[i] = FieldMetadata.getReflectionType(args[i]);
         }
     }
-    
+
     /**
-     * Search the method object in the POJO by analyzing present method.
-     * The name of the method and the argument type are checked.
-     * @throws NoSuchMethodException : occurs when the method cannot be found either in the pojo class either in parent classes.
+     * Search the looked method in the given method arrays.
+     * @param methods : method array in which we need to look
+     * @return the method object or null if not found
      */
-    protected void searchMethod() throws NoSuchMethodException {
-        Method[] methods = m_manager.getClazz().getDeclaredMethods();
+    private Method searchMethodInMethodArray(Method[] methods) {
         for (int i = 0; i < methods.length; i++) {
             // First check the method name
             if (methods[i].getName().equals(m_method)) {
                 // Check arguments
                 Class[] clazzes = methods[i].getParameterTypes();
                 if (clazzes.length == m_args.length) { // Test size to avoid useless loop
-                    boolean ok = true;
-                    for (int j = 0; j < m_args.length; j++) {
-                        if (!m_args[j].equals(clazzes[j].getName())) {
-                            ok = false;
+                    int argIndex = 0;
+                    for (; argIndex < m_args.length; argIndex++) {
+                        if (!m_args[argIndex].equals(clazzes[argIndex].getName())) {
                             break;
                         }
                     }
-                    if (ok) {
-                        m_methodObj = methods[i]; // It is the looked method.
-                        break;
-                    } 
+                    if (argIndex == m_args.length) { // No mismatch detected. 
+                        return methods[i]; // It is the looked method.
+                    }
                 }
-
             }
         }
-        
-        if (m_methodObj == null) { //look at parent classes
+        return null;
+    }
+
+    /**
+     * Search the method object in the POJO by analyzing present method. The name of the method and the argument type are checked.
+     * @throws NoSuchMethodException : occurs when the method cannot be found either in the pojo class either in parent classes.
+     */
+    protected void searchMethod() throws NoSuchMethodException {
+        Method[] methods = m_manager.getClazz().getDeclaredMethods();
+        m_methodObj = searchMethodInMethodArray(methods);
+
+        if (m_methodObj == null) { // look at parent classes
             methods = m_manager.getClazz().getMethods();
-            for (int i = 0; i < methods.length; i++) {
-                // First check the method name
-                if (methods[i].getName().equals(m_method)) {
-                    // Check arguments
-                    Class[] clazzes = methods[i].getParameterTypes();
-                    if (clazzes.length == m_args.length) { // Test size to avoid useless loop
-                        boolean ok = true;
-                        for (int j = 0; j < m_args.length; j++) {
-                            if (!m_args[j].equals(clazzes[j].getName())) {
-                                ok = false;
-                                break;
-                            }
-                        }
-                        if (ok) {
-                            m_methodObj = methods[i]; // It is the looked method.
-                            break;
-                        } 
-                    }
-                }
-            }
+            m_methodObj = searchMethodInMethodArray(methods);
         }
-        
+
         if (m_methodObj == null) {
             throw new NoSuchMethodException(m_method);
         } else {
@@ -199,7 +161,6 @@
 
     /**
      * Call the method.
-     * 
      * @return the result of the invocation, null for void method, the last result for multi-object instance
      * @throws NoSuchMethodException : Method is not found in the class
      * @throws InvocationTargetException : The method is not static
@@ -211,7 +172,6 @@
 
     /**
      * Call the current callback method on the instance given in parameter.
-     * 
      * @param instance : instance on which call the callback
      * @return the result of the invocation, null for void method
      * @throws NoSuchMethodException : the method was not found
@@ -224,19 +184,17 @@
 
     /**
      * Call the callback on the method with the argument given in parameter.
-     * 
      * @param arg : the parameters
      * @return the result of the invocation, null for void method, the last result for multi-object instance
      * @throws NoSuchMethodException : the callback method is not found
      * @throws IllegalAccessException : the callback method cannot be called
-     * @throws InvocationTargetException : an error occurs inside the called
-     * method
+     * @throws InvocationTargetException : an error occurs inside the called method
      */
     public Object call(Object[] arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
         if (m_methodObj == null) {
             searchMethod();
         }
-        
+
         if (m_isStatic) {
             return m_methodObj.invoke(null, arg);
         } else {
@@ -246,35 +204,32 @@
             if (m_manager.getPojoObjects() == null) {
                 return m_methodObj.invoke(m_manager.getPojoObject(), arg);
             } else {
-                Object r = null;
+                Object newObject = null;
                 for (int i = 0; i < m_manager.getPojoObjects().length; i++) {
-                    r = m_methodObj.invoke(m_manager.getPojoObjects()[i], arg);
+                    newObject = m_methodObj.invoke(m_manager.getPojoObjects()[i], arg);
                 }
-                return r;
+                return newObject;
             }
         }
     }
 
     /**
-     * Call the callback on the method with the argument given in parameter and
-     * with the arguments given in parameter too.
-     * 
+     * Call the callback on the method with the argument given in parameter and with the arguments given in parameter too.
      * @param instance : instance on which call the callback
      * @param arg : the argument array
      * @return the result of the invocation, null for void method
      * @throws NoSuchMethodException : the callback method is not found
      * @throws IllegalAccessException : the callback method cannot be called
-     * @throws InvocationTargetException : an error occurs inside the called
-     * method
+     * @throws InvocationTargetException : an error occurs inside the called method
      */
     public Object call(Object instance, Object[] arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
         if (m_methodObj == null) {
             searchMethod();
         }
-        
+
         return m_methodObj.invoke(instance, arg);
     }
-    
+
     public String getMethod() {
         return m_method;
     }



Mime
View raw message