OW2 Consortium
Search OW2 Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | fractal-commits List | March 2006 Index

<--  Date Index  --> <--  Thread Index  -->

CVS update of <fraclet-annotation>/src/org/objectweb/fractal/fraclet/annotation (5 files)


    Date: Friday, March 31, 2006 @ 11:38:51
  Author: pessemier
    Path: .../fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation

   Added: template/util/None.java
Modified: FractalBC.java processor/FractalComponentProcessor.java
          processor/util/ADLFileFactory.java template/BcTemplate.java

add a parameter "signature" to the @FractalBC annotation in order to write 
java 1.4 compatible code for collection interfaces.


------------------------------------------+
 FractalBC.java                           |   55 ++++++-----
 processor/FractalComponentProcessor.java |    2 
 processor/util/ADLFileFactory.java       |    7 +
 template/BcTemplate.java                 |  142 +++++++++++++++++++++++++++--
 template/util/None.java                  |    5 +
 5 files changed, 179 insertions(+), 32 deletions(-)


Index: 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/FractalBC.java
diff -u 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/FractalBC.java:1.1
 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/FractalBC.java:1.2
--- 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/FractalBC.java:1.1
  Tue Feb 14 15:59:58 2006
+++ 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/FractalBC.java
      Fri Mar 31 11:38:50 2006
@@ -1,32 +1,33 @@
 
/*==============================================================================
-Fraclet annotation - Copyright (C) 2002-2006 INRIA Futurs / LIFL
-Fractal Component Model (contact: fractal@xxxxxxxxxxxxx)
+ Fraclet annotation - Copyright (C) 2002-2006 INRIA Futurs / LIFL
+ Fractal Component Model (contact: fractal@xxxxxxxxxxxxx)
 
-This library is free software; you can redistribute it and/or modify it 
under 
-the terms of the GNU Lesser General Public License as published by the Free 
-Software Foundation; either version 2.1 of the License, or any later version.
-
-This library is distributed in the hope that it will be useful, but WITHOUT 
ANY 
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR A 
-PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
details.
-
-You should have received a copy of the GNU Lesser General Public License 
along 
-with this library; if not, write to the Free Software Foundation, Inc., 
-59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ This library is free software; you can redistribute it and/or modify it 
under 
+ the terms of the GNU Lesser General Public License as published by the Free 
+ Software Foundation; either version 2.1 of the License, or any later 
version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT 
ANY 
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR A 
+ PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
details.
+
+ You should have received a copy of the GNU Lesser General Public License 
along 
+ with this library; if not, write to the Free Software Foundation, Inc., 
+ 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
-Initial developer(s): Nicolas Pessemier (nicolas.pessemier@xxxxxxx)
-==============================================================================*/
+ Initial developer(s): Nicolas Pessemier (nicolas.pessemier@xxxxxxx)
+ 
==============================================================================*/
 
 package org.objectweb.fractal.fraclet.annotation;
 
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Target;
+import org.objectweb.fractal.fraclet.annotation.template.util.None;
 
 /**
- * An annotation to inject the binding controller 
- *
- * @author  Nicolas Pessemier <Nicolas.Pessemier@xxxxxxx>
- *
+ * An annotation to inject the binding controller
+ * 
+ * @author Nicolas Pessemier <Nicolas.Pessemier@xxxxxxx>
+ * 
  */
 @Target(ElementType.FIELD)
 public @interface FractalBC {
@@ -35,15 +36,27 @@
         * @return the name of the bound Fractal interface
         */
        String name();
+
        /**
         * 
-        * @return the cardinality["singleton"/"collection"] of the bound 
Fractal interface
+        * @return the signature of the interface (optional). Thanks to Java5 
type
+        *         safety this parameter can be automatically computed, even 
with
+        *         collection interfaces (HashMap<String,Service>
+        *         collectionBinding)
+        */
+       Class signature() default None.class;
+
+       /**
+        * 
+        * @return the cardinality["singleton"/"collection"] of the bound 
Fractal
+        *         interface
         */
        String cardinality() default "singleton";
+
        /**
         * 
         * @return the contingency["mandatory"/"optional"] of the Fractal 
interface
         */
        String contingency() default "mandatory";
-       
+
 }
Index: 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/FractalComponentProcessor.java
diff -u 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/FractalComponentProcessor.java:1.4
 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/FractalComponentProcessor.java:1.5
--- 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/FractalComponentProcessor.java:1.4
        Wed Mar 22 16:10:18 2006
+++ 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/FractalComponentProcessor.java
    Fri Mar 31 11:38:51 2006
@@ -135,7 +135,7 @@
                                continue;
 
                        ADLFileFactory.printItfSignature(pw, field, 
bindingAnnotation
-                                       .name(), 
bindingAnnotation.cardinality(), bindingAnnotation
+                                       .name(), 
bindingAnnotation.signature(), bindingAnnotation.cardinality(), 
bindingAnnotation
                                        .contingency(), 
ADLFileFactory.ROLE_CLIENT);
                }
                // -----------------------------------------------------
