Commit f5981ecd authored by Lionel Seinturier's avatar Lionel Seinturier

Add a setFcContentClassName method in the SCA Content control interface...

Add a setFcContentClassName method in the SCA Content control interface (feature suggested by Valerio.)
Associated test.
parent 69ebbf2a
Tinfi 0.6.1
-----------
* add a setFcContentClassName method in the SCA Content control interface
(feature suggested by Valerio)
Tinfi 0.6
---------
* let the sca-intent-controller control interface be visible
......
......@@ -26,6 +26,8 @@ package org.ow2.frascati.tinfi.control.content;
import java.util.Stack;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.api.control.LifeCycleController;
import org.objectweb.fractal.api.control.NameController;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.objectweb.fractal.julia.Controller;
......@@ -92,8 +94,24 @@ implements Controller, SCAContentController {
* initialized.
*/
String fcContentDesc = (String) ic.content;
innerSetFcContentClassName(fcContentDesc);
}
/**
* Declares the name of the content class which should be used. This
* operation can only be performed if the component is stopped. This method
* is synchronized to prevent inconsistent concurrent changes.
*
* @since 0.6
*/
private synchronized void innerSetFcContentClassName( String name )
throws InstantiationException {
/*
* Content class meta data and scope manager retrievals.
*/
try {
ccmd = ContentClassMetaData.get(fcContentDesc);
ccmd = ContentClassMetaData.get(name);
}
catch( IllegalContentClassMetaData e ) {
throw new ChainedInstantiationException(
......@@ -127,12 +145,33 @@ implements Controller, SCAContentController {
throw new InstantiationException(msg);
}
}
// -------------------------------------------------------------------------
// Implementation of the SCAContentController interface
// -------------------------------------------------------------------------
/**
* @since 0.6
*/
public void setFcContentClassName( String name )
throws IllegalLifeCycleException, InstantiationException {
/*
* Lifecycle check.
*/
String state = _this_weaveableOptLC.getFcState();
if( ! state.equals(LifeCycleController.STOPPED) ) {
String msg = "Component should be stopped";
throw new IllegalLifeCycleException(msg);
}
/*
* Content class meta data and scope manager retrievals.
*/
innerSetFcContentClassName(name);
}
public void eagerInit() throws InstantiationException {
if( ccmd.eagerinit != null ) {
if( !(sm instanceof CompositeScopeManager) ) {
......@@ -215,4 +254,10 @@ implements Controller, SCAContentController {
* this controller object belongs.
*/
public SCAPropertyController _this_weavablePC;
/**
* The {@link LifeCycleController} interface of the component to which
* this controller object belongs.
*/
public LifeCycleController _this_weaveableOptLC;
}
......@@ -53,6 +53,7 @@
SCAContentControllerImpl
org.objectweb.fractal.julia.BasicControllerMixin
org.objectweb.fractal.julia.UseComponentMixin
org.objectweb.fractal.julia.control.lifecycle.UseLifeCycleControllerMixin
org.objectweb.fractal.julia.control.name.UseNameControllerMixin
org.ow2.frascati.tinfi.control.property.UseSCAPropertyControllerMixin
org.ow2.frascati.tinfi.control.component.UseComponentContextMixin
......
......@@ -25,6 +25,7 @@ package org.ow2.frascati.tinfi.control.content;
import java.util.Stack;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.julia.type.BasicInterfaceType;
......@@ -47,6 +48,18 @@ public interface SCAContentController {
SCAContentController.class.getName(),
false, false, false );
/**
* Declares the name of the content class which should be used. This
* operation can only be performed if the component is stopped.
*
* @param name the content class name
* @throws IllegalLifeCycleException if the component is not stopped
* @throws InstantiationException if the content can not be instantiated
* @since 0.6
*/
public void setFcContentClassName( String name )
throws IllegalLifeCycleException, InstantiationException;
/**
* Return a content instance according to the scope policy defined for this
* component.
......@@ -63,8 +76,8 @@ public interface SCAContentController {
*
* @param content the content instance which is released
* @param isEndMethod
* true if the method which releases the content instance is annotated
* with {@link org.osoa.sca.annotations.EndsConversation}.
* <code>true</code> if the method which releases the content instance
* is annotated with {@link org.osoa.sca.annotations.EndsConversation}
*/
public void releaseFcContent( Object content, boolean isEndMethod );
......
......@@ -88,6 +88,7 @@
<adl>org.ow2.frascati.tinfi.ReferenceMultiple</adl>
<adl>org.ow2.frascati.tinfi.ReferenceNotSet</adl>
<adl>org.ow2.frascati.tinfi.SCAContentController</adl>
<adl>org.ow2.frascati.tinfi.SCAContentControllerDummy</adl>
<adl>org.ow2.frascati.tinfi.ScopeComposite</adl>
<adl>org.ow2.frascati.tinfi.ScopeConversation</adl>
<adl>org.ow2.frascati.tinfi.ScopeRequest</adl>
......
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2009 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: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
package org.ow2.frascati.tinfi;
/**
* Component implementation class used for testing the features provided by the
* {@link SCAContentController} interface.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 0.6
*/
public class SCAContentControllerImpl1 implements SCAContentControllerItf {
public String getClassName() {
Class<?> cl = getClass();
return cl.getName();
}
}
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2009 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: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
package org.ow2.frascati.tinfi;
/**
* Component implementation class used for testing the features provided by the
* {@link SCAContentController} interface.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 0.6
*/
public class SCAContentControllerImpl2 implements SCAContentControllerItf {
public String getClassName() {
Class<?> cl = getClass();
return cl.getName();
}
}
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2009 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: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
package org.ow2.frascati.tinfi;
/**
* Interface provided by the component implementation used for testing the
* features provided by the {@link SCAContentController} interface.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 0.6
*/
public interface SCAContentControllerItf {
public String getClassName();
}
......@@ -3,9 +3,14 @@
<definition name="org.ow2.frascati.tinfi.SCAContentController" >
<interface name="r" role="server" signature="org.ow2.frascati.tinfi.SCAContentControllerItf" />
<component name="client">
<content class="org.ow2.frascati.tinfi.DummyClass" />
<interface name="r" role="server" signature="org.ow2.frascati.tinfi.SCAContentControllerItf" />
<content class="org.ow2.frascati.tinfi.SCAContentControllerImpl1" />
<controller desc="scaPrimitive" />
</component>
<binding client="this.r" server="client.r" />
</definition>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE definition PUBLIC "-//objectweb.org//DTD Fractal ADL 2.0//EN" "classpath://org/objectweb/fractal/adl/xml/standard.dtd">
<definition name="org.ow2.frascati.tinfi.SCAContentControllerDummy" >
<component name="dummy">
<content class="org.ow2.frascati.tinfi.DummyClass" />
<controller desc="scaPrimitive" />
</component>
</definition>
......@@ -23,17 +23,20 @@
package org.ow2.frascati.tinfi;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.Type;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
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.api.type.TypeFactory;
import org.objectweb.fractal.util.Fractal;
import org.ow2.frascati.tinfi.TinfiDomain;
import org.ow2.frascati.tinfi.control.content.SCAContentController;
/**
* Class for testing the SCA Content Controller.
......@@ -42,7 +45,75 @@ import org.ow2.frascati.tinfi.TinfiDomain;
* @since 0.3
*/
public class SCAContentControllerTestCase extends TestCase {
private Component client;
@Override
protected void setUp()
throws
ClassNotFoundException, InstantiationException, IllegalAccessException,
IllegalLifeCycleException, NoSuchInterfaceException,
java.lang.InstantiationException {
String adl = getClass().getPackage().getName()+".SCAContentController";
Component root = TinfiDomain.getComponent(adl);
Component[] subs =
Fractal.getContentController(root).getFcSubComponents();
client = subs[0];
}
/**
* @since 0.6
*/
public void testGetContentClassName()
throws IllegalLifeCycleException, NoSuchInterfaceException {
SCAContentControllerItf r =
(SCAContentControllerItf) client.getFcInterface("r");
Fractal.getLifeCycleController(client).startFc();
String expected = SCAContentControllerImpl1.class.getName();
String name = r.getClassName();
Assert.assertEquals(expected,name);
}
/**
* Test that the content class of <code>scaPrimitive</code> components can
* be changed by invoking {@link
* SCAContentController#setFcContentClassName(String)}.
*
* @since 0.6
*/
public void testSetContentClassName()
throws
IllegalLifeCycleException, NoSuchInterfaceException,
InstantiationException {
SCAContentControllerItf r =
(SCAContentControllerItf) client.getFcInterface("r");
// Start and invoke the component once
Fractal.getLifeCycleController(client).startFc();
r.getClassName();
// Reconfigure the content class
String expected = SCAContentControllerImpl2.class.getName();
Fractal.getLifeCycleController(client).stopFc();
SCAContentController scacc = (SCAContentController)
client.getFcInterface(SCAContentController.NAME);
scacc.setFcContentClassName(expected);
Fractal.getLifeCycleController(client).startFc();
// Re-invoke the component and check that the content class has changed
String name = r.getClassName();
Assert.assertEquals(expected,name);
}
/**
* Test that a custom class loader can be transmitted to {@link
* GenericFactory#newFcInstance(Type, Object, Object)} when instantiating a
* component.
*/
public void testContentClassLoadableWithDedicatedClassLoader()
throws InstantiationException, NoSuchInterfaceException {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment