Mail Archive Home | fractal-commits List | October 2006 Index
| <-- Date Index --> | <-- Thread Index --> |
Date: Friday, October 27, 2006 @ 16:09:35
Author: pessemier
Path: .../fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation
Added: generator/template/LifeCycleTemplateStart.java
generator/template/LifeCycleTemplateStop.java
Modified: ant/FracletAnnotation.java
generator/template/LifeCycleTemplate.java
processor/ComponentProcessor.java
processor/FractalAnnotationProcessor.java
Removed: processor/LifeCycleProcessor.java
fix a bug: now the @LifeCycle annotation can be used on two methods in a same
component (start AND stop)
------------------------------------------------+
ant/FracletAnnotation.java | 5 -
generator/template/LifeCycleTemplate.java | 35 +++----
generator/template/LifeCycleTemplateStart.java | 104 ++++++++++++++++++++++
generator/template/LifeCycleTemplateStop.java | 107 +++++++++++++++++++++++
processor/ComponentProcessor.java | 56 ++++++++++++
processor/FractalAnnotationProcessor.java | 2
processor/LifeCycleProcessor.java | 78 ----------------
7 files changed, 288 insertions(+), 99 deletions(-)
Index:
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/ant/FracletAnnotation.java
diff -u
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/ant/FracletAnnotation.java:1.12
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/ant/FracletAnnotation.java:1.13
---
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/ant/FracletAnnotation.java:1.12
Wed Sep 6 14:04:37 2006
+++
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/ant/FracletAnnotation.java
Fri Oct 27 16:09:33 2006
@@ -22,7 +22,6 @@
import org.objectweb.fractal.fraclet.annotation.processor.AttributeProcessor;
import org.objectweb.fractal.fraclet.annotation.processor.ComponentProcessor;
import org.objectweb.fractal.fraclet.annotation.processor.InterfaceProcessor;
-import org.objectweb.fractal.fraclet.annotation.processor.LifeCycleProcessor;
import
org.objectweb.fractal.fraclet.annotation.processor.MonologHandlerProcessor;
import org.objectweb.fractal.fraclet.annotation.processor.MonologProcessor;
import org.objectweb.fractal.fraclet.annotation.processor.ServiceProcessor;
@@ -66,8 +65,8 @@
.getCanonicalName()));
addProcessor(new ProcessorType(ServiceProcessor.class
.getCanonicalName()));
- addProcessor(new ProcessorType(LifeCycleProcessor.class
- .getCanonicalName()));
+// addProcessor(new ProcessorType(LifeCycleProcessor.class
+// .getCanonicalName()));
super.execute();
Index:
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/generator/template/LifeCycleTemplate.java
diff -u
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/generator/template/LifeCycleTemplate.java:1.3
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/generator/template/LifeCycleTemplate.java:1.4
---
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/generator/template/LifeCycleTemplate.java:1.3
Wed Sep 6 14:04:37 2006
+++
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/generator/template/LifeCycleTemplate.java
Fri Oct 27 16:09:33 2006
@@ -22,8 +22,6 @@
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.api.control.LifeCycleController;
-import org.objectweb.fractal.fraclet.annotation.LifeCycle;
-import org.objectweb.fractal.fraclet.annotation.LifeCycleType;
import spoon.reflect.code.CtInvocation;
import spoon.reflect.declaration.CtClass;
@@ -46,19 +44,24 @@
@SuppressWarnings("unchecked")
@Local
- public LifeCycleTemplate(CtMethod<?> processedMethod, LifeCycle
lcAnnotation) {
- _methodCall_ =
processedMethod.getFactory().Core().createInvocation();
- _methodCall_.setTarget(processedMethod.getFactory().Code()
+ public LifeCycleTemplate(CtMethod<?> methodToStart,
+ CtMethod<?> methodToStop) {
+ _methodCall_ =
methodToStart.getFactory().Core().createInvocation();
+ _methodCall_.setTarget(methodToStart.getFactory().Code()
.createThisAccess(
-
processedMethod.getFactory().Type().createReference(
-
processedMethod.getParent(CtClass.class)
+
methodToStart.getFactory().Type().createReference(
+
methodToStart.getParent(CtClass.class)
.getActualClass())));
- _methodCall_.setExecutable((CtExecutableReference)
processedMethod
+ _methodCall_.setExecutable((CtExecutableReference)
methodToStart
+ .getReference());
+ _methodCallStop_ =
methodToStop.getFactory().Core().createInvocation();
+ _methodCallStop_.setTarget(methodToStop.getFactory()
+ .Code().createThisAccess(
+
methodToStop.getFactory().Type().createReference(
+
methodToStop.getParent(CtClass.class)
+
.getActualClass())));
+ _methodCallStop_.setExecutable((CtExecutableReference)
methodToStop
.getReference());
- if (lcAnnotation.on().equals(LifeCycleType.START))
- start = true;
- else
- start = false;
}
@@ -66,7 +69,7 @@
CtInvocation<?> _methodCall_;
@Parameter
- boolean start;
+ CtInvocation<?> _methodCallStop_;
/**
*
@@ -92,8 +95,7 @@
public void startFc() throws IllegalLifeCycleException {
try {
_fcState = true;
- if (start)
- _methodCall_.S();
+ _methodCall_.S();
} catch (Exception e) {
throw new IllegalLifeCycleException(e.getMessage());
}
@@ -106,8 +108,7 @@
*/
public void stopFc() throws IllegalLifeCycleException {
try {
- if (!start)
- _methodCall_.S();
+ _methodCallStop_.S();
_fcState = false;
} catch (Exception e) {
Index:
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/generator/template/LifeCycleTemplateStart.java
diff -u /dev/null
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/generator/template/LifeCycleTemplateStart.java:1.1
--- /dev/null Fri Oct 27 16:09:35 2006
+++
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/generator/template/LifeCycleTemplateStart.java
Fri Oct 27 16:09:33 2006
@@ -0,0 +1,104 @@
+/*==============================================================================
+ 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)
+ Contributor(s): Renaud Pawlak (renaud.pawlak@xxxxxxx)
+
==============================================================================*/
+
+package org.objectweb.fractal.fraclet.annotation.generator.template;
+
+import org.objectweb.fractal.api.control.IllegalLifeCycleException;
+import org.objectweb.fractal.api.control.LifeCycleController;
+
+import spoon.reflect.code.CtInvocation;
+import spoon.reflect.declaration.CtClass;
+import spoon.reflect.declaration.CtMethod;
+import spoon.reflect.reference.CtExecutableReference;
+import spoon.template.Local;
+import spoon.template.Parameter;
+import spoon.template.Template;
+
+/**
+ * A template code to manage the LifeCycle annotation. This template
introdudes
+ * the implementation of the LifeCycle controller and then call the annotated
+ * method in the start or stop method (depending on the parameter of the
+ * annotation).
+ *
+ * @author Nicolas Pessemier <Nicolas.Pessemier@xxxxxxx>
+ *
+ */
+public class LifeCycleTemplateStart implements LifeCycleController, Template
{
+
+ @SuppressWarnings("unchecked")
+ @Local
+ public LifeCycleTemplateStart(CtMethod<?> processedMethod) {
+ _methodCall_ =
processedMethod.getFactory().Core().createInvocation();
+ _methodCall_.setTarget(processedMethod.getFactory().Code()
+ .createThisAccess(
+
processedMethod.getFactory().Type().createReference(
+
processedMethod.getParent(CtClass.class)
+
.getActualClass())));
+ _methodCall_.setExecutable((CtExecutableReference)
processedMethod
+ .getReference());
+ }
+
+ @Parameter
+ CtInvocation<?> _methodCall_;
+
+ /**
+ *
+ */
+ private boolean _fcState = false;
+
+ /**
+ * (non-Javadoc) Method automatically generated with Spoon
+ *
+ * @see
org.objectweb.fractal.api.control.LifeCycleController#getFcState()
+ */
+ public String getFcState() {
+ if (_fcState)
+ return "STARTED";
+ return "STOPPED";
+ }
+
+ /**
+ * (non-Javadoc) Method automatically generated with Spoon
+ *
+ * @see
org.objectweb.fractal.api.control.LifeCycleController#startFc()
+ */
+ public void startFc() throws IllegalLifeCycleException {
+ try {
+ _fcState = true;
+ _methodCall_.S();
+ } catch (Exception e) {
+ throw new IllegalLifeCycleException(e.getMessage());
+ }
+ }
+
+ /**
+ * (non-Javadoc) Method automatically generated with Spoon
+ *
+ * @see org.objectweb.fractal.api.control.LifeCycleController#stopFc()
+ */
+ public void stopFc() throws IllegalLifeCycleException {
+ try {
+ _fcState = false;
+ } catch (Exception e) {
+ throw new IllegalLifeCycleException(e.getMessage());
+ }
+ }
+
+}
Index:
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/generator/template/LifeCycleTemplateStop.java
diff -u /dev/null
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/generator/template/LifeCycleTemplateStop.java:1.1
--- /dev/null Fri Oct 27 16:09:35 2006
+++
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/generator/template/LifeCycleTemplateStop.java
Fri Oct 27 16:09:33 2006
@@ -0,0 +1,107 @@
+/*==============================================================================
+ 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)
+ Contributor(s): Renaud Pawlak (renaud.pawlak@xxxxxxx)
+
==============================================================================*/
+
+package org.objectweb.fractal.fraclet.annotation.generator.template;
+
+import org.objectweb.fractal.api.control.IllegalLifeCycleException;
+import org.objectweb.fractal.api.control.LifeCycleController;
+
+import spoon.reflect.code.CtInvocation;
+import spoon.reflect.declaration.CtClass;
+import spoon.reflect.declaration.CtMethod;
+import spoon.reflect.reference.CtExecutableReference;
+import spoon.template.Local;
+import spoon.template.Parameter;
+import spoon.template.Template;
+
+/**
+ * A template code to manage the LifeCycle annotation. This template
introdudes
+ * the implementation of the LifeCycle controller and then call the annotated
+ * method in the start or stop method (depending on the parameter of the
+ * annotation).
+ *
+ * @author Nicolas Pessemier <Nicolas.Pessemier@xxxxxxx>
+ *
+ */
+public class LifeCycleTemplateStop implements LifeCycleController, Template {
+
+ @SuppressWarnings("unchecked")
+ @Local
+ public LifeCycleTemplateStop(CtMethod<?> processedMethod) {
+ _methodCall_ =
processedMethod.getFactory().Core().createInvocation();
+ _methodCall_.setTarget(processedMethod.getFactory().Code()
+ .createThisAccess(
+
processedMethod.getFactory().Type().createReference(
+
processedMethod.getParent(CtClass.class)
+
.getActualClass())));
+ _methodCall_.setExecutable((CtExecutableReference)
processedMethod
+ .getReference());
+
+ }
+
+ @Parameter
+ CtInvocation<?> _methodCall_;
+
+ /**
+ *
+ */
+ private boolean _fcState = false;
+
+ /**
+ * (non-Javadoc) Method automatically generated with Spoon
+ *
+ * @see
org.objectweb.fractal.api.control.LifeCycleController#getFcState()
+ */
+ public String getFcState() {
+ if (_fcState)
+ return "STARTED";
+ return "STOPPED";
+ }
+
+ /**
+ * (non-Javadoc) Method automatically generated with Spoon
+ *
+ * @see
org.objectweb.fractal.api.control.LifeCycleController#startFc()
+ */
+ public void startFc() throws IllegalLifeCycleException {
+ try {
+ _fcState = true;
+ } catch (Exception e) {
+ throw new IllegalLifeCycleException(e.getMessage());
+ }
+ }
+
+ /**
+ * (non-Javadoc) Method automatically generated with Spoon
+ *
+ * @see org.objectweb.fractal.api.control.LifeCycleController#stopFc()
+ */
+ public void stopFc() throws IllegalLifeCycleException {
+ try {
+
+ _methodCall_.S();
+ _fcState = false;
+
+ } catch (Exception e) {
+ throw new IllegalLifeCycleException(e.getMessage());
+ }
+ }
+
+}
Index:
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/ComponentProcessor.java
diff -u
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/ComponentProcessor.java:1.2
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/ComponentProcessor.java:1.3
---
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/ComponentProcessor.java:1.2
Wed Sep 6 14:04:37 2006
+++
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/ComponentProcessor.java
Fri Oct 27 16:09:33 2006
@@ -21,15 +21,22 @@
import java.util.List;
+import org.objectweb.fractal.api.control.LifeCycleController;
import org.objectweb.fractal.fraclet.annotation.FractalComponent;
+import org.objectweb.fractal.fraclet.annotation.LifeCycle;
+import org.objectweb.fractal.fraclet.annotation.LifeCycleType;
import org.objectweb.fractal.fraclet.annotation.Service;
import
org.objectweb.fractal.fraclet.annotation.generator.ComponentADLGenerator;
+import
org.objectweb.fractal.fraclet.annotation.generator.template.LifeCycleTemplate;
+import
org.objectweb.fractal.fraclet.annotation.generator.template.LifeCycleTemplateStart;
+import
org.objectweb.fractal.fraclet.annotation.generator.template.LifeCycleTemplateStop;
import
org.objectweb.fractal.fraclet.annotation.generator.template.RequiresTemplate;
import
org.objectweb.fractal.fraclet.annotation.generator.template.util.NonTypedFractalAttributeException;
import spoon.processing.AbstractProcessor;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtElement;
+import spoon.reflect.declaration.CtMethod;
import spoon.template.Substitution;
/**
@@ -68,5 +75,54 @@
e.printStackTrace();
}
}
+
+
+ // Manage LifeCycle annotation
+ List<CtElement> elts =
processedClass.getAnnotatedChildren(LifeCycle.class);
+
+ boolean start = false, stop = false;
+
+ CtMethod startM = null, stopM = null;
+
+ for (CtElement elt : elts) {
+ LifeCycle annot = elt.getAnnotation(LifeCycle.class);
+
+ if (annot.on().equals(LifeCycleType.START)) {
+ start = true;
+ startM = (CtMethod) elt;
+ if (startM.getParameters().size() > 0)
+ System.err
+ .println("WARNING: a
method annotated with @LifeCycle shouldn't "
+ +
"have parameters! Please revise your method signature.");
+ }
+
+ if (annot.on().equals(LifeCycleType.STOP)) {
+ stop = true;
+ stopM = (CtMethod) elt;
+ if (stopM.getParameters().size() > 0)
+ System.err
+ .println("WARNING: a
method annotated with @LifeCycle shouldn't "
+ +
"have parameters! Please revise your method signature.");
+
+ }
+ }
+
+ if (start && !stop)
+ Substitution.insertAll(processedClass, new
LifeCycleTemplateStart(startM));
+
+ if (stop && !start)
+ Substitution.insertAll(processedClass, new
LifeCycleTemplateStop(stopM));
+ if (start && stop)
+ Substitution
+ .insertAll(processedClass, new
LifeCycleTemplate(startM, stopM));
+ if (start || stop)
+ if (!processedClass.getSuperInterfaces().contains(
+ getFactory().Type().createReference(
+
LifeCycleController.class))) {
+ processedClass.getSuperInterfaces().add(
+
getFactory().Type().createReference(
+
LifeCycleController.class));
+ }
+
}
}
Index:
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/FractalAnnotationProcessor.java
diff -u
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/FractalAnnotationProcessor.java:1.9
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/FractalAnnotationProcessor.java:1.10
---
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/FractalAnnotationProcessor.java:1.9
Mon Jun 12 15:50:50 2006
+++
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/FractalAnnotationProcessor.java
Fri Oct 27 16:09:33 2006
@@ -49,7 +49,7 @@
pf.addProcessor( new MonologHandlerProcessor() );
pf.addProcessor( new MonologProcessor() );
pf.addProcessor( new ServiceProcessor() );
- pf.addProcessor( new LifeCycleProcessor() );
+// pf.addProcessor( new LifeCycleProcessor() );
first = false;
}
}
Index:
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/LifeCycleProcessor.java
diff -u
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/LifeCycleProcessor.java:1.3
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/LifeCycleProcessor.java:removed
---
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/LifeCycleProcessor.java:1.3
Wed Sep 6 14:04:37 2006
+++
fraclet/fraclet-annotation/src/org/objectweb/fractal/fraclet/annotation/processor/LifeCycleProcessor.java
Fri Oct 27 16:09:35 2006
@@ -1,78 +0,0 @@
-/*==============================================================================
- 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)
- Contributor(s): Renaud Pawlak (renaud.pawlak@xxxxxxx)
-
==============================================================================*/
-
-package org.objectweb.fractal.fraclet.annotation.processor;
-
-import org.objectweb.fractal.api.control.LifeCycleController;
-import org.objectweb.fractal.fraclet.annotation.LifeCycle;
-import
org.objectweb.fractal.fraclet.annotation.generator.template.LifeCycleTemplate;
-
-import spoon.processing.AbstractAnnotationProcessor;
-import spoon.reflect.declaration.CtClass;
-import spoon.reflect.declaration.CtMethod;
-import spoon.template.Substitution;
-
-/**
- * An annotation processor to manage the LifeCycle annotation.
- *
- * @author Nicolas Pessemier <Nicolas.Pessemier@xxxxxxx>
- *
- */
-public class LifeCycleProcessor extends
- AbstractAnnotationProcessor<LifeCycle, CtMethod<?>> {
-
- @Override
- public void init() {
- addProcessedAnnotationType(LifeCycle.class);
- super.init();
- }
-
- @Override
- public boolean inferConsumedAnnotationType() {
- return false;
- }
-
- /**
- * A constructor for the AttributeProcessor
- *
- * @param lcAnnotation
- * the LifeCycle annotation
- * @param processedMethod
- * the CtMethod processed
- */
- public void process(LifeCycle lcAnnotation, CtMethod<?>
processedMethod) {
- CtClass<?> target = processedMethod.getParent(CtClass.class);
- if (processedMethod.getParameters().size() > 0)
- System.err
- .println("WARNING: a method annotated
with @LifeCycle shouldn't "
- + "have parameters!
Please revise your method signature.");
- else {
- Substitution.insertAll(target, new LifeCycleTemplate(
- processedMethod, lcAnnotation));
- if (!target.getSuperInterfaces().contains(
- getFactory().Type().createReference(
-
LifeCycleController.class))) {
- target.getSuperInterfaces().add(
-
getFactory().Type().createReference(
-
LifeCycleController.class));
- }
- }
- }
-}
| <-- Date Index --> | <-- Thread Index --> |
Powered by MHonArc.
Copyright © 2006-2007, OW2 Consortium | contact | webmaster.