You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gu...@apache.org on 2013/06/03 17:49:22 UTC

svn commit: r1489041 [2/2] - in /felix/trunk/ipojo/manipulator: annotations/src/main/java/org/apache/felix/ipojo/annotations/ annotations/src/main/java/org/apache/felix/ipojo/extender/ annotations/src/main/java/org/apache/felix/ipojo/handler/temporal/ ...

Added: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/replay/VisitEnd.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/replay/VisitEnd.java?rev=1489041&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/replay/VisitEnd.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/replay/VisitEnd.java Mon Jun  3 15:49:20 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.stereotype.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/stereotype/replay/VisitEnum.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/replay/VisitEnum.java?rev=1489041&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/replay/VisitEnum.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/replay/VisitEnum.java Mon Jun  3 15:49:20 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.stereotype.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);
+    }
+}

Added: 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=1489041&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/FieldStereotypeVisitor.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/FieldStereotypeVisitor.java Mon Jun  3 15:49:20 2013
@@ -0,0 +1,51 @@
+/*
+ * 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 java.util.List;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.stereotype.replay.RootAnnotationRecorder;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+
+/**
+ * User: guillaume
+ * Date: 30/05/13
+ * Time: 18:55
+ */
+public class FieldStereotypeVisitor extends EmptyVisitor {
+
+    private final FieldVisitor delegate;
+    private final List<RootAnnotationRecorder> m_recorder;
+
+    public FieldStereotypeVisitor(final FieldVisitor delegate, List<RootAnnotationRecorder> recorder) {
+        this.delegate = delegate;
+        m_recorder = recorder;
+    }
+
+    @Override
+    public void visitEnd() {
+        // Replay stereotype annotations
+        for (RootAnnotationRecorder recorder : m_recorder) {
+            recorder.accept(delegate);
+        }
+    }
+}

Added: 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=1489041&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/MethodStereotypeVisitor.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/MethodStereotypeVisitor.java Mon Jun  3 15:49:20 2013
@@ -0,0 +1,51 @@
+/*
+ * 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 java.util.List;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.stereotype.replay.RootAnnotationRecorder;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+
+/**
+ * User: guillaume
+ * Date: 30/05/13
+ * Time: 18:55
+ */
+public class MethodStereotypeVisitor extends EmptyVisitor {
+
+    private final MethodVisitor delegate;
+    private final List<RootAnnotationRecorder> m_recorder;
+
+    public MethodStereotypeVisitor(final MethodVisitor delegate, List<RootAnnotationRecorder> recorder) {
+        this.delegate = delegate;
+        m_recorder = recorder;
+    }
+
+    @Override
+    public void visitEnd() {
+        // Replay stereotype annotations
+        for (RootAnnotationRecorder recorder : m_recorder) {
+            recorder.accept(delegate);
+        }
+    }
+}

Added: 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=1489041&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/ParameterStereotypeVisitor.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/ParameterStereotypeVisitor.java Mon Jun  3 15:49:20 2013
@@ -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.stereotype;
+
+import java.util.List;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.stereotype.replay.RootAnnotationRecorder;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+
+/**
+ * User: guillaume
+ * Date: 30/05/13
+ * Time: 18:55
+ */
+public class ParameterStereotypeVisitor extends EmptyVisitor {
+
+    private final MethodVisitor delegate;
+    private final int index;
+    private final List<RootAnnotationRecorder> m_recorder;
+
+    public ParameterStereotypeVisitor(final MethodVisitor delegate, final int index, List<RootAnnotationRecorder> recorder) {
+        this.delegate = delegate;
+        this.index = index;
+        m_recorder = recorder;
+    }
+
+    @Override
+    public void visitEnd() {
+        // Replay stereotype annotations
+        for (RootAnnotationRecorder recorder : m_recorder) {
+            recorder.accept(delegate, index);
+        }
+    }
+}

