org.openpermis.policy.bean.basic
Class BasicPart

java.lang.Object
  extended by org.openpermis.policy.bean.basic.BasicPart
All Implemented Interfaces:
Serializable, Part
Direct Known Subclasses:
BasicPartBean, InternalSubject

public abstract class BasicPart
extends Object
implements Part

Abstract base class for policy parts.

Mix-in Interfaces

This base class provides support for the mix-in interfaces:

To create an implementation that features one of the mix-in interfaces listed above simply implement the interface in your AbstractPart extension, the base class will take care of the mix-in interface implementation details.

State of Extensions

If your part implementation features additional state make sure to provide implementations for the following methods:

(If your identity part does not have further state there is no need to provide implementations of the methods listed above. The default implementations will guarantee that your identity part implementation works as expected.)

Note: If your implementation contains lists or sets of part beans make sure they are compared using BasicUtilities.equalLists(java.util.List, java.util.List) and the hash code is calculated using BasicUtilities.listHashCode(java.util.List). These implementations disregard the list item order.

Getters/Setters

Follow the JavaBean property specification when implementing getters and setters, e.g. if your part features a value called myValue then provide MyType getMyValue() and setMyValue(Type myValue).

Make sure collection classes are cloned before you assign them to your internal state, otherwise the caller can modify the collection from outside again.

See Also:
Serialized Form
Since:
0.1.0

Field Summary
private static URI EMPTY_URI
          The URI consisting of an empty string.
private  URI identity
          The identity of this part.
private  String name
          The name of this part.
private static long serialVersionUID
           
 
Constructor Summary
protected BasicPart()
          Creates a new, uninitialized basic part.
 
Method Summary
protected  StringBuilder appendDetails(StringBuilder sb, String type, Object details)
          Convenience method to append the details of an extended part to a string builder.
private  void appendIdentityDetails(StringBuilder sb)
          Appends the identity details of this part to the string builder specified.
private  void appendNameDetails(StringBuilder sb)
          Appends the name details of this part to the string builder specified.
protected  void appendPartDetails(StringBuilder sb)
          Appends the details of this extended part for the string representation of this part.
protected abstract  boolean comparablePart(BasicPart part)
          Check if the part specified is comparable to this part.
private  boolean equalIdentity(BasicPart part)
          Check if the identity of this part and the part specified are equivalent.
private  boolean equalName(BasicPart part)
          Check if the name of this part and the part specified are equivalent.
protected  boolean equalPart(BasicPart part)
          Compares another part to this part.
 boolean equals(Object obj)
          Check if this policy part is equivalent to the one specified.
 URI getIdentity()
          Returns the URI that serves as identity of this part.
 String getName()
          Returns the name of this part.
protected  String getSerialNumberString()
          Returns the string representation of this parts serial number if it has any.
protected  String getSimpleClassName()
          Returns the simple implementation class name of this class.
 int hashCode()
          Returns the hash code of this policy part.
protected  boolean hasPartIdentity()
          Check if the implementation of this part supports a Identifiable.
protected  boolean hasPartName()
          Check if the implementation of this part supports a Nameable.
private  int identityHashCode()
          Returns the identity hash code of this part.
protected  boolean isChildCollectionValid(PartProblemReporter reporter, Iterable<? extends Part> collection, boolean checkNotEmpty, boolean checkValid, boolean checkNameUniqueness, boolean checkObjectUniqueness, boolean checkIdentityUniqueness)
          Checks if a collection is set, elements are set and valid and not empty.
protected  boolean isChildNotNull(PartProblemReporter reporter, Part part)
          Checks if a child part is not null.
protected  boolean isChildNullOrValid(PartProblemReporter reporter, Part part)
          Checks if a child part is null or valid.
protected  boolean isChildValid(PartProblemReporter reporter, Part part)
          Checks if a child part is set and valid.
 boolean isIdentityValid(PartProblemReporter reporter)
          Checks if the identity portion of this part is valid.
 boolean isNameValid(PartProblemReporter reporter)
          Checks if the name portion of this part is valid.
 boolean isPartValid(PartProblemReporter reporter)
          Checks if the extended state of this part is valid.
 boolean isValid(PartProblemReporter reporter)
          Check if this part and all parts contained are valid.
