Mail Archive Home | fractal-commits List | March 2006 Index
| <-- Date Index --> | <-- Thread Index --> |
Date: Friday, March 31, 2006 @ 10:44:24
Author: pessemier
Path: .../fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation
Added: FractalRC.java
Modified: template/BcTemplate.java
Add the @FractalRC field annotation to get the Component reference of a
component
--------------------------+
FractalRC.java | 33 +++++++++++++++++++++
template/BcTemplate.java | 70 ++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 102 insertions(+), 1 deletion(-)
Index:
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/FractalRC.java
diff -u /dev/null
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/FractalRC.java:1.1
--- /dev/null Fri Mar 31 10:44:24 2006
+++
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/FractalRC.java
Fri Mar 31 10:44:24 2006
@@ -0,0 +1,33 @@
+/*==============================================================================
+ 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
+
+ Initial developer(s): Nicolas Pessemier (nicolas.pessemier@xxxxxxx)
+
==============================================================================*/
+package org.objectweb.fractal.fraclet.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * This field annotation provides a way to get the Component reference of a
component
+ *
+ * @author Nicolas Pessemier <Nicolas.Pessemier@xxxxxxx>
+ *
+ */
+@Target(ElementType.FIELD)
+public @interface FractalRC {
+
+}
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.2
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.2
Mon Mar 6 17:54:02 2006
+++
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/template/BcTemplate.java
Fri Mar 31 10:44:23 2006
@@ -24,10 +24,12 @@
import java.util.List;
import java.util.Map;
+import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.BindingController;
import org.objectweb.fractal.api.control.IllegalBindingException;
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._R_;
import org.objectweb.fractal.fraclet.annotation.template.util._T_;
@@ -38,7 +40,6 @@
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtField;
import spoon.reflect.reference.CtTypeReference;
-import spoon.support.reflect.code.CtStatementListImpl;
import spoon.template.Local;
import spoon.template.Parameter;
import spoon.template.Substitution;
@@ -84,6 +85,22 @@
List<CtField<?>> fields = target.getFields();
// iterate over target fields
for (CtField<?> field : fields) {
+
+ //////////////////////////////////////////////////////
+ ///////// Manage the @FractalRC annotation //////////
+ /////////////////////////////////////////////////////
+
+ FractalRC
rcAnnotation=field.getAnnotation(FractalRC.class);
+ if (rcAnnotation!=null){
+ Template rcT= new
BindRcTemplate(field.getType(), field
+ .getSimpleName());
+ CtBlock<?> rcBlock =
Substitution.substituteMethodBody(target, rcT, "bind",new
CtTypeReference<?>[]{
+
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);
// if the field is not annotated continue
@@ -580,3 +597,54 @@
}
}
+/**
+ * A template to manage the bindFc method
+ *
+ * @author Nicolas Pessemier <Nicolas.Pessemier@xxxxxxx>
+ *
+ */
+class BindRcTemplate implements Template {
+
+ @Local
+ // A Local variable which is the reference to the singeton field
+ Component _service_;
+
+
+ @Parameter("_service_")
+ // The name of the singleton field
+ String __service_;
+
+ /**
+ * 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 BindRcTemplate(CtTypeReference serviceType,
+ String serviceName) {
+ this.__service_ = serviceName;
+
+ }
+
+ /**
+ * 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 bind(String clientItfName, Object serverItf) throws
NoSuchInterfaceException, IllegalBindingException {
+ if (clientItfName.equals("component")) {
+ _service_ = (Component) serverItf;
+ return;
+ }
+ }
+
+}
| <-- Date Index --> | <-- Thread Index --> |
Powered by MHonArc.
Copyright © 2006-2007, OW2 Consortium | contact | webmaster.