|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.openpermis.policy.bean.basic.BasicPart
org.openpermis.policy.bean.basic.BasicPartBean
public abstract class BasicPartBean
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.
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 |
---|
protected BasicPartBean(Class<? extends PartBean> partBeanType, SerialNumber serialNumber)
partBeanType
- the primary part bean interface class that this part implements.serialNumber
- the serial number of this part.Method Detail |
---|
protected final void firePropertyChange(String propertyName, Object oldValue, Object newValue)
No event is fired if old and new are equal and non-null.
The event will use the event hash code as propagation ID.
propertyName
- the programmatic name of the property that was changed.oldValue
- the old value of the property.newValue
- the new value of the property.public Class<? extends PartBean> getPartBeanType()
PartBean
getPartBeanType
in interface PartBean
public boolean instanceOf(Class<? extends PartBean> type)
PartBean
true
if this part bean is instance of type.
instanceOf
in interface PartBean
type
- the type to check for.
true
if this part bean is instance of type.public final SerialNumber getSerialNumber()
PartBean
getSerialNumber
in interface PartBean
public boolean equalSerialNumber(PartBean part)
PartBean
equalSerialNumber
in interface PartBean
part
- the part bean whose serial number to compare to this one.
true
if the specified part has the same serial number as this one,
false
otherwise.public PartBean findBySerialNumber(SerialNumber partSerialNumber)
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.
findBySerialNumber
in interface PartBean
partSerialNumber
- the SerialNumber
of the part bean to return.
PartBean
or null
if no
matching part bean is found.public final String toShortString()
PartBean
The simplified string representation only consists only of the
simple implementation class name
of this part followed
by the serial number in square brackets.
toShortString
in interface PartBean
public void addPropertyChangeListener(PropertyChangeListener listener)
PartBean
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.
addPropertyChangeListener
in interface PartBean
listener
- the listener to be added, may be null
.public void removePropertyChangeListener(PropertyChangeListener listener)
PartBean
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.
removePropertyChangeListener
in interface PartBean
listener
- the listener to be removed, may be null
.public final void accept(PartBeanVisitor visitor)
PartBean
Each part bean must call method visitor.visit(this)
accept
in interface PartBean
visitor
- a PartBeanVisitor
.protected String getSerialNumberString()
BasicPart
The default implementation simply returns null
.
getSerialNumberString
in class BasicPart
protected final void notifyIdentityChange(URI oldIdentity, URI newIdentity)
BasicPart
The default implementation does nothing.
notifyIdentityChange
in class BasicPart
oldIdentity
- the old identity.newIdentity
- the new identity.protected final void notifyNameChange(String oldName, String newName)
BasicPart
The default implementation does nothing.
notifyNameChange
in class BasicPart
oldName
- the old name.newName
- the new name.
|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
OpenPermis Role Based Access Control 0.9.0 (Build 16)
2009/08/13 07:16:59
Copyright (c) 2002-2007 Ergon Informatik AG