org.norther.tammi.core.relation
Class Relation

java.lang.Object
  extended by org.norther.tammi.core.base.Referable
      extended by org.norther.tammi.core.relation.Relation
All Implemented Interfaces:
Serializable, EventListener, MBeanRegistration, NotificationBroadcaster, NotificationEmitter, NotificationListener, Relation, RelationSupportMBean, Identifiable, MBeanDelegate, NamePattern, ReferableMBean, RelationMBean
Direct Known Subclasses:
VariableTree

public class Relation
extends Referable
implements RelationMBean, NotificationListener

A default implementation of a relation MBean.

Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
static String RELATION_NOTIF_DESCRIPTION
          The notification description.
static MBeanNotificationInfo[] RELATION_NOTIFICATIONS
          Relation notifications.
protected  InternalRole roleUpdate
          The role to be updated and synchronized during use.
 
Fields inherited from class org.norther.tammi.core.base.Referable
ID_LENGTH, REFERABLE_ATTRIBUTES, REFERABLE_NOTIF_DESCRIPTION, REFERABLE_NOTIFICATIONS
 
Fields inherited from interface org.norther.tammi.core.base.ReferableMBean
DEFAULT_ID, ID, MBEAN, MBEAN_DESCRIPTION, TYPE
 
Fields inherited from interface org.norther.tammi.core.base.MBeanDelegate
ARRAY_TYPE, OBJECT_TYPE, PRIMITIVE_TYPE, STRING_TYPE
 
Constructor Summary
Relation()
          Constructs a new relation MBean.
Relation(ReferableMBean adapter, String id, String name)
          Constructs a named relation adaptee.
Relation(ReferableMBean adapter, String id, String name, RoleList roles)
          Constructs a named relation adaptee with initial roles.
Relation(ReferableMBean adaptee, String id, String name, RoleList roles, boolean listener)
          Constructs a named relation adapter with initial roles and an actor listener.
Relation(String id, String name)
          Constructs a named relation MBean.
Relation(String id, String name, RoleList roles)
          Constructs a named relation MBean with initial roles.
Relation(String id, String name, RoleList roles, boolean listener)
          Constructs a named relation MBean with initial roles and an actor listener.
 
Method Summary
 boolean addActorName(String theRoleName, int index, ObjectName actor)
          Adds an actor to the specified index of the specified role.
 boolean addActorName(String theRoleName, ObjectName actor)
          Adds an actor to the specified role.
 boolean addActorNames(String theRoleName, Collection actors)
          Adds actors to the specified role.
 void addToService()
          Adds the relation to the relation service.
 void clearRole(String theRoleName)
          Clears all actors from the specified role without checking write mode.
 Object getActor(String theRoleName)
          Gets the first actor of the specified role.
 Object getActor(String theRoleName, int index)
          Gets the indexed actor of the specified role.
 Object getActor(String theRoleName, ObjectName actor)
          Gets the named actor of the specified role.
 ObjectName getActorName(String theRoleName)
          Gets the first actor of the specified role.
 ObjectName getActorName(String theRoleName, int index)
          Gets the indexed actor of the specified role.
 RoleResult getAllRoles()
          Gets all roles present in the relation.
 MBeanNotificationInfo[] getNotificationInfo()
           
 Map getReferencedMBeans()
          Gets MBeans referenced in the various roles of the relation.
 String getRelationId()
          Gets the relation identifier.
 RelationServiceMBean getRelationService()
          Gets the configurable relation service.
 ObjectName getRelationServiceName()
          Gets the object name of the relation service hadling the relation.
 String getRelationTypeName()
          Gets the name of the associated relation type.
 List getRole(String theRoleName)
          Gets role value for the given role name and checks if the role exists and is readable according to the relation type.
 List getRoleActors(String theRoleName)
          Gets actors of the specified role.
 Integer getRoleCardinality(String theRoleName)
          Gets the number of MBeans currently referenced in the given role.
protected  ArrayList getRoleDirect(String theRoleName, boolean forced)
          Gets the given role without cloning.
 RoleResult getRoles(String[] theRoleNameArray)
          Gets values of roles with given names.
protected  Object getRoleWithStatus(String theRoleName, boolean forced)
          Gets the given role and return the status.
 void handleMBeanUnregistration(ObjectName theObjName, String theRoleName)
          Callback used by the relation service when an MBean referenced in a role is unregistered.
 void handleNotification(Notification notif, Object handback)
          A dummy notification handler.