Index: 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/util/ADLFileFactory.java
diff -u 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/util/ADLFileFactory.java:1.2
 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/util/ADLFileFactory.java:1.3
--- 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/util/ADLFileFactory.java:1.2
      Wed Feb 15 11:44:25 2006
+++ 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/util/ADLFileFactory.java
  Fri Mar 31 11:38:51 2006
@@ -24,6 +24,8 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 
+import org.objectweb.fractal.fraclet.annotation.template.util.None;
+
 import spoon.reflect.declaration.CtField;
 import spoon.reflect.declaration.CtSimpleType;
 
@@ -109,7 +111,7 @@
        }
 
        public static void printItfSignature(PrintWriter pw, CtField field,
-                       String fractalItfName, String cardinality, String 
contingency,
+                       String fractalItfName, Class signature, String 
cardinality, String contingency,
                        String clientServer) {
                if (cardinality == null)
                        cardinality = "singleton";
@@ -117,6 +119,9 @@
                if (cardinality.equals("singleton"))
                        itfName = field.getType().getQualifiedName();
                else if (cardinality.equals("collection")) {
+                       if (!signature.equals(None.class))
+                               itfName=signature.getName();
+                       else
                        itfName = 
field.getType().getActualTypeArguments().get(1)
                                        .getQualifiedName();
                        // System.out.println(fieldName);
Index: 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/template/BcTemplate.java
diff -u 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/template/BcTemplate.java:1.3
 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/template/BcTemplate.java:1.4
--- 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/template/BcTemplate.java:1.3
        Fri Mar 31 10:44:23 2006
+++ 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/template/BcTemplate.java
    Fri Mar 31 11:38:50 2006
@@ -31,6 +31,7 @@
 import org.objectweb.fractal.fraclet.annotation.FractalBC;
 import org.objectweb.fractal.fraclet.annotation.FractalRC;
 import 
org.objectweb.fractal.fraclet.annotation.template.util.NonTypedFractalAttributeException;
+import org.objectweb.fractal.fraclet.annotation.template.util.None;
 import org.objectweb.fractal.fraclet.annotation.template.util._R_;
 import org.objectweb.fractal.fraclet.annotation.template.util._T_;
 
@@ -86,9 +87,9 @@
                // iterate over target fields
                for (CtField<?> field : fields) {
                        
-                       //////////////////////////////////////////////////////
-                       ///////// Manage the @FractalRC annotation //////////
-                       /////////////////////////////////////////////////////
+                       // 
////////////////////////////////////////////////////
+                       // /////// Manage the @FractalRC annotation //////////
+                       // ///////////////////////////////////////////////////
                        
                        FractalRC 
rcAnnotation=field.getAnnotation(FractalRC.class);
                        if (rcAnnotation!=null){
@@ -98,8 +99,8 @@
                                                
spoonFactory.Type().createReference(String.class),spoonFactory.Type().createReference(Object.class)});
                                
binds.getStatements().add(rcBlock.getStatements().get(0));
                        }
-                       ////////////////////////////////////////////////////
-                       ////////////////////////////////////////////////////
+                       // //////////////////////////////////////////////////
+                       // //////////////////////////////////////////////////
                        
                        // get the FractalBC annotation
                        FractalBC bindingAnnotation = 
field.getAnnotation(FractalBC.class);
@@ -166,10 +167,16 @@
                                // 
//////////////////////////////////////////////////
                                // the BindFcTemplate
                                // 
//////////////////////////////////////////////////
-                               if 
(field.getType().getActualTypeArguments().size()<2) 
+                               if 
(bindingAnnotation.signature().equals(None.class) && 
field.getType().getActualTypeArguments().size()<2) 
                                        throw new 
NonTypedFractalAttributeException("Fractal attribute "+field.getSimpleName()+
                                        " must be typed to generate the 
appropriate binding controller implementation");
-                               t= new 
BindFcTemplate(bindingAnnotation.name(),field.getSimpleName(),field.getType().getActualTypeArguments().get(1));
+                               else 
if(!bindingAnnotation.signature().equals(None.class) ){
+                                       t= new 
NotTypedBindFcTemplate(bindingAnnotation.name(),field.getSimpleName(),spoonFactory.Type().createReference(bindingAnnotation.signature()));
+                                       
+                               }
+                               else {
+                                       t= new 
BindFcTemplate(bindingAnnotation.name(),field.getSimpleName(),field.getType().getActualTypeArguments().get(1));
+                               }
                                block = 
Substitution.substituteMethodBody(target, t, "bindCollection",new 
CtTypeReference<?>[]{
                                                
spoonFactory.Type().createReference(String.class),spoonFactory.Type().createReference(Object.class)});
                                
binds.getStatements().add(block.getStatements().get(0));
@@ -499,7 +506,7 @@
 }
 
 /**
- * A template to manage the bindFc method
+ * A template to manage the LookupFc method
  * 
  * @author Nicolas Pessemier <Nicolas.Pessemier@xxxxxxx>
  * 
@@ -597,8 +604,125 @@
                
        }
 }
+
 /**
- * A template to manage the bindFc method
+ * A template to manage the bindFc method when the field is not well typed, 
and
+ * the signature parameter is used.
+ * 
+ * @author Nicolas Pessemier <Nicolas.Pessemier@xxxxxxx>
+ * 
+ */
+class NotTypedBindFcTemplate implements Template {
+       
+       // ///////////////////////
+       // Parameters for singleton bindings
+       // /////////////////////////
+       @Parameter
+       // The name of the interface (singleton bindings)
+       String _itfName_;
+       
+       @Parameter
+       // A Type Reference which is the type of the singleton service
+       CtTypeReference _T_;
+
+       
+       @Local
+       // A Local variable which is the reference to the singeton field
+       _T_ _service_;
+       
+       
+       @Parameter("_service_")
+       // The name of the singleton field
+       String __service_;
+       
+       
+       // /////////////////////////
+       // Parameters for collection bindings
+       // /////////////////////////
+       @Parameter("_servicesMap_")
+       // The name of the java field (collection bindings)
+       String __servicesMap_;
+       
+       @Local
+       // The field that contains the collection bindings (collection 
bindings)
+       Map _servicesMap_;
+       
+       
+       /**
+        * Use this constructor for singeton bindings
+        * 
+        * @param itfName
+        *            The name of the Fractal interface
+        * @param serviceType
+        *            The java type of the binding
+        * @param serviceName
+        *            The name of the java field
+        */
+       public NotTypedBindFcTemplate(String itfName, CtTypeReference 
serviceType,
+                       String serviceName) {
+               this._itfName_ = itfName;
+               this._T_ = serviceType;
+               this.__service_ = serviceName;
+               
+       }
+       
+       /**
+        * Use this constructor for collection bindings`
+        * 
+        * @param fieldName
+        *            the name of the map field
+        */
+       public NotTypedBindFcTemplate(String itfName, String fieldName 
,CtTypeReference serviceType) {
+               this._itfName_ = itfName;
+               this.__servicesMap_ = fieldName;        
+               this._T_=serviceType;
+       }
+       
+       /**
+        * Block to add into the bindFc method (for singleton bindings)
+        * 
+        * @param clientItfName
+        *            the Fractal binding name
+        * @param serverItf
+        *            the reference to the server
+        * @throws IllegalBindingException
+        *             when attempting to bind incompatible interfaces
+        */
+       void bindSingleton(String clientItfName, Object serverItf)  throws 
NoSuchInterfaceException, IllegalBindingException {
+               if (clientItfName.equals(_itfName_)) {
+                       if 
(!(_T_.class.isAssignableFrom(serverItf.getClass()))) {
+                               throw new IllegalBindingException("server 
interfaces connected to " + clientItfName + " must be instances of " + 
_T_.class.getName());
+                       }               
+                       _service_ = (_T_) serverItf;
+                       return;
+               }
+       }
+       
+       /**
+        * Block to add into the bindFc method (for collection bindings)
+        * 
+        * @param clientItfName
+        *            the Fractal binding name
+        * @param serverItf
+        *            the reference to the server
+        * @throws IllegalBindingException
+        *             when attempting to bind incompatible interfaces
+        */
+       void bindCollection(String clientItfName, Object serverItf) throws 
NoSuchInterfaceException, IllegalBindingException {
+               if (clientItfName.startsWith(_itfName_)) {
+                       if 
(!(_T_.class.isAssignableFrom(serverItf.getClass()))) {
+                               throw new IllegalBindingException("server 
interfaces connected to " + clientItfName + " must be instances of " + 
_T_.class.getName());
+                       }
+                       _servicesMap_.put(clientItfName, serverItf);
+                       return;
+               }
+               
+       }
+}
+
+
+/**
+ * A template to manage the bindFc method to get the Component reference
  * 
  * @author Nicolas Pessemier <Nicolas.Pessemier@xxxxxxx>
  * 
Index: 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/template/util/None.java
diff -u /dev/null 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/template/util/None.java:1.1
--- /dev/null   Fri Mar 31 11:38:51 2006
+++ 
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/template/util/None.java
     Fri Mar 31 11:38:50 2006
@@ -0,0 +1,5 @@
+package org.objectweb.fractal.fraclet.annotation.template.util;
+
+public class None {
+
+}



<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 2006-2007, OW2 Consortium | contact | webmaster.