Added: 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=1489041&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/TypeStereotypeVisitor.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/stereotype/TypeStereotypeVisitor.java Mon Jun  3 15:49:20 2013
@@ -0,0 +1,50 @@
+/*
+ * 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 java.util.List;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.stereotype.replay.RootAnnotationRecorder;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.commons.EmptyVisitor;
+
+/**
+ * User: guillaume
+ * Date: 30/05/13
+ * Time: 18:55
+ */
+public class TypeStereotypeVisitor extends EmptyVisitor {
+
+    private final ClassVisitor delegate;
+    private final List<RootAnnotationRecorder> m_recorder;
+
+    public TypeStereotypeVisitor(final ClassVisitor delegate, List<RootAnnotationRecorder> recorder) {
+        this.delegate = delegate;
+        m_recorder = recorder;
+    }
+
+    @Override
+    public void visitEnd() {
+        // Replay stereotype annotations
+        for (RootAnnotationRecorder recorder : m_recorder) {
+            recorder.accept(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=1489041&r1=1489040&r2=1489041&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 Mon Jun  3 15:49:20 2013
@@ -20,8 +20,15 @@
 package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.util;
 
 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.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;
@@ -30,20 +37,25 @@ import org.apache.felix.ipojo.manipulato
 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.Collections;
 import java.util.List;
 import java.util.ServiceLoader;
-import java.util.regex.Pattern;
 
 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;
 
 /**
@@ -51,16 +63,6 @@ import static org.apache.felix.ipojo.man
  */
 public class Bindings {
 
-    private static List<Binding> DEFAULT_BINDINGS;
-    static {
-        DEFAULT_BINDINGS = new ArrayList<Binding>();
-        DEFAULT_BINDINGS.add(newGenericTypeBinding());
-        DEFAULT_BINDINGS.add(newGenericFieldBinding());
-        DEFAULT_BINDINGS.add(newGenericMethodBinding());
-        DEFAULT_BINDINGS.add(newGenericParameterBinding());
-        DEFAULT_BINDINGS = Collections.unmodifiableList(DEFAULT_BINDINGS);
-    }
-
     private static Binding newGenericTypeBinding() {
         Binding binding = new Binding();
         // ElementType is TYPE
@@ -138,8 +140,9 @@ public class Bindings {
     }
 
 
-    public static BindingRegistry newBindingRegistry(Reporter reporter) {
+    public static BindingRegistry newBindingRegistry(Reporter reporter, ResourceStore store) {
 
+        AnnotationRegistry ar = new AnnotationRegistry();
         BindingRegistry registry = new BindingRegistry(reporter);
         ServiceLoader<Module> loader = ServiceLoader.load(Module.class, classloader());
 
@@ -150,13 +153,129 @@ public class Bindings {
         }
 
         // Do not forget the default Bindings
-        registry.getDefaultBindings().addAll(DEFAULT_BINDINGS);
+        registry.getDefaultBindings().addAll(newDefaultBindings(store, ar));
 
         return registry;
     }
 
-    public static List<Binding> getDefaultBindings() {
-        return DEFAULT_BINDINGS;
+    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()));
+                        if (bytes != null) {
+                            StereotypeParser parser = new StereotypeParser();
+                            parser.read(bytes);
+                            if (parser.isStereotype()) {
+                                registry.addStereotype(type, parser.getRecorders());
+                                return true;
+                            } else {
+                                registry.addUnbound(type);
+                                return false;
+                            }
+                        }
+                        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() {

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=1489041&r1=1489040&r2=1489041&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 Mon Jun  3 15:49:20 2013
@@ -40,19 +40,22 @@ public class BindingContext {
     private int parameterIndex;
     private Reporter reporter;
     private Type annotationType;
+    private Object visitor;
 
     public BindingContext(final ComponentWorkbench workbench,
                           final Reporter reporter,
                           final Type annotationType,
                           final MemberNode node,
                           final ElementType elementType,
-                          final int parameterIndex) {
+                          final int parameterIndex,
+                          final Object visitor) {
         this.workbench = workbench;
         this.reporter = reporter;
         this.annotationType = annotationType;
         this.node = node;
         this.elementType = elementType;
         this.parameterIndex = parameterIndex;
+        this.visitor = visitor;
     }
 
     public ComponentWorkbench getWorkbench() {
@@ -78,4 +81,8 @@ public class BindingContext {
     public Type getAnnotationType() {
         return annotationType;
     }
+
+    public Object getVisitor() {
+        return visitor;
+    }
 }

Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/AnnotationRegistryTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/AnnotationRegistryTestCase.java?rev=1489041&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/AnnotationRegistryTestCase.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/AnnotationRegistryTestCase.java Mon Jun  3 15:49:20 2013
@@ -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 java.util.Collections;
+
+import org.apache.felix.ipojo.manipulator.metadata.annotation.stereotype.replay.RootAnnotationRecorder;
+import org.objectweb.asm.Type;
+
+import junit.framework.TestCase;
+
+/**
+ * User: guillaume
+ * Date: 31/05/13
+ * Time: 00:18
+ */
+public class AnnotationRegistryTestCase extends TestCase {
+    public void testEmptyRegistry() throws Exception {
+        AnnotationRegistry registry = new AnnotationRegistry();
+        assertTrue(registry.isUnknown(Type.BOOLEAN_TYPE));
+        assertFalse(registry.isStereotype(Type.BOOLEAN_TYPE));
+        assertFalse(registry.isUnbound(Type.BOOLEAN_TYPE));
+    }
+
+    public void testRegistry1() throws Exception {
+        AnnotationRegistry registry = new AnnotationRegistry();
+        registry.addStereotype(Type.BOOLEAN_TYPE, Collections.<RootAnnotationRecorder>emptyList());
+
+        assertFalse(registry.isUnknown(Type.BOOLEAN_TYPE));
+        assertTrue(registry.isStereotype(Type.BOOLEAN_TYPE));
+        assertFalse(registry.isUnbound(Type.BOOLEAN_TYPE));
+    }
+
+    public void testRegistry2() throws Exception {
+        AnnotationRegistry registry = new AnnotationRegistry();
+        registry.addUnbound(Type.BOOLEAN_TYPE);
+
+        assertFalse(registry.isUnknown(Type.BOOLEAN_TYPE));
+        assertFalse(registry.isStereotype(Type.BOOLEAN_TYPE));
+        assertTrue(registry.isUnbound(Type.BOOLEAN_TYPE));
+    }
+}

Modified: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/SelectionTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/SelectionTestCase.java?rev=1489041&r1=1489040&r2=1489041&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/SelectionTestCase.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/registry/SelectionTestCase.java Mon Jun  3 15:49:20 2013
@@ -21,6 +21,7 @@ package org.apache.felix.ipojo.manipulat
 
 import junit.framework.TestCase;
 import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.ResourceStore;
 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;
@@ -64,6 +65,8 @@ public class SelectionTestCase extends T
     private AnnotationVisitorFactory factory;
     @Mock
     private AnnotationVisitor visitor;
+    @Mock
+    private ResourceStore store;
 
     @Override
     public void setUp() throws Exception {
@@ -149,7 +152,7 @@ public class SelectionTestCase extends T
         assertMethodSelection(OnMethodOnly.class, nullValue());
         assertParameterSelection(OnParameterOnly.class, nullValue());
 
-        registry.getDefaultBindings().addAll(Bindings.getDefaultBindings());
+        registry.getDefaultBindings().addAll(Bindings.newDefaultBindings(store, new AnnotationRegistry()));
 
         // Verifications
         assertClassSelection(OnTypeOnly.class, instanceOf(TypeGenericVisitor.class));
@@ -161,7 +164,7 @@ public class SelectionTestCase extends T
 
     private void assertClassSelection(Class<? extends Annotation> type, Matcher matcher) {
         Selection selection = new Selection(registry, null, reporter);
-        selection.type(classNode());
+        selection.type(null, classNode());
         selection.annotatedWith(descriptor(type));
 
         assertTrue(matcher.matches(selection.get()));
@@ -169,7 +172,7 @@ public class SelectionTestCase extends T
 
     private void assertFieldSelection(Class<? extends Annotation> type, Matcher matcher) {
         Selection selection = new Selection(registry, null, reporter);
-        selection.field(fieldNode());
+        selection.field(null, fieldNode());
         selection.annotatedWith(descriptor(type));
 
         assertTrue(matcher.matches(selection.get()));
@@ -177,7 +180,7 @@ public class SelectionTestCase extends T
 
     private void assertMethodSelection(Class<? extends Annotation> type, Matcher matcher) {
         Selection selection = new Selection(registry, null, reporter);
-        selection.method(methodNode());
+        selection.method(null, methodNode());
         selection.annotatedWith(descriptor(type));
 
         assertTrue(matcher.matches(selection.get()));
@@ -185,7 +188,7 @@ public class SelectionTestCase extends T
 
     private void assertParameterSelection(Class<? extends Annotation> type, Matcher matcher) {
         Selection selection = new Selection(registry, null, reporter);
-        selection.parameter(methodNode(), 0);
+        selection.parameter(null, methodNode(), 0);
         selection.annotatedWith(descriptor(type));
 
         assertTrue(matcher.matches(selection.get()));
@@ -204,7 +207,7 @@ public class SelectionTestCase extends T
     public void testSelectionWithEmptyRegistry() throws Exception {
         Selection selection = new Selection(registry, null, reporter);
 
-        selection.field(fieldNode())
+        selection.field(null, fieldNode())
                 .annotatedWith(descriptor(OnTypeOnly.class));
 
         assertNull(selection.get());

Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/StereotypeParserTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/StereotypeParserTestCase.java?rev=1489041&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/StereotypeParserTestCase.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/StereotypeParserTestCase.java Mon Jun  3 15:49:20 2013
@@ -0,0 +1,115 @@
+/*
+ * 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.stereotype;
+
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.when;
+
+import java.net.URL;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Instantiate;
+import org.apache.felix.ipojo.annotations.Stereotype;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.stereotype.replay.RootAnnotationRecorder;
+import org.apache.felix.ipojo.manipulator.util.Streams;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.Type;
+
+import junit.framework.TestCase;
+
+/**
+ * User: guillaume
+ * Date: 30/05/13
+ * Time: 23:51
+ */
+public class StereotypeParserTestCase extends TestCase {
+    public static final String COMPONENT_DESC = Type.getType(Component.class).getDescriptor();
+    public static final String INSTANTIATE_DESC = Type.getType(Instantiate.class).getDescriptor();
+    @Mock
+    private AnnotationVisitor av;
+
+    @Mock
+    private ClassVisitor cv;
+
+    @Override
+    public void setUp() throws Exception {
+        MockitoAnnotations.initMocks(this);
+    }
+
+    public void testStereotypeParsing() throws Exception {
+        StereotypeParser parser = new StereotypeParser();
+        parser.read(resource(IsStereotype.class));
+        assertTrue(parser.isStereotype());
+    }
+
+    public void testStereotypeParsingWithAnnotations() throws Exception {
+
+        when(cv.visitAnnotation(COMPONENT_DESC, false))
+                .thenReturn(av);
+        when(cv.visitAnnotation(INSTANTIATE_DESC, false))
+                .thenReturn(av);
+
+        StereotypeParser parser = new StereotypeParser();
+        parser.read(resource(ComponentInstanceStereotype.class));
+        assertTrue(parser.isStereotype());
+        assertEquals(2, parser.getRecorders().size());
+
+        RootAnnotationRecorder rec1 = parser.getRecorders().get(0);
+        rec1.accept(cv);
+        RootAnnotationRecorder rec2 = parser.getRecorders().get(1);
+        rec2.accept(cv);
+
+        InOrder order = inOrder(cv, av);
+        order.verify(cv).visitAnnotation(COMPONENT_DESC, false);
+        order.verify(av).visit("immediate", Boolean.TRUE);
+        order.verify(av).visitEnd();
+        order.verify(cv).visitAnnotation(INSTANTIATE_DESC, false);
+        order.verify(av).visitEnd();
+    }
+
+    public void testNoStereotypeParsing() throws Exception {
+        StereotypeParser parser = new StereotypeParser();
+        parser.read(resource(NoStereotype.class));
+        assertFalse(parser.isStereotype());
+    }
+
+    private byte[] resource(final Class<?> aClass) throws Exception {
+        String name = aClass.getDeclaringClass().getSimpleName() +
+                "$" + aClass.getSimpleName()
+                + ".class";
+        URL url = aClass.getResource(name);
+        return Streams.readBytes(url.openStream());
+    }
+
+    @Stereotype
+    public static @interface IsStereotype {}
+
+    public static @interface NoStereotype {}
+
+    @Component(immediate = true)
+    @Instantiate
+    @Stereotype
+    public static @interface ComponentInstanceStereotype {}
+
+}

Added: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/replay/AnnotationRecorderTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/replay/AnnotationRecorderTestCase.java?rev=1489041&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/replay/AnnotationRecorderTestCase.java (added)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/stereotype/replay/AnnotationRecorderTestCase.java Mon Jun  3 15:49:20 2013
@@ -0,0 +1,92 @@
+/*
+ * 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.stereotype.replay;
+
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.objectweb.asm.AnnotationVisitor;
+
+import junit.framework.TestCase;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * User: guillaume
+ * Date: 30/05/13
+ * Time: 22:04
+ */
+public class AnnotationRecorderTestCase extends TestCase {
+
+    @Mock
+    private AnnotationVisitor visitor;
+
+    @Override
+    public void setUp() throws Exception {
+        MockitoAnnotations.initMocks(this);
+    }
+
+    public void testVisitRecord() throws Exception {
+        AnnotationRecorder recorder = new AnnotationRecorder();
+        recorder.visit("attribute", "a value");
+        recorder.accept(visitor);
+        verify(visitor).visit("attribute", "a value");
+    }
+
+    public void testVisitEndRecord() throws Exception {
+        AnnotationRecorder recorder = new AnnotationRecorder();
+        recorder.visitEnd();
+        recorder.accept(visitor);
+        verify(visitor).visitEnd();
+    }
+
+    public void testVisitEnumRecord() throws Exception {
+        AnnotationRecorder recorder = new AnnotationRecorder();
+        recorder.visitEnum("name", "type-desc", "A");
+        recorder.accept(visitor);
+        verify(visitor).visitEnum("name", "type-desc", "A");
+    }
+
+    public void testVisitAnnotationRecord() throws Exception {
+
+        when(visitor.visitAnnotation("name", "type-desc")).thenReturn(visitor);
+
+        AnnotationRecorder recorder = new AnnotationRecorder();
+        AnnotationVisitor sub = recorder.visitAnnotation("name", "type-desc");
+        sub.visit("name2", "value2");
+        recorder.accept(visitor);
+
+        verify(visitor).visitAnnotation("name", "type-desc");
+        verify(visitor).visit("name2", "value2");
+    }
+
+    public void testVisitArrayRecord() throws Exception {
+
+        when(visitor.visitArray("name")).thenReturn(visitor);
+
+        AnnotationRecorder recorder = new AnnotationRecorder();
+        AnnotationVisitor sub = recorder.visitArray("name");
+        sub.visit("name2", "value2");
+        recorder.accept(visitor);
+
+        verify(visitor).visitArray("name");
+        verify(visitor).visit("name2", "value2");
+    }
+}