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).
 

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@684736 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
index da02b49..64c625f 100644
--- a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
+++ b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
@@ -138,5 +138,9 @@
 

         return elem;

     }

+    

+    public Map getFields() {

+        return m_fields;

+    }

 

 }

diff --git a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
index e918289..5c334ba 100644
--- a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
+++ b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
@@ -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]);

+            }

+        }

+        

     }

 

     /**