protected  boolean isActorInDirectRole(String theRoleName, ObjectName actor)
          Checks directly whether an actor is in the specified role.
 Boolean isInRelationService()
          Checks whether the relation is still handled by the relation service.
 boolean isNamedActorInRole(String theRoleName, ObjectName actor)
          Checks whether an actor is in the specified role.
 void postDeregister()
          Allows the MBean to perform any operations needed after having been de-registered in the MBean server.
 void postRegister(Boolean done)
          Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.
 void preDeregister()
          Allows the MBean to perform any operations it needs before being de-registered by the MBean server.
 ObjectName preRegister(MBeanServer server, ObjectName name)
          Allows the MBean to perform any operations it needs before being registered in the MBean server.
 ObjectName removeActorName(String theRoleName, int index)
          Removes an indexed actor from the specified role.
 boolean removeActorName(String theRoleName, ObjectName actor)
          Removes an actor from the specified role.
 boolean removeActorNames(String theRoleName, Collection actors)
          Removes actors from the specified role.
 void removeFromService()
          Removes the relation the relation service.
 RoleList retrieveAllRoles()
          Retrieves all roles in the relation without checking read mode.
 List retrieveRole(String theRoleName)
          Retrieves actors from the specified role without checking read mode.
 Collection roleCollection()
          Returns a snapshot collection of roles.
 ObjectName setActorName(String theRoleName, int index, ObjectName actor)
          Sets the indexed actor of the specified role.
 void setActorName(String theRoleName, ObjectName actor)
          Sets an actor to be the only one for the specified role.
 void setRelationId(String id)
          Sets the relation identifier.
 void setRelationServiceManagementFlag(Boolean theFlg)
          Sets a flag to specify that the relation is handled or not by the relation service.
 void setRelationTypeName(String name)
          Sets the name of the associated relation type.
 void setRole(Role theRole)
          Sets the given role and checks if the role exists and is writable according to the relation type.
protected  void setRoleDirect(Role theRole, ObjectName added, ObjectName removed, boolean update, boolean forced)
          Sets the given role without cloning.
 RoleResult setRoles(RoleList theRoleList)
          Sets the given roles.
protected  Object setRoleWithStatus(Role theRole, ObjectName added, ObjectName removed, boolean update, boolean forced)
          Sets the given role and returns the status.
 
Methods inherited from class org.norther.tammi.core.base.Referable
addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNamePattern, getObjectName, getQueryPattern, getRegistrationTime, getSequenceNumber, getUniqueName, hasListeners, isUnregistered, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, setCanonicalName, setMBeanServer, setNamePattern, setObjectName, setQueryPattern, unregister, unregistered
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.core.base.ReferableMBean
getMBean
 

Field Detail

RELATION_NOTIF_DESCRIPTION

public static final String RELATION_NOTIF_DESCRIPTION
The notification description.

See Also:
Constant Field Values

RELATION_NOTIFICATIONS

public static final MBeanNotificationInfo[] RELATION_NOTIFICATIONS
Relation notifications.


roleUpdate

protected final InternalRole roleUpdate
The role to be updated and synchronized during use.

Constructor Detail

Relation

public Relation()
Constructs a new relation MBean.


Relation

public Relation(String id,
                String name)
Constructs a named relation MBean.

Parameters:
id - the relation id.
name - the relation type name.

Relation

public Relation(String id,
                String name,
                RoleList roles)
Constructs a named relation MBean with initial roles.

Parameters:
id - the relation id.
name - the relation type name.
roles - an optional role list for initializing the relation.

Relation

public Relation(String id,
                String name,
                RoleList roles,
                boolean listener)
Constructs a named relation MBean with initial roles and an actor listener.

Parameters:
id - the relation id.
name - the relation type name.
roles - an optional role list for initializing the relation.
listener - a flag to listen to all actor notifications.

Relation

public Relation(ReferableMBean adapter,
                String id,
                String name)
Constructs a named relation adaptee.

Parameters:
adapter - the adapter MBean.
id - the relation id.
name - the relation type name.

Relation

public Relation(ReferableMBean adapter,
                String id,
                String name,
                RoleList roles)
Constructs a named relation adaptee with initial roles.

Parameters:
adapter - the adapter MBean.
id - the relation id.
name - the relation type name.
roles - an optional role list for initializing the relation.

Relation

public Relation(ReferableMBean adaptee,
                String id,
                String name,
                RoleList roles,
                boolean listener)
Constructs a named relation adapter with initial roles and an actor listener.

Parameters:
adaptee - the adaptee MBean.
id - the relation id.
name - the relation type name.
roles - an optional role list for initializing the relation.
listener - a flag to listen to all actor notifications.
Method Detail

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
                       throws Exception
Description copied from class: Referable
Allows the MBean to perform any operations it needs before being registered in the MBean server. The referable MBean provides a default name, if the name of the MBean is not specified. It also sends a registration notification for any client MBeans. If any exception is raised, the MBean will not be registered in the MBean server. Any subclasses must redirect their preRegister method to super MBean.

Specified by:
preRegister in interface MBeanRegistration
Overrides:
preRegister in class Referable
Parameters:
server - the MBean server in which the MBean will be registered.
name - the object name of the MBean (may be null).
Returns:
the name of the registered MBean.
Throws:
Exception - for errors.

postRegister

public void postRegister(Boolean done)
Description copied from class: Referable
Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.

Specified by:
postRegister in interface MBeanRegistration
Overrides:
postRegister in class Referable
Parameters:
done - indicates whether or not the MBean has been registered.

preDeregister

public void preDeregister()
                   throws Exception
Description copied from class: Referable
Allows the MBean to perform any operations it needs before being de-registered by the MBean server. The configurable MBean sends an unregistration notifitation for any referencing MBeans.

Specified by:
preDeregister in interface MBeanRegistration
Overrides:
preDeregister in class Referable
Throws:
Exception - on errors.

postDeregister

public void postDeregister()
Description copied from class: Referable
Allows the MBean to perform any operations needed after having been de-registered in the MBean server.

Specified by:
postDeregister in interface MBeanRegistration
Overrides:
postDeregister in class Referable

getAllRoles

public RoleResult getAllRoles()
                       throws RelationServiceNotRegisteredException
Gets all roles present in the relation.

Specified by:
getAllRoles in interface Relation
Returns:
a role result including found and unresolved roles in separate lists.
Throws:
RelationServiceNotRegisteredException - if the service is not registered.

getReferencedMBeans

public Map getReferencedMBeans()
Gets MBeans referenced in the various roles of the relation.

Specified by:
getReferencedMBeans in interface Relation
Returns:
mappings between object names and roles.

getRelationId

public String getRelationId()
Gets the relation identifier.

Specified by:
getRelationId in interface Relation
Returns:
the relation identifier.

getRelationServiceName

public ObjectName getRelationServiceName()
Gets the object name of the relation service hadling the relation.

Specified by:
getRelationServiceName in interface Relation
Returns:
the object name of the relation service.

getRelationTypeName

public String getRelationTypeName()
Gets the name of the associated relation type.

Specified by:
getRelationTypeName in interface Relation
Returns:
the relation type name.

getRole

public List getRole(String theRoleName)
             throws RelationServiceNotRegisteredException,
                    RoleNotFoundException
Gets role value for the given role name and checks if the role exists and is readable according to the relation type.

Specified by:
getRole in interface Relation
Parameters:
theRoleName - the name of a role.
Returns:
an array list of object names being the role value.
Throws:
RoleNotFoundException - if there is no role with the given name.
RelationServiceNotRegisteredException - if the service is not registered.

getRoleCardinality

public Integer getRoleCardinality(String theRoleName)
                           throws RoleNotFoundException
Gets the number of MBeans currently referenced in the given role.

Specified by:
getRoleCardinality in interface Relation
Parameters:
theRoleName - the name of a role.
Returns:
the number of currently referenced MBeans in that role.
Throws:
RoleNotFoundException - if there is no role with the given name.

getRoles

public RoleResult getRoles(String[] theRoleNameArray)
                    throws RelationServiceNotRegisteredException
Gets values of roles with given names.

Specified by:
getRoles in interface Relation
Parameters:
theRoleNameArray - an array of names of roles to be retrieved.
Returns:
a role result including a list of roles.
Throws:
RelationServiceNotRegisteredException - if the service is not registered.

handleMBeanUnregistration

public void handleMBeanUnregistration(ObjectName theObjName,
                                      String theRoleName)
                               throws RoleNotFoundException,
                                      InvalidRoleValueException,
                                      RelationNotFoundException,
                                      RelationTypeNotFoundException,
                                      RelationServiceNotRegisteredException
Callback used by the relation service when an MBean referenced in a role is unregistered. The relation service will call this method to let the relation take action to reflect the impact of such unregistration. The user is not expected to call this method.

Specified by:
handleMBeanUnregistration in interface Relation
Parameters:
theObjName - the object name of the unregistered MBean.
theRoleName - the name of role where the MBean is referenced.
Throws:
RoleNotFoundException - if there is no role with the given name.
InvalidRoleValueException - if the value provided for the role is not valid.
RelationNotFoundException - if the relation has not been added in the service.
RelationTypeNotFoundException - if the relation type has not been declared.
RelationServiceNotRegisteredException - if the service is not registered.

