Mail Archive Home | fractal-commits List | March 2006 Index
| <-- Date Index --> | <-- Thread Index --> |
Date: Wednesday, March 29, 2006 @ 20:54:22
Author: seintur
Path: .../aokell/src/org/objectweb/fractal/aokell/lib/control/component
Modified: ComponentImpl.java ComponentItf.java
New (simpler, more modular) implementation of the binding, content and
component controllers.
--------------------+
ComponentImpl.java | 436 ++++++---------------------------------------------
ComponentItf.java | 64 +++----
2 files changed, 83 insertions(+), 417 deletions(-)
Index:
aokell/src/org/objectweb/fractal/aokell/lib/control/component/ComponentImpl.java
diff -u
aokell/src/org/objectweb/fractal/aokell/lib/control/component/ComponentImpl.java:1.7
aokell/src/org/objectweb/fractal/aokell/lib/control/component/ComponentImpl.java:1.8
---
aokell/src/org/objectweb/fractal/aokell/lib/control/component/ComponentImpl.java:1.7
Tue Mar 28 00:42:08 2006
+++
aokell/src/org/objectweb/fractal/aokell/lib/control/component/ComponentImpl.java
Wed Mar 29 20:54:22 2006
@@ -23,26 +23,20 @@
package org.objectweb.fractal.aokell.lib.control.component;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
-import org.objectweb.fractal.aokell.lib.CloneableItf;
import org.objectweb.fractal.aokell.lib.InterfaceImpl;
import org.objectweb.fractal.aokell.lib.control.CloneCtrlException;
import org.objectweb.fractal.aokell.lib.control.Controller;
-import org.objectweb.fractal.aokell.lib.control.binding.BindingControllerItf;
-import org.objectweb.fractal.aokell.lib.interf.Delegator;
-import org.objectweb.fractal.aokell.lib.util.FractalHelper;
+import org.objectweb.fractal.aokell.lib.interf.InterfaceManager;
+import org.objectweb.fractal.aokell.lib.interf.PrimitiveExtItfManager;
+import org.objectweb.fractal.aokell.lib.util.MembraneHelper;
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.type.ComponentType;
import org.objectweb.fractal.api.type.InterfaceType;
@@ -61,18 +55,14 @@
* Julia. Extending InterfaceImpl is better.
*/
extends InterfaceImpl
-
implements ComponentItf, ComponentDescItf, Controller {
- private Type type;
- private Object controllerDesc;
- private Object contentDesc;
-
public ComponentImpl() {
/*
* Can not call super as the 1st argument should be this (and this is
* forbidden when calling super). See below: Interface is overriden.
*/
+ im = new PrimitiveExtItfManager();
}
@@ -80,69 +70,22 @@
// Implementation of the Component interface
// ------------------------------------------------------------------
- public Type getFcType() {
- return type;
- }
-
+ /** The interfaces managed by this component. */
+ protected InterfaceManager im;
+
/**
- * @return the instance implementing the given interface name for this
- * component
+ * Return the instance implementing the {@link Interface} corresponding
to
+ * the given name. Whereas this is the case most of the time, it is not
+ * mandatory for the returned value to be of type {@link Interface}.
+ *
*/
public Object getFcInterface(String interfaceName)
throws NoSuchInterfaceException {
- // Lookup the name in the singleton Interface list
- List singletonItfs = getFcSingletonInterfaces();
- for (Iterator iter = singletonItfs.iterator(); iter.hasNext();) {
- Interface itf = (Interface) iter.next();
- if( itf.getFcItfName().equals(interfaceName) ) {
- return itf;
- }
- }
-
- // Lookup the name in the collection Interface list
- List collectionItfs = getFcCollectionInterfaces();
- for (Iterator iter = collectionItfs.iterator(); iter.hasNext();) {
- Interface itf = (Interface) iter.next();
- if( itf.getFcItfName().equals(interfaceName) ) {
- return itf;
- }
- }
-
- /*
- * The interface has not been found in the collection interface list.
- * A possible cause if that a interface name such as foo004 is looked
- * up. In such a case the corresponding Interface instance must be
- * generated on the fly, and registered into the list of collection
- * interfaces.
- */
- for (Iterator iter = collectionItfs.iterator(); iter.hasNext();) {
- Interface itf = (Interface) iter.next();
- if( interfaceName.startsWith(itf.getFcItfName()) ) {
-
- /*
- * Check whether the requested interface has been requested
- * before.
- */
- List dynCollectionItfs = getFcDynCollectionInterfaces();
- for (Iterator iterator = dynCollectionItfs.iterator();
iterator
- .hasNext();) {
- Interface element = (Interface) iterator.next();
- if( interfaceName.equals(element.getFcItfName()) ) {
- return element;
- }
- }
-
- /*
- * Generate a new interface.
- */
- InterfaceImpl clone = (InterfaceImpl)
((CloneableItf)itf).clone();
- clone.setFcItfName(interfaceName);
- dynCollectionItfs.add(clone);
-
- return clone;
- }
+ try {
+ return im.getFcInterface(interfaceName);
}
+ catch( NoSuchInterfaceException nsie ) {}
/*
* Components with a content (all primitives have a content,
composites
@@ -151,7 +94,7 @@
* but is Julia-specific.
*/
if( interfaceName.equals("/content") ) {
- return getContentPart();
+ return contentPart;
}
if( interfaceName.equals("/desc") ) {
@@ -162,91 +105,22 @@
* This was our last chance. If the interface has still not been
found,
* throw NoSuchInterfaceException.
*/
-
throw new NoSuchInterfaceException(interfaceName);
}
/**
- * The array of Interface instances provided by this component and
- * returned by getFcInterfaces().
- */
- private Object[] itfs;
-
- /**
- * Return the array of Interface instances implemented by this component.
+ * Return the array of {@link Interface} instances implemented by this
+ * component. Whereas this is the case most of the time, it is not
+ * mandatory for the returned values to be of type {@link Interface}.
*/
public Object[] getFcInterfaces() {
-
- if( itfs == null ) {
-
- // Get singleton interfaces
- List singletonItfs = getFcSingletonInterfaces();
-
- // Remove interfaces with a name which begins with /
- List sItfs = new ArrayList(singletonItfs);
- for (Iterator iter = singletonItfs.iterator(); iter.hasNext();) {
- Interface itf = (Interface) iter.next();
- if( itf.getFcItfName().startsWith("/") ) {
- sItfs.remove(itf);
- }
- }
-
- itfs = (Interface[]) sItfs.toArray( new Interface[sItfs.size()]
);
- }
-
- // Add client collection interfaces currently bound
- List colItfs = new ArrayList();
-
- BindingControllerItf bc =
FractalHelper.getBindingControllerItf(this);
-
- List collectionInterfaces = getFcCollectionInterfaces();
- List boundedCollectionInterfaceNames = new ArrayList();
- bc.addFcCollectionInterfaceNames(boundedCollectionInterfaceNames);
-
- for (Iterator iter = boundedCollectionInterfaceNames.iterator(); iter
- .hasNext();) {
- String bciName = (String) iter.next();
- for (Iterator iterator = collectionInterfaces.iterator();
iterator
- .hasNext();) {
- Interface itf = (Interface) iterator.next();
- if( bciName.startsWith(itf.getFcItfName()) ) {
- /*
- * The collection Interface instance corresponding to the
- * bound name has been found.
- */
- InterfaceImpl clone =
- (InterfaceImpl) ((CloneableItf)itf).clone();
- clone.setFcItfName(bciName);
- colItfs.add(clone);
- }
- }
- }
-
- // Add server collection interfaces currently bound
- for (Iterator iter = collectionInterfaces.iterator(); iter
- .hasNext();) {
- Interface itf = (Interface) iter.next();
- InterfaceType it = (InterfaceType) itf.getFcItfType();
- if( ! it.isFcClientItf() ) {
- String itfName = itf.getFcItfName();
- Object[] rb = bc.reverseLookupFc(itfName);
- if( rb != null && rb.length != 0 ) {
- // The server collection interface is currently bound
- colItfs.add(itf);
- }
- }
- }
-
-
- if( colItfs.size() == 0 ) {
- // No collection interface bound
- return itfs;
- }
-
- colItfs.addAll( Arrays.asList(itfs) );
- return colItfs.toArray();
+ return im.getFcInterfaces();
}
+ public Type getFcType() {
+ return type;
+ }
+
// ------------------------------------------------------------------
// Implementation of the ComponentDescItf interface
@@ -265,6 +139,11 @@
// Implementation of the ComponentItf interface
// ------------------------------------------------------------------
+ private Type type;
+ private Object controllerDesc;
+ private Object contentDesc;
+ private Object contentPart;
+
public void initFc(
Type type, Object controllerDesc, Object contentDesc,
Object contentPart ) {
@@ -273,7 +152,10 @@
this.controllerDesc = controllerDesc;
this.contentDesc = contentDesc;
this.contentPart = contentPart;
+
+ im.initFc(type,this,contentPart);
}
+
// <InterfaceType,Object>
// Not all controllers implements Controller (hence Object)
@@ -292,240 +174,37 @@
*/
public void addFcController( InterfaceType it, Object ctrl ) {
ctrls.put(it,ctrl);
+ im.registerFcControlInterface(it,ctrl);
}
-
- /**
- * Return the list of client interfaces implemented by this component.
- */
- public List getFcSingletonClientInterfaces() {
-
- List clientItfs = new ArrayList();
-
- // Add client singleton interfaces
- List singletonItfs = getFcSingletonInterfaces();
- for (Iterator iter = singletonItfs.iterator(); iter.hasNext();) {
- Interface itf = (Interface) iter.next();
- InterfaceType it = (InterfaceType) itf.getFcItfType();
- if( it.isFcClientItf() )
- clientItfs.add(itf);
- }
-
-// // Add client collection interfaces
-// List collectionItfs = getFcCollectionInterfaces();
-// for (Iterator iter = collectionItfs.iterator(); iter.hasNext();) {
-// Interface itf = (Interface) iter.next();
-// InterfaceType it = (InterfaceType) itf.getFcItfType();
-// if( it.isFcClientItf() )
-// clientItfs.add(itf);
-// }
-
- return clientItfs;
- }
-
+
/**
- * Return the instance implementing the given client interface name for
this
- * component. This method is a clone for getFcInterface(String).
+ * Register a new collection {@link Interface} instance.
+ * The given name must start with an existing collection interface name
+ * decalred in the component type.
+ *
+ * @param interfaceName the interface name (e.g. foo004)
+ * @throws NoSuchInterfaceException
+ * if there is no such collection interface
*/
- public Object getFcClientInterface(String interfaceName)
+ public Interface registerFcInterface( String interfaceName )
throws NoSuchInterfaceException {
-
- // Lookup the name in the singleton Interface list
- List singletonItfs = getFcSingletonInterfaces();
- for (Iterator iter = singletonItfs.iterator(); iter.hasNext();) {
- Interface itf = (Interface) iter.next();
- InterfaceType it = (InterfaceType) itf.getFcItfType();
- if( it.isFcClientItf() &&
- itf.getFcItfName().equals(interfaceName) ) {
- return itf;
- }
- }
-
- /*
- * Lookup the name in the collection Interface list.
- * When such an interface is looked up its name is something like
foo004
- * which does not exists as an interface name (but foo does).
- * See TestBindingController.
- */
- List collectionItfs = getFcCollectionInterfaces();
- for (Iterator iter = collectionItfs.iterator(); iter.hasNext();) {
- Interface itf = (Interface) iter.next();
- InterfaceType it = (InterfaceType) itf.getFcItfType();
- if( it.isFcClientItf() &&
- interfaceName.startsWith(itf.getFcItfName()) ) {
- return itf;
- }
- }
-
- throw new NoSuchInterfaceException(interfaceName);
- }
-
- /** The list of Interface instances for singleton interfaces. */
- private List singletonItfs;
-
- /**
- * @return the list of singleton Interface instances implemented by this
- * component
- */
- public List getFcSingletonInterfaces() {
-
- if( singletonItfs != null )
- return singletonItfs;
-
- List sbi = getFcSingletonBusinessInterfaces();
- List sci = getFcSingletonControlInterfaces();
-
- singletonItfs = new ArrayList( sbi.size() + sci.size() );
- singletonItfs.addAll(sbi);
- singletonItfs.addAll(sci);
-
- return singletonItfs;
- }
-
- /** The list of Interface instances for singleton business interfaces. */
- private List singletonBusinessItfs;
-
- /**
- * @return the list of singleton business Interface instances
implemented
- * by this component
- */
- public List getFcSingletonBusinessInterfaces() {
-
- if( singletonBusinessItfs != null )
- return singletonBusinessItfs;
-
- singletonBusinessItfs = new ArrayList();
-
- ComponentType ct = (ComponentType) getFcType();
- InterfaceType[] its = ct.getFcInterfaceTypes();
-
- // User-defined singleton interfaces
- for (int i = 0; i < its.length; i++) {
- if( ! its[i].isFcCollectionItf() ) {
- Interface itf = getFcInterface(its[i],this);
- singletonBusinessItfs.add(itf);
- }
- }
-
- return singletonBusinessItfs;
- }
-
- /** The list of Interface instances for singleton control interfaces. */
- private List singletonControlItfs;
-
- /**
- * @return the list of singleton control Interface instances implemented
- * by this component
- */
- public List getFcSingletonControlInterfaces() {
-
- if( singletonControlItfs != null )
- return singletonControlItfs;
-
- singletonControlItfs = new ArrayList();
-
- for (Iterator iter = ctrls.entrySet().iterator(); iter.hasNext(); ) {
- Map.Entry entry = (Map.Entry) iter.next();
- InterfaceType it = (InterfaceType) entry.getKey();
- Object ctrl = entry.getValue();
-
- Interface itf = getProxyInterface(it,this,ctrl,false);
- singletonControlItfs.add(itf);
- }
-
- return singletonControlItfs;
- }
-
- /** The list of Interface instances for collection interfaces. */
- private List collectionItfs;
-
- /**
- * @return the list of collection Interface instances implemented by
this
- * component
- */
- public List getFcCollectionInterfaces() {
-
- if( collectionItfs != null )
- return collectionItfs;
-
- collectionItfs = new ArrayList();
-
- ComponentType ct = (ComponentType) getFcType();
- InterfaceType[] its = ct.getFcInterfaceTypes();
-
- // User-defined collection interfaces
- for (int i = 0; i < its.length; i++) {
- if( its[i].isFcCollectionItf() ) {
- Interface itf = getFcInterface(its[i],this);
- collectionItfs.add(itf);
- }
- }
-
- return collectionItfs;
- }
-
- /**
- * The list of dynamically defined collection Interface instances (e.g.
foo004).
- */
- private List dynCollectionItfs;
-
- /**
- * @return the list of dynamically defined collection Interface
instances
- * (e.g. foo004).
- */
- private List getFcDynCollectionInterfaces() {
- if( dynCollectionItfs == null ) {
- dynCollectionItfs = new ArrayList();
- }
-
- return dynCollectionItfs;
- }
-
- /**
- * Get the Interface instance associated to the given interface type for
the
- * given component.
- */
- protected Interface getFcInterface( InterfaceType it, Component itfOwner
) {
- return getProxyInterface(
- it,itfOwner,getContentPart(),
- it.isFcClientItf() // boundable when client
- ); // implemented when server
+ return im.registerFcInterface(interfaceName);
}
-
+
/**
- * Return an Interface instance for the given interface type.
- * The returned instance implements both the Interface interface and the
- * Java interface specified in the given interface type. The instance is
a
- * proxy generated with ASM when the fcinterface feature is set to asm.
+ * Unregister a collection {@link Interface} instance.
+ * The given name must start with an existing collection interface name
+ * decalred in the component type.
*
- * @param it the interface type
- * @param itfOwner the component owning this interface
- * @param content the instance implementing the content
- * @param boundable
- * true if the interface can be bound (e.g. client for a primitive)
- * false otherwise (e.g. server for a primitive)
- * @return the interface instance
+ * @param interfaceName the interface name (e.g. foo004)
+ * @throws NoSuchInterfaceException
+ * if there is no such collection interface
*/
- public static Interface getProxyInterface(
- InterfaceType it, Component itfOwner, Object content,
- boolean boundable ) {
-
- Object proxy = Delegator.generate(
- it, // interface type
- itfOwner, // component owning the interface
- content, // the instance holding the content
- false, // external interface
- boundable // boundable or implemented
- );
-
- return (Interface) proxy;
+ public void unregisterFcInterface( String interfaceName )
+ throws NoSuchInterfaceException {
+ im.unregisterFcInterface(interfaceName);
}
- private Object contentPart;
-
- protected Object getContentPart() {
- return contentPart;
- }
-
// --------------------------------------------------------------
// Interface interface
@@ -569,15 +248,8 @@
/**
* Initialize the controller.
*/
- public void initFcCtrl() {
-
- // (re)initialize cached values
- collectionItfs = null;
- dynCollectionItfs = null;
- itfs = null;
- singletonBusinessItfs = null;
- singletonControlItfs = null;
- singletonItfs = null;
+ public void initFcCtrl() {
+ // Indeed nothing
}
/**
Index:
aokell/src/org/objectweb/fractal/aokell/lib/control/component/ComponentItf.java
diff -u
aokell/src/org/objectweb/fractal/aokell/lib/control/component/ComponentItf.java:1.3
aokell/src/org/objectweb/fractal/aokell/lib/control/component/ComponentItf.java:1.4
---
aokell/src/org/objectweb/fractal/aokell/lib/control/component/ComponentItf.java:1.3
Tue Mar 28 00:42:08 2006
+++
aokell/src/org/objectweb/fractal/aokell/lib/control/component/ComponentItf.java
Wed Mar 29 20:54:22 2006
@@ -23,10 +23,9 @@
package org.objectweb.fractal.aokell.lib.control.component;
-import java.util.List;
-
import org.objectweb.fractal.aokell.lib.type.InterfaceTypeImpl;
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.type.InterfaceType;
@@ -54,44 +53,39 @@
/**
* Declare a new controller implemented by the component.
+ *
+ * @param it the control interface type
+ * @param ctrl the controller.
+ * The controller (i.e. the instance of
+ * {@link org.objectweb.fractal.aokell.lib.control.Controller})
+ * with object-oriented membranes.
+ * The proxy interface with componentized membranes.
*/
public void addFcController( InterfaceType it, Object ctrl );
/**
- * Return the list of client interfaces implemented by this component.
- */
- public List getFcSingletonClientInterfaces();
-
- /**
- * Return the instance implementing the given client interface name for
this
- * component. This method is a clone for getFcInterface(String).
- */
- public Object getFcClientInterface(String interfaceName)
- throws NoSuchInterfaceException;
-
- /**
- * @return the list of singleton Interface instances implemented by this
- * component
- */
- public List getFcSingletonInterfaces();
-
- /**
- * @return the list of singleton business Interface instances
implemented
- * by this component
- */
- public List getFcSingletonBusinessInterfaces();
-
- /**
- * @return the list of singleton control Interface instances implemented
- * by this component
- */
- public List getFcSingletonControlInterfaces();
-
- /**
- * @return the list of collection Interface instances implemented by
this
- * component
+ * Register a new collection {@link Interface} instance.
+ * The given name must start with an existing collection interface name
+ * declared in the component type.
+ *
+ * @param interfaceName the interface name (e.g. foo004)
+ * @throws NoSuchInterfaceException
+ * if there is no such collection interface
+ */
+ public Interface registerFcInterface( String interfaceName )
+ throws NoSuchInterfaceException;
+
+ /**
+ * Unregister a collection {@link Interface} instance.
+ * The given name must start with an existing collection interface name
+ * declared in the component type.
+ *
+ * @param interfaceName the interface name (e.g. foo004)
+ * @throws NoSuchInterfaceException
+ * if there is no such collection interface
*/
- public List getFcCollectionInterfaces();
+ public void unregisterFcInterface( String interfaceName )
+ throws NoSuchInterfaceException;
public void initFc(
Type type, Object controllerDesc, Object contentDesc,
| <-- Date Index --> | <-- Thread Index --> |
Powered by MHonArc.
Copyright © 2006-2007, OW2 Consortium | contact | webmaster.