felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From guilla...@apache.org
Subject svn commit: r1507289 [2/3] - in /felix/trunk/ipojo/manipulator: annotations/src/main/java/org/apache/felix/ipojo/annotations/ manipulator-it/ipojo-manipulator-manipulation-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/ manipulator-i...
Date Fri, 26 Jul 2013 12:33:30 GMT
Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitAnnotation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitAnnotation.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitAnnotation.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitAnnotation.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,46 @@
+/*
+ * 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.model.parser.replay;
+
+import org.objectweb.asm.AnnotationVisitor;
+
+/**
+* User: guillaume
+* Date: 30/05/13
+* Time: 17:24
+*/
+public class VisitAnnotation implements Replay {
+    private final String m_name;
+    private final String m_desc;
+    private final AnnotationRecorder m_sub;
+
+    public VisitAnnotation(final String name, final String desc, final AnnotationRecorder sub) {
+        m_name = name;
+        m_desc = desc;
+        m_sub = sub;
+    }
+
+    public void accept(final AnnotationVisitor visitor) {
+        AnnotationVisitor child = visitor.visitAnnotation(m_name, m_desc);
+        if (child != null) {
+            m_sub.accept(child);
+        }
+    }
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitArray.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitArray.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitArray.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitArray.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.model.parser.replay;
+
+import org.objectweb.asm.AnnotationVisitor;
+
+/**
+* User: guillaume
+* Date: 30/05/13
+* Time: 17:24
+*/
+public class VisitArray implements Replay {
+    private final String m_name;
+    private final AnnotationRecorder m_sub;
+
+    public VisitArray(final String name, final AnnotationRecorder sub) {
+        m_name = name;
+        m_sub = sub;
+    }
+
+    public void accept(final AnnotationVisitor visitor) {
+        AnnotationVisitor child = visitor.visitArray(m_name);
+        if (child != null) {
+            m_sub.accept(child);
+        }
+    }
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitEnd.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitEnd.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitEnd.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitEnd.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,34 @@
+/*
+ * 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.model.parser.replay;
+
+import org.objectweb.asm.AnnotationVisitor;
+
+/**
+* User: guillaume
+* Date: 30/05/13
+* Time: 17:24
+*/
+public class VisitEnd implements Replay {
+
+    public void accept(final AnnotationVisitor visitor) {
+        visitor.visitEnd();
+    }
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitEnum.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitEnum.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitEnum.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/model/parser/replay/VisitEnum.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.model.parser.replay;
+
+import org.objectweb.asm.AnnotationVisitor;
+
+/**
+* User: guillaume
+* Date: 30/05/13
+* Time: 17:23
+*/
+public class VisitEnum implements Replay {
+    private final String m_name;
+    private final String m_desc;
+    private final String m_value;
+
+    public VisitEnum(final String name, final String desc, final String value) {m_name = name;
+        m_desc = desc;
+        m_value = value;
+    }
+
+    public void accept(final AnnotationVisitor visitor) {
+        visitor.visitEnum(m_name, m_desc, m_value);
+    }
+}

Modified: 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=1507289&r1=1507288&r2=1507289&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/Binding.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/Binding.java Fri Jul 26 12:33:28 2013
@@ -19,8 +19,11 @@
 
 package org.apache.felix.ipojo.manipulator.metadata.annotation.registry;
 
+import static java.lang.String.format;
+
 import org.apache.felix.ipojo.manipulator.spi.AnnotationVisitorFactory;
 import org.apache.felix.ipojo.manipulator.spi.Predicate;
+import org.objectweb.asm.Type;
 
 import java.lang.annotation.Annotation;
 
@@ -29,15 +32,15 @@ import java.lang.annotation.Annotation;
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class Binding {
-    private Class<? extends Annotation> annotationType;
+    private Type annotationType;
     private AnnotationVisitorFactory factory;
     private Predicate predicate;
 
-    public Class<? extends Annotation> getAnnotationType() {
+    public Type getAnnotationType() {
         return annotationType;
     }
 
-    public void setAnnotationType(Class<? extends Annotation> annotationType) {
+    public void setAnnotationType(Type annotationType) {
         this.annotationType = annotationType;
     }
 
@@ -56,4 +59,9 @@ public class Binding {
     public void setPredicate(Predicate predicate) {
         this.predicate = predicate;
     }
+
+    @Override
+    public String toString() {
+        return format("Binding[@%s->%s]", annotationType.getClassName(), factory);
+    }
 }

Modified: 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=1507289&r1=1507288&r2=1507289&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/BindingRegistry.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/BindingRegistry.java Fri Jul 26 12:33:28 2013
@@ -19,65 +19,25 @@
 
 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;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
 
 /**
- * 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>
+ * User: guillaume
+ * Date: 11/07/13
+ * Time: 16:12
  */
-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>();
-    }
+public interface BindingRegistry {
+    void addBindings(Iterable<Binding> bindings);
 
-    /**
-     * 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);
-        }
-    }
+    Selection selection(ComponentWorkbench workbench);
 
     /**
-     * Initiate a {@link Selection} for the given workbench.
+     * Find the list of {@link Binding} registered with the given annotation type.
+     * This method returns an empty List if no bindings are registered.
+     * @param descriptor denotes the annotation's type
+     * @return the list of {@link Binding} registered with the given descriptor, the list may be empty if no bindings are found.
      */
-    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;
-    }
+    List<Binding> getBindings(String descriptor);
 }

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/CompletableBindingRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/CompletableBindingRegistry.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/CompletableBindingRegistry.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/CompletableBindingRegistry.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,62 @@
+/*
+ * 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 java.util.List;
+
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
+import org.objectweb.asm.Type;
+
+/**
+ * User: guillaume
+ * Date: 11/07/13
+ * Time: 16:09
+ */
+public abstract class CompletableBindingRegistry implements BindingRegistry {
+    private final BindingRegistry m_delegate;
+    private final Reporter m_reporter;
+
+    public CompletableBindingRegistry(final BindingRegistry delegate, final Reporter reporter) {
+        m_delegate = delegate;
+        m_reporter = reporter;
+    }
+
+    public List<Binding> getBindings(final String descriptor) {
+        List<Binding> bindings = m_delegate.getBindings(descriptor);
+        if (bindings.isEmpty()) {
+            List<Binding> ignored = createBindings(Type.getType(descriptor));
+            m_delegate.addBindings(ignored);
+            return ignored;
+        }
+        return bindings;
+    }
+
+    protected abstract List<Binding> createBindings(final Type type);
+
+    public void addBindings(final Iterable<Binding> bindings) {
+        m_delegate.addBindings(bindings);
+    }
+
+    public Selection selection(final ComponentWorkbench workbench) {
+        return new Selection(this, workbench, m_reporter);
+    }
+
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/DefaultBindingRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/DefaultBindingRegistry.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/DefaultBindingRegistry.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/DefaultBindingRegistry.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,79 @@
+/*
+ * 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 static java.util.Collections.emptyList;
+
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
+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 DefaultBindingRegistry implements BindingRegistry {
+    private final Map<String, List<Binding>> tree = new HashMap<String, List<Binding>>();
+    protected final Reporter reporter;
+
+    public DefaultBindingRegistry(Reporter reporter) {
+        this.reporter = reporter;
+    }
+
+    /**
+     * Stores the given Bindings
+     */
+    public void addBindings(Iterable<Binding> bindings) {
+        for (Binding binding : bindings) {
+            Type type = 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);
+            }
+
+            reporter.trace("Registered @%s", type.getClassName());
+            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) {
+        List<Binding> bindings = tree.get(descriptor);
+        if (bindings == null) {
+            bindings = emptyList();
+        }
+        return bindings;
+    }
+
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/IgnoreAllBindingRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/IgnoreAllBindingRegistry.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/IgnoreAllBindingRegistry.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/IgnoreAllBindingRegistry.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,46 @@
+/*
+ * 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 static java.util.Collections.singletonList;
+
+import java.util.List;
+
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding;
+import org.objectweb.asm.Type;
+
+/**
+ * User: guillaume
+ * Date: 11/07/13
+ * Time: 16:09
+ */
+public class IgnoreAllBindingRegistry extends CompletableBindingRegistry {
+
+    public IgnoreAllBindingRegistry(final BindingRegistry delegate, final Reporter reporter) {
+        super(delegate, reporter);
+    }
+
+    @Override
+    protected List<Binding> createBindings(final Type type) {
+        return singletonList((Binding) new NullBinding(type));
+    }
+
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/LegacyGenericBindingRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/LegacyGenericBindingRegistry.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/LegacyGenericBindingRegistry.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/LegacyGenericBindingRegistry.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,98 @@
+/*
+ * 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 static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
+import static org.apache.felix.ipojo.manipulator.spi.helper.Predicates.alwaysTrue;
+
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.FieldGenericVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.MethodGenericVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.ParameterGenericVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.TypeGenericVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.util.Elements;
+import org.apache.felix.ipojo.manipulator.spi.AnnotationVisitorFactory;
+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.MethodNode;
+
+/**
+ * User: guillaume
+ * Date: 11/07/13
+ * Time: 16:09
+ */
+public class LegacyGenericBindingRegistry extends CompletableBindingRegistry {
+    public static final Pattern CUSTOM_HANDLER_PATTERN = Pattern.compile("(.*\\.ipojo\\..*)|(.*\\.handler\\..*)");
+
+    public LegacyGenericBindingRegistry(final BindingRegistry delegate, final Reporter reporter) {
+        super(delegate, reporter);
+    }
+
+    @Override
+    protected List<Binding> createBindings(final Type type) {
+        if (CUSTOM_HANDLER_PATTERN.matcher(type.getClassName()).matches()) {
+            Binding binding = new Binding();
+            binding.setAnnotationType(type);
+            binding.setPredicate(alwaysTrue());
+            binding.setFactory(new AnnotationVisitorFactory() {
+                // Need to build a new Element instance for each created visitor
+                public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+                    if (context.getNode() instanceof ClassNode) {
+                        return new TypeGenericVisitor(context.getWorkbench(),
+                                                      Elements.buildElement(type));
+                    } else if (context.getNode() instanceof FieldNode) {
+                        return new FieldGenericVisitor(context.getWorkbench(),
+                                                       Elements.buildElement(type),
+                                                       (FieldNode) context.getNode());
+
+                    } else if ((context.getNode() instanceof MethodNode) &&
+                            (context.getParameterIndex() == BindingContext.NO_INDEX)) {
+                        return new MethodGenericVisitor(context.getWorkbench(),
+                                                        Elements.buildElement(type),
+                                                        (MethodNode) context.getNode());
+                    } else {
+                        // last case: method parameter annotation
+                        return new ParameterGenericVisitor(context.getWorkbench(),
+                                                           Elements.buildElement(type),
+                                                           (MethodNode) context.getNode(),
+                                                           context.getParameterIndex());
+                    }
+                }
+
+                @Override
+                public String toString() {
+                    return "LegacyGenericVisitorFactory";
+                }
+            });
+
+            // Return the produced generic binding
+            return singletonList(binding);
+        }
+
+        return emptyList();
+    }
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/MetaAnnotationBindingRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/MetaAnnotationBindingRegistry.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/MetaAnnotationBindingRegistry.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/MetaAnnotationBindingRegistry.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,160 @@
+/*
+ * 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 static java.util.Collections.emptyList;
+import static java.util.Collections.unmodifiableList;
+import static org.apache.felix.ipojo.manipulator.spi.helper.Predicates.alwaysTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.ipojo.annotations.HandlerBinding;
+import org.apache.felix.ipojo.annotations.Ignore;
+import org.apache.felix.ipojo.annotations.Stereotype;
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.ResourceStore;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.AnnotationType;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.discovery.ChainedAnnotationDiscovery;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.discovery.HandlerBindingDiscovery;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.discovery.IgnoredDiscovery;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.discovery.StereotypeDiscovery;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.parser.AnnotationParser;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.GenericVisitorFactory;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype.StereotypeVisitorFactory;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.util.Elements;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.Type;
+
+/**
+ * The {@link MetaAnnotationBindingRegistry} is a registry that tries to complete its list
+ * of bindings when an unknown one is detected.
+ * It uses the given {@link ResourceStore} to parse the annotation's type and find if
+ * it's annotated with @{@link org.apache.felix.ipojo.annotations.Stereotype},
+ * @{@link org.apache.felix.ipojo.annotations.HandlerBinding} or @{@link org.apache.felix.ipojo.annotations.Ignore}
+ */
+public class MetaAnnotationBindingRegistry extends CompletableBindingRegistry {
+
+    private ResourceStore m_store;
+    private Reporter m_reporter;
+
+    public MetaAnnotationBindingRegistry(final BindingRegistry delegate, final Reporter reporter, final ResourceStore store) {
+        super(delegate, reporter);
+        this.m_reporter = reporter;
+        this.m_store = store;
+        addBindings(nullBindingsForMetaAnnotations());
+    }
+
+    protected Iterable<Binding> nullBindingsForMetaAnnotations() {
+        // Do not re-apply meta-annotations
+        ArrayList<Binding> bindings = new ArrayList<Binding>();
+        bindings.add(new NullBinding(Type.getType(Stereotype.class)));
+        bindings.add(new NullBinding(Type.getType(HandlerBinding.class)));
+        bindings.add(new NullBinding(Type.getType(Ignore.class)));
+        return bindings;
+    }
+
+    @Override
+    protected List<Binding> createBindings(final Type type) {
+
+        // Parse the annotation
+        byte[] bytes;
+        try {
+            bytes = m_store.read(type.getInternalName().concat(".class"));
+        } catch (IOException e) {
+            // Annotation type cannot be read
+            m_reporter.trace("Could not read bytecode for @%s", type.getClassName());
+            return emptyList();
+        }
+        AnnotationParser parser = new AnnotationParser();
+        AnnotationType annotationType = parser.read(bytes);
+
+        // Search meta-annotations
+        ChainedAnnotationDiscovery chain = new ChainedAnnotationDiscovery();
+        StereotypeDiscovery stereotypeDiscovery = new StereotypeDiscovery();
+        HandlerBindingDiscovery handlerBindingDiscovery = new HandlerBindingDiscovery();
+        IgnoredDiscovery ignoredDiscovery = new IgnoredDiscovery();
+        chain.getDiscoveries().add(stereotypeDiscovery);
+        chain.getDiscoveries().add(handlerBindingDiscovery);
+        chain.getDiscoveries().add(ignoredDiscovery);
+
+        annotationType.traverse(chain);
+
+        // Produced Bindings
+        List<Binding> bindings = new ArrayList<Binding>();
+
+        // @Stereotype support
+        if (stereotypeDiscovery.isStereotype()) {
+            m_reporter.trace("@Stereotype detected: @%s", type.getClassName());
+            Binding binding = new Binding();
+            binding.setAnnotationType(type);
+            binding.setPredicate(alwaysTrue());
+            binding.setFactory(new StereotypeVisitorFactory(annotationType));
+
+            bindings.add(binding);
+        }
+
+        // @HandlerBinding support
+        if (handlerBindingDiscovery.isHandlerBinding()) {
+
+            m_reporter.trace("@HandlerBinding detected: @%s", type.getClassName());
+            Binding binding = new Binding();
+            binding.setAnnotationType(type);
+            binding.setPredicate(alwaysTrue());
+            final Element element = buildElement(handlerBindingDiscovery, type);
+            binding.setFactory(new GenericVisitorFactory(element.getName(), element.getNameSpace()));
+
+            bindings.add(binding);
+        }
+
+        // Its IMPORTANT that the @Ignore is processed last since it removes existing bindings
+        if (ignoredDiscovery.isIgnore()) {
+            m_reporter.trace("@Ignore detected: @%s", type.getClassName());
+            Binding binding = new NullBinding(type);
+
+            bindings.clear();
+            bindings.add(binding);
+            bindings = unmodifiableList(bindings); // just in case of ...
+        }
+
+        return bindings;
+
+    }
+
+    private Element buildElement(final HandlerBindingDiscovery handler, final Type type) {
+        Element element;
+        if ((handler.getNamespace() == null) &&
+                (handler.getValue() == null)) {
+            // No attributes specified, use annotation type as element's source
+            element = Elements.buildElement(type);
+        } else if ((handler.getNamespace() == null) &&
+                (handler.getValue() != null)) {
+            // Namespace attribute is omitted
+            element = Elements.buildElement(handler.getValue());
+        } else {
+            element = Elements.buildElement(handler.getNamespace(),
+                                            handler.getValue());
+        }
+        return element;
+    }
+
+}

Modified: 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=1507289&r1=1507288&r2=1507289&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/Selection.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/Selection.java Fri Jul 26 12:33:28 2013
@@ -22,6 +22,7 @@ package org.apache.felix.ipojo.manipulat
 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.apache.felix.ipojo.manipulator.util.ChainedAnnotationVisitor;
 import org.objectweb.asm.AnnotationVisitor;
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.FieldVisitor;
@@ -34,7 +35,6 @@ import org.objectweb.asm.tree.MethodNode
 
 import java.lang.annotation.ElementType;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -42,13 +42,13 @@ import java.util.List;
  * It's a query DSL.
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public class Selection implements Iterable<AnnotationVisitor> {
+public class Selection {
 
     private BindingRegistry registry;
     private ComponentWorkbench workbench;
     private Reporter reporter;
     private MemberNode node;
-    private int index = -1;
+    private int index = BindingContext.NO_INDEX;
     private String annotation;
     private ElementType elementType = null;
     private Object visitor;
@@ -94,32 +94,34 @@ public class Selection implements Iterab
     }
 
     public AnnotationVisitor get() {
-        Iterator<AnnotationVisitor> i = iterator();
-        if (iterator().hasNext()) {
-            return i.next();
+        List<AnnotationVisitor> visitors = list();
+
+        if (visitors.isEmpty()) {
+            return null;
+        }
+
+        if (visitors.size() == 1) {
+            return visitors.get(0);
         }
-        return null;
-    }
 
-    public Iterator<AnnotationVisitor> iterator() {
+        ChainedAnnotationVisitor chained = new ChainedAnnotationVisitor();
+        chained.getVisitors().addAll(visitors);
+        return chained;
+    }
 
-        List<AnnotationVisitor> visitors = new ArrayList<AnnotationVisitor>();
+    private List<AnnotationVisitor> list() {
 
         BindingContext context = new BindingContext(workbench, reporter, Type.getType(annotation), node, elementType, index, visitor);
         List<Binding> predicates = registry.getBindings(annotation);
 
+        List<AnnotationVisitor> visitors = new ArrayList<AnnotationVisitor>();
         if (predicates != null && !predicates.isEmpty()) {
             collectMatchingVisitors(predicates, context, visitors);
         }
-
-        if (visitors.isEmpty() && !registry.getDefaultBindings().isEmpty()) {
-            collectMatchingVisitors(registry.getDefaultBindings(), context, visitors);
-        }
-
-
-        return visitors.iterator();
+        return visitors;
     }
 
+
     private void collectMatchingVisitors(List<Binding> bindings, BindingContext context, List<AnnotationVisitor> visitors) {
         for (Binding binding : bindings) {
             if (binding.getPredicate().matches(context)) {

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/generic/GenericVisitorFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/generic/GenericVisitorFactory.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/generic/GenericVisitorFactory.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/generic/GenericVisitorFactory.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,73 @@
+/*
+ * 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.generic;
+
+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.ClassNode;
+import org.objectweb.asm.tree.FieldNode;
+import org.objectweb.asm.tree.MethodNode;
+
+/**
+* User: guillaume
+* Date: 11/07/13
+* Time: 14:41
+*/
+public class GenericVisitorFactory implements AnnotationVisitorFactory {
+    private final String m_name;
+    private final String m_namespace;
+
+    public GenericVisitorFactory(final String name, final String namespace) {
+        m_name = name;
+        m_namespace = namespace;
+    }
+
+    // Need to build a new Element instance for each created visitor
+    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+        if (context.getNode() instanceof ClassNode) {
+            return new TypeGenericVisitor(context.getWorkbench(),
+                                          new Element(m_name, m_namespace));
+        } else if (context.getNode() instanceof FieldNode) {
+            return new FieldGenericVisitor(context.getWorkbench(),
+                                           new Element(m_name, m_namespace),
+                                           (FieldNode) context.getNode());
+
+        } else if ((context.getNode() instanceof MethodNode) &&
+                (context.getParameterIndex() == BindingContext.NO_INDEX)) {
+            return new MethodGenericVisitor(context.getWorkbench(),
+                                            new Element(m_name, m_namespace),
+                                            (MethodNode) context.getNode());
+        } else {
+            // last case: method parameter annotation
+            return new ParameterGenericVisitor(context.getWorkbench(),
+                                               new Element(m_name, m_namespace),
+                                               (MethodNode) context.getNode(),
+                                               context.getParameterIndex());
+        }
+    }
+
+    @Override
+    public String toString() {
+        return "GenericVisitorFactory";
+    }
+
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ignore/NullBinding.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ignore/NullBinding.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ignore/NullBinding.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ignore/NullBinding.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,40 @@
+/*
+ * 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.ignore;
+
+import static org.apache.felix.ipojo.manipulator.spi.helper.Predicates.alwaysTrue;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding;
+import org.objectweb.asm.Type;
+
+/**
+ * User: guillaume
+ * Date: 10/07/13
+ * Time: 15:04
+ */
+public class NullBinding extends Binding {
+    public NullBinding(final Type type) {
+        super();
+        setAnnotationType(type);
+        setPredicate(alwaysTrue());
+        setFactory(NullVisitorFactory.INSTANCE);
+
+    }
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ignore/NullVisitorFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ignore/NullVisitorFactory.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ignore/NullVisitorFactory.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/ignore/NullVisitorFactory.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.ignore;
+
+import org.apache.felix.ipojo.manipulator.spi.AnnotationVisitorFactory;
+import org.apache.felix.ipojo.manipulator.spi.BindingContext;
+import org.objectweb.asm.AnnotationVisitor;
+
+/**
+* User: guillaume
+* Date: 10/07/13
+* Time: 15:05
+*/
+public class NullVisitorFactory implements AnnotationVisitorFactory {
+    public static final AnnotationVisitorFactory INSTANCE = new NullVisitorFactory();
+
+    public AnnotationVisitor newAnnotationVisitor(final BindingContext context) {
+        return null;
+    }
+
+    @Override
+    public String toString() {
+        return getClass().getSimpleName();
+    }
+}

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/FieldStereotypeVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/FieldStereotypeVisitor.java?rev=1507289&r1=1507288&r2=1507289&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/FieldStereotypeVisitor.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/FieldStereotypeVisitor.java Fri Jul 26 12:33:28 2013
@@ -19,10 +19,8 @@
 
 package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype;
 
-import java.util.List;
-
-import org.apache.felix.ipojo.manipulator.metadata.annotation.stereotype.replay.RootAnnotationRecorder;
-import org.objectweb.asm.ClassVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.AnnotationType;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.Playback;
 import org.objectweb.asm.FieldVisitor;
 import org.objectweb.asm.commons.EmptyVisitor;
 
@@ -33,19 +31,19 @@ import org.objectweb.asm.commons.EmptyVi
  */
 public class FieldStereotypeVisitor extends EmptyVisitor {
 
-    private final FieldVisitor delegate;
-    private final List<RootAnnotationRecorder> m_recorder;
+    private final FieldVisitor m_delegate;
+    private final AnnotationType m_annotationType;
 
-    public FieldStereotypeVisitor(final FieldVisitor delegate, List<RootAnnotationRecorder> recorder) {
-        this.delegate = delegate;
-        m_recorder = recorder;
+    public FieldStereotypeVisitor(final FieldVisitor delegate, AnnotationType annotationType) {
+        this.m_delegate = delegate;
+        m_annotationType = annotationType;
     }
 
     @Override
     public void visitEnd() {
         // Replay stereotype annotations
-        for (RootAnnotationRecorder recorder : m_recorder) {
-            recorder.accept(delegate);
+        for (Playback playback : m_annotationType.getPlaybacks()) {
+            playback.accept(m_delegate);
         }
     }
 }

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/MethodStereotypeVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/MethodStereotypeVisitor.java?rev=1507289&r1=1507288&r2=1507289&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/MethodStereotypeVisitor.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/MethodStereotypeVisitor.java Fri Jul 26 12:33:28 2013
@@ -19,10 +19,8 @@
 
 package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype;
 
-import java.util.List;
-
-import org.apache.felix.ipojo.manipulator.metadata.annotation.stereotype.replay.RootAnnotationRecorder;
-import org.objectweb.asm.FieldVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.AnnotationType;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.Playback;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.commons.EmptyVisitor;
 
@@ -33,19 +31,19 @@ import org.objectweb.asm.commons.EmptyVi
  */
 public class MethodStereotypeVisitor extends EmptyVisitor {
 
-    private final MethodVisitor delegate;
-    private final List<RootAnnotationRecorder> m_recorder;
+    private final MethodVisitor m_delegate;
+    private final AnnotationType m_annotationType;
 
-    public MethodStereotypeVisitor(final MethodVisitor delegate, List<RootAnnotationRecorder> recorder) {
-        this.delegate = delegate;
-        m_recorder = recorder;
+    public MethodStereotypeVisitor(final MethodVisitor delegate, AnnotationType annotationType) {
+        this.m_delegate = delegate;
+        m_annotationType = annotationType;
     }
 
     @Override
     public void visitEnd() {
         // Replay stereotype annotations
-        for (RootAnnotationRecorder recorder : m_recorder) {
-            recorder.accept(delegate);
+        for (Playback playback : m_annotationType.getPlaybacks()) {
+            playback.accept(m_delegate);
         }
     }
 }

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/ParameterStereotypeVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/ParameterStereotypeVisitor.java?rev=1507289&r1=1507288&r2=1507289&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/ParameterStereotypeVisitor.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/ParameterStereotypeVisitor.java Fri Jul 26 12:33:28 2013
@@ -19,10 +19,8 @@
 
 package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype;
 
-import java.util.List;
-
-import org.apache.felix.ipojo.manipulator.metadata.annotation.stereotype.replay.RootAnnotationRecorder;
-import org.objectweb.asm.FieldVisitor;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.AnnotationType;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.Playback;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.commons.EmptyVisitor;
 
@@ -33,21 +31,21 @@ import org.objectweb.asm.commons.EmptyVi
  */
 public class ParameterStereotypeVisitor extends EmptyVisitor {
 
-    private final MethodVisitor delegate;
+    private final MethodVisitor m_delegate;
     private final int index;
-    private final List<RootAnnotationRecorder> m_recorder;
+    private final AnnotationType m_annotationType;
 
-    public ParameterStereotypeVisitor(final MethodVisitor delegate, final int index, List<RootAnnotationRecorder> recorder) {
-        this.delegate = delegate;
+    public ParameterStereotypeVisitor(final MethodVisitor delegate, final int index, AnnotationType annotationType) {
+        this.m_delegate = delegate;
         this.index = index;
-        m_recorder = recorder;
+        m_annotationType = annotationType;
     }
 
     @Override
     public void visitEnd() {
         // Replay stereotype annotations
-        for (RootAnnotationRecorder recorder : m_recorder) {
-            recorder.accept(delegate, index);
+        for (Playback playback : m_annotationType.getPlaybacks()) {
+            playback.accept(m_delegate, index);
         }
     }
 }

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/StereotypeVisitorFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/StereotypeVisitorFactory.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/StereotypeVisitorFactory.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/StereotypeVisitorFactory.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,71 @@
+/*
+ * 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.stereotype;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.AnnotationType;
+import org.apache.felix.ipojo.manipulator.spi.AnnotationVisitorFactory;
+import org.apache.felix.ipojo.manipulator.spi.BindingContext;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.FieldNode;
+import org.objectweb.asm.tree.MethodNode;
+
+/**
+* User: guillaume
+* Date: 11/07/13
+* Time: 14:26
+*/
+public class StereotypeVisitorFactory implements AnnotationVisitorFactory {
+    private final AnnotationType m_annotationType;
+
+    public StereotypeVisitorFactory(final AnnotationType annotationType) {
+        m_annotationType = annotationType;
+    }
+
+    public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
+        if (context.getNode() instanceof ClassNode) {
+            return new TypeStereotypeVisitor((ClassVisitor) context.getVisitor(),
+                                             m_annotationType);
+        } else if (context.getNode() instanceof FieldNode) {
+            return new FieldStereotypeVisitor((FieldVisitor) context.getVisitor(),
+                                              m_annotationType);
+
+        } else if ((context.getNode() instanceof MethodNode) &&
+                (context.getParameterIndex() == BindingContext.NO_INDEX)) {
+            return new MethodStereotypeVisitor((MethodVisitor) context.getVisitor(),
+                                               m_annotationType);
+
+        } else {
+            // last case: method parameter annotation
+            return new ParameterStereotypeVisitor((MethodVisitor) context.getVisitor(),
+                                                  context.getParameterIndex(),
+                                                  m_annotationType);
+        }
+
+    }
+
+    @Override
+    public String toString() {
+        return "StereotypeVisitorFactory";
+    }
+}

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/TypeStereotypeVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/TypeStereotypeVisitor.java?rev=1507289&r1=1507288&r2=1507289&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/TypeStereotypeVisitor.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/TypeStereotypeVisitor.java Fri Jul 26 12:33:28 2013
@@ -19,9 +19,8 @@
 
 package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype;
 
-import java.util.List;
-
-import org.apache.felix.ipojo.manipulator.metadata.annotation.stereotype.replay.RootAnnotationRecorder;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.AnnotationType;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.Playback;
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.commons.EmptyVisitor;
 
@@ -32,19 +31,19 @@ import org.objectweb.asm.commons.EmptyVi
  */
 public class TypeStereotypeVisitor extends EmptyVisitor {
 
-    private final ClassVisitor delegate;
-    private final List<RootAnnotationRecorder> m_recorder;
+    private final ClassVisitor m_delegate;
+    private final AnnotationType m_annotationType;
 
-    public TypeStereotypeVisitor(final ClassVisitor delegate, List<RootAnnotationRecorder> recorder) {
-        this.delegate = delegate;
-        m_recorder = recorder;
+    public TypeStereotypeVisitor(final ClassVisitor delegate, AnnotationType annotationType) {
+        this.m_delegate = delegate;
+        m_annotationType = annotationType;
     }
 
     @Override
     public void visitEnd() {
         // Replay stereotype annotations
-        for (RootAnnotationRecorder recorder : m_recorder) {
-            recorder.accept(delegate);
+        for (Playback playback : m_annotationType.getPlaybacks()) {
+            playback.accept(m_delegate);
         }
     }
 }

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Bindings.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Bindings.java?rev=1507289&r1=1507288&r2=1507289&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Bindings.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Bindings.java Fri Jul 26 12:33:28 2013
@@ -21,129 +21,31 @@ package org.apache.felix.ipojo.manipulat
 
 import org.apache.felix.ipojo.manipulator.Reporter;
 import org.apache.felix.ipojo.manipulator.ResourceStore;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.AnnotationRegistry;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.stereotype.StereotypeParser;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.DefaultBindingRegistry;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.IgnoreAllBindingRegistry;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.LegacyGenericBindingRegistry;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.MetaAnnotationBindingRegistry;
 import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.BindingRegistry;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype.FieldStereotypeVisitor;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype.MethodStereotypeVisitor;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype.ParameterStereotypeVisitor;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype.TypeStereotypeVisitor;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.FieldGenericVisitor;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.MethodGenericVisitor;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.ParameterGenericVisitor;
-import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.TypeGenericVisitor;
-import org.apache.felix.ipojo.manipulator.spi.AnnotationVisitorFactory;
-import org.apache.felix.ipojo.manipulator.spi.BindingContext;
 import org.apache.felix.ipojo.manipulator.spi.Module;
-import org.apache.felix.ipojo.manipulator.spi.Predicate;
-import org.apache.felix.ipojo.manipulator.util.Strings;
-import org.apache.felix.ipojo.metadata.Element;
-import org.objectweb.asm.AnnotationVisitor;
-import org.objectweb.asm.ClassVisitor;
-import org.objectweb.asm.FieldVisitor;
-import org.objectweb.asm.MethodVisitor;
-import org.objectweb.asm.Type;
-import org.objectweb.asm.tree.FieldNode;
-import org.objectweb.asm.tree.MethodNode;
 
-import java.io.IOException;
-import java.lang.annotation.ElementType;
-import java.util.ArrayList;
-import java.util.List;
 import java.util.ServiceLoader;
 
-import static org.apache.felix.ipojo.manipulator.spi.helper.Predicates.and;
-import static org.apache.felix.ipojo.manipulator.spi.helper.Predicates.on;
 import static org.apache.felix.ipojo.manipulator.spi.helper.Predicates.or;
-import static org.apache.felix.ipojo.manipulator.spi.helper.Predicates.pattern;
 
 /**
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class Bindings {
 
-    private static Binding newGenericTypeBinding() {
-        Binding binding = new Binding();
-        // ElementType is TYPE
-        // Annotation descriptor is matching generic pattern
-        binding.setPredicate(
-                and(
-                        on(ElementType.TYPE),
-                        customAnnotationPattern()
-                ));
-        binding.setFactory(new AnnotationVisitorFactory() {
-            public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
-                Element element = Elements.buildElement(context.getAnnotationType());
-                return new TypeGenericVisitor(context.getWorkbench(), element);
-            }
-        });
-        return binding;
-    }
-
-    private static Predicate customAnnotationPattern() {
-        return pattern("(.*\\.ipojo\\..*)|(.*\\.handler\\..*)").matches();
-    }
-
-    private static Binding newGenericFieldBinding() {
-        Binding binding = new Binding();
-        // ElementType is FIELD
-        // Annotation descriptor is matching generic pattern
-        binding.setPredicate(
-                and(
-                        on(ElementType.FIELD),
-                        customAnnotationPattern()
-                ));
-        binding.setFactory(new AnnotationVisitorFactory() {
-            public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
-                Element element = Elements.buildElement(context.getAnnotationType());
-                return new FieldGenericVisitor(context.getWorkbench(), element, (FieldNode) context.getNode());
-            }
-        });
-        return binding;
-    }
-
-    private static Binding newGenericMethodBinding() {
-        Binding binding = new Binding();
-        // ElementType is METHOD
-        // Annotation descriptor is matching generic pattern
-        binding.setPredicate(
-                and(
-                        on(ElementType.METHOD),
-                        customAnnotationPattern()
-                ));
-        binding.setFactory(new AnnotationVisitorFactory() {
-            public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
-                Element element = Elements.buildElement(context.getAnnotationType());
-                return new MethodGenericVisitor(context.getWorkbench(), element, (MethodNode) context.getNode());
-            }
-        });
-        return binding;
-    }
-
-    private static Binding newGenericParameterBinding() {
-        Binding binding = new Binding();
-        // ElementType is METHOD
-        // Annotation descriptor is matching generic pattern
-        binding.setPredicate(
-                and(
-                        on(ElementType.PARAMETER),
-                        customAnnotationPattern()
-                ));
-        binding.setFactory(new AnnotationVisitorFactory() {
-            public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
-                Element element = Elements.buildElement(context.getAnnotationType());
-                return new ParameterGenericVisitor(context.getWorkbench(), element, (MethodNode) context.getNode(), context.getParameterIndex());
-            }
-        });
-        return binding;
-    }
-
-
     public static BindingRegistry newBindingRegistry(Reporter reporter, ResourceStore store) {
 
-        AnnotationRegistry ar = new AnnotationRegistry();
-        BindingRegistry registry = new BindingRegistry(reporter);
+        // Build the registry by aggregation of the features we want
+        // TODO We can enable/disable the legacy support easily here
+        BindingRegistry registry = new DefaultBindingRegistry(reporter);
+        registry = new MetaAnnotationBindingRegistry(registry, reporter, store);
+        registry = new LegacyGenericBindingRegistry(registry, reporter);
+        registry = new IgnoreAllBindingRegistry(registry, reporter);
+
         ServiceLoader<Module> loader = ServiceLoader.load(Module.class, classloader());
 
         // Build each Module and add its contributed Bindings in the registry
@@ -152,127 +54,9 @@ public class Bindings {
             registry.addBindings(module);
         }
 
-        // Do not forget the default Bindings
-        registry.getDefaultBindings().addAll(newDefaultBindings(store, ar));
-
         return registry;
     }
 
-    public static List<Binding> newDefaultBindings(final ResourceStore store, final AnnotationRegistry ar) {
-        List<Binding> bindings = new ArrayList<Binding>();
-
-        // Register Stereotype binding support first
-        // That allows iPOJO to provide its own stereotyped annotations
-        bindings.add(newStereotypeTypeBinding(store, ar));
-        bindings.add(newStereotypeFieldBinding(store, ar));
-        bindings.add(newStereotypeMethodBinding(store, ar));
-        bindings.add(newStereotypeParameterBinding(store, ar));
-
-        // Then register the generic bindings
-        bindings.add(newGenericTypeBinding());
-        bindings.add(newGenericFieldBinding());
-        bindings.add(newGenericMethodBinding());
-        bindings.add(newGenericParameterBinding());
-        return bindings;
-
-    }
-
-    private static Binding newStereotypeParameterBinding(final ResourceStore store, final AnnotationRegistry registry) {
-        Binding binding = new Binding();
-        binding.setPredicate(
-                and(
-                        on(ElementType.PARAMETER),
-                        stereotype(store, registry)
-                ));
-        binding.setFactory(new AnnotationVisitorFactory() {
-            public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
-                return new ParameterStereotypeVisitor((MethodVisitor) context.getVisitor(),
-                                                      context.getParameterIndex(),
-                                                      registry.getRecorders(context.getAnnotationType()));
-            }
-        });
-        return binding;
-    }
-
-    private static Binding newStereotypeMethodBinding(final ResourceStore store, final AnnotationRegistry registry) {
-        Binding binding = new Binding();
-        binding.setPredicate(
-                and(
-                        on(ElementType.METHOD),
-                        stereotype(store, registry)
-                ));
-        binding.setFactory(new AnnotationVisitorFactory() {
-            public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
-                return new MethodStereotypeVisitor((MethodVisitor) context.getVisitor(),
-                                                  registry.getRecorders(context.getAnnotationType()));
-            }
-        });
-        return binding;
-    }
-
-    private static Binding newStereotypeFieldBinding(final ResourceStore store, final AnnotationRegistry registry) {
-        Binding binding = new Binding();
-        binding.setPredicate(
-                and(
-                        on(ElementType.FIELD),
-                        stereotype(store, registry)
-                ));
-        binding.setFactory(new AnnotationVisitorFactory() {
-            public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
-                return new FieldStereotypeVisitor((FieldVisitor) context.getVisitor(),
-                                                  registry.getRecorders(context.getAnnotationType()));
-            }
-        });
-        return binding;
-    }
-
-    private static Binding newStereotypeTypeBinding(final ResourceStore store, final AnnotationRegistry registry) {
-        Binding binding = new Binding();
-        binding.setPredicate(
-                and(
-                        on(ElementType.TYPE),
-                        stereotype(store, registry)
-                ));
-        binding.setFactory(new AnnotationVisitorFactory() {
-            public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
-                return new TypeStereotypeVisitor((ClassVisitor) context.getVisitor(),
-                                                 registry.getRecorders(context.getAnnotationType()));
-            }
-        });
-        return binding;
-    }
-
-    private static Predicate stereotype(final ResourceStore store, final AnnotationRegistry registry) {
-        return new Predicate() {
-            public boolean matches(final BindingContext context) {
-
-                Type type = context.getAnnotationType();
-                if (registry.isUnknown(type)) {
-                    // The given annotation type was never parsed before
-                    try {
-
-                        // Try to read the annotation's byte code
-                        byte[] bytes = store.read(Strings.asResourcePath(context.getAnnotationType().getClassName()));
-                        StereotypeParser parser = new StereotypeParser();
-                        parser.read(bytes);
-                        if (parser.isStereotype()) {
-                            registry.addStereotype(type, parser.getRecorders());
-                            return true;
-                        }
-                        registry.addUnbound(type);
-                        return false;
-                    } catch (IOException e) {
-                        // Cannot load the byte code, assume it's not a stereotype
-                        // TODO print a warning ?
-                        registry.addUnbound(type);
-                        return false;
-                    }
-                }
-                return registry.isStereotype(type);
-            }
-        };
-    }
-
     private static ClassLoader classloader() {
         return Bindings.class.getClassLoader();
     }

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Elements.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Elements.java?rev=1507289&r1=1507288&r2=1507289&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Elements.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/util/Elements.java Fri Jul 26 12:33:28 2013
@@ -19,6 +19,8 @@
 
 package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.util;
 
+import static java.lang.String.format;
+
 import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
 import org.apache.felix.ipojo.metadata.Element;
 import org.objectweb.asm.Type;
@@ -41,7 +43,38 @@ public class Elements {
         int index = name.lastIndexOf('.');
         String local = name.substring(index + 1);
         String namespace = name.substring(0, index);
-        return new Element(local, namespace);
+        return buildElement(namespace, local);
+    }
+
+    /**
+     * Build an {@link Element} using the provided namespace and local name.
+     */
+    public static Element buildElement(final String namespace, final String name) {
+        return new Element(name, namespace);
+    }
+
+    /**
+     * Build an {@link Element} using the provided binding information.
+     * Expected format is {@literal [namespace:]name} (eg: {@literal com.acme:foo} or {@literal foo} if namespace
+     * by default -org.apache.felix.ipojo- has to be used).
+     * Notice that the ':' character usage in namespace or name part may lead to unexpected results.
+     * In that case, the @HandlerBinding(namespace = "urn:my:namespace", value = "foo:handler") usage is preferred.
+     * @param binding the condensed element name
+     * @return the new element
+     */
+    public static Element buildElement(String binding) {
+        String[] split = binding.split(":");
+        if (split.length == 1) {
+            return buildElement("", binding);
+        }
+        if (split.length > 2) {
+            throw new IllegalArgumentException(
+                    format("@HandlerBinding(\"%s\") is invalid: only 1 ':' char is authorized, please" +
+                           " use the @HandlerBinding(namespace=\"...\", value=\"...\") form instead.",
+                           binding)
+            );
+        }
+        return buildElement(split[0], split[1]);
     }
 
     /**
@@ -52,7 +85,7 @@ public class Elements {
     public static Element getPropertiesElement(ComponentWorkbench workbench) {
         Element properties = workbench.getIds().get("properties");
         if (properties == null) {
-            properties = new Element("properties", "");
+            properties = buildElement("", "properties");
             workbench.getIds().put("properties", properties);
             workbench.getElements().put(properties, null);
         }

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/AbsBindingModule.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/AbsBindingModule.java?rev=1507289&r1=1507288&r2=1507289&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/AbsBindingModule.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/AbsBindingModule.java Fri Jul 26 12:33:28 2013
@@ -19,21 +19,23 @@
 
 package org.apache.felix.ipojo.manipulator.spi;
 
-import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding;
+import static org.apache.felix.ipojo.manipulator.spi.helper.Predicates.onlySupportedElements;
 
 import java.lang.annotation.Annotation;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Target;
 import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 
-import static org.apache.felix.ipojo.manipulator.spi.helper.Predicates.alwaysTrue;
-import static org.apache.felix.ipojo.manipulator.spi.helper.Predicates.on;
-import static org.apache.felix.ipojo.manipulator.spi.helper.Predicates.onlySupportedElements;
-import static org.apache.felix.ipojo.manipulator.spi.helper.Predicates.or;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.AnnotationType;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.literal.AnnotationLiteral;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.literal.AnnotationPlayback;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.GenericVisitorFactory;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype.StereotypeVisitorFactory;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.util.Elements;
+import org.apache.felix.ipojo.metadata.Element;
+import org.objectweb.asm.Type;
 
 /**
  * All provided {@link Module}s have to inherit from this class.
@@ -66,6 +68,18 @@ public abstract class AbsBindingModule i
         return new AnnotationBindingBuilder(bindings, annotationType);
     }
 
+    protected StereotypeBindingBuilder bindStereotype(Class<? extends Annotation> annotationType) {
+        return new StereotypeBindingBuilder(bindings, annotationType);
+    }
+
+    protected HandlerBindingBuilder bindHandlerBinding(Class<? extends Annotation> annotationType) {
+        return new HandlerBindingBuilder(bindings, annotationType);
+    }
+
+    protected void bindIgnore(Class<? extends Annotation> annotationType) {
+        bindings.add(new NullBinding(Type.getType(annotationType)));
+    }
+
     /**
      * DSL helper class.
      */
@@ -104,7 +118,7 @@ public abstract class AbsBindingModule i
          */
         private Binding build() {
             Binding binding = new Binding();
-            binding.setAnnotationType(annotationType);
+            binding.setAnnotationType(Type.getType(annotationType));
             binding.setPredicate(onlySupportedElements(annotationType));
             binding.setFactory(factory);
             return binding;
@@ -145,4 +159,40 @@ public abstract class AbsBindingModule i
         }
     }
 
+    public class StereotypeBindingBuilder {
+        private final AnnotationType m_annotationType;
+
+        public StereotypeBindingBuilder(final List<Binding> bindings, final Class<? extends Annotation> type) {
+            m_annotationType = new AnnotationType(Type.getType(type));
+            Binding binding = new Binding();
+            binding.setAnnotationType(m_annotationType.getType());
+            binding.setPredicate(onlySupportedElements(type));
+            binding.setFactory(new StereotypeVisitorFactory(m_annotationType));
+            bindings.add(binding);
+        }
+
+        public StereotypeBindingBuilder with(AnnotationLiteral<?> literal) {
+            m_annotationType.getPlaybacks().add(new AnnotationPlayback(literal));
+            return this;
+        }
+    }
+
+    public class HandlerBindingBuilder {
+
+        private final Binding m_binding;
+
+        public HandlerBindingBuilder(final List<Binding> bindings, final Class<? extends Annotation> annotationType) {
+            m_binding = new Binding();
+            Type type = Type.getType(annotationType);
+            m_binding.setAnnotationType(type);
+            m_binding.setPredicate(onlySupportedElements(annotationType));
+            Element e = Elements.buildElement(type);
+            m_binding.setFactory(new GenericVisitorFactory(e.getName(), e.getNameSpace()));
+            bindings.add(m_binding);
+        }
+
+        public void to(String namespace, String name) {
+            m_binding.setFactory(new GenericVisitorFactory(name, namespace));
+        }
+    }
 }

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/BindingContext.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/BindingContext.java?rev=1507289&r1=1507288&r2=1507289&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/BindingContext.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/spi/BindingContext.java Fri Jul 26 12:33:28 2013
@@ -31,6 +31,8 @@ import java.lang.annotation.ElementType;
  */
 public class BindingContext {
 
+    public static final int NO_INDEX = -1;
+
     /**
      *
      */

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/util/ChainedAnnotationVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/util/ChainedAnnotationVisitor.java?rev=1507289&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/util/ChainedAnnotationVisitor.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/util/ChainedAnnotationVisitor.java Fri Jul 26 12:33:28 2013
@@ -0,0 +1,88 @@
+/*
+ * 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.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.model.discovery.ChainedAnnotationDiscovery;
+import org.objectweb.asm.AnnotationVisitor;
+
+/**
+* User: guillaume
+* Date: 10/07/13
+* Time: 16:43
+*/
+public class ChainedAnnotationVisitor implements AnnotationVisitor {
+
+    private List<AnnotationVisitor> m_visitors = new ArrayList<AnnotationVisitor>();
+
+    public List<AnnotationVisitor> getVisitors() {
+        return m_visitors;
+    }
+
+    public void visit(final String name, final Object value) {
+        for (AnnotationVisitor visitor : m_visitors) {
+            visitor.visit(name, value);
+        }
+    }
+
+    public void visitEnum(final String name, final String desc, final String value) {
+        for (AnnotationVisitor visitor : m_visitors) {
+            visitor.visitEnum(name, desc, value);
+        }
+    }
+
+    public AnnotationVisitor visitAnnotation(final String name, final String desc) {
+        ChainedAnnotationVisitor chain = null;
+        for (AnnotationVisitor visitor : m_visitors) {
+            AnnotationVisitor child = visitor.visitAnnotation(name, desc);
+            if (child != null) {
+                if (chain == null) {
+                    chain = new ChainedAnnotationVisitor();
+                }
+                chain.getVisitors().add(child);
+            }
+
+        }
+        return chain;
+    }
+
+    public AnnotationVisitor visitArray(final String name) {
+        ChainedAnnotationVisitor chain = null;
+        for (AnnotationVisitor visitor : m_visitors) {
+            AnnotationVisitor child = visitor.visitArray(name);
+            if (child != null) {
+                if (chain == null) {
+                    chain = new ChainedAnnotationVisitor();
+                }
+                chain.getVisitors().add(child);
+            }
+
+        }
+        return chain;
+    }
+
+    public void visitEnd() {
+        for (AnnotationVisitor visitor : m_visitors) {
+            visitor.visitEnd();
+        }
+    }
+}



Mime
View raw message