incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lin...@apache.org
Subject svn commit: r943694 - in /incubator/aries/trunk/blueprint: blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/ blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/ blueprint-sample-annotation/src...
Date Wed, 12 May 2010 21:20:01 GMT
Author: linsun
Date: Wed May 12 21:20:00 2010
New Revision: 943694

URL: http://svn.apache.org/viewvc?rev=943694&view=rev
Log:
[blueprint annotation] add @bind, @Unbind, @Register, @Unregister annotation and update how
reference and reference list are injected

Added:
    incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Bind.java
  (with props)
    incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Register.java
  (with props)
    incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unbind.java
  (with props)
    incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unregister.java
  (with props)
Modified:
    incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Reference.java
    incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/ReferenceList.java
    incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/ReferenceListener.java
    incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/RegistrationListener.java
    incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Service.java
    incubator/aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/BlueprintAnnotationScannerImpl.java
    incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/AccountFactory.java
    incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/BindingListener.java
    incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Foo.java
    incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/FooRegistrationListener.java
    incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/InterfaceA.java
    incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/InterfaceB.java
    incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/ListBindingListener.java
    incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/NewAccount.java

Added: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Bind.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Bind.java?rev=943694&view=auto
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Bind.java
(added)
+++ incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Bind.java
Wed May 12 21:20:00 2010
@@ -0,0 +1,31 @@
+/**
+ *  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.aries.blueprint.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * used to annotation bind-method in blueprint reference listeners
+ *
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Bind {
+}

Propchange: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Bind.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Bind.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Bind.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Reference.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Reference.java?rev=943694&r1=943693&r2=943694&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Reference.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Reference.java
Wed May 12 21:20:00 2010
@@ -21,7 +21,7 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-@Target(ElementType.TYPE)
+@Target(ElementType.FIELD)
 @Retention(RetentionPolicy.RUNTIME)
 public @interface Reference
 {    
@@ -51,9 +51,9 @@ public @interface Reference
     String availability() default "";
     
     /**
-     * the reference listener for the service reference, to receive bind and unbind events.
+     * the reference listeners for the service reference, to receive bind and unbind events.
      */
-    ReferenceListener[] referenceListener();
+    ReferenceListener[] referenceListeners() default {};
 
     /**
      * the timeout property.  If the timeout is not specified,

Modified: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/ReferenceList.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/ReferenceList.java?rev=943694&r1=943693&r2=943694&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/ReferenceList.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/ReferenceList.java
Wed May 12 21:20:00 2010
@@ -21,7 +21,7 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-@Target(ElementType.TYPE)
+@Target(ElementType.FIELD)
 @Retention(RetentionPolicy.RUNTIME)
 public @interface ReferenceList
 {    
@@ -51,9 +51,9 @@ public @interface ReferenceList
     String availability() default "";
     
     /**
-     * the reference listener for the service reference, to receive bind and unbind events.
+     * the reference listeners for the service reference, to receive bind and unbind events.
      */
-    ReferenceListener[] referenceListener();
+    ReferenceListener[] referenceListeners() default {};
     
     /**
      * the value of the memberType property.

Modified: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/ReferenceListener.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/ReferenceListener.java?rev=943694&r1=943693&r2=943694&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/ReferenceListener.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/ReferenceListener.java
Wed May 12 21:20:00 2010
@@ -24,10 +24,5 @@ import java.lang.annotation.Target;
 @Target(ElementType.TYPE)
 @Retention(RetentionPolicy.RUNTIME)
 public @interface ReferenceListener {
-    /**
-     * the component that will receive bind and unbind events.
-     */
-    String ref();
-    String bind();
-    String unbind();
+    String ref() default "";
 }

