org.escot
Class DefaultBroker

java.lang.Object
  |
  +--org.escot.Broker
        |
        +--org.escot.DefaultBroker

public class DefaultBroker
extends Broker

An implementation of the Broker interface that manages Ports that describe the interoperability characteristics of the beans it brokers.


Field Summary
protected  com.sun.java.util.collections.Map mBeanPortTable
           
protected  com.sun.java.util.collections.Vector mBeans
           
protected  org.escot.PortFactory mBuilder
           
protected  com.sun.java.util.collections.Vector mEventBindings
           
protected  com.sun.java.util.collections.Map mIdBeanTable
           
protected  WireFactory mWireFactory
           
protected  com.sun.java.util.collections.Vector mWires
          A list of wires.
 
Fields inherited from class org.escot.Broker
mBeanListeners, mBeanWiringListeners, mFeatureListeners, mWiringListeners
 
Constructor Summary
DefaultBroker()
           
 
Method Summary
 void addBean(Object bean)
          Adds bean to the set of beans brokered by this Broker instance.
 void addBean(Object bean, String id)
          Adds bean to the set of beans brokered by this Broker instance.
 boolean addEventBinding(Object source, Object target, String eventSetName)
          Binds target as a listener to source for the specified event.
 boolean canWire(Object publisher, String publisherPropName, Object subscriber, String subscriberPropName)
          Returns whether the features may be connected.
protected  String createID(Object o)
           
protected  String ensureUniqueID(Object o, String id)
           
 EventBinding findEventBinding(Object source, Object target, String eventSetName)
           
 Wire findWire(Object publisher, String publisherPropName, Object subscriber, String subscriberPropName)
          Returns the wire between a published property and subscribing property, or null if it does not exist.
 Object getBean(String id)
          Returns the bean corresponding to the specified id.
 com.sun.java.util.collections.Collection getBeans()
          Returns a Collection of the beans brokered by this Broker instance.
 com.sun.java.util.collections.Collection getEventBindings()
           
 com.sun.java.util.collections.Collection getExplicitFeatures(Object bean)
          Returns a Collection of dynamic EscotFeatures.
 EscotFeature getFeatureByName(Object bean, String name)
          Returns a EscotFeature corresponding to the specified name.
 FeatureDescriptor getFeatureDescriptor(Object bean, String name)
          Returns the FeatureDescriptor corresponding to the named feature for the specified bean.
 com.sun.java.util.collections.Collection getFeatures(Object bean)
          Returns a Collection of EscotFeatures.
 String getID(Object bean)
          Returns the id corresponding to the specified bean.
protected  org.escot.Port getPort(Object bean)
          Returns the Port instance created for the bean.
protected  org.escot.Port getPort(String id)
           
 com.sun.java.util.collections.Vector getWires()
          Returns a Collection of Wires.
 com.sun.java.util.collections.Collection getWires(Object bean, String featureName)
          Returns a Collection of Wires involving the specified bean.
 boolean hasEventBinding(Object source, Object target, String eventSetName)
          Returns whether target is bound as a listener to source for the specified event.
protected  void notifyFeatureAdded(FeatureEvent evt)
           
protected  void notifyFeatureRemoved(FeatureEvent evt)
           
 void removeAllBeans()
          Removes all beans.
 void removeBean(Object bean)
          Removes bean from the set of beans brokered by this Broker instance.
 void removeEventBinding(Object source, Object target, String eventSetName)
          Removes binding of target as a listener to source for the specified event.
 void setID(Object bean, String id)
           
protected  void setPortFactory(org.escot.PortFactory builder)
          Sets the PortBuilder, which builds a Port for each bean.
protected  void setWireFactory(WireFactory wf)
          Sets the PortBuilder, which builds a Port for each bean.
 void setWires(com.sun.java.util.collections.Vector v)
          For restoring the Broker state on load.
protected  void unwire(Object bean, String featureName)
           
 void unwire(Object publisher, String publisherPropName, Object subscriber, String subscriberPropName)
          Disconnects a published property from a subscribing property.
 void unwire(Wire wire)
          Disconnects the properties specified in the Wire.
 void unwireAll()
          Disconnects everything.
 void wire(Object publisher, String publisherPropName, Object subscriber, String subscriberPropName)
          Connects a published property to a subscribing property.
protected  void wire(Object publisher, String publisherPropName, Object subscriber, String subscriberPropName, boolean addNonBrokeredBeans)
           
 
Methods inherited from class org.escot.Broker
addBeanWiringListener, addBrokerBeanListener, addBrokerFeatureListener, addBrokerWiringListener, isWired, notifyBeanAdded, notifyBeanRemoved, notifyWireAdded, notifyWireRemoved, removeBean, removeBeanWiringListener, removeBrokerBeanListener, removeBrokerFeatureListener, removeBrokerWiringListener, unwireAll, unwireAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mBeans

protected com.sun.java.util.collections.Vector mBeans

mWires

protected com.sun.java.util.collections.Vector mWires
A list of wires.

mEventBindings

protected com.sun.java.util.collections.Vector mEventBindings

mIdBeanTable

protected com.sun.java.util.collections.Map mIdBeanTable

mBuilder

protected org.escot.PortFactory mBuilder

mWireFactory

protected WireFactory mWireFactory

mBeanPortTable

protected com.sun.java.util.collections.Map mBeanPortTable
Constructor Detail

DefaultBroker

public DefaultBroker()
Method Detail

setPortFactory

protected void setPortFactory(org.escot.PortFactory builder)
Sets the PortBuilder, which builds a Port for each bean.

setWireFactory

protected void setWireFactory(WireFactory wf)
Sets the PortBuilder, which builds a Port for each bean.

getPort

protected org.escot.Port getPort(Object bean)
Returns the Port instance created for the bean.

getPort

protected org.escot.Port getPort(String id)

getBean

public Object getBean(String id)
Description copied from class: Broker
Returns the bean corresponding to the specified id.
Overrides:
getBean in class Broker
Following copied from class: org.escot.Broker
Returns:
the bean corresponding to the specified id

getID

public String getID(Object bean)
Description copied from class: Broker
Returns the id corresponding to the specified bean.
Overrides:
getID in class Broker
Following copied from class: org.escot.Broker
Returns:
the id corresponding to the specified bean

setID

public void setID(Object bean,
                  String id)

addBean

public void addBean(Object bean)
Description copied from class: Broker
Adds bean to the set of beans brokered by this Broker instance.
Overrides:
addBean in class Broker
Following copied from class: org.escot.Broker
Parameters:
bean - the bean to add.

addBean

public void addBean(Object bean,
                    String id)
Description copied from class: Broker
Adds bean to the set of beans brokered by this Broker instance.
Overrides:
addBean in class Broker
Following copied from class: org.escot.Broker
Parameters:
bean - the bean to add
id - an id to associate with the bean

removeBean

public void removeBean(Object bean)
Description copied from class: Broker
Removes bean from the set of beans brokered by this Broker instance.
Overrides:
removeBean in class Broker
Following copied from class: org.escot.Broker
Parameters:
bean - the bean to remove

removeAllBeans

public void removeAllBeans()
Description copied from class: Broker
Removes all beans.
Overrides:
removeAllBeans in class Broker

getBeans

public com.sun.java.util.collections.Collection getBeans()
Description copied from class: Broker
Returns a Collection of the beans brokered by this Broker instance.
Overrides:
getBeans in class Broker

notifyFeatureAdded

protected void notifyFeatureAdded(FeatureEvent evt)

notifyFeatureRemoved

protected void notifyFeatureRemoved(FeatureEvent evt)

findWire

public Wire findWire(Object publisher,
                     String publisherPropName,
                     Object subscriber,
                     String subscriberPropName)
Description copied from class: Broker
Returns the wire between a published property and subscribing property, or null if it does not exist.
Overrides:
findWire in class Broker
Following copied from class: org.escot.Broker
Returns:
a Wire

canWire

public boolean canWire(Object publisher,
                       String publisherPropName,
                       Object subscriber,
                       String subscriberPropName)
Description copied from class: Broker
Returns whether the features may be connected.
Overrides:
canWire in class Broker
Following copied from class: org.escot.Broker
Parameters:
publisher - a bean which publishes a property
publisherPropName - name of a property of the publisher
subscriber - a bean which subscribes to a property
subscriberPropName - name of a property of the subscriber

wire

public void wire(Object publisher,
                 String publisherPropName,
                 Object subscriber,
                 String subscriberPropName)
          throws WiringException
