org.openpermis.policy.bean.basic
Class BasicPartBean

java.lang.Object
  extended by org.openpermis.policy.bean.basic.BasicPart
      extended by org.openpermis.policy.bean.basic.BasicPartBean
All Implemented Interfaces:
Serializable, PartBean, Part
Direct Known Subclasses:
AbstractPredicate, BasicAbstractCollection, BasicAction, BasicAuthority, BasicDomain, BasicObligation, BasicPolicy, BasicRoleAssignmentRule, BasicRoleHierarchy, BasicTarget, BasicTargetAccessRule, False, True

public abstract class BasicPartBean
extends BasicPart
implements PartBean

Abstract part bean implementation that features JavaBean event and serial number support.

JavaBean support

Extending classes are expected to fire property change events using firePropertyChange(String, Object, Object) for all properties changes.

The general implementation of a change should look as follows:

 public void setSomeValue (SomeValue someValue) {
   final SomeValue oldSomeValue = getSomeValue();  // Use getter here!
   this.someValue = someValue;  // Create a clone of someValue if necessary.
   firePropertyChange("someValue", oldSomeValue, getSomeValue());  // Use getter again!
 }

Use of getters is mandatory since otherwise you might pass out mutable state in the property change event!

Also make sure that you clone any collections received to make sure that the caller cannot change internal state after the call.

JavaBean content change forwarding

Bean events of contained part beans and collections containing part beans are forwarded automatically using null as old and new value of the affected property. All you have to do in your implementation is to make sure that you are firing property change events properly, the rest will be handled by the abstract implementation.

Example: Consider the Target holds its Actions with the beans property actions. If the actions held are changed then a property change event with the old and new actions are fired. If the state of one of the actions contained changes then the Target will fire an event for property actions but without old or new values. Listeners are then prompted to refresh the complete state they hold about the actions of the target.

SerialNumber support

Serial numbers are supported as immutable property and have to be supplied at creation time. They allow to identity the bean, even if its contents is changed. In contrast to using the System.identityHashCode(Object) the serial number is serializable and can be passed on the other objects (e.g. if an implementation class needs to clone a part bean in a setter).

Apart from supplying the correct serial number an implementation class need not be concerned about the presence of serial numbers.

SerialNumbers and factory methods

Should you require to create new parts in your implementation (e.g. in factory methods) use getSerialNumber().next() to create a unique serial number that lies in the same context as the serial number of this part.

See Also:
Serialized Form
Since:
0.1.0

Constructor Summary
protected BasicPartBean(Class<? extends PartBean> partBeanType, SerialNumber serialNumber)
          Creates a new part bean with the specified serial number.
 
Method Summary
 void accept(PartBeanVisitor visitor)
          Allows traversing the model according to the visitor pattern.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a property change listener to this part bean.
 boolean equalSerialNumber(PartBean part)
          Compares the serial number of this part to the one of the specified part.
 PartBean findBySerialNumber(SerialNumber partSerialNumber)
          Returns the part bean corresponding to the specified serial number.
protected  void firePropertyChange(String propertyName, Object oldValue, Object newValue)
          Report a bound property update to any registered listeners.
 Class<? extends PartBean> getPartBeanType()
          Returns the primary part bean interface class that this part implements.
 SerialNumber getSerialNumber()
          Returns the serial number of this part.
protected  String getSerialNumberString()
          Returns the string representation of this parts serial number if it has any.
 boolean instanceOf(Class<? extends PartBean> type)
          Returns true if this part bean is instance of type.
protected  void notifyIdentityChange(URI oldIdentity, URI newIdentity)
          Notifies a change of the identity property.
protected  void notifyNameChange(String oldName, String newName)
          Notifies a change of the name property.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes a property change listener from this part bean.
 String toShortString()
          Returns the serial number string representation of this class.
 
Methods inherited from class org.openpermis.policy.bean.basic.BasicPart
appendDetails, appendPartDetails, areIdentitiesUnique, areNamesUnique, checkLocalConsistency, checkLocalPartConsistency, comparablePart, equalPart, equals, getIdentity, getName, getSimpleClassName, hashCode, hasPartIdentity, hasPartName, isIdentityValid, isNameValid, partHashCode, reportProblem, setIdentity, setName, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.openpermis.policy.bean.PartBean
accept, checkLocalPartConsistency
 
Methods inherited from interface org.openpermis.policy.Part
equals, hashCode, toString
 

Constructor Detail

BasicPartBean

protected BasicPartBean(Class<? extends PartBean> partBeanType,
                        SerialNumber serialNumber)
Creates a new part bean with the specified serial number.

Parameters:
partBeanType - the primary part bean interface class that this part implements.
serialNumber - the serial number of this part.
Since:
0.1.0
0.3.0 added partBeanType.
Method Detail

firePropertyChange

