You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2012/11/09 11:05:47 UTC

svn commit: r1407407 [1/3] - in /felix/trunk/ipojo/manipulator/manipulator/src: main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/module/ main/java/org/apache/felix/ipojo/...

Author: clement
Date: Fri Nov  9 10:05:42 2012
New Revision: 1407407

URL: http://svn.apache.org/viewvc?rev=1407407&view=rev
Log:
Fix FELIX-3749 (https://issues.apache.org/jira/browse/FELIX-3749)

Apply patch from Guillaume Sauthier, forgot some files...

Added:
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ClassMetadataCollector.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbench.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/FieldMetadataCollector.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/MethodMetadataCollector.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/module/
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/module/DefaultBindingModule.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/Binding.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/BindingRegistry.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/Selection.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ComponentVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ControllerVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/FieldPropertyVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/InstantiateVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/LifecycleVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/MethodPropertyVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ParameterPropertyVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/PostRegistrationVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/PostUnregistrationVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ProvidesVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/RequiresVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ServiceControllerVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/UpdatedVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/bind/
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/bind/AbstractBindVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/bind/Action.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/bind/MethodBindVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/bind/ParameterBindVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/generic/
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/generic/FieldGenericVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/generic/GenericVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/generic/MethodGenericVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/generic/ParameterGenericVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/generic/RootGenericVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/generic/SubArrayVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/generic/TypeGenericVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Bindings.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Elements.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Names.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/AbsBindingModule.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/AnnotationVisitorFactory.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/BindingContext.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/Module.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/Predicate.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/helper/
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/helper/Predicates.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/resources/META-INF/
    felix/trunk/ipojo/manipulator/manipulator/src/main/resources/META-INF/services/
    felix/trunk/ipojo/manipulator/manipulator/src/main/resources/META-INF/services/org.apache.felix.ipojo.manipulator.spi.Module
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbenchTestCase.java
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/BindingRegistryTestCase.java
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/SelectionTestCase.java
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ComponentVisitorTestCase.java
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/spi/
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/spi/AbsBindingModuleTestCase.java

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ClassMetadataCollector.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ClassMetadataCollector.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ClassMetadataCollector.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ClassMetadataCollector.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation;
+
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.BindingRegistry;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.FieldNode;
+import org.objectweb.asm.tree.MethodNode;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ClassMetadataCollector extends EmptyVisitor {
+
+    /**
+     * Binding's registry.
+     */
+    private BindingRegistry registry;
+
+    /**
+     * Output information.
+     */
+    private Reporter reporter;
+
+    /**
+     * Workbench where produced Elements will be merged and hierarchically organized.
+     */
+    private ComponentWorkbench workbench;
+
+    /**
+     * Class currently being analyzed.
+     */
+    private ClassNode node;
+
+    private Element componentMetadata;
+
+    private Element instanceMetadata;
+
+    public ClassMetadataCollector(BindingRegistry registry, Reporter reporter) {
+        this.registry = registry;
+        this.reporter = reporter;
+        node = new ClassNode();
+    }
+
+    /**
+     * Build metadata. May be {@literal null} if no "component type" was found.
+     * @return Build metadata. May be {@literal null} if no "component type" was found.
+     */
+    public Element getComponentMetadata() {
+        return componentMetadata;
+    }
+
+    /**
+     * Build metadata. May be {@literal null} if no "component type" was found.
+     * @return Build metadata. May be {@literal null} if no "component type" was found.
+     */
+    public Element getInstanceMetadata() {
+        return instanceMetadata;
+    }
+
+    @Override
+    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
+        node.visit(version, access, name, signature, superName, interfaces);
+        workbench = new ComponentWorkbench(registry, node);
+    }
+
+    /**
+     * Visit class annotations.
+     * This method detects @component and @provides annotations.
+     * @param desc : annotation descriptor.
+     * @param visible : is the annotation visible at runtime.
+     * @return the annotation visitor.
+     * @see org.objectweb.asm.ClassAdapter#visitAnnotation(java.lang.String, boolean)
+     */
+    public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
+
+        // Return the visitor to be executed (may be null)
+        return registry.selection(workbench)
+                .type(node)
+                .annotatedWith(desc)
+                .get();
+
+    }
+
+    /**
+     * Visit a field.
+     * Call the field collector visitor.
+     * @param access : field access.
+     * @param name : field name
+     * @param desc : field descriptor
+     * @param signature : field signature
+     * @param value : field value (static field only)
+     * @return the field visitor.
+     * @see org.objectweb.asm.ClassAdapter#visitField(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)
+     */
+    public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
+        return new FieldMetadataCollector(workbench, new FieldNode(access, name, desc, signature, value));
+    }
+
+    /**
+     * Visit a method.
+     * Call the method collector visitor.
+     * @param access : method access
+     * @param name : method name
+     * @param desc : method descriptor
+     * @param signature : method signature
+     * @param exceptions : method exceptions
+     * @return the Method Visitor.
+     * @see org.objectweb.asm.ClassAdapter#visitMethod(int, java.lang.String, java.lang.String, java.lang.String, java.lang.String[])
+     */
+    public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
+        return new MethodMetadataCollector(workbench, new MethodNode(access, name, desc, signature, exceptions), reporter);
+    }
+
+    /**
+     * End of the visit : compute final elements.
+     * @see org.objectweb.asm.commons.EmptyVisitor#visitEnd()
+     */
+    @Override
+    public void visitEnd() {
+        if (workbench.getRoot() == null) {
+            // No 'top-level' element has been contributed
+
+            if (!workbench.getElements().isEmpty()) {
+                // There are other annotation's contribution on this type (additional handler declaration/configuration)
+                // That means that there is a missing 'component type' annotation
+
+                reporter.warn("Class %s has not been marked as a component type (no @Component, @Handler, ...). It will be ignored in manipulation.",
+                        workbench.getType().getClassName());
+                return;
+            } // else: no root and no elements
+            return;
+        }
+
+        componentMetadata = workbench.build();
+        instanceMetadata = workbench.getInstance();
+    }
+
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbench.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbench.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbench.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbench.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.BindingRegistry;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.ClassNode;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ComponentWorkbench {
+
+    /**
+     * Root element (usually <component /> or <handler/>).
+     * Maybe null until set.
+     */
+    private Element root;
+
+    /**
+     * Instance element (may be {@literal null}).
+     */
+    private Element instance;
+
+    /**
+     * Map of [element ids, element].
+     * This map is used to easily get an already created element.
+     */
+    private Map<String, Element> m_ids = new TreeMap<String, Element>();
+
+    /**
+     * Map of [element, referto].
+     * This map is used to recreate the element hierarchy.
+     * Stored element are added under referred element.
+     */
+    private Map<Element, String> m_elements = new LinkedHashMap<Element, String>();
+
+    private Type type;
+
+    private BindingRegistry bindingRegistry;
+
+    private ClassNode classNode;
+
+    public ComponentWorkbench(BindingRegistry bindingRegistry, ClassNode node) {
+        this.bindingRegistry = bindingRegistry;
+        this.classNode = node;
+        this.type = Type.getObjectType(node.name);
+    }
+
+    public Type getType() {
+        return type;
+    }
+
+    public BindingRegistry getBindingRegistry() {
+        return bindingRegistry;
+    }
+
+    public ClassNode getClassNode() {
+        return classNode;
+    }
+
+    /**
+     * The identified root Element. May be null if at the visit time, the root as not been identified.
+     * @return the root Element. or {@literal null} if not defined at the execution time.
+     */
+    public Element getRoot() {
+        return root;
+    }
+
+    public void setRoot(Element root) {
+        // TODO check if root already assigned
+        this.root = root;
+    }
+
+    public Element getInstance() {
+        return instance;
+    }
+
+    public void setInstance(Element instance) {
+        this.instance = instance;
+    }
+
+    public Map<String, Element> getIds() {
+        return m_ids;
+    }
+
+    public Map<Element, String> getElements() {
+        return m_elements;
+    }
+
+    public Element build() {
+
+        if (root == null) {
+            // No 'top level' component Element has been registered
+            return null;
+        }
+
+        // Iterates on all contributed Elements
+        for (Element current : m_elements.keySet()) {
+
+            // If the traversed Element has a reference to another Element,
+            // it has to be moved inside that referenced Element
+            // This is useful for contributing data to other handlers
+
+            String refId = m_elements.get(current);
+            if (refId == null) {
+                // No reference provided, just add it a a direct child
+                root.addElement(current);
+            } else {
+
+                // Get the referenced Element (if any)
+                Element ref = m_ids.get(refId);
+                if (ref == null) {
+                    // Add to the root Element
+                    root.addElement(current);
+                } else {
+                    // Add as child of the referenced Element
+                    ref.addElement(current);
+                }
+            }
+        }
+
+        // Clear
+        m_ids.clear();
+        m_elements.clear();
+
+        return root;
+
+    }
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/FieldMetadataCollector.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/FieldMetadataCollector.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/FieldMetadataCollector.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/FieldMetadataCollector.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.BindingRegistry;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+import org.objectweb.asm.tree.FieldNode;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class FieldMetadataCollector extends EmptyVisitor implements FieldVisitor {
+
+    /**
+     * Binding's registry.
+     */
+    private BindingRegistry registry;
+
+    /**
+     * The workbench currently in use.
+     */
+    private ComponentWorkbench workbench;
+
+    /**
+     * Visited field.
+     */
+    private FieldNode node;
+
+    public FieldMetadataCollector(ComponentWorkbench workbench, FieldNode node) {
+        this.workbench = workbench;
+        this.node = node;
+        this.registry = workbench.getBindingRegistry();
+    }
+
+    /**
+     * Visit annotations on the current field.
+     * @param desc : annotation name
+     * @param visible : is the annotation a runtime annotation.
+     * @return the annotation visitor visiting the annotation
+     * @see org.objectweb.asm.FieldVisitor#visitAnnotation(java.lang.String, boolean)
+     */
+    public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
+
+        // Return the visitor to be executed (may be null)
+        return registry.selection(workbench)
+                .field(node)
+                .annotatedWith(desc)
+                .get();
+
+    }
+
+
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/MethodMetadataCollector.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/MethodMetadataCollector.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/MethodMetadataCollector.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/MethodMetadataCollector.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation;
+
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.BindingRegistry;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+import org.objectweb.asm.tree.MethodNode;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class MethodMetadataCollector extends EmptyVisitor implements MethodVisitor {
+
+    /**
+     * Binding's registry.
+     */
+    private BindingRegistry registry;
+
+    /**
+     * Output informations.
+     */
+    private Reporter reporter;
+
+    /**
+     * The workbench currently in use.
+     */
+    private ComponentWorkbench workbench;
+
+    /**
+     * Visited field.
+     */
+    private MethodNode node;
+
+    public MethodMetadataCollector(ComponentWorkbench workbench, MethodNode node, Reporter reporter) {
+        this.workbench = workbench;
+        this.reporter = reporter;
+        this.node = node;
+        this.registry = workbench.getBindingRegistry();
+    }
+
+    /**
+     * Visit method annotations.
+     *
+     * @param desc : annotation name.
+     * @param visible : is the annotation visible at runtime.
+     * @return the visitor paring the visited annotation.
+     * @see org.objectweb.asm.commons.EmptyVisitor#visitAnnotation(java.lang.String, boolean)
+     */
+    public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
+
+        // Return the visitor to be executed (may be null)
+        return registry.selection(workbench)
+                .method(node)
+                .annotatedWith(desc)
+                .get();
+
+    }
+
+    /**
+     * Visit a parameter annotation.
+     *
+     * @see org.objectweb.asm.commons.EmptyVisitor#visitParameterAnnotation(int, java.lang.String, boolean)
+     */
+    public AnnotationVisitor visitParameterAnnotation(int index,
+                                                      String desc,
+                                                      boolean visible) {
+        // Only process annotations on constructor
+        if (node.name.equals("<init>")) {
+
+            // Return the visitor to be executed (may be null)
+            return registry.selection(workbench)
+                    .parameter(node, index)
+                    .annotatedWith(desc)
+                    .get();
+
+        }
+        return super.visitParameterAnnotation(index, desc, visible);
+    }
+
+
+
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/module/DefaultBindingModule.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/module/DefaultBindingModule.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/module/DefaultBindingModule.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/module/DefaultBindingModule.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,318 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation.module;
+
+import org.apache.felix.ipojo.annotations.Bind;
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Controller;
+import org.apache.felix.ipojo.annotations.Handler;
+import org.apache.felix.ipojo.annotations.HandlerDeclaration;
+import org.apache.felix.ipojo.annotations.Instantiate;
+import org.apache.felix.ipojo.annotations.Invalidate;
+import org.apache.felix.ipojo.annotations.Modified;
+import org.apache.felix.ipojo.annotations.PostRegistration;
+import org.apache.felix.ipojo.annotations.PostUnregistration;
+import org.apache.felix.ipojo.annotations.Property;
+import org.apache.felix.ipojo.annotations.Provides;
+import org.apache.felix.ipojo.annotations.Requires;
+import org.apache.felix.ipojo.annotations.ServiceController;
+import org.apache.felix.ipojo.annotations.ServiceProperty;
+import org.apache.felix.ipojo.annotations.Unbind;
+import org.apache.felix.ipojo.annotations.Updated;
+import org.apache.felix.ipojo.annotations.Validate;
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ComponentVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ControllerVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.FieldPropertyVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.HandlerDeclarationVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.HandlerVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.InstantiateVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.LifecycleVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.MethodPropertyVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ParameterPropertyVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.PostRegistrationVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ProvidesVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.RequiresVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ServiceControllerVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.UpdatedVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.bind.Action;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.bind.MethodBindVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.bind.ParameterBindVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.util.Elements;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.util.Names;
+import org.apache.felix.ipojo.manipulator.spi.AbsBindingModule;
+import org.apache.felix.ipojo.manipulator.spi.AnnotationVisitorFactory;
+import org.apache.felix.ipojo.manipulator.spi.BindingContext;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.tree.FieldNode;
+import org.objectweb.asm.tree.MethodNode;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.lang.annotation.ElementType;
+
+import static org.apache.felix.ipojo.manipulator.spi.helper.Predicates.on;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class DefaultBindingModule extends AbsBindingModule {
+
+    /**
+     * Configure all the iPOJO's default annotation's bindings.
+     */
+    public void configure() {
+
+        // Class level annotations
+        // --------------------------------
+        bind(Component.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        return new ComponentVisitor(context.getWorkbench(), context.getReporter());
+                    }
+                });
+
+        bind(Handler.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        return new HandlerVisitor(context.getWorkbench(), context.getReporter());
+                    }
+                });
+
+        bind(Provides.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        return new ProvidesVisitor(context.getWorkbench());
+                    }
+                });
+
+
+        bind(HandlerDeclaration.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        Reporter reporter = context.getReporter();
+                        return new HandlerDeclarationVisitor(context.getWorkbench(), getFreshDocumentBuilder(reporter), reporter);
+                    }
+                });
+
+        bind(Instantiate.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        return new InstantiateVisitor(context.getWorkbench());
+                    }
+                });
+
+        // Field level annotations
+        // --------------------------------
+        bind(Requires.class)
+                .when(on(ElementType.FIELD))
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        return new RequiresVisitor(context.getWorkbench(), ((FieldNode) context.getNode()).name);
+                    }
+                })
+                .when(on(ElementType.PARAMETER))
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        return new ParameterBindVisitor(context.getWorkbench(), Action.BIND, context.getParameterIndex());
+                    }
+                });
+
+        bind(Controller.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        return new ControllerVisitor(context.getWorkbench(), ((FieldNode) context.getNode()).name);
+                    }
+                });
+
+        bind(ServiceProperty.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        String name = ((FieldNode) context.getNode()).name;
+                        ComponentWorkbench workbench = context.getWorkbench();
+
+                        if (!workbench.getIds().containsKey("provides")) {
+                            // The provides annotation is already computed.
+                            context.getReporter().warn("The component does not provide services, skip ServiceProperty for {}", name);
+                            return null;
+                        } else {
+                            // Get the provides element
+                            Element provides = workbench.getIds().get("provides");
+                            return new FieldPropertyVisitor(name, provides);
+                        }
+
+                    }
+                });
+
+        bind(ServiceController.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        String name = ((FieldNode) context.getNode()).name;
+                        ComponentWorkbench workbench = context.getWorkbench();
+
+                        if (!workbench.getIds().containsKey("provides")) { // The provides annotation is already computed.
+                            context.getReporter().warn("The component does not provide services, skip @ServiceController for {}", name);
+                            return null;
+                        } else {
+                            // Get the provides element
+                            Element provides = workbench.getIds().get("provides");
+                            return new ServiceControllerVisitor(name, provides);
+                        }
+
+                    }
+                });
+
+        bind(Property.class)
+                .when(on(ElementType.FIELD))
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+
+                        ComponentWorkbench workbench = context.getWorkbench();
+                        Element properties = Elements.getPropertiesElement(workbench);
+                        String name = ((FieldNode) context.getNode()).name;
+                        return new FieldPropertyVisitor(name, properties);
+                    }
+
+                })
+                .when(on(ElementType.METHOD))
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+
+                        ComponentWorkbench workbench = context.getWorkbench();
+                        // @Property on method parameter
+                        Element properties = Elements.getPropertiesElement(workbench);
+                        String name = ((MethodNode) context.getNode()).name;
+                        return new MethodPropertyVisitor(properties, name);
+                    }
+                })
+                .when(on(ElementType.PARAMETER))
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+
+                        ComponentWorkbench workbench = context.getWorkbench();
+                        // @Property on method parameter
+                        Element properties = Elements.getPropertiesElement(workbench);
+                        MethodNode method = (MethodNode) context.getNode();
+                        return new ParameterPropertyVisitor(properties, method, context.getParameterIndex());
+                    }
+                });
+
+        bind(Validate.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        MethodNode node = (MethodNode) context.getNode();
+                        return new LifecycleVisitor(context.getWorkbench(),
+                                Names.computeEffectiveMethodName(node.name),
+                                LifecycleVisitor.Transition.VALIDATE);
+                    }
+                });
+
+        bind(Invalidate.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        MethodNode node = (MethodNode) context.getNode();
+                        return new LifecycleVisitor(context.getWorkbench(),
+                                Names.computeEffectiveMethodName(node.name),
+                                LifecycleVisitor.Transition.INVALIDATE);
+                    }
+                });
+
+        bind(Updated.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        MethodNode node = (MethodNode) context.getNode();
+                        return new UpdatedVisitor(context.getWorkbench(),
+                                Names.computeEffectiveMethodName(node.name));
+                    }
+                });
+
+        bind(Bind.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        MethodNode node = (MethodNode) context.getNode();
+                        return new MethodBindVisitor(context.getWorkbench(), Action.BIND, node.name);
+                    }
+                });
+
+        bind(Unbind.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        MethodNode node = (MethodNode) context.getNode();
+                        return new MethodBindVisitor(context.getWorkbench(), Action.UNBIND, node.name);
+                    }
+                });
+
+        bind(Modified.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        MethodNode node = (MethodNode) context.getNode();
+                        return new MethodBindVisitor(context.getWorkbench(), Action.MODIFIED, node.name);
+                    }
+                });
+
+        bind(PostRegistration.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        MethodNode node = (MethodNode) context.getNode();
+                        return new PostRegistrationVisitor(context.getWorkbench(), node.name);
+                    }
+                });
+
+        bind(PostUnregistration.class)
+                .to(new AnnotationVisitorFactory() {
+                    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                        MethodNode node = (MethodNode) context.getNode();
+                        return new PostRegistrationVisitor(context.getWorkbench(), node.name);
+                    }
+                });
+    }
+
+    private DocumentBuilder m_builder;
+
+
+    /**
+     * Creates a 'fresh' document builder.
+     * @return a new document builder is not already created, else reset
+     * the created one, and return it.
+     */
+    protected DocumentBuilder getFreshDocumentBuilder(Reporter reporter) {
+        if (m_builder == null) {
+
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+            factory.setNamespaceAware(true);
+            try {
+                m_builder = factory.newDocumentBuilder();
+            } catch (ParserConfigurationException e) {
+                // TODO GSA is this acceptable to throw a RuntimeException here ?
+                reporter.warn("Cannot get a fresh DocumentBuilder", e);
+            }
+
+            return m_builder;
+        }
+
+        // The builder has to be reseted
+        m_builder.reset();
+
+        return m_builder;
+    }
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/Binding.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/Binding.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/Binding.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/Binding.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation.registry;
+
+import org.apache.felix.ipojo.manipulator.spi.AnnotationVisitorFactory;
+import org.apache.felix.ipojo.manipulator.spi.Predicate;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * Triple storing the source annotation, the associated factory and the predicate for conditional support.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Binding {
+    private Class<? extends Annotation> annotationType;
+    private AnnotationVisitorFactory factory;
+    private Predicate predicate;
+
+    public Class<? extends Annotation> getAnnotationType() {
+        return annotationType;
+    }
+
+    public void setAnnotationType(Class<? extends Annotation> annotationType) {
+        this.annotationType = annotationType;
+    }
+
+    public AnnotationVisitorFactory getFactory() {
+        return factory;
+    }
+
+    public void setFactory(AnnotationVisitorFactory factory) {
+        this.factory = factory;
+    }
+
+    public Predicate getPredicate() {
+        return predicate;
+    }
+
+    public void setPredicate(Predicate predicate) {
+        this.predicate = predicate;
+    }
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/BindingRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/BindingRegistry.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/BindingRegistry.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/BindingRegistry.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation.registry;
+
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
+import org.apache.felix.ipojo.manipulator.spi.Predicate;
+import org.objectweb.asm.Type;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Stores all the {@link Binding}s coming from the {@link org.apache.felix.ipojo.manipulator.spi.Module}.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class BindingRegistry {
+    private Map<String, List<Binding>> tree;
+    private Reporter reporter;
+
+    /**
+     * When no other Binding is selected, the default Bindings list is used.
+     */
+    private List<Binding> defaultBindings;
+
+    public BindingRegistry(Reporter reporter) {
+        this.reporter = reporter;
+        tree = new HashMap<String, List<Binding>>();
+        defaultBindings = new ArrayList<Binding>();
+    }
+
+    /**
+     * Stores the given Bindings
+     */
+    public void addBindings(Iterable<Binding> bindings) {
+        for (Binding binding : bindings) {
+            Type type = Type.getType(binding.getAnnotationType());
+
+            List<Binding> potential = tree.get(type.getDescriptor());
+            if (potential == null) {
+                // Annotation is not already found in supported list
+                potential = new ArrayList<Binding>();
+                tree.put(type.getDescriptor(), potential);
+            }
+
+            potential.add(binding);
+        }
+    }
+
+    /**
+     * Initiate a {@link Selection} for the given workbench.
+     */
+    public Selection selection(ComponentWorkbench workbench) {
+        return new Selection(this, workbench, reporter);
+    }
+
+    public List<Binding> getBindings(String descriptor) {
+        return tree.get(descriptor);
+    }
+
+    public List<Binding> getDefaultBindings() {
+        return defaultBindings;
+    }
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/Selection.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/Selection.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/Selection.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/Selection.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation.registry;
+
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
+import org.apache.felix.ipojo.manipulator.spi.BindingContext;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.FieldNode;
+import org.objectweb.asm.tree.MemberNode;
+import org.objectweb.asm.tree.MethodNode;
+
+import java.lang.annotation.ElementType;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A {@link Selection} is used to select a subset of all supported {@link AnnotationVisitor}.
+ * It's a query DSL.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Selection implements Iterable<AnnotationVisitor> {
+
+    private BindingRegistry registry;
+    private ComponentWorkbench workbench;
+    private Reporter reporter;
+    private MemberNode node;
+    private int index = -1;
+    private String annotation;
+    private ElementType elementType = null;
+
+    public Selection(BindingRegistry registry, ComponentWorkbench workbench, Reporter reporter) {
+        this.registry = registry;
+        this.workbench = workbench;
+        this.reporter = reporter;
+    }
+
+    public Selection field(FieldNode node) {
+        this.node = node;
+        this.elementType = ElementType.FIELD;
+        return this;
+    }
+
+    public Selection method(MethodNode node) {
+        this.node = node;
+        this.elementType = ElementType.METHOD;
+        return this;
+    }
+
+    public Selection type(ClassNode node) {
+        this.node = node;
+        this.elementType = ElementType.TYPE;
+        return this;
+    }
+
+    public Selection parameter(MethodNode node, int index) {
+        this.index = index;
+        this.node = node;
+        this.elementType = ElementType.PARAMETER;
+        return this;
+    }
+
+    public Selection annotatedWith(String desc) {
+        this.annotation = desc;
+        return this;
+    }
+
+    public AnnotationVisitor get() {
+        Iterator<AnnotationVisitor> i = iterator();
+        if (iterator().hasNext()) {
+            return i.next();
+        }
+        return null;
+    }
+
+    public Iterator<AnnotationVisitor> iterator() {
+
+        List<AnnotationVisitor> visitors = new ArrayList<AnnotationVisitor>();
+
+        BindingContext context = new BindingContext(workbench, reporter, Type.getType(annotation), node, elementType, index);
+        List<Binding> predicates = registry.getBindings(annotation);
+
+        if (predicates != null && !predicates.isEmpty()) {
+            collectMatchingVisitors(predicates, context, visitors);
+        }
+
+        if (visitors.isEmpty() && !registry.getDefaultBindings().isEmpty()) {
+            collectMatchingVisitors(registry.getDefaultBindings(), context, visitors);
+        }
+
+
+        return visitors.iterator();
+    }
+
+    private void collectMatchingVisitors(List<Binding> bindings, BindingContext context, List<AnnotationVisitor> visitors) {
+        for (Binding binding : bindings) {
+            if (binding.getPredicate().matches(context)) {
+                AnnotationVisitor visitor = binding.getFactory().newAnnotationVisitor(context);
+                visitors.add(visitor);
+            }
+        }
+    }
+
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ComponentVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ComponentVisitor.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ComponentVisitor.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ComponentVisitor.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor;
+
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+
+/**
+ * Parse the @Component annotation.
+ * @see org.apache.felix.ipojo.annotations.Component
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ComponentVisitor extends EmptyVisitor implements AnnotationVisitor {
+
+    private Reporter reporter;
+
+    /**
+     * Element 'properties'.
+     */
+    private Element m_props = new Element("properties", "");
+
+    private Element component = new Element("component", "");
+
+    private ComponentWorkbench workbench;
+
+    public ComponentVisitor(ComponentWorkbench workbench, Reporter reporter) {
+        this.workbench = workbench;
+        this.reporter = reporter;
+    }
+
+    /**
+     * Visit @Component annotation attribute.
+     * @param name attribute name
+     * @param value attribute value
+     * @see org.objectweb.asm.commons.EmptyVisitor#visit(java.lang.String, java.lang.Object)
+     */
+    public void visit(String name, Object value) {
+        if (name.equals("public_factory")  || name.equals("publicFactory")) {
+            // public_factory is deprecated, but must sill be supported
+            String factory = value.toString();
+            if (factory != null && factory.equalsIgnoreCase("false")) {
+                component.addAttribute(new Attribute("public", "false"));
+            } else {
+                component.addAttribute(new Attribute("public", "true"));
+            }
+            return;
+        }
+
+        if (name.equals("name")) {
+            component.addAttribute(new Attribute("name", value.toString()));
+            return;
+        }
+        if (name.equals("immediate")) {
+            component.addAttribute(new Attribute("immediate", value.toString()));
+            return;
+        }
+        if (name.equals("architecture")) {
+            component.addAttribute(new Attribute("architecture", value.toString()));
+            return;
+        }
+        if (name.equals("propagation") && (value != null)) {
+            if (arePropertiesEmpty()) {
+                initComponentProperties();
+            }
+            m_props.addAttribute(new Attribute("propagation", value.toString()));
+            return;
+        }
+        if (name.equals("managedservice") && (value != null)) {
+            if (arePropertiesEmpty()) {
+                initComponentProperties();
+            }
+            m_props.addAttribute(new Attribute("pid", value.toString()));
+            return;
+        }
+        if ((name.equals("factory_method")  || name.equals("factoryMethod")) && (value != null)) {
+            // factory_method is deprecated, but must still be supported.
+            component.addAttribute(new Attribute("factory-method", value.toString()));
+            return;
+        }
+        if (name.equals("version") && (value != null)) {
+            component.addAttribute(new Attribute("version", value.toString()));
+        }
+    }
+
+    private boolean arePropertiesEmpty() {
+        return m_props.getElements().length == 0;
+    }
+
+    private void initComponentProperties() {
+        workbench.getElements().put(m_props, null);
+        workbench.getIds().put("properties", m_props);
+    }
+
+    /**
+     * End of the visit.
+     * Append to the "component" element computed attribute.
+     * @see org.objectweb.asm.commons.EmptyVisitor#visitEnd()
+     */
+    public void visitEnd() {
+
+        String classname = workbench.getType().getClassName();
+
+        if (component.getAttribute("name") == null) {
+            component.addAttribute(new Attribute("name", classname));
+        }
+
+        component.addAttribute(new Attribute("classname", classname));
+
+        if (workbench.getRoot() == null) {
+            workbench.setRoot(component);
+        } else {
+            // Error case: 2 component type's annotations (@Component and @Handler for example) on the same class
+            reporter.error("Multiple 'component type' annotations on the class '{}'.", classname);
+            reporter.warn("@Component will be ignored.");
+        }
+    }
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ControllerVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ControllerVisitor.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ControllerVisitor.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ControllerVisitor.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+
+/**
+ * Parses the @Controller annotation.
+ * @see org.apache.felix.ipojo.annotations.Controller
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ControllerVisitor extends EmptyVisitor implements AnnotationVisitor {
+
+    private ComponentWorkbench workbench;
+
+    private String field;
+
+    public ControllerVisitor(ComponentWorkbench workbench, String field) {
+        this.workbench = workbench;
+        this.field = field;
+    }
+
+    /**
+     * Visit @Handler annotation attributes.
+     * @see org.objectweb.asm.commons.EmptyVisitor#visit(String, Object)
+     */
+    public void visitEnd() {
+        Element controller = new Element("controller", "");
+        controller.addAttribute(new Attribute("field", field));
+        workbench.getElements().put(controller, null);
+    }
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/FieldPropertyVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/FieldPropertyVisitor.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/FieldPropertyVisitor.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/FieldPropertyVisitor.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor;
+
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+
+/**
+ * Parses a Property or ServiceProperty annotation.
+ * @see org.apache.felix.ipojo.annotations.ServiceProperty
+ * @see org.apache.felix.ipojo.annotations.Property
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class FieldPropertyVisitor extends EmptyVisitor implements AnnotationVisitor {
+
+    /**
+     * Parent element element.
+     */
+    private Element m_parent;
+
+    /**
+     * Field name.
+     */
+    private String m_field;
+
+    /**
+     * Property name.
+     */
+    private String m_name;
+
+    /**
+     * Property value.
+     */
+    private String m_value;
+
+    /**
+     * Property mandatory aspect.
+     */
+    private String m_mandatory;
+
+    /**
+     * Property type.
+     */
+    private String m_type;
+
+
+    /**
+     * Constructor without field
+     * @param parent : element element..
+     */
+    public FieldPropertyVisitor(Element parent) {
+        this(null, parent);
+    }
+
+    /**
+     * Constructor.
+     * @param parent : element element.
+     * @param field : field name.
+     */
+    public FieldPropertyVisitor(String field, Element parent) {
+        m_parent = parent;
+        m_field = field;
+    }
+
+    /**
+     * Visit one "simple" annotation.
+     * @param name : annotation name
+     * @param value : annotation value
+     * @see org.objectweb.asm.AnnotationVisitor#visit(String, Object)
+     */
+    public void visit(String name, Object value) {
+        if (name.equals("name")) {
+            m_name = value.toString();
+            return;
+        }
+        if (name.equals("value")) {
+            m_value = value.toString();
+            return;
+        }
+        if (name.equals("mandatory")) {
+            m_mandatory = value.toString();
+            return;
+        }
+        if (name.equals("type")) {
+        	m_type = value.toString();
+        }
+    }
+
+    /**
+     * End of the annotation.
+     * Create a "property" element
+     * @see org.objectweb.asm.AnnotationVisitor#visitEnd()
+     */
+    public void visitEnd() {
+        if (m_field != null  && m_name == null) {
+            m_name = m_field;
+        }
+
+
+        Element[] props = m_parent.getElements("property");
+        Element prop = null;
+        for (int i = 0; prop == null && props != null && i < props.length; i++) {
+            String name = props[i].getAttribute("name");
+            if (name != null && name.equals(m_name)) {
+                prop = props[i];
+            }
+        }
+
+        if (prop == null) {
+            prop = new Element("property", "");
+            m_parent.addElement(prop);
+            if (m_name != null) {
+                prop.addAttribute(new Attribute("name", m_name));
+            }
+        }
+
+        if (m_field != null) {
+        	prop.addAttribute(new Attribute("field", m_field));
+        }
+        if (m_type != null) {
+        	prop.addAttribute(new Attribute("type", m_type));
+        }
+
+        if (m_value != null) {
+            prop.addAttribute(new Attribute("value", m_value));
+        }
+        if (m_mandatory != null) {
+            prop.addAttribute(new Attribute("mandatory", m_mandatory));
+        }
+
+    }
+}
\ No newline at end of file

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitor.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitor.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitor.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor;
+
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.NodeList;
+
+import javax.xml.parsers.DocumentBuilder;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Parse the @HandlerDeclaration annotation.
+ * @see org.apache.felix.ipojo.annotations.HandlerDeclaration
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class HandlerDeclarationVisitor extends EmptyVisitor implements AnnotationVisitor {
+
+    /**
+     * XML accepted by the handler.
+     */
+    private String m_value;
+
+    private DocumentBuilder builder;
+
+    private ComponentWorkbench workbench;
+    private Reporter reporter;
+
+    public HandlerDeclarationVisitor(ComponentWorkbench workbench, DocumentBuilder builder, Reporter reporter) {
+        this.workbench = workbench;
+        this.builder = builder;
+        this.reporter = reporter;
+    }
+
+    /**
+     * Parses the value attribute.
+     * @param name 'value'
+     * @param value the value
+     * @see org.objectweb.asm.commons.EmptyVisitor#visit(java.lang.String, java.lang.Object)
+     */
+    public void visit(String name, Object value) {
+        // there is only a 'value' attribute
+        this.m_value = (String) value;
+    }
+
+    /**
+     * End of the visit.
+     * Builds the XML document.
+     * @see org.objectweb.asm.commons.EmptyVisitor#visitEnd()
+     */
+    public void visitEnd() {
+        // The value is an XML document
+        InputStream is = new ByteArrayInputStream(m_value.getBytes());
+        Document document = null;
+        try {
+            document = builder.parse(is);
+            Element e = convertDOMElements(document.getDocumentElement());
+            workbench.getElements().put(e, null);
+        } catch (Exception e) {
+            reporter.warn("Cannot convert {} to iPOJO Elements.", m_value, e);
+        } finally {
+            try {
+                is.close();
+            } catch (IOException e) {
+                reporter.trace("Cannot close correctly the value input stream ({}).", m_value, e);
+            }
+        }
+    }
+
+    /**
+     * Converts recursively the given XML Element into an iPOJO Element.
+     * @param xmlElement DOM Element to be converted
+     */
+    private static Element convertDOMElements(final org.w3c.dom.Element xmlElement) {
+
+        // Create an equivalent iPOJO element
+        Element converted = transformElement(xmlElement);
+
+        convertDOMElements(converted, xmlElement);
+
+        return converted;
+    }
+
+    /**
+     * Converts recursively the given XML Element into an iPOJO Element.
+     * @param root iPOJO root Element
+     * @param xmlElement DOM Element to be converted
+     */
+    private static void convertDOMElements(final Element root,
+                                           final org.w3c.dom.Element xmlElement) {
+
+        // Convert attributes if any
+        if (xmlElement.hasAttributes()) {
+            NamedNodeMap attributes = xmlElement.getAttributes();
+            for (int i = 0; i < attributes.getLength(); i++) {
+                Attr attr = (Attr) attributes.item(i);
+                root.addAttribute(transformAttribute(attr));
+            }
+        }
+
+        // Convert child elements if any
+        if (xmlElement.hasChildNodes()) {
+            NodeList children = xmlElement.getChildNodes();
+            for (int i = 0; i < children.getLength(); i++) {
+
+                // Create an equivalent iPOJO element
+                org.w3c.dom.Element child = (org.w3c.dom.Element) children.item(i);
+                Element converted = transformElement(child);
+
+                // Add converted element as a root's child
+                root.addElement(converted);
+
+                // Recursive call
+                convertDOMElements(converted, child);
+            }
+        }
+
+    }
+
+    private static Attribute transformAttribute(Attr attr) {
+        return new Attribute(attr.getName(),
+                attr.getNamespaceURI(),
+                attr.getValue());
+    }
+
+    private static Element transformElement(org.w3c.dom.Element xmlElement) {
+        return new Element(xmlElement.getLocalName(), xmlElement.getNamespaceURI());
+    }
+
+}
+

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerVisitor.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerVisitor.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerVisitor.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor;
+
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+
+/**
+ * Parses the @Handler annotation.
+ * @see org.apache.felix.ipojo.annotations.Handler
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class HandlerVisitor extends EmptyVisitor implements AnnotationVisitor {
+
+    private Element handler = new Element("handler", "");
+
+    private ComponentWorkbench workbench;
+
+    private Reporter reporter;
+
+    public HandlerVisitor(ComponentWorkbench workbench, Reporter reporter) {
+        this.workbench = workbench;
+        this.reporter = reporter;
+    }
+
+    /**
+     * Visit @Handler annotation attributes.
+     * @param name : annotation attribute name
+     * @param value : annotation attribute value
+     * @see org.objectweb.asm.commons.EmptyVisitor#visit(java.lang.String, java.lang.Object)
+     */
+    public void visit(String name, Object value) {
+        if (name.equals("name")) {
+            handler.addAttribute(new Attribute("name", value.toString()));
+            return;
+        }
+        if (name.equals("namespace")) {
+            handler.addAttribute(new Attribute("namespace", value.toString()));
+            return;
+        }
+        if (name.equals("level")) {
+            handler.addAttribute(new Attribute("level", value.toString()));
+            return;
+        }
+        if (name.equals("architecture")) {
+            handler.addAttribute(new Attribute("architecture", value.toString()));
+        }
+    }
+
+
+    /**
+     * End of the visit.
+     * Append to the "component" element computed attribute.
+     * @see org.objectweb.asm.commons.EmptyVisitor#visitEnd()
+     */
+    public void visitEnd() {
+
+        String classname = workbench.getType().getClassName();
+        handler.addAttribute(new Attribute("classname", classname));
+
+        if (workbench.getRoot() == null) {
+            workbench.setRoot(handler);
+        } else {
+            // Error case: 2 component type's annotations (@Component and @Handler for example) on the same class
+            reporter.error("Multiple 'component type' annotations on the class '{}'.", classname);
+            reporter.warn("@Handler will be ignored.");
+        }
+    }
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/InstantiateVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/InstantiateVisitor.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/InstantiateVisitor.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/InstantiateVisitor.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+
+/**
+ * Parse the @Instantitate annotation.
+ * @see org.apache.felix.ipojo.annotations.Instantiate
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class InstantiateVisitor extends EmptyVisitor implements AnnotationVisitor {
+
+    private Element instance = new Element("instance", "");
+
+    private ComponentWorkbench workbench;
+
+    public InstantiateVisitor(ComponentWorkbench workbench) {
+        this.workbench = workbench;
+    }
+
+    /**
+     * Visit an annotation attribute.
+     * @param name the attribute name
+     * @param value the attribute value
+     * @see org.objectweb.asm.commons.EmptyVisitor#visit(java.lang.String, java.lang.Object)
+     */
+    public void visit(String name, Object value) {
+        if (name.equals("name")) {
+            instance.addAttribute(new Attribute("name", (String) value));
+        }
+    }
+
+    /**
+     * End of the visit. Creates the instance element.
+     * @see org.objectweb.asm.commons.EmptyVisitor#visitEnd()
+     */
+    public void visitEnd() {
+        // TODO Is this really the classname that we need here ? Or the component's name ?
+        instance.addAttribute(new Attribute("component", workbench.getType().getClassName()));
+
+        workbench.setInstance(instance);
+
+    }
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/LifecycleVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/LifecycleVisitor.java?rev=1407407&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/LifecycleVisitor.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/LifecycleVisitor.java Fri Nov  9 10:05:42 2012
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+
+/**
+ * Parse @Validate and @Invalidate annotations.
+ * @see org.apache.felix.ipojo.annotations.Validate
+ * @see org.apache.felix.ipojo.annotations.Invalidate
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class LifecycleVisitor extends EmptyVisitor implements AnnotationVisitor {
+
+    public static enum Transition {
+        VALIDATE, INVALIDATE
+    }
+
+    private ComponentWorkbench workbench;
+    private String name;
+    private Transition transition;
+
+    public LifecycleVisitor(ComponentWorkbench workbench, String name, Transition transition) {
+        this.workbench = workbench;
+        this.name = name;
+        this.transition = transition;
+    }
+
+    @Override
+    public void visitEnd() {
+        Element cb = new Element("callback", "");
+        cb.addAttribute(new Attribute("transition", transition.name().toLowerCase()));
+        cb.addAttribute(new Attribute("method", name));
+        workbench.getElements().put(cb, null);
+    }
+}