Commit f4b21900 authored by seinturier's avatar seinturier

Remove the Tinfi Fractal provider class.

Rely on the Fractal provider class defined in Juliac.
parent 8c791b66
Tinfi 0.4.2
-----------
* move to Juliac 2.1.2
* remove the Tinfi Fractal provider class and rely on the Juliac one
Tinfi 0.4.1
-----------
* bug fix for scaComposite membranes (reported by Damien)
......
......@@ -27,7 +27,6 @@ import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.juliac.Utils;
import org.objectweb.fractal.juliac.proxy.ProxyClassGenerator;
import org.objectweb.fractal.juliac.visit.MethodSourceCodeVisitor;
import org.scorware.tinfi.Factory;
/**
* This class generates the source code for initializing Fractal components.
......@@ -71,9 +70,4 @@ extends org.objectweb.fractal.juliac.opt.oo.InitializerOOCtrlClassGenerator {
mv.visit (Utils.javaifyContentDesc(contentDesc).toString());
mv.visitln(";");
}
@Override
public String[] getImplementedInterfaceNames() {
return new String[]{Factory.class.getName()};
}
}
......@@ -39,9 +39,9 @@ import org.objectweb.fractal.julia.ComponentInterface;
import org.objectweb.fractal.julia.Controller;
import org.objectweb.fractal.julia.InitializationContext;
import org.objectweb.fractal.julia.factory.ChainedInstantiationException;
import org.scorware.tinfi.ClassLoaderFcItf;
import org.scorware.tinfi.ClassLoaderItf;
import org.scorware.tinfi.Tinfi;
import org.objectweb.fractal.juliac.runtime.ClassLoaderFcItf;
import org.objectweb.fractal.juliac.runtime.ClassLoaderItf;
import org.objectweb.fractal.juliac.runtime.Juliac;
import org.scorware.tinfi.TinfiComponentInterceptor;
import org.scorware.tinfi.TinfiRuntimeException;
import org.scorware.tinfi.control.content.ClassMetaData;
......@@ -308,7 +308,7 @@ implements Controller, SCAIntentController {
*/
private ClassLoaderItf getFcClassLoader() {
if( loader == null ) {
Component boot = new Tinfi().newFcInstance();
Component boot = new Juliac().newFcInstance();
try {
loader = (ClassLoaderItf) boot.getFcInterface(ClassLoaderFcItf.NAME);
}
......
......@@ -14,7 +14,7 @@
<properties>
<julia.version>2.5.2</julia.version>
<juliac.version>2.1.1</juliac.version>
<juliac.version>2.1.2-SNAPSHOT</juliac.version>
</properties>
<modules>
......
......@@ -19,6 +19,11 @@
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.objectweb.fractal.juliac</groupId>
<artifactId>juliac-runtime</artifactId>
<version>${juliac.version}</version>
</dependency>
</dependencies>
</project>
/***
* Tinfi
* Copyright (C) 2008 INRIA, USTL
*
* 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: Lionel.Seinturier@univ-lille1.fr
*
* Author: Lionel Seinturier
*/
package org.scorware.tinfi;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Type;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.julia.BasicComponentInterface;
import org.objectweb.fractal.julia.type.BasicInterfaceType;
/**
* Implementation of the Fractal interface for {@link ClassLoaderItf}.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 0.3
*/
public class ClassLoaderFcItf
extends BasicComponentInterface implements ClassLoaderItf {
/** <code>NAME</code> of the class loader Fractal interface. */
final public static String NAME = "classloader";
/** <code>TYPE</code> of the class loader Fractal interface. */
final public static InterfaceType TYPE =
new BasicInterfaceType(
NAME,
ClassLoaderItf.class.getName(),
false, false, false );
public ClassLoaderFcItf( Component component, String s, Type type, boolean flag, Object obj ) {
super(component, s, type, flag, obj);
}
public Object getFcItfImpl() {
return impl;
}
public void setFcItfImpl(Object obj) {
impl = (ClassLoaderItf) obj;
}
private ClassLoaderItf impl;
public Class<?> loadClass( String name ) throws ClassNotFoundException {
if (impl == null)
throw new NullPointerException(
"Trying to invoke a method on a client interface, or on a server interface whose complementary interface is not bound.");
return impl.loadClass(name);
}
}
/***
* Tinfi
* Copyright (C) 2008 INRIA, USTL
*
* 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: Lionel.Seinturier@univ-lille1.fr
*
* Author: Lionel Seinturier
*/
package org.scorware.tinfi;
/**
* Interface for class loading.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 0.3
*/
public interface ClassLoaderItf {
/**
* Load the class whose name is specified.
*
* @param name the name of the class
* @return the corresponding class
* @throws ClassNotFoundException if the class can not be found
*/
public Class<?> loadClass( String name ) throws ClassNotFoundException;
}
/***
* Juliac
* Copyright (C) 2007 INRIA, France Telecom, USTL
*
* 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: Lionel.Seinturier@univ-lille1.fr
*
* Author: Lionel Seinturier
*/
package org.scorware.tinfi;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.factory.InstantiationException;
/**
* A factory for instantiating components.
*
* This factory instantiates components of a particular type, with a particular
* control membrane and with a particular content implementation.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 0.3
*/
public interface Factory extends org.objectweb.fractal.api.factory.Factory {
/**
* Return a new component instance.
*
* @param content the content instance
* @return a new component instance
*/
public Component newFcInstance( Object content )
throws InstantiationException;
}
/***
* Tinfi
* Copyright (C) 2008 INRIA, USTL
*
* 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: Lionel.Seinturier@univ-lille1.fr
*
* Author: Lionel Seinturier
*/
package org.scorware.tinfi;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Type;
import org.objectweb.fractal.api.factory.GenericFactory;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.julia.BasicComponentInterface;
import org.objectweb.fractal.julia.type.BasicInterfaceType;
/**
* Implementation of the Fractal interface for {@link GenericFactory}.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 0.3
*/
public class GenericFactoryFcItf
extends BasicComponentInterface implements GenericFactory {
/** <code>NAME</code> of the generic factory Fractal interface. */
final public static String NAME = "generic-factory";
/** <code>TYPE</code> of the generic factory Fractal interface. */
final public static InterfaceType TYPE =
new BasicInterfaceType(
NAME,
GenericFactory.class.getName(),
false, false, false );
public GenericFactoryFcItf( Component component, String s, Type type, boolean flag, Object obj ) {
super(component,s,type,flag,obj);
}
public Object getFcItfImpl() { return impl; }
public void setFcItfImpl(Object obj) {
impl = (GenericFactory)obj;
}
private GenericFactory impl;
public Component newFcInstance( Type arg0, Object arg1, Object arg2 )
throws InstantiationException {
if( impl == null )
throw new NullPointerException("Trying to invoke a method on a client interface, or on a server interface whose complementary interface is not bound.");
return impl.newFcInstance(arg0, arg1, arg2);
}
}
/***
* Tinfi
* Copyright (C) 2008 INRIA, USTL
*
* 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: Lionel.Seinturier@univ-lille1.fr.fr
*
* Author: Lionel Seinturier
*/
package org.scorware.tinfi;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Type;
import org.objectweb.fractal.api.factory.Factory;
import org.objectweb.fractal.api.factory.GenericFactory;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.objectweb.fractal.api.type.ComponentType;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.api.type.TypeFactory;
import org.objectweb.fractal.julia.type.BasicComponentType;
/**
* The Fractal provider class for Tinfi.
* This class provides the {@link #newFcInstance()} method for retrieving an
* instance of the Tinfi bootstrap component.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
*/
public class Tinfi implements Factory, GenericFactory {
/** The package prefix for code generated by Juliac. */
final public static String JULIAC_GENERATED = "juliac.generated";
public Tinfi() {}
// -----------------------------------------------------------------------
// Implementation of the Factory interface
// -----------------------------------------------------------------------
/**
* Return the reference of the bootstrap component.
* This method is called by {@link
* org.objectweb.fractal.api.Fractal#getBootstrapComponent()}
* The bootstrap component provides the following interfaces:
* <ul>
* <li> {@link TypeFactory} </li>
* <li> {@link GenericFactory} </li>
* <li> {@link ClassLoaderItf} </li>
* </ul>
*/
public Component newFcInstance() {
return newFcInstance(null,null,null);
}
public Object getFcContentDesc() {
return TinfiBootstrapComponentImpl.class.getName();
}
public Object getFcControllerDesc() {
return CONTROLLER_DESC;
}
public Type getFcInstanceType() {
if( TYPE == null ) {
try {
TYPE =
new BasicComponentType(
new InterfaceType[]{
TypeFactoryFcItf.TYPE,
GenericFactoryFcItf.TYPE,
ClassLoaderFcItf.TYPE
}
);
}
catch( InstantiationException e ) {
throw new RuntimeException(e);
}
}
return TYPE;
}
private static ComponentType TYPE = null;
final private static Object CONTROLLER_DESC = "bootstrap";
// -----------------------------------------------------------------------
// Implementation of the GenericFactory interface
// -----------------------------------------------------------------------
/**
* Return the reference of the bootstrap component.
* This method is called by {@link
* org.objectweb.fractal.util.Fractal#getBootstrapComponent(java.util.Map)}
*/
public Component newFcInstance(
Type type, Object controllerDesc, Object contentDesc ) {
if( bootstrap == null ) {
bootstrap = new TinfiBootstrapComponentImpl();
}
return bootstrap;
}
/** The singleton instance of the bootstrap component. */
private static Component bootstrap;
}
/***
* Tinfi
* Copyright (C) 2008 INRIA, USTL
*
* 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: Lionel.Seinturier@univ-lille1.fr
*
* Author: Lionel Seinturier
*/
package org.scorware.tinfi;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Interface;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.Type;
import org.objectweb.fractal.api.factory.GenericFactory;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.objectweb.fractal.api.type.ComponentType;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.api.type.TypeFactory;
import org.objectweb.fractal.julia.factory.ChainedInstantiationException;
import org.objectweb.fractal.julia.type.BasicComponentType;
import org.objectweb.fractal.julia.type.BasicInterfaceType;
/**
* A simple factory for components with an initializer class.
* This factory assumes the component class and the initializer class have been
* previously generated.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 0.3
*/
public class TinfiBootstrapComponentImpl
implements TypeFactory, GenericFactory, ClassLoaderItf, Component {
public TinfiBootstrapComponentImpl() {
/*
* Create the component interfaces.
*/
interfaces =
new Object[]{
new TypeFactoryFcItf( this, TypeFactoryFcItf.NAME, TypeFactoryFcItf.TYPE, false, this ),
new GenericFactoryFcItf( this, GenericFactoryFcItf.NAME, GenericFactoryFcItf.TYPE, false, this ),
new ClassLoaderFcItf( this, ClassLoaderFcItf.NAME, ClassLoaderFcItf.TYPE, false, this ),
};
}
// -----------------------------------------------------------------
// Implementation of the TypeFactory interface
// -----------------------------------------------------------------
public InterfaceType createFcItfType(
String name, String signature,
boolean isClient, boolean isOptional, boolean isCollection ) {
return new BasicInterfaceType(
name, signature, isClient, isOptional, isCollection );
}
public ComponentType createFcType( InterfaceType[] interfaceTypes )
throws InstantiationException {
return new BasicComponentType(interfaceTypes);
}
// -----------------------------------------------------------------
// Implementation of the GenericFactory interface
// -----------------------------------------------------------------
/**
* Create a new component.
*
* @param type the component type
* @param controllerDesc
* the description of the control membrane associated
* to the component
* @param contentDesc
* the description of the content of the component
*/
public Component newFcInstance(
Type type, Object controllerDesc, Object contentDesc )
throws InstantiationException {
/*
* When called from Fractal ADL, the component creation process may be
* accompagnied with some hints. One of the them is the class loader to
* be used. In this case, the controllerDesc parameter is an array where
* the 1st element contains the class loader.
*/
if( controllerDesc.getClass().isArray() ) {
Object[] array = (Object[]) controllerDesc;
ClassLoader classLoader = (ClassLoader) array[0];
tl.set(classLoader);
controllerDesc = array[1];
}
/*
* Adaptation for templates components.
* Templates are created with something like:
* Component cTmpl = cf.newFcInstance(
* cType, "flatPrimitiveTemplate",
* new Object[] { "flatPrimitive", "ClientImpl" });
*/
if( controllerDesc instanceof String ) {
if( ((String)controllerDesc).endsWith("Template") ) {
Object[] cont = (Object[]) contentDesc;
contentDesc = cont[1];
}
}
if( !(type instanceof ComponentType) ) {
String msg = "ComponentType expected";
throw new InstantiationException(msg);
}
/*
* Compute the hash code used as the suffix by the initializer class.
* The idea is that there is a class for each different record of
* content class, controller descriptor and component type. The two
* first elements are, by nature, identify. A hash is computed to
* uniquely identifies component types.
*/
ComponentType ct = (ComponentType) type;
String sct = ct.toString();
int hashct = sct.hashCode();
String hexhashct = Integer.toHexString(hashct);
/*
* If contentDesc is a string, consider that it is the fully qualified
* name of the class which needs to be instantiated. Else, consider that
* this is the instance which must be associated with the component.
*/
String membraneClassname =
contentDesc == null ?
Tinfi.JULIAC_GENERATED+"."+controllerDesc :
(contentDesc instanceof String ? contentDesc : contentDesc.getClass().getName())
+"FC"+controllerDesc;
String targetClassname = membraneClassname+"FC"+hexhashct;
Class<?> cl = null;
try {
cl = loadClass(targetClassname);
}
catch (ClassNotFoundException e) {
throw new ChainedInstantiationException(e,null,"");
}
Factory f = (Factory) instanciateClass(cl);
Component c =
(contentDesc==null || contentDesc instanceof String) ?
f.newFcInstance() :
f.newFcInstance(contentDesc);
return c;
}
// -----------------------------------------------------------------
// Implementation of the ClassLoaderItf interface
// -----------------------------------------------------------------
private ThreadLocal<ClassLoader> tl = new ThreadLocal<ClassLoader>();
/**
* Load the class whose name is specified.
*
* @param name the name of the class
* @return the corresponding class
* @throws ClassNotFoundException if the class can not be found
*/
public Class<?> loadClass( String name ) throws ClassNotFoundException {
ClassLoader cl = tl.get();
Class<?> c =
( cl == null ) ?
Class.forName(name) :
cl.loadClass(name);
return c;
}
// -----------------------------------------------------------------
// Utility methods
// -----------------------------------------------------------------
/**
* Instantiate the given class name.
*/
private Object instanciateClass( Class<?> cl ) throws InstantiationException {
try {
Object o = cl.newInstance();
return o;
}
catch( java.lang.InstantiationException ie ) {
final String msg =
"java.lang.InstantiationException when instantiating class: "+
cl.getName();
throw new ChainedInstantiationException(ie,null,msg);
}
catch( IllegalAccessException iae ) {
final String msg =
"IllegalAccessException when instantiating class: "+
cl.getName();
throw new ChainedInstantiationException(iae,null,msg);
}
}
// -----------------------------------------------------------------
// Implementation of the Component interface
// -----------------------------------------------------------------
public Object getFcInterface(String arg0) throws NoSuchInterfaceException {
for (int i = 0; i < interfaces.length; i++) {
String name = ((Interface)interfaces[i]).getFcItfName();
if( name.equals(arg0) ) {
return interfaces[i];
}
}
throw new NoSuchInterfaceException(arg0);
}
public Object[] getFcInterfaces() {
return interfaces;
}
public Type getFcType() {
return new Tinfi().getFcInstanceType();
}
private Object[] interfaces;
}
/***
* Tinfi
* Copyright (C) 2008 INRIA, USTL
*
* 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.