isInRelationService

public Boolean isInRelationService()
Checks whether the relation is still handled by the relation service.

Specified by:
isInRelationService in interface RelationSupportMBean
Returns:
true, if the relation is still in the service.

retrieveAllRoles

public RoleList retrieveAllRoles()
Retrieves all roles in the relation without checking read mode.

Specified by:
retrieveAllRoles in interface Relation
Returns:
a list of all roles.

setRelationServiceManagementFlag

public void setRelationServiceManagementFlag(Boolean theFlg)
Sets a flag to specify that the relation is handled or not by the relation service. This method should not be called by the user.

Specified by:
setRelationServiceManagementFlag in interface RelationSupportMBean
Parameters:
theFlg - the flag.

setRole

public void setRole(Role theRole)
             throws RoleNotFoundException,
                    InvalidRoleValueException,
                    RelationNotFoundException,
                    RelationTypeNotFoundException,
                    RelationServiceNotRegisteredException
Sets the given role and checks if the role exists and is writable according to the relation type.

Specified by:
setRole in interface Relation
Parameters:
theRole - the role to be set.
Throws:
RoleNotFoundException - if there is no role with the given name.
InvalidRoleValueException - if the value provided for the role is not valid.
RelationNotFoundException - if the relation has not been added in the service.
RelationTypeNotFoundException - if the relation type has not been declared.
RelationServiceNotRegisteredException - if the service is not registered.

setRoles

public RoleResult setRoles(RoleList theRoleList)
                    throws RelationNotFoundException,
                           RelationTypeNotFoundException,
                           RelationServiceNotRegisteredException
Sets the given roles.

Specified by:
setRoles in interface Relation
Parameters:
theRoleList - the list of roles to be set.
Returns:
a role result including a list of set roles.
Throws:
RelationNotFoundException - if the relation has not been added in the service.
RelationTypeNotFoundException - if the relation type has not been declared.
RelationServiceNotRegisteredException - if the service is not registered.

getRelationService

public RelationServiceMBean getRelationService()
                                        throws RelationServiceNotRegisteredException
Description copied from interface: RelationMBean
Gets the configurable relation service.

Specified by:
getRelationService in interface RelationMBean
Returns:
the relation service.
Throws:
RelationServiceNotRegisteredException - if the service is not registered.

retrieveRole

public List retrieveRole(String theRoleName)
Description copied from interface: RelationMBean
Retrieves actors from the specified role without checking read mode.

Specified by:
retrieveRole in interface RelationMBean
Parameters:
theRoleName - the name of the role.
Returns:
the role value or an empty list.

clearRole

public void clearRole(String theRoleName)
               throws RoleNotFoundException,
                      InvalidRoleValueException,
                      RelationNotFoundException,
                      RelationTypeNotFoundException,
                      RelationServiceNotRegisteredException
Description copied from interface: RelationMBean
Clears all actors from the specified role without checking write mode.

Specified by:
clearRole in interface RelationMBean
Parameters:
theRoleName - the name of the role.
Throws:
RoleNotFoundException - if there is no role with given name.
InvalidRoleValueException - if the value provided for the role is not valid.
RelationNotFoundException - if the relation has not been added in the service.
RelationTypeNotFoundException - if the relation type has not been declared.
RelationServiceNotRegisteredException - if the service is not registered.

isNamedActorInRole

public boolean isNamedActorInRole(String theRoleName,
                                  ObjectName actor)
                           throws RoleNotFoundException,
                                  RelationServiceNotRegisteredException
Description copied from interface: RelationMBean
Checks whether an actor is in the specified role.

Specified by:
isNamedActorInRole in interface RelationMBean
Parameters:
theRoleName - the name of the role.
actor - an actor for the role.
Returns:
true if the actor is in the role, otherwise false.
Throws:
RoleNotFoundException - if there is no role with given name.
RelationServiceNotRegisteredException - if the service is not registered.

setActorName

public void setActorName(String theRoleName,
                         ObjectName actor)
                  throws RoleNotFoundException,
                         InvalidRoleValueException,
                         RelationNotFoundException,
                         RelationTypeNotFoundException,
                         RelationServiceNotRegisteredException
Description copied from interface: RelationMBean
Sets an actor to be the only one for the specified role.

Specified by:
setActorName in interface RelationMBean
Parameters:
theRoleName - the name of the role.
actor - an actor for the role.
Throws:
RoleNotFoundException - if there is no role with given name.
InvalidRoleValueException - if the value provided for the role is not valid.
RelationNotFoundException - if the relation has not been added in the service.
RelationTypeNotFoundException - if the relation type has not been declared.
RelationServiceNotRegisteredException - if the service is not registered.

setActorName

public ObjectName setActorName(String theRoleName,
                               int index,
                               ObjectName actor)
                        throws RoleNotFoundException,
                               InvalidRoleValueException,
                               RelationNotFoundException,
                               RelationTypeNotFoundException,
                               RelationServiceNotRegisteredException
Description copied from interface: RelationMBean
Sets the indexed actor of the specified role.

Specified by:
setActorName in interface RelationMBean
Parameters:
theRoleName - the name of the role.
index - the index of the actor.
actor - an actor for the role.
Returns:
the previous actor of the index and role.
Throws:
RoleNotFoundException - if there is no role with given name.
InvalidRoleValueException - if the value provided for the role is not valid.
RelationNotFoundException - if the relation has not been added in the service.
RelationTypeNotFoundException - if the relation type has not been declared.
RelationServiceNotRegisteredException - if the service is not registered.

addActorName

public boolean addActorName(String theRoleName,
                            ObjectName actor)
                     throws RoleNotFoundException,
                            InvalidRoleValueException,
                            RelationNotFoundException,
                            RelationTypeNotFoundException,
                            RelationServiceNotRegisteredException
Description copied from interface: RelationMBean
Adds an actor to the specified role.

Specified by:
addActorName in interface RelationMBean
Parameters:
theRoleName - the name of the role.
actor - an actor for the role.
Returns:
true if the actor was added, false if it existed already.
Throws:
RoleNotFoundException - if there is no role with given name.
InvalidRoleValueException - if the value provided for the role is not valid.
RelationNotFoundException - if the relation has not been added in the service.
RelationTypeNotFoundException - if the relation type has not been declared.
RelationServiceNotRegisteredException - if the service is not registered.

addActorName

public boolean addActorName(String theRoleName,
                            int index,
                            ObjectName actor)
                     throws RoleNotFoundException,
                            InvalidRoleValueException,
                            RelationNotFoundException,
                            RelationTypeNotFoundException,
                            RelationServiceNotRegisteredException
Description copied from interface: RelationMBean
Adds an actor to the specified index of the specified role.

Specified by:
addActorName in interface RelationMBean
Parameters:
theRoleName - the name of the role.
index - the index of the actor.
actor - an actor for the role.
Returns:
true if the actor was added, false if it existed already.
Throws:
RoleNotFoundException - if there is no role with given name.
InvalidRoleValueException - if the value provided for the role is not valid.
RelationNotFoundException - if the relation has not been added in the service.
RelationTypeNotFoundException - if the relation type has not been declared.
RelationServiceNotRegisteredException - if the service is not registered.

addActorNames

public boolean addActorNames(String theRoleName,
                             Collection actors)
                      throws RoleNotFoundException,
                             InvalidRoleValueException,
                             RelationNotFoundException,
                             RelationTypeNotFoundException,
                             RelationServiceNotRegisteredException
Description copied from interface: RelationMBean
Adds actors to the specified role.

Specified by:
addActorNames in interface RelationMBean
Parameters:
theRoleName - the name of the role.
actors - a collection of actors for the role.
Returns:
true if any new actors were added, otherwe false.
Throws:
RoleNotFoundException - if there is no role with given name.
InvalidRoleValueException - if the value provided for the role is not valid.
RelationNotFoundException - if the relation has not been added in the service.
RelationTypeNotFoundException - if the relation type has not been declared.
RelationServiceNotRegisteredException - if the service is not registered.

removeActorName

public boolean removeActorName(String theRoleName,
                               ObjectName actor)
                        throws RoleNotFoundException,
                               InvalidRoleValueException,
                               RelationNotFoundException,
                               RelationTypeNotFoundException,
                               RelationServiceNotRegisteredException
Description copied from interface: RelationMBean
Removes an actor from the specified role.

Specified by:
removeActorName in interface RelationMBean
Parameters:
theRoleName - the name of the role.
actor - an actor in the role.
Returns:
true if removed, otherwise false.
Throws:
RoleNotFoundException - if there is no role with given name.
InvalidRoleValueException - if the value provided for the role is not valid.
RelationNotFoundException - if the relation has not been added in the service.
RelationTypeNotFoundException - if the relation type has not been declared.
RelationServiceNotRegisteredException - if the service is not registered.

removeActorName

public ObjectName removeActorName(String theRoleName,
                                  int index)
                           throws RoleNotFoundException,
                                  InvalidRoleValueException,
                                  RelationNotFoundException,
                                  RelationTypeNotFoundException,
                                  RelationServiceNotRegisteredException