Description copied from class: Broker
Connects a published property to a subscribing property. Does nothing if the wire already exists. Throws a BrokerException if the features cannot be wired.
Overrides:
wire in class Broker
Following copied from class: org.escot.Broker
Parameters:
publisher - a bean which publishes a property
publisherPropName - name of a property of the publisher
subscriber - a bean which subscribes to a property
subscriberPropName - name of a property of the subscriber

wire

protected void wire(Object publisher,
                    String publisherPropName,
                    Object subscriber,
                    String subscriberPropName,
                    boolean addNonBrokeredBeans)
             throws WiringException
Parameters:
addNonBrokeredBeans - if true, adds subscriber and publisher as beans if not brokered.

unwire

public void unwire(Object publisher,
                   String publisherPropName,
                   Object subscriber,
                   String subscriberPropName)
Description copied from class: Broker
Disconnects a published property from a subscribing property. Does nothing if there was no wire.
Overrides:
unwire in class Broker
Following copied from class: org.escot.Broker
Parameters:
publisher - a bean which publishes a property
publisherPropName - name of a property of the publisher
subscriber - a bean which subscribes to a property
subscriberPropName - name of a property of the subscriber

unwire

protected void unwire(Object bean,
                      String featureName)

unwire

public void unwire(Wire wire)
Description copied from class: Broker
Disconnects the properties specified in the Wire.
Overrides:
unwire in class Broker

unwireAll

public void unwireAll()
Description copied from class: Broker
Disconnects everything.
Overrides:
unwireAll in class Broker

setWires

public void setWires(com.sun.java.util.collections.Vector v)
For restoring the Broker state on load.

getWires

public com.sun.java.util.collections.Vector getWires()
Description copied from class: Broker
Returns a Collection of Wires. !! Note: for now, we return a java.util.Vector, but we should return an immutable java.util.Collection. Unfortunately, this wouldn't compile under 1.1. A java.util.Collection is necessary instead of com.sun.java.util.collections.Collection, so the data can be saved by archiver.
Overrides:
getWires in class Broker

getWires

public com.sun.java.util.collections.Collection getWires(Object bean,
                                                         String featureName)
Description copied from class: Broker
Returns a Collection of Wires involving the specified bean.
Overrides:
getWires in class Broker

getFeatureByName

public EscotFeature getFeatureByName(Object bean,
                                     String name)
                              throws IntrospectionException
Description copied from class: Broker
Returns a EscotFeature corresponding to the specified name. The default implementation calls the Introspector on the bean.
Overrides:
getFeatureByName in class Broker

getFeatureDescriptor

public FeatureDescriptor getFeatureDescriptor(Object bean,
                                              String name)
                                       throws IntrospectionException
Description copied from class: Broker
Returns the FeatureDescriptor corresponding to the named feature for the specified bean.
Overrides:
getFeatureDescriptor in class Broker

getFeatures

public com.sun.java.util.collections.Collection getFeatures(Object bean)
Description copied from class: Broker
Returns a Collection of EscotFeatures.
Overrides:
getFeatures in class Broker

getExplicitFeatures

public com.sun.java.util.collections.Collection getExplicitFeatures(Object bean)
Description copied from class: Broker
Returns a Collection of dynamic EscotFeatures.
Overrides:
getExplicitFeatures in class Broker

ensureUniqueID

protected String ensureUniqueID(Object o,
                                String id)

createID

protected String createID(Object o)

addEventBinding

public boolean addEventBinding(Object source,
                               Object target,
                               String eventSetName)
Binds target as a listener to source for the specified event. Returns whether event binding succeeded.
Overrides:
addEventBinding in class Broker

removeEventBinding

public void removeEventBinding(Object source,
                               Object target,
                               String eventSetName)
Removes binding of target as a listener to source for the specified event.
Overrides:
removeEventBinding in class Broker

hasEventBinding

public boolean hasEventBinding(Object source,
                               Object target,
                               String eventSetName)
Returns whether target is bound as a listener to source for the specified event.
Overrides:
hasEventBinding in class Broker

findEventBinding

public EventBinding findEventBinding(Object source,
                                     Object target,
                                     String eventSetName)

getEventBindings

public com.sun.java.util.collections.Collection getEventBindings()