Commit cddc6fd5 authored by Philippe Merle's avatar Philippe Merle
Browse files

Added a new FraSCAti module implementing:

* a new state controller
* a new membrane scaPrimitiveWithState
* plugins for the OW2 FraSCAti Component Factory.
parent 832cfefe
<?xml version="1.0"?>
<!--
* OW2 FraSCAti SCA Membrane with State Controller
*
* Copyright (c) 2012 Inria, University of Lille 1
*
* 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 of the License, or (at your option) 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
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
*
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- ===================== -->
<!-- General Information -->
<!-- ===================== -->
<parent>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-modules</artifactId>
<version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-membrane-scaPrimitiveWithState</artifactId>
<name>OW2 FraSCAti: SCA Membrane with State Controller (scaPrimitiveWithState) Module</name>
<packaging>jar</packaging>
<url>http://frascati.ow2.org</url>
<inceptionYear>2007</inceptionYear>
<developers>
<developer>
<id>merle</id>
<name>Philippe Merle</name>
<email>Philippe.Merle@inria.fr</email>
<organization>INRIA</organization>
<organizationUrl>http://www.inria.fr</organizationUrl>
<roles>
<role>Architect</role>
<role>Developer</role>
</roles>
</developer>
</developers>
<!-- ======= -->
<!-- Build -->
<!-- ======= -->
<build>
<plugins>
<!-- ======================================================== -->
<!-- Generate and compile the scaPrimitiveWithState membrane. -->
<!-- ======================================================== -->
<plugin>
<groupId>org.objectweb.fractal.juliac</groupId>
<artifactId>maven-juliac-plugin</artifactId>
<configuration>
<adls>
<adl>org.ow2.frascati.membrane.state.juliac.ForGeneratingMembraneScaPrimitiveWithState</adl>
</adls>
<adlParsers><adlParser>org.ow2.frascati.tinfi.tinfilet.TinfiParserSupportImpl</adlParser></adlParsers>
<!--
For Lionel: Instead of the four previous lines, I would prefer to provide something like:
<membranes>
<membrane>org.ow2.frascati.membrane.state.juliac.SCAPrimitiveWithState</membrane>
</membranes>
Then the ForGeneratingMembraneScaPrimitiveWithState class can be removed as it provides no business functionalities.
-->
<modules>
<module>org.ow2.frascati.tinfi:frascati-tinfi-oo:${tinfi.version}</module>
<module>org.objectweb.fractal.juliac:juliac-jdt:${juliac.version}</module>
<module>org.objectweb.fractal.juliac:juliac-spoon:${juliac.version}</module>
</modules>
</configuration>
</plugin>
</plugins>
</build>
<!-- ============ -->
<!-- Dependencies -->
<!-- ============ -->
<dependencies>
<!-- OW2 FraSCAti Tinfi OO Membrane Generator. -->
<!-- For accessing to SCAPrimitive and FCOOCtrlSourceCodeGenerator classes. -->
<dependency>
<groupId>org.ow2.frascati.tinfi</groupId>
<artifactId>frascati-tinfi-oo</artifactId>
<version>${tinfi.version}</version>
<exclusions>
<!-- Following dependency is not required. -->
<exclusion>
<groupId>org.objectweb.monolog</groupId>
<artifactId>monolog</artifactId>
</exclusion>
<!-- Avoid to pull Juliac systematically. -->
<exclusion>
<groupId>org.objectweb.fractal.juliac</groupId>
<artifactId>juliac-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
/**
* OW2 FraSCAti SCA Membrane with State Controller
* Copyright (C) 2012 Inria, University of Lille 1
*
* 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 of the License, or (at your option) 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
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*/
package org.ow2.frascati.membrane.state.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotates a content class field as a state field.
*
* @author Philippe Merle at Inria
* @since 1.5
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface StateField
{
/**
* The name of the state field.
* When not defined then the name of the annotated field is used instead of.
*/
String name() default "";
}
/**
* OW2 FraSCAti SCA Membrane with State Controller
* Copyright (C) 2012 Inria, University of Lille 1
*
* 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 of the License, or (at your option) 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
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*/
package org.ow2.frascati.membrane.state.api;
/**
* A state is a collection of state fields.
* Each state field has a name and a value.
*
* @author Philippe Merle at Inria
* @since 1.5
*/
public interface State
{
/**
* Gets all state field names.
*
* @return All state field names.
*/
String[] getFields();
/**
* Gets the value of a state field.
*
* @param fieldName The name of the state field.
* @param type The type of the state value.
* @return The value of the state field.
*/
<T> T getField(String fieldName, Class<T> type);
/**
* Sets the value of a state field.
*
* @param fieldName The name of the state field.
* @param value The value of the state field.
*/
<T> void setField(String fieldName, T value);
}
/**
* OW2 FraSCAti SCA Membrane with State Controller
* Copyright (C) 2012 Inria, University of Lille 1
*
* 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 of the License, or (at your option) 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
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*/
package org.ow2.frascati.membrane.state.api;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.ow2.frascati.tinfi.api.control.ContentInstantiationException;
/**
* Controller to manage the state of a component.
*
* @author Philippe Merle at Inria
* @since 1.5
*/
public interface StateController
{
/**
* The interface name of the state controller.
*/
String NAME = "state-controller";
/**
* Gets the state of a component.
*
* @return The state of a component.
* @throws IllegalLifeCycleException Thrown when the component is not stopped.
* @throws ContentInstantiationException Thrown when the content can not be instantiated.
*/
State getState() throws IllegalLifeCycleException, ContentInstantiationException;
/**
* Sets the state of a component.
*
* @param state The state of a component.
* @throws IllegalLifeCycleException Thrown when the component is not stopped.
* @throws ContentInstantiationException Thrown when the content can not be instantiated.
*/
void setState(State state) throws IllegalLifeCycleException, ContentInstantiationException;
}
/**
* OW2 FraSCAti SCA Membrane with State Controller
* Copyright (C) 2012 Inria, University of Lille 1
*
* 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 of the License, or (at your option) 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
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*/
package org.ow2.frascati.membrane.state.juliac;
/**
* Juliac generator for membrane scaPrimitiveWithState.
*
* @author Philippe Merle at Inria
* @since 1.5
*/
public class FCOOCtrlSourceCodeGenerator
extends org.ow2.frascati.tinfi.opt.oo.FCOOCtrlSourceCodeGenerator
{
@Override
public void postInit()
{
/*
* Don't call super.postInit() as this generator must only deal
* with the scaPrimitiveWithState membrane.
*/
// Register the scaPrimitiveWithState membrane.
jc.getJuliacConfig().getJulietLoader().
put(SCAPrimitiveWithState.NAME,SCAPrimitiveWithState.class);
}
}
/**
* OW2 FraSCAti SCA Membrane with State Controller
* Copyright (C) 2012 Inria, University of Lille 1
*
* 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 of the License, or (at your option) 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
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*
* Contributor(s):
*
*/
package org.ow2.frascati.membrane.state.juliac;
/**
* Dummy class used to generate the code of the scaPrimitiveWithState membrane.
*
* @author Philippe Merle at Inria.
* @since 1.5
*/
@org.objectweb.fractal.fraclet.extensions.Membrane(controllerDesc=SCAPrimitiveWithState.class)
public class ForGeneratingMembraneScaPrimitiveWithState
{
}
/**
* OW2 FraSCAti SCA Membrane with State Controller
* Copyright (C) 2012 Inria, University of Lille 1
*
* 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 of the License, or (at your option) 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
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*/
package org.ow2.frascati.membrane.state.juliac;
import org.objectweb.fractal.fraclet.extensions.Controller;
import org.objectweb.fractal.fraclet.extensions.Membrane;
import org.ow2.frascati.membrane.state.api.StateController;
import org.ow2.frascati.tinfi.membrane.SCAPrimitive;
/**
* Definition of the membrane for SCA primitive components with a state controller.
*
* This membrane extends the SCA primitive membrane and add the state controller.
*
* @author Philippe Merle at Inria
* @since 1.5
*/
@Membrane(desc=SCAPrimitiveWithState.NAME)
public class SCAPrimitiveWithState extends SCAPrimitive
{
/**
* The name of this membrane.
*/
public static final String NAME = "scaPrimitiveWithState";
/**
* The state controller.
*/
@Controller(
name=StateController.NAME,
impl="StateControllerImpl",
mixins={
StateControllerMixin.class // Class implementing this controller.
})
protected StateController stateController;
}
/**
* OW2 FraSCAti SCA Membrane with State Controller
* Copyright (C) 2012 Inria, University of Lille 1
*
* 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 of the License, or (at your option) 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
*
* Contact: frascati@ow2.org
*
* Author: Philippe Merle
*/
package org.ow2.frascati.membrane.state.juliac;
import java.lang.reflect.Field;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.api.control.LifeCycleController;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.objectweb.fractal.julia.Controller;
import org.objectweb.fractal.julia.InitializationContext;
import org.ow2.frascati.membrane.state.annotation.StateField;
import org.ow2.frascati.membrane.state.api.State;
import org.ow2.frascati.membrane.state.api.StateController;
import org.ow2.frascati.tinfi.api.control.ContentInstantiationException;
import org.ow2.frascati.tinfi.api.control.SCAContentController;
/**
* Implementation of the state controller.
*
* @author Philippe Merle at Inria
* @since 1.5
*/
public class StateControllerMixin implements StateController, Controller
{
// -------------------------------------------------------------------------
// Implementation of the Controller interface
// -------------------------------------------------------------------------
/**
* Called at the initialisation of the controller.
*/
public void initFcController(final InitializationContext ic)
throws InstantiationException {
// Obtain the life cycle controller of the enclosing component.
lifeCycleController = (LifeCycleController)ic.interfaces.get("lifecycle-controller");
// Obtain the SCA content controller of the enclosing component.
scaContentController = (SCAContentController)ic.interfaces.get(SCAContentController.NAME);
}
// -------------------------------------------------------------------------
// Internals related to the life cycle management
// -------------------------------------------------------------------------
/**
* Reference to the life cycle controller.
*/
private LifeCycleController lifeCycleController;
/**
* Checks that the enclosing component is stopped.
*
* @throws IllegalLifeCycleException Thrown when the enclosing component is not stopped.
*/
private void checkFcStopped() throws IllegalLifeCycleException
{
// If the component has a lifecycle controller
if( lifeCycleController != null ) {
// then the life cycle state must be equals to STOPPED
if( ! LifeCycleController.STOPPED.equals(lifeCycleController.getFcState()) ) {
// else throws an IllegalLifeCycleException.
throw new IllegalLifeCycleException("Component is not stopped");
}
}
}
// -------------------------------------------------------------------------
// Internals related to the content management
// -------------------------------------------------------------------------
/**
* Reference to the SCA content controller.
*/
private SCAContentController scaContentController;
// -------------------------------------------------------------------------
// Implementation of the StateController interface
// -------------------------------------------------------------------------
/**
* @see StateController#getState()
*/
public State getState() throws IllegalLifeCycleException, ContentInstantiationException
{
// Check if the component is stopped.
checkFcStopped();
// Get the current content.
Object content = scaContentController.getFcContent();
// Create the state to return.
State state = new StateImpl();