private  int nameHashCode()
          Returns the name hash code of this part.
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.
protected  int partHashCode()
          Returns the hash code of the extended part state.
protected  void reportProblem(PartProblemReporter reporter, PartProblemReporter.ProblemMessage message, Object... param)
          Convenience method to reports a problem using the specified reporter.
 void setIdentity(URI identity)
          Sets the URI that serves as identity of this part.
 void setName(String name)
          Sets the name of this part.
 String toString()
          Returns a string representation of this policy part.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Constant Field Value:
5635383950293028314L
Since:
0.1.0

EMPTY_URI

private static final URI EMPTY_URI
The URI consisting of an empty string.

See Also:
isIdentityValid(PartProblemReporter)
Since:
0.1.0

identity

private URI identity
The identity of this part.

Only used if the mix-in interface Identifiable is implemented.

See Also:
hasPartIdentity()
Since:
0.1.0

name

private String name
The name of this part.

Only used if the mix-in interface Nameable is implemented.

See Also:
hasPartName()
Since:
0.1.0
Constructor Detail

BasicPart

protected BasicPart()
Creates a new, uninitialized basic part.

Since:
0.1.0
Method Detail

reportProblem

protected final void reportProblem(PartProblemReporter reporter,
                                   PartProblemReporter.ProblemMessage message,
                                   Object... param)
Convenience method to reports a problem using the specified reporter.

This method guarantees that the reporter is only called if it is not null.

Parameters:
reporter - the problem reporter to use, may be null.
message - the problem to report.
param - additional details about the type of violation.
Since:
0.1.0

appendDetails

protected final StringBuilder appendDetails(StringBuilder sb,
                                            String type,
                                            Object details)
Convenience method to append the details of an extended part to a string builder.

The convenience method takes care of the correct formatting.

Parameters:
sb - the string builder to append the details to.
type - the type of details to add.
details - the details to add.
Returns:
the string builder specified to allow call chaining.
Since:
0.1.0

equalPart

protected boolean equalPart(BasicPart part)
Compares another part to this part.

Notes:
The part supplied is guaranteed to be comparable to this part (i.e. it is safe to cast the object without any further checks if the implementation of comparablePart(BasicPart) makes the instanceof check).
Parameters:
part - the part to compare to this part.
Returns:
true if the part supplied is considered equivalent to this part.
See Also:
BasicUtilities.equalObjects(Object, Object), BasicPart
Since:
0.1.0

comparablePart

protected abstract boolean comparablePart(BasicPart part)
Check if the part specified is comparable to this part.

Notes:
Extensions should perform an instanceof check with the implementation class. This check is performed in equals(Object) before calling equalPart(BasicPart) to guarantee symmetry and transitivity on both objects.
Parameters:
part - the part to check.
Returns:
true if the part supplied is comparable to this part.
See Also:
BasicPart
Since:
0.1.0

partHashCode

protected int partHashCode()
Returns the hash code of the extended part state.

Notes:
Extensions should calculate a combined hash code for all their extended state, use BasicUtilities.multiHashCode(int...) to get a suitable hash code distribution.
Returns:
the hash code of the extended part state.
See Also:
BasicPart, BasicUtilities.multiHashCode(int...)
Since:
0.1.0

isChildNotNull

protected boolean isChildNotNull(PartProblemReporter reporter,
                                 Part part)
Checks if a child part is not null.

Parameters:
part - child part to check.
Returns:
if all conditions are ok
Since:
0.1.0

isChildNullOrValid

protected boolean isChildNullOrValid(PartProblemReporter reporter,
                                     Part part)
Checks if a child part is null or valid.

Parameters:
part - child part to check.
Returns:
if all conditions are ok
Since:
0.1.0

isChildValid

protected boolean isChildValid(PartProblemReporter reporter,
                               Part part)
Checks if a child part is set and valid.

Parameters:
part - child part to check.
Returns:
if all conditions are ok
Since:
0.1.0

isChildCollectionValid

protected boolean isChildCollectionValid(PartProblemReporter reporter,
                                         Iterable<? extends Part> collection,
                                         boolean checkNotEmpty,
                                         boolean checkValid,
                                         boolean checkNameUniqueness,
                                         boolean checkObjectUniqueness,
                                         boolean checkIdentityUniqueness)
Checks if a collection is set, elements are set and valid and not empty.

Parameters:
reporter - reporter to use.
collection - the collection to check.
checkNotEmpty - check if collection is empty.
checkValid - check if collection's elements are valid.
checkNameUniqueness - check if collection's elements are name-unique.
checkObjectUniqueness - check if collection's elements are object-unique.
checkIdentityUniqueness - check if collectrion's elements are identity-unique.
Returns:
true if all conditions are ok.
Since:
0.3.0

isPartValid

public boolean isPartValid(PartProblemReporter reporter)
Checks if the extended state of this part is valid.

Notes:
Extensions should check their extended part state. Use reportProblem(org.openpermis.policy.PartProblemReporter, org.openpermis.policy.PartProblemReporter.ProblemMessage, java.lang.Object...) to avoid having to deal with null reporters.
Parameters:
reporter - the problem reporter to use, may be null.
See Also:
BasicPart, Part.isValid(PartProblemReporter), reportProblem(org.openpermis.policy.PartProblemReporter, org.openpermis.policy.PartProblemReporter.ProblemMessage, java.lang.Object...)
Since:
0.1.0

appendPartDetails

protected void appendPartDetails(StringBuilder sb)
Appends the details of this extended part for the string representation of this part.

Notes:
Extensions can add their details using the convenience method appendDetails(StringBuilder, String, Object) to guarantee proper formatting.
Parameters:
sb - the string builder to add the details to.
See Also:
BasicPart, appendDetails(StringBuilder, String, Object)
Since:
0.1.0

getSerialNumberString

protected String getSerialNumberString()
Returns the string representation of this parts serial number if it has any.

The default implementation simply returns null.

Returns:
the string representation of this parts serial number if it has any.
Since:
0.1.0

notifyIdentityChange

protected void notifyIdentityChange(URI oldIdentity,
                                    URI newIdentity)
Notifies a change of the identity property.

The default implementation does nothing.

Parameters:
oldIdentity - the old identity.
newIdentity - the new identity.
Since:
0.1.0

notifyNameChange

protected void notifyNameChange(String oldName,
                                String newName)
Notifies a change of the name property.

The default implementation does nothing.

Parameters:
oldName - the old name.
newName - the new name.
Since:
0.1.0

getSimpleClassName

protected String getSimpleClassName()
Returns the simple implementation class name of this class.

If your implementation represents an interface implementation return the interface simple class name here. In short: return the instance you are checking against in comparablePart(BasicPart).

Returns:
the simple implementation class name of this class.
Since:
0.1.0

hasPartIdentity

protected final boolean hasPartIdentity()
Check if the implementation of this part supports a Identifiable.

Returns:
true if this part is a Identifiable.
Since:
0.1.0

equalIdentity

private final boolean equalIdentity(BasicPart part)
Check if the identity of this part and the part specified are equivalent.

Makes sure that both objects implement the Identifiable mix-in interface and then compares the identities. Also returns true if both objects do not support the Identifiable interface.

Parameters:
part - the part to compare this identity to, must not be null.
Since:
0.1.0

identityHashCode

private final int identityHashCode()
Returns the identity hash code of this part.

If this part hasPartIdentity() then the hash code of the identity is returned. if it does not support the Identifiable mix-in interface 0 is returned.

Returns:
the identity hash code of this part or 0.
Since:
0.1.0

isIdentityValid

public final boolean isIdentityValid(PartProblemReporter reporter)
Checks if the identity portion of this part is valid.

The identity portion is only checked if this part hasPartIdentity().

Returns:
true if the identity portion of this part is valid or this part does not implement the mix-in interface Identifiable.
Since:
0.1.0

appendIdentityDetails

private void appendIdentityDetails(StringBuilder sb)
Appends the identity details of this part to the string builder specified.

The identity details are only added if this part hasPartIdentity().

Parameters:
sb - the string builder to append to.
Since:
0.1.0

getIdentity

public final URI getIdentity()
Returns the URI that serves as identity of this part.

Returns:
the identity URI of this part.
Since:
0.1.0

setIdentity

public final void setIdentity(URI identity)
Sets the URI that serves as identity of this part.

Parameters:
identity - the new identity URI of this part to set.
Since:
0.1.0

hasPartName

protected final boolean hasPartName()
Check if the implementation of this part supports a Nameable.

Returns:
true if this part is a Nameable.
Since:
0.1.0

equalName

private final boolean equalName(BasicPart part)
Check if the name of this part and the part specified are equivalent.

Makes sure that both objects implement the Nameable mix-in interface and then compares the name. Also returns true if both objects do not support the Nameable interface.

Parameters:
part - the part to compare this name to, must not be null.
Since:
0.1.0

nameHashCode

private final int nameHashCode()
Returns the name hash code of this part.

If this part hasPartName() then the hash code of the name is returned. if it does not support the Nameable mix-in interface 0 is returned.

Returns:
the name hash code of this part or 0.
Since:
0.1.0

isNameValid

public final boolean isNameValid(PartProblemReporter reporter)
Checks if the name portion of this part is valid.

The name portion is only checked if this part hasPartName().

Returns:
true if the name portion of this part is valid or this part does not implement the mix-in interface Nameable.
Since:
0.1.0

appendNameDetails

private void appendNameDetails(StringBuilder sb)
Appends the name details of this part to the string builder specified.

The name details are only added if this part hasPartName().

Parameters:
sb - the string builder to append to.
Since:
0.1.0

getName

public final String getName()
Returns the name of this part.

Returns:
the name of this part.
Since:
0.1.0

setName

public final void setName(String name)
Sets the name of this part.

Parameters:
name - the new name of this part.
Since:
0.1.0

isValid

public final boolean isValid(PartProblemReporter reporter)
Description copied from interface: Part
Check if this part and all parts contained are valid.

Instead of enforcing that a part is valid at all times a part may be invalid (for example while loading a policy from a file or while editing a part). Use this method to assert that a part is valid.

Specified by:
isValid in interface Part
Parameters:
reporter - optional callback where violiations are reported, may be null if the caller is not interested in details about the violations.
Returns:
true if the part and all parts contained are valid, false if this part or at least one part contained are invalid.
Since:
0.1.0

equals

public final boolean equals(Object obj)
Description copied from interface: Part
Check if this policy part is equivalent to the one specified.

A part is considered equivalent to this part if it's state is equivalent to the state of this part and all parts contained are equivalent to the parts contained in this policy part.

Specified by:
equals in interface Part
Overrides:
equals in class Object
Parameters:
obj - the policy part to compare this policy part to.
See Also:
Part.hashCode()
Since:
0.1.0

hashCode

public final int hashCode()
Description copied from interface: Part
Returns the hash code of this policy part.

In addition to the general contract for Object.hashCode() the hash code of a policy part should not make use of the default object hash code. Instead the hash code of a policy part should only be calculated according to the contents of the policy part in such a way that different instances of a policy part with the same content return the same hash code.

Specified by:
hashCode in interface Part
Overrides:
hashCode in class Object
Returns:
the hash code of this policy part.
See Also:
Part.equals(Object)
Since:
0.1.0

toString

public final String toString()
Description copied from interface: Part
Returns a string representation of this policy part.

The string representation is purely informational and provides summary of the part in the following form: PartName [serial=value, ...]. The string representation starts with the simple implementation class name and is followed by its details in square brackets.

Specified by:
toString in interface Part
Overrides:
toString in class Object
Returns:
the string representation of this policy part.
See Also:
Object.toString()
Since:
0.1.0


PERMIS Role Based Access Control 0.4.0 (Build 15)
2009/05/20 08:14:59
Copyright (c) 2002-2007 Ergon Informatik AG