felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r684736 - in /felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo: manipulation/Manipulator.java manipulator/Pojoization.java
Date Mon, 11 Aug 2008 12:30:43 GMT
Author: clement
Date: Mon Aug 11 05:30:42 2008
New Revision: 684736

URL: http://svn.apache.org/viewvc?rev=684736&view=rev
Log:
Fix the issue Felix-678.
Improve the missing field detection. Now, each 'field' attribute is checked. So, external
handlers profit of the same field detection during the packaging time (instead of at runtime).
 

Modified:
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java?rev=684736&r1=684735&r2=684736&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
(original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
Mon Aug 11 05:30:42 2008
@@ -138,5 +138,9 @@
 
         return elem;
     }
+    
+    public Map getFields() {
+        return m_fields;
+    }
 
 }

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java?rev=684736&r1=684735&r2=684736&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
(original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
Mon Aug 11 05:30:42 2008
@@ -348,6 +348,7 @@
         Manipulator man = new Manipulator();
         try {
             byte[] out = man.manipulate(in); // iPOJO manipulation
+            ci.detectMissingFields(man.getFields()); // Detect missing field
             // Insert information to metadata
             ci.m_componentMetadata.addElement(man.getManipulationMetadata());
             ci.m_isManipulated = true;
@@ -407,6 +408,41 @@
             this.m_componentMetadata = met;
             m_isManipulated = false;
         }
+        
+        /**
+         * Detects missing fields.
+         * If a referenced field does not exist in the class
+         * the method throws an error breaking the build process.
+         * @param fields : field found in the manipulated class
+         */
+        void detectMissingFields(Map fields) {
+            // First, compute the list of referred fields
+            List list = new ArrayList();
+            computeReferredFields(list, m_componentMetadata);
+            // Then, try to find each referred field in the given field map
+            for (int i = 0; i < list.size(); i++) {
+                if (!fields.containsKey(list.get(i))) {
+                    error("The field " + list.get(i) + " is referenced in the "
+                            + "metadata but does not exist in the " + m_classname + " class");
+                }
+            }
+        }
+        
+        /**
+         * Looks for 'field' attribute in the given metadata.
+         * @param list : discovered field (accumulator)
+         * @param metadata : metadata to inspect
+         */
+        private void computeReferredFields(List list, Element metadata) {
+            String field = metadata.getAttribute("field");
+            if (field != null && ! list.contains(field)) {
+                list.add(field);
+            }
+            for (int i = 0; i < metadata.getElements().length; i++) {
+                computeReferredFields(list, metadata.getElements()[i]);
+            }
+        }
+        
     }
 
     /**



Mime
View raw message