Added: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Register.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Register.java?rev=943694&view=auto
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Register.java
(added)
+++ incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Register.java
Wed May 12 21:20:00 2010
@@ -0,0 +1,31 @@
+/**
+ *  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.aries.blueprint.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * used to annotation register-method in blueprint registration listeners
+ *
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Register {
+}

Propchange: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Register.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Register.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Register.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/RegistrationListener.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/RegistrationListener.java?rev=943694&r1=943693&r2=943694&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/RegistrationListener.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/RegistrationListener.java
Wed May 12 21:20:00 2010
@@ -24,10 +24,6 @@ import java.lang.annotation.Target;
 @Target(ElementType.TYPE)
 @Retention(RetentionPolicy.RUNTIME)
 public @interface RegistrationListener {
-    /**
-     * the component that will receive registration and unregistration events.
-     */
-    String id();
-    String register();
-    String unregister();
+
+    String ref() default "";
 }

Modified: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Service.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Service.java?rev=943694&r1=943693&r2=943694&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Service.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Service.java
Wed May 12 21:20:00 2010
@@ -29,7 +29,7 @@ public @interface Service {
      * the registration listeners to be notified when the service is
      * registered and unregistered with the framework.
      */
-    RegistrationListener[] registerationListener();
+    RegistrationListener[] registerationListeners() default {};
     
     /**
      *  the ranking value to use when advertising the service.  If the

Added: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unbind.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unbind.java?rev=943694&view=auto
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unbind.java
(added)
+++ incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unbind.java
Wed May 12 21:20:00 2010
@@ -0,0 +1,31 @@
+/**
+ *  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.aries.blueprint.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * used to annotation unbind-method in blueprint reference listeners
+ *
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Unbind {
+}

Propchange: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unbind.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unbind.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unbind.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unregister.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unregister.java?rev=943694&view=auto
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unregister.java
(added)
+++ incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unregister.java
Wed May 12 21:20:00 2010
@@ -0,0 +1,31 @@
+/**
+ *  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.aries.blueprint.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * used to annotation unregister-method in blueprint registration listeners
+ *
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Unregister {
+}

Propchange: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unregister.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unregister.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/trunk/blueprint/blueprint-annotation-api/src/main/java/org/apache/aries/blueprint/annotation/Unregister.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/BlueprintAnnotationScannerImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/BlueprintAnnotationScannerImpl.java?rev=943694&r1=943693&r2=943694&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/BlueprintAnnotationScannerImpl.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-annotation-impl/src/main/java/org/apache/aries/blueprint/annotation/impl/BlueprintAnnotationScannerImpl.java
Wed May 12 21:20:00 2010
@@ -18,14 +18,15 @@ package org.apache.aries.blueprint.annot
 
 import java.io.File;
 import java.io.IOException;
-import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.math.BigInteger;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
@@ -33,6 +34,7 @@ import javax.xml.bind.Marshaller;
 
 import org.apache.aries.blueprint.annotation.Arg;
 import org.apache.aries.blueprint.annotation.Bean;
+import org.apache.aries.blueprint.annotation.Bind;
 import org.apache.aries.blueprint.annotation.Blueprint;
 import org.apache.aries.blueprint.annotation.Destroy;
 import org.apache.aries.blueprint.annotation.Init;
@@ -40,8 +42,11 @@ import org.apache.aries.blueprint.annota
 import org.apache.aries.blueprint.annotation.Reference;
 import org.apache.aries.blueprint.annotation.ReferenceList;
 import org.apache.aries.blueprint.annotation.ReferenceListener;
+import org.apache.aries.blueprint.annotation.Register;
 import org.apache.aries.blueprint.annotation.RegistrationListener;
 import org.apache.aries.blueprint.annotation.Service;
+import org.apache.aries.blueprint.annotation.Unbind;
+import org.apache.aries.blueprint.annotation.Unregister;
 import org.apache.aries.blueprint.annotation.service.BlueprintAnnotationScanner;
 import org.apache.aries.blueprint.jaxb.Targument;
 import org.apache.aries.blueprint.jaxb.Tbean;
@@ -163,8 +168,10 @@ public class BlueprintAnnotationScannerI
 
         List<Class> blueprintClasses = baf.findAnnotatedClasses(Blueprint.class);
         List<Class> beanClasses = baf.findAnnotatedClasses(Bean.class);
-        List<Class> refClasses = baf.findAnnotatedClasses(Reference.class);
-        List<Class> refListClasses = baf.findAnnotatedClasses(ReferenceList.class);
+        List<Class> refListenerClasses = baf.findAnnotatedClasses(ReferenceListener.class);
+        List<Class> regListenerClasses = baf.findAnnotatedClasses(RegistrationListener.class);
+        Map<String, TreferenceListener> reflMap = new HashMap<String, TreferenceListener>();
+        Map<String, TregistrationListener> reglMap = new HashMap<String, TregistrationListener>();
         
         Tblueprint tblueprint = new Tblueprint();
         
@@ -179,6 +186,35 @@ public class BlueprintAnnotationScannerI
 
         List<Object> components = tblueprint.getServiceOrReferenceListOrBean();
         
+        // try to process classes that have @ReferenceListener or @RegistrationLister first
+        // as we want the refl and regl maps populated before processing @Bean annotation.
+        for (Class refListener : refListenerClasses) {
+            Bean bean = (Bean) refListener.getAnnotation(Bean.class);
+                       
+            // register the treference with its id
+            TreferenceListener tref = generateTrefListener(refListener);
+            
+            if (bean.id().length() > 0) {
+                reflMap.put(bean.id(), tref);
+            } else {
+                throw new BlueprintAnnotationException("Unable to find the id for the @ReferenceListener
annotated class " + refListener.getName());
+            }
+        }
+        
+        
+        for (Class regListener : regListenerClasses) {
+            Bean bean = (Bean) regListener.getAnnotation(Bean.class);
+            
+            // register the tregistrationListener with its id
+            TregistrationListener tref = generateTregListener(regListener);
+            
+            if (bean.id().length() > 0) {
+                reglMap.put(bean.id(), tref);
+            } else {
+                throw new BlueprintAnnotationException("Unable to find the id for the @RegistrationListener
annotated class " + regListener.getName());
+            }   
+        }
+        
         for (Class clazz : beanClasses) {
             // @Bean annotation detected
             Bean bean = (Bean)clazz.getAnnotation(Bean.class);
@@ -261,9 +297,22 @@ public class BlueprintAnnotationScannerI
             
             Field[] fields = clazz.getDeclaredFields();
             for (int i = 0; i < fields.length; i++) {
-                if (fields[i].isAnnotationPresent(Inject.class)) {          
-                    Tproperty tp = createTproperty(fields[i].getName(), fields[i].getAnnotation(Inject.class));
-                    props.add(tp);
+                if (fields[i].isAnnotationPresent(Inject.class)) { 
+                    if (fields[i].isAnnotationPresent(Reference.class)) {
+                        // the field is also annotated with @Reference
+                        Reference ref = (Reference)fields[i].getAnnotation(Reference.class);
+                        Treference tref = generateTref(ref, reflMap);
+                        components.add(tref);
+                    } else if (fields[i].isAnnotationPresent(ReferenceList.class)) {
+                        // the field is also annotated with @ReferenceList
+                        ReferenceList ref = (ReferenceList)fields[i].getAnnotation(ReferenceList.class);
+                        TreferenceList tref = generateTrefList(ref, reflMap);
+                        components.add(tref);
+                        
+                    } else {
+                        Tproperty tp = createTproperty(fields[i].getName(), fields[i].getAnnotation(Inject.class));
+                        props.add(tp);
+                    }
                 }
             }
                     
@@ -277,7 +326,7 @@ public class BlueprintAnnotationScannerI
                 } else if (methods[i].isAnnotationPresent(Inject.class)) {
                     String propertyName = convertFromMethodName(methods[i].getName());
                     Tproperty tp = createTproperty(propertyName, methods[i].getAnnotation(Inject.class));
-                    props.add(tp);     
+                    props.add(tp);  
                 } else if (methods[i].isAnnotationPresent(Arg.class)) {
                     Targument targ = createTargument(methods[i].getAnnotation(Arg.class));
                     props.add(targ);     
@@ -286,7 +335,7 @@ public class BlueprintAnnotationScannerI
             
             // check if the bean also declares service
             if (clazz.getAnnotation(Service.class) != null) {
-                Tservice tservice = generateTservice(clazz, id);
+                Tservice tservice = generateTservice(clazz, id, reglMap);
                 components.add(tservice);
             }
             
@@ -300,18 +349,89 @@ public class BlueprintAnnotationScannerI
                 components.add(tbean);
             }
         }
+
+        return tblueprint;
+    }
+
+    private TreferenceListener generateTrefListener(Class refListener) {
+        ReferenceListener rl = (ReferenceListener) refListener.getAnnotation(ReferenceListener.class);
+        
+        String ref = rl.ref();
+        String bind = null;
+        String unbind = null;
+        
+        // also check bind/unbind method
+        Method[] methods = refListener.getDeclaredMethods();
+        for (int i = 0; i < methods.length; i++) {
+            if (methods[i].isAnnotationPresent(Bind.class)) {
+                if (bind == null) {
+                    bind = methods[i].getName();
+                } else if (!bind.equals(methods[i].getName())) {
+                    throw new BlueprintAnnotationException("@Bind annottaed method for reference
listener " + refListener.getName() + " are not consistent");       
+                }
+                continue;
+            }
+            if (methods[i].isAnnotationPresent(Unbind.class)) {
+                if (unbind == null) {
+                  unbind = methods[i].getName();
+                } else if (!unbind.equals(methods[i].getName())) {
+                    throw new BlueprintAnnotationException("@Unbind annotated method for
reference listener " + refListener.getName() + " are not consistent");       
+                }
+                continue;
+            }
+        }
         
-        for (Class refClass : refClasses) {
-            Treference tref = generateTref(refClass);
-            components.add(tref);
+        TreferenceListener trl = new TreferenceListener();
+        if (bind != null) {
+            trl.setBindMethod(bind);
         }
-
-        for (Class refListClass : refListClasses) {
-            TreferenceList trefList = generateTrefList(refListClass);
-            components.add(trefList);
+        if (unbind != null) {
+            trl.setUnbindMethod(unbind);
         }
-
-        return tblueprint;
+        
+        if (ref != null) {
+            trl.setRefAttribute(ref);
+        }
+        
+        return trl;
+    }
+    
+    private TregistrationListener generateTregListener(Class regListener) {
+        RegistrationListener rl = (RegistrationListener) regListener.getAnnotation(RegistrationListener.class);
+        
+        String register = null;
+        String unregister = null;
+        
+        // also check bind/unbind method
+        Method[] methods = regListener.getDeclaredMethods();
+        for (int i = 0; i < methods.length; i++) {
+            if (methods[i].isAnnotationPresent(Register.class)) {
+                if (register == null) {
+                    register = methods[i].getName();
+                } else if (!register.equals(methods[i].getName())) {
+                    throw new BlueprintAnnotationException("@Register annottaed method for
registration listener " + regListener.getName() + " are not consistent");       
+                }
+                continue;
+            }
+            if (methods[i].isAnnotationPresent(Unregister.class)) {
+                if (unregister == null) {
+                  unregister = methods[i].getName();
+                } else if (!unregister.equals(methods[i].getName())) {
+                    throw new BlueprintAnnotationException("@Unregister annotated method
for registration listener " + regListener.getName() + " are not consistent");       
+                }
+                continue;
+            }
+        }
+        
+        TregistrationListener trl = new TregistrationListener();
+        if (register != null) {
+            trl.setRegistrationMethod(register);
+        }
+        if (unregister != null) {
+            trl.setUnregistrationMethod(unregister);
+        }
+        
+        return trl;
     }
 
     private Targument createTargument(Arg arg) {
@@ -419,17 +539,15 @@ public class BlueprintAnnotationScannerI
                 + filePath;
     }
     
-    private Treference generateTref(Class refClass) {
-        // @Reference annotation detected
-        Reference ref = (Reference)refClass.getAnnotation(Reference.class);
-        
+    private Treference generateTref(Reference ref, Map<String, TreferenceListener>
reflMap) {
+
         String id = ref.id();
         String availability = ref.availability();
         String compName = ref.componentName();
         String desp = ref.description();
         String filter = ref.filter();
         Class<?> serviceInterface = ref.serviceInterface();
-        ReferenceListener[] refListeners = ref.referenceListener();
+        ReferenceListener[] refListeners = ref.referenceListeners();
         int timeout = ref.timeout();
         Treference tref = new Treference();
         
@@ -456,43 +574,33 @@ public class BlueprintAnnotationScannerI
         }
         if (serviceInterface != Object.class) {
             tref.setInterface(serviceInterface.getName());
-        } else {
-            boolean isInterface =  refClass.isInterface();
-            if (isInterface) {
-                tref.setInterface(refClass.getName());
-            } else {
-                // should we throw an exception?  
-            }
         }
         
         if (timeout > 0) {
             tref.setTimeout(convertToBigInteger(timeout));
         }
         for (ReferenceListener rl : refListeners) {
-            TreferenceListener trl = new TreferenceListener();
             String rf = rl.ref();
-            String bindMethod = rl.bind();
-            String unbindMethod = rl.unbind();
-            trl.setRefAttribute(rf);
-            trl.setBindMethod(bindMethod);
-            trl.setUnbindMethod(unbindMethod);
-            tref.getReferenceListener().add(trl);
+            TreferenceListener trl = reflMap.get(rf);
+            if (trl != null) {
+                trl.setRefAttribute(rf);
+                tref.getReferenceListener().add(trl);
+            } else {
+                throw new BlueprintAnnotationException("Unable to find the ReferenceListener
ref " + rf);
+            }
         }
         
         return tref;
     }
     
-    private TreferenceList generateTrefList(Class refClass) {
-        // @ReferenceList annotation detected
-        ReferenceList ref = (ReferenceList)refClass.getAnnotation(ReferenceList.class);
-        
+    private TreferenceList generateTrefList(ReferenceList ref, Map<String, TreferenceListener>
reflMap) {
         String id = ref.id();
         String availability = ref.availability();
         String compName = ref.componentName();
         String desp = ref.description();
         String filter = ref.filter();
         Class<?> serviceInterface = ref.serviceInterface();
-        ReferenceListener[] refListeners = ref.referenceListener();
+        ReferenceListener[] refListeners = ref.referenceListeners();
         TreferenceList tref = new TreferenceList();
         
         // can not think of configuring depends on for referencelist
@@ -518,34 +626,28 @@ public class BlueprintAnnotationScannerI
         }
         if (serviceInterface  != Object.class) {
             tref.setInterface(serviceInterface.getName());
-        } else {
-            boolean isInterface =  refClass.isInterface();
-            if (isInterface) {
-                tref.setInterface(refClass.getName());
-            } else {
-                // should we throw an exception?  
-            }
-        }
+        } 
+        
         for (ReferenceListener rl : refListeners) {
-            TreferenceListener trl = new TreferenceListener();
             String rf = rl.ref();
-            String bindMethod = rl.bind();
-            String unbindMethod = rl.unbind();
-            trl.setRefAttribute(rf);
-            trl.setBindMethod(bindMethod);
-            trl.setUnbindMethod(unbindMethod);
-            tref.getReferenceListener().add(trl);
+            TreferenceListener trl = reflMap.get(rf);
+            if (trl != null) {
+                trl.setRefAttribute(rf);
+                tref.getReferenceListener().add(trl);
+            } else {
+                throw new BlueprintAnnotationException("Unable to find the ReferenceListener
ref " + rf);
+            }
         }
         
         return tref;
     }
     
-    private Tservice generateTservice(Class clazz, String id) {
+    private Tservice generateTservice(Class clazz, String id, Map<String, TregistrationListener>
reglMap) {
         Service service = (Service) clazz.getAnnotation(Service.class);
         Class<?>[] interfaces = service.interfaces();
         int ranking = service.ranking();
         String autoExport = service.autoExport();
-        RegistrationListener[] regListeners = service.registerationListener();
+        RegistrationListener[] regListeners = service.registerationListeners();
         
         Tservice tservice = new Tservice();
         
@@ -570,12 +672,10 @@ public class BlueprintAnnotationScannerI
         }
         
         for (RegistrationListener regListener : regListeners) {
-            String regListenerId = regListener.id();
-            if (regListenerId.length() > 0) {
-                TregistrationListener tregListener = new TregistrationListener();
-                tregListener.setRefAttribute(regListenerId);
-                tregListener.setRegistrationMethod(regListener.register());
-                tregListener.setUnregistrationMethod(regListener.unregister());
+            String ref = regListener.ref();
+            if (ref.length() > 0) {
+                TregistrationListener tregListener = reglMap.get(ref);
+                tregListener.setRefAttribute(ref);
                 tservice.getRegistrationListener().add(tregListener);
                 
             } else {

Modified: incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/AccountFactory.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/AccountFactory.java?rev=943694&r1=943693&r2=943694&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/AccountFactory.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/AccountFactory.java
Wed May 12 21:20:00 2010
@@ -27,8 +27,8 @@ public class AccountFactory {
         this.factoryName = factoryName;
     }
 
-    public AccountNew createAccount(long number) {
-        return new AccountNew(number);
+    public NewAccount createAccount(long number) {
+        return new NewAccount(number);
     }
     
     public String getFactoryName() {

Modified: incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/BindingListener.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/BindingListener.java?rev=943694&r1=943693&r2=943694&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/BindingListener.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/BindingListener.java
Wed May 12 21:20:00 2010
@@ -20,12 +20,21 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.aries.blueprint.annotation.Bean;
+import org.apache.aries.blueprint.annotation.Bind;
 import org.apache.aries.blueprint.annotation.Init;
+import org.apache.aries.blueprint.annotation.Inject;
+import org.apache.aries.blueprint.annotation.Reference;
+import org.apache.aries.blueprint.annotation.ReferenceListener;
+import org.apache.aries.blueprint.annotation.Unbind;
 import org.osgi.framework.ServiceReference;
 
 @Bean(id="bindingListener")
+@ReferenceListener
 public class BindingListener {
 
+    @Inject @Reference (id="ref2", 
+            serviceInterface = InterfaceA.class,
+            timeout=100, referenceListeners=@ReferenceListener(ref="bindingListener"))
     private InterfaceA a;
     private Map props;
     private ServiceReference reference;
@@ -55,20 +64,24 @@ public class BindingListener {
     public void init() {
     }
 
+    @Bind
     public void bind(InterfaceA a, Map props) {
         this.a = a;
         this.props = props;
     }
 
+    @Bind
     public void bind(ServiceReference ref) {
         this.reference = ref;
     }
 
+    @Unbind
     public void unbind(InterfaceA a, Map props) {
         this.a = null;
         this.props = null;
     }
 
+    @Unbind
     public void unbind(ServiceReference ref) {
         this.reference = null;
     }

Modified: incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Foo.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Foo.java?rev=943694&r1=943693&r2=943694&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Foo.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/Foo.java
Wed May 12 21:20:00 2010
@@ -32,7 +32,7 @@ import org.apache.aries.blueprint.annota
 @Bean(id="foo")
 @Service(autoExport="all-classes",
         serviceProperties = @ServiceProperty(key="blueprint.annotation.sample", value="true"),
-        registerationListener = @RegistrationListener(id="fooRegistrationListener", register="serviceRegistered",
unregister="serviceUnregistered"), 
+        registerationListeners = @RegistrationListener(ref="fooRegistrationListener"), 
         ranking=0)
 public class Foo implements Serializable {
     

Modified: incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/FooRegistrationListener.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/FooRegistrationListener.java?rev=943694&r1=943693&r2=943694&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/FooRegistrationListener.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/FooRegistrationListener.java
Wed May 12 21:20:00 2010
@@ -20,15 +20,20 @@ import java.io.Serializable;
 import java.util.Map;
 
 import org.apache.aries.blueprint.annotation.Bean;
-
+import org.apache.aries.blueprint.annotation.Register;
+import org.apache.aries.blueprint.annotation.RegistrationListener;
+import org.apache.aries.blueprint.annotation.Unregister;
 
 @Bean(id="fooRegistrationListener")
+@RegistrationListener
 public class FooRegistrationListener {
         
+    @Register
     public void serviceRegistered(Serializable foo, Map props) {
         System.out.println("Service registration notification: " + foo + " " + props);
     }
     
+    @Unregister
     public void serviceUnregistered(Foo foo, Map props) {
         System.out.println("Service unregistration notification: " + foo + " " + props);
     }

Modified: incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/InterfaceA.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/InterfaceA.java?rev=943694&r1=943693&r2=943694&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/InterfaceA.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/InterfaceA.java
Wed May 12 21:20:00 2010
@@ -16,12 +16,6 @@
  */
 package org.apache.aries.blueprint.sample;
 
-import org.apache.aries.blueprint.annotation.Reference;
-import org.apache.aries.blueprint.annotation.ReferenceListener;
-
-@Reference (id="ref2", 
-        referenceListener = {@ReferenceListener(ref="bindingListener", bind="bind", unbind="unbind")},

-        timeout=100)
 public interface InterfaceA {
 
     String hello(String msg);

Modified: incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/InterfaceB.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/InterfaceB.java?rev=943694&r1=943693&r2=943694&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/InterfaceB.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/InterfaceB.java
Wed May 12 21:20:00 2010
@@ -16,11 +16,6 @@
  */
 package org.apache.aries.blueprint.sample;
 
-import org.apache.aries.blueprint.annotation.ReferenceList;
-import org.apache.aries.blueprint.annotation.ReferenceListener;
-
-@ReferenceList (id="ref-list", 
-        referenceListener = @ReferenceListener(ref="listBindingListener", bind="bind", unbind="unbind"))
 public interface InterfaceB {
 
     String hello(String msg);

Modified: incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/ListBindingListener.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/ListBindingListener.java?rev=943694&r1=943693&r2=943694&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/ListBindingListener.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/ListBindingListener.java
Wed May 12 21:20:00 2010
@@ -20,12 +20,21 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.aries.blueprint.annotation.Bean;
+import org.apache.aries.blueprint.annotation.Bind;
 import org.apache.aries.blueprint.annotation.Init;
+import org.apache.aries.blueprint.annotation.Inject;
+import org.apache.aries.blueprint.annotation.ReferenceList;
+import org.apache.aries.blueprint.annotation.ReferenceListener;
+import org.apache.aries.blueprint.annotation.Unbind;
 import org.osgi.framework.ServiceReference;
 
 @Bean(id="listBindingListener")
+@ReferenceListener
 public class ListBindingListener {
 
+    @Inject @ReferenceList (id="ref-list", 
+            serviceInterface = InterfaceA.class,
+            referenceListeners=@ReferenceListener(ref="listBindingListener"))
     private InterfaceA a;
     private Map props;
     private ServiceReference reference;
@@ -55,20 +64,24 @@ public class ListBindingListener {
     public void init() {
     }
 
+    @Bind
     public void bind(InterfaceA a, Map props) {
         this.a = a;
         this.props = props;
     }
 
+    @Bind
     public void bind(ServiceReference ref) {
         this.reference = ref;
     }
 
+    @Unbind
     public void unbind(InterfaceA a, Map props) {
         this.a = null;
         this.props = null;
     }
 
+    @Unbind
     public void unbind(ServiceReference ref) {
         this.reference = null;
     }

Modified: incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/NewAccount.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/NewAccount.java?rev=943694&r1=943693&r2=943694&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/NewAccount.java
(original)
+++ incubator/aries/trunk/blueprint/blueprint-sample-annotation/src/main/java/org/apache/aries/blueprint/sample/NewAccount.java
Wed May 12 21:20:00 2010
@@ -17,8 +17,12 @@
 package org.apache.aries.blueprint.sample;
 
 import org.apache.aries.blueprint.annotation.Bean;
+import org.apache.aries.blueprint.annotation.Arg;
 
-//@Bean(id="accountThree", factoryRef="accountFactory")
+@Bean(id="accountThree", 
+      factoryRef="accountFactory", 
+      factoryMethod="createAccount", 
+      args=@Arg(value="3"))
 public class NewAccount {
     
     private long accountNumber;



Mime
View raw message