Commit 4424c2a4 authored by Lionel Seinturier's avatar Lionel Seinturier

Intent handlers on client interfaces.

Methods for listing and removing intent handlers in the SCA Intent Handler control interface.
Cosmetic.
parent 211f7d74
......@@ -3,8 +3,7 @@ Tinfi 0.4.4
* move to org.ow2.frascati for artifacts and Java packages
* support SCA annotations on private fields (suggested by Nicolas P.)
* support unannotated POJO component implementations
* bug fix for intent handlers on component with client interfaces
(reported by Nicolas D.)
* support intent handlers on component with client interfaces
* move to Juliac 2.1.5
......
mixins/
* support intent handlers on client interfaces
runtime/
* add listFcHandlers and removeFcHandlers methods in SCABasicIntentController
runtime-dyn/
* provide a runtime-generic module which would be able to instanciate components
without relying on a generated initializer class. The idea would be that this
module would also rely on ASM to generate FcItf, FcOutIf, FcSR,
......@@ -13,4 +9,7 @@ runtime/
ASM (not so sure for Interceptor*, but anyway...) whereas generating
initializer classes with ASM or julia-asm requires a lot of work. Having a
generic initializer should bypass this difficulty.
\ No newline at end of file
runtime-oo/
* support polymorphic setter methods in POJOs (see p12 of "SCA Service Component
Architectue Java Component Implementation Specification")
......@@ -81,12 +81,7 @@ extends AbstractInterceptorSourceCodeGenerator {
return false;
}
// Skip client interfaces
if( it.isFcClientItf() ) {
return false;
}
// Match all other interfaces (business server)
// Match all other interfaces (business server and client)
return true;
}
......@@ -264,6 +259,11 @@ extends AbstractInterceptorSourceCodeGenerator {
mv.visitln(" super.initFcController(ic);");
}
@Override
public void generateMethodClone( MethodSourceCodeVisitor mv, UnifiedClass proxycl ) {
mv.visitln(" initFcClone(clone);");
}
@Override
public void generateProxyMethodBodyBeforeCode(
MethodSourceCodeVisitor mv, UnifiedClass proxycl, UnifiedMethod proxym ) {
......
......@@ -29,6 +29,7 @@ import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.BindingController;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.julia.ComponentInterface;
import org.objectweb.fractal.julia.Interceptor;
/**
* Provides a basic implementation of the {@link BindingController} interface.
......@@ -42,8 +43,7 @@ public abstract class BasicBindingControllerMixin implements BindingController {
// Private constructor
// -------------------------------------------------------------------------
private BasicBindingControllerMixin () {
}
private BasicBindingControllerMixin () {}
// -------------------------------------------------------------------------
// Fields and methods added and overriden by the mixin class
......@@ -75,22 +75,32 @@ public abstract class BasicBindingControllerMixin implements BindingController {
return names;
}
public Object lookupFc(final String clientItfName) throws NoSuchInterfaceException {
public Object lookupFc( final String clientItfName )
throws NoSuchInterfaceException {
ComponentInterface ci = (ComponentInterface) _this_weaveableC.getFcInterface(clientItfName);
Object dst = ci.getFcItfImpl();
// Skip client interceptor
Interceptor interceptor = (Interceptor) ci.getFcItfImpl();
Object dst = interceptor.getFcItfDelegate();
return dst;
}
public void bindFc(final String clientItfName, final Object serverItf)
public void bindFc( final String clientItfName, final Object serverItf )
throws NoSuchInterfaceException {
ComponentInterface ci = (ComponentInterface) _this_weaveableC.getFcInterface(clientItfName);
ci.setFcItfImpl(serverItf);
// Skip client interceptor
Interceptor interceptor = (Interceptor) ci.getFcItfImpl();
interceptor.setFcItfDelegate(serverItf);
}
public void unbindFc(final String clientItfName)
public void unbindFc( final String clientItfName )
throws NoSuchInterfaceException {
ComponentInterface ci = (ComponentInterface) _this_weaveableC.getFcInterface(clientItfName);
ci.setFcItfImpl(null);
// Skip client interceptor
Interceptor interceptor = (Interceptor) ci.getFcItfImpl();
interceptor.setFcItfDelegate(null);
}
// -------------------------------------------------------------------------
......
......@@ -23,17 +23,16 @@
package org.ow2.frascati.tinfi.control.intent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Interface;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.julia.ComponentInterface;
import org.ow2.frascati.tinfi.TinfiComponentInterceptor;
import org.ow2.frascati.tinfi.TinfiRuntimeException;
import org.ow2.frascati.tinfi.control.intent.IntentHandler;
import org.ow2.frascati.tinfi.control.intent.SCABasicIntentController;
/**
* Mixin layer for implementing the {@link SCABasicIntentController} interface.
......@@ -55,34 +54,116 @@ implements SCABasicIntentController {
// -------------------------------------------------------------------------
/**
* Add the specified intent handler on all service and reference methods of
* the current component.
* Add the specified intent handler on all interfaces (service and
* reference) of the current component.
*
* @param handler the intent handler to add
*/
public void addFcIntentHandler( IntentHandler handler ) {
List<TinfiComponentInterceptor> interceptors = getFcInterceptors();
for (TinfiComponentInterceptor tci : interceptors) {
Map<String,TinfiComponentInterceptor> interceptors = getFcInterceptors();
Collection<TinfiComponentInterceptor> tcis = interceptors.values();
for (TinfiComponentInterceptor tci : tcis) {
tci.addFcIntentHandler(handler);
}
}
/**
* Add the specified intent handler on the interface (service or reference)
* whose name is specified.
*
* @param handler the intent handler to add
* @param name the interface name
* @throws NoSuchInterfaceException if the interface does not exist
* @since 0.4.4
*/
public void addFcIntentHandler( IntentHandler handler, String name )
throws NoSuchInterfaceException {
Map<String,TinfiComponentInterceptor> interceptors = getFcInterceptors();
if( ! interceptors.containsKey(name) ) {
throw new NoSuchInterfaceException(name);
}
TinfiComponentInterceptor tci = interceptors.get(name);
tci.addFcIntentHandler(handler);
}
/**
* Return the list of all intent handlers associated with the interface
* (service or reference) whose name is specified.
*
* @param handler the intent handler to add
* @throws NoSuchInterfaceException if the interface does not exist
* @since 0.4.4
*/
public List<IntentHandler> listFcIntentHandler( String name )
throws NoSuchInterfaceException {
Map<String,TinfiComponentInterceptor> interceptors = getFcInterceptors();
if( ! interceptors.containsKey(name) ) {
throw new NoSuchInterfaceException(name);
}
TinfiComponentInterceptor tci = interceptors.get(name);
List<IntentHandler> handlers = tci.listFcIntentHandler(); // Already a copy
return handlers;
}
/**
* Remove the specified intent handler on all interfaces (service and
* reference) of the current component.
*
* @param handler the intent handler to remove
* @since 0.4.4
*/
public void removeFcIntentHandler( IntentHandler handler ) {
Map<String,TinfiComponentInterceptor> interceptors = getFcInterceptors();
Collection<TinfiComponentInterceptor> tcis = interceptors.values();
for (TinfiComponentInterceptor tci : tcis) {
tci.removeFcIntentHandler(handler);
}
}
/**
* Remove the specified intent handler on the interface (service or
* reference) whose name is specified.
*
* @param handler the intent handler to remove
* @param name the interface name
* @throws NoSuchInterfaceException if the interface does not exist
* @since 0.4.4
*/
public void removeFcIntentHandler( IntentHandler handler, String name )
throws NoSuchInterfaceException {
Map<String,TinfiComponentInterceptor> interceptors = getFcInterceptors();
if( ! interceptors.containsKey(name) ) {
throw new NoSuchInterfaceException(name);
}
TinfiComponentInterceptor tci = interceptors.get(name);
tci.removeFcIntentHandler(handler);
}
// -------------------------------------------------------------------------
// Implementation specific
// -------------------------------------------------------------------------
/**
* Return the list of interceptors associated with the business interfaces
* of the current component.
* Return the interceptors associated with the business interfaces of the
* current component.
*/
private List<TinfiComponentInterceptor> getFcInterceptors() {
private Map<String,TinfiComponentInterceptor> getFcInterceptors() {
if( interceptors != null ) {
return interceptors;
}
interceptors = new ArrayList<TinfiComponentInterceptor>();
interceptors = new HashMap<String,TinfiComponentInterceptor>();
Object[] itfs = _this_weaveableOptC.getFcInterfaces();
for (Object o : itfs) {
Interface itf = (Interface) o;
......@@ -93,12 +174,6 @@ implements SCABasicIntentController {
continue;
}
// Skip client interfaces
InterfaceType it = (InterfaceType) itf.getFcItfType();
if( it.isFcClientItf() ) {
continue;
}
Object i = ((ComponentInterface)itf).getFcItfImpl();
if( ! (i instanceof TinfiComponentInterceptor) ) {
/*
......@@ -114,12 +189,12 @@ implements SCABasicIntentController {
}
TinfiComponentInterceptor tci = (TinfiComponentInterceptor) i;
interceptors.add(tci);
interceptors.put(name,tci);
}
return interceptors;
}
private List<TinfiComponentInterceptor> interceptors;
private Map<String,TinfiComponentInterceptor> interceptors;
// -------------------------------------------------------------------------
......
......@@ -76,6 +76,15 @@ public abstract class TinfiComponentInterceptor implements Interceptor {
@Override
public abstract Object clone();
/**
* Initialize a clone instance. This method is called by generated
* subclasses.
*/
protected void initFcClone( TinfiComponentInterceptor clone ) {
clone.intentHandlersMap = intentHandlersMap;
clone.owner = owner;
}
// -----------------------------------------------------------------------
......@@ -123,6 +132,42 @@ public abstract class TinfiComponentInterceptor implements Interceptor {
handlers.add(handler);
}
/**
* Return the list of all intent handlers managed by this interceptor.
*
* @since 0.4.4
*/
public List<IntentHandler> listFcIntentHandler() {
List<IntentHandler> all = new ArrayList<IntentHandler>();
for (Map.Entry<Method,List<IntentHandler>> entry : intentHandlersMap.entrySet()) {
List<IntentHandler> handlers = entry.getValue();
all.addAll(handlers);
}
return all;
}
/**
* Return the list of all intent handlers managed by this interceptor for
* the specified method.
*
* @throws NoSuchMethodException
* if the specified method is not a component method managed by this
* interceptor
* @since 0.4.4
*/
public List<IntentHandler> listFcIntentHandler( Method method )
throws NoSuchMethodException {
if( ! intentHandlersMap.containsKey(method) ) {
throw new NoSuchMethodException();
}
List<IntentHandler> handlers = intentHandlersMap.get(method);
List<IntentHandler> all = new ArrayList<IntentHandler>();
all.addAll(handlers);
return all;
}
/**
* Remove the specified intent handler for all component methods managed by
* this interceptor.
......@@ -152,6 +197,7 @@ public abstract class TinfiComponentInterceptor implements Interceptor {
handlers.remove(handler);
}
// -----------------------------------------------------------------------
// Implementation specific
// -----------------------------------------------------------------------
......
......@@ -73,7 +73,8 @@ public class AnnotatedElementsManager {
* if the reference is declared more than once
*/
public void addAllReferences()
throws AnnotatedElementNotFoundException, DuplicateAnnotatedElementException {
throws
AnnotatedElementNotFoundException, DuplicateAnnotatedElementException {
AccessibleObject[] aos = cmd.getAllAnnotatedMethodsAndFields(annot);
......@@ -268,8 +269,7 @@ public class AnnotatedElementsManager {
*/
private void addReference( AccessibleObject[] aos0, String name )
throws
AnnotatedElementNotFoundException,
DuplicateAnnotatedElementException {
AnnotatedElementNotFoundException, DuplicateAnnotatedElementException {
AccessibleObject[] aos = getAllAnnotatedFieldsAndMethodsFor(aos0,name);
......
......@@ -18,7 +18,8 @@
*
* Contact: frascati@ow2.org
*
* Authors: Lionel Seinturier, Philippe Merle
* Author: Lionel Seinturier
* Contributor: Philippe Merle
*/
package org.ow2.frascati.tinfi.control.content.scope;
......@@ -42,6 +43,7 @@ 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.julia.ComponentInterface;
import org.objectweb.fractal.julia.Interceptor;
import org.objectweb.fractal.julia.factory.ChainedInstantiationException;
import org.osoa.sca.CallableReference;
import org.osoa.sca.ComponentContext;
......@@ -325,7 +327,12 @@ public class AbstractScopeManager {
* may have been injected via an @Constructor annotation.
* See {@link #createFcInstance()}.
*/
// TODO we should be checking that all properties have been injected either as a constructor, or as a annonated element or as a POJO
if( ! initnames.contains(name) ) {
String msg =
"Reference or property "+name+
" can not be injected on "+ccmd.fcContentClass;
throw new InstantiationException(msg);
}
}
}
}
......@@ -398,7 +405,8 @@ public class AbstractScopeManager {
ServiceReference<?> sref = (ServiceReference<?>) sr;
ComponentInterface ci = (ComponentInterface) sref.getService();
Object impl = ci.getFcItfImpl();
Interceptor intercept = (Interceptor) ci.getFcItfImpl(); // Skip the interceptor
Object impl = intercept.getFcItfDelegate();
if( impl == null ) {
Reference ref = (Reference) ccmd.refs.getAnnotation(name);
if (ref.required()) {
......@@ -411,8 +419,8 @@ public class AbstractScopeManager {
}
/**
* Return the ServiceRefence (or the list of ServiceReference) associated to
* the specified InterfaceType.
* Return the {@link ServiceRefence} (or the list of {@link
* ServiceReference}s) associated to the specified {@link InterfaceType}.
*/
private Object getServiceReference( InterfaceType it )
throws NoSuchInterfaceException {
......@@ -468,10 +476,11 @@ public class AbstractScopeManager {
/**
* ThreadLocal stack holding request contexts.
*
* An element is pushed on the stack by the interface (see classes generated
* by InterfaceSourceFileGenerator) each time an invocation is received.
* The element is poped when the invocation has been processed and just
* before returning the result.
* by {@link InterfaceSourceCodeGeneratorFactory}) each time an invocation
* is received. The element is poped when the invocation has been processed
* and just before returning the result.
*/
protected ThreadLocal<Stack<RequestContext>> tl =
new ThreadLocal<Stack<RequestContext>>();
......
/***
* 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.control.intent;
import org.ow2.frascati.tinfi.TinfiException;
/**
* Exception thrown when a component interface can not be found.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 0.4.4
*/
public class NoSuchInterfaceException extends TinfiException {
private static final long serialVersionUID = -8810897401998352174L;
public NoSuchInterfaceException( String name ) {
super(name);
}
}
......@@ -23,6 +23,8 @@
package org.ow2.frascati.tinfi.control.intent;
import java.util.List;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.julia.type.BasicInterfaceType;
......@@ -54,4 +56,48 @@ public interface SCABasicIntentController {
*/
public void addFcIntentHandler( IntentHandler handler )
throws IllegalLifeCycleException;
/**
* Add the specified intent handler on the service or reference interface
* whose name is specified.
*
* @param handler the intent handler to add
* @param name the interface name
* @throws NoSuchInterfaceException if the interface does not exist
* @since 0.4.4
*/
public void addFcIntentHandler( IntentHandler handler, String name )
throws NoSuchInterfaceException;
/**
* Return the list of all intent handlers associated with the interface
* (service or reference) whose name is specified.
*
* @param handler the intent handler to add
* @throws NoSuchInterfaceException if the interface does not exist
* @since 0.4.4
*/
public List<IntentHandler> listFcIntentHandler( String name )
throws NoSuchInterfaceException;
/**
* Remove the specified intent handler on all interfaces (service and
* reference) of the current component.
*
* @param handler the intent handler to remove
* @since 0.4.4
*/
public void removeFcIntentHandler( IntentHandler handler );
/**
* Remove the specified intent handler on the interface (service or
* reference) whose name is specified.
*
* @param handler the intent handler to remove
* @param name the interface name
* @throws NoSuchInterfaceException if the interface does not exist
* @since 0.4.4
*/
public void removeFcIntentHandler( IntentHandler handler, String name )
throws NoSuchInterfaceException;
}
......@@ -23,6 +23,9 @@
package org.ow2.frascati.tinfi;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.ow2.frascati.tinfi.ReferenceMultipleImpl;
import org.ow2.frascati.tinfi.TinfiDomain;
import org.ow2.frascati.tinfi.TinfiRuntimeException;
......@@ -36,7 +39,11 @@ import junit.framework.TestCase;
*/
public class ReferenceTestCase extends TestCase {
public void testMandatory() throws Exception {
public void testMandatory()
throws
ClassNotFoundException, InstantiationException, IllegalAccessException,
IllegalLifeCycleException, NoSuchInterfaceException,
java.lang.InstantiationException {
String adl = getClass().getPackage().getName()+".ReferenceNotSet";
String service = "r";
......@@ -49,7 +56,11 @@ public class ReferenceTestCase extends TestCase {
catch(TinfiRuntimeException re) {}
}
public void testMultiple() throws Exception {
public void testMultiple()
throws
ClassNotFoundException, InstantiationException, IllegalAccessException,
IllegalLifeCycleException, NoSuchInterfaceException,
java.lang.InstantiationException {
String adl = getClass().getPackage().getName()+".ReferenceMultiple";
String service = "r";
......
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