protected final void firePropertyChange(String propertyName,
                                        Object oldValue,
                                        Object newValue)
Report a bound property update to any registered listeners.

No event is fired if old and new are equal and non-null.

The event will use the event hash code as propagation ID.

Notes:
Take care to always use getters when retrieving the old/new values to fire to avoid passing out mutable objects!
Parameters:
propertyName - the programmatic name of the property that was changed.
oldValue - the old value of the property.
newValue - the new value of the property.
Since:
0.1.0

getPartBeanType

public Class<? extends PartBean> getPartBeanType()
Description copied from interface: PartBean
Returns the primary part bean interface class that this part implements.

Specified by:
getPartBeanType in interface PartBean
Returns:
the primary part bean interface class that this part implements.
Since:
0.3.0

instanceOf

public boolean instanceOf(Class<? extends PartBean> type)
Description copied from interface: PartBean
Returns true if this part bean is instance of type.

Specified by:
instanceOf in interface PartBean
Parameters:
type - the type to check for.
Returns:
true if this part bean is instance of type.
Since:
0.9.0

getSerialNumber

public final SerialNumber getSerialNumber()
Description copied from interface: PartBean
Returns the serial number of this part.

Specified by:
getSerialNumber in interface PartBean
Returns:
the serial number of this part.
Since:
0.1.0

equalSerialNumber

public boolean equalSerialNumber(PartBean part)
Description copied from interface: PartBean
Compares the serial number of this part to the one of the specified part.

Specified by:
equalSerialNumber in interface PartBean
Parameters:
part - the part bean whose serial number to compare to this one.
Returns:
true if the specified part has the same serial number as this one, false otherwise.
Since:
0.1.0

findBySerialNumber

public PartBean findBySerialNumber(SerialNumber partSerialNumber)
Returns the part bean corresponding to the specified serial number.

If the part bean contains other part beans, it searches its child beans recursively.

The basic implementation returns this bean if its serial number matches the one passed in or null if not. Subclasses that contain other parts must traverse their children.

Specified by:
findBySerialNumber in interface PartBean
Parameters:
partSerialNumber - the SerialNumber of the part bean to return.
Returns:
the matching PartBean or null if no matching part bean is found.
Since:
0.1.0

toShortString

public final String toShortString()
Description copied from interface: PartBean
Returns the serial number string representation of this class.

The simplified string representation only consists only of the simple implementation class name of this part followed by the serial number in square brackets.

Specified by:
toShortString in interface PartBean
Returns:
the serial number string representation of this class.
Since:
0.1.0

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Description copied from interface: PartBean
Adds a property change listener to this part bean.

The change listener will be notified whenever this part or a sub part that is contained in this part changes.

Changes of parts contained are forwarded with a property change event that is using null as old and new value.

The same listener object may be added more than once, and will be called as many times as it is added.

If the listener is null, no action is taken.

Specified by:
addPropertyChangeListener in interface PartBean
Parameters:
listener - the listener to be added, may be null.
Since:
0.1.0

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Description copied from interface: PartBean
Removes a property change listener from this part bean.

If the same listener was added more than once, it will be notified one less time after being removed.

If the listener is null, or was never added, no action is taken.

Specified by:
removePropertyChangeListener in interface PartBean
Parameters:
listener - the listener to be removed, may be null.
Since:
0.1.0

accept

public final void accept(PartBeanVisitor visitor)
Description copied from interface: PartBean
Allows traversing the model according to the visitor pattern. Visit is called exactly ones one each part in the domain model.

Each part bean must call method visitor.visit(this)

Specified by:
accept in interface PartBean
Parameters:
visitor - a PartBeanVisitor.
Since:
0.9.0

getSerialNumberString

protected String getSerialNumberString()
Description copied from class: BasicPart
Returns the string representation of this parts serial number if it has any.

The default implementation simply returns null.

Overrides:
getSerialNumberString in class BasicPart
Returns:
the string representation of this parts serial number if it has any.
Since:
0.1.0

notifyIdentityChange

protected final void notifyIdentityChange(URI oldIdentity,
                                          URI newIdentity)
Description copied from class: BasicPart
Notifies a change of the identity property.

The default implementation does nothing.

Overrides:
notifyIdentityChange in class BasicPart
Parameters:
oldIdentity - the old identity.
newIdentity - the new identity.
Since:
0.1.0

notifyNameChange

protected final void notifyNameChange(String oldName,
                                      String newName)
Description copied from class: BasicPart
Notifies a change of the name property.

The default implementation does nothing.

Overrides:
notifyNameChange in class BasicPart
Parameters:
oldName - the old name.
newName - the new name.
Since:
0.1.0


OpenPermis Role Based Access Control 0.9.0 (Build 16)
2009/08/13 07:16:59
Copyright (c) 2002-2007 Ergon Informatik AG