|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.openpermis.policy.bean.basic.BasicPart
public abstract class BasicPart
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:
isPartValid(PartProblemReporter)
equalPart(BasicPart)
comparablePart(BasicPart)
partHashCode()
appendPartDetails(StringBuilder)
(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.
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. |
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. |
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 . |
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. |
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 |
Constructor Detail |
---|
protected BasicPart()
Method Detail |
---|
protected final void reportProblem(PartProblemReporter reporter, PartProblemReporter.ProblemMessage message, Object... param)
This method guarantees that the reporter is only called if it is not null
.
reporter
- the problem reporter to use, may be null
.message
- the problem to report.param
- additional details about the type of violation.protected final StringBuilder appendDetails(StringBuilder sb, String type, Object details)
The convenience method takes care of the correct formatting.
sb
- the string builder to append the details to.type
- the type of details to add.details
- the details to add.
protected boolean equalPart(BasicPart part)
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).part
- the part to compare to this part.BasicUtilities.equalObjects(Object, Object)
,
BasicPart
true
if the part supplied is considered equivalent to this part.protected abstract boolean comparablePart(BasicPart part)
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.part
- the part to check.BasicPart
true
if the part supplied is comparable to this part.protected int partHashCode()
BasicUtilities.multiHashCode(int...)
to get a suitable hash code distribution.BasicPart
,
BasicUtilities.multiHashCode(int...)
protected boolean isChildNotNull(PartProblemReporter reporter, Part part)
part
- child part to check.
protected boolean isChildNullOrValid(PartProblemReporter reporter, Part part)
part
- child part to check.
protected boolean isChildValid(PartProblemReporter reporter, Part part)
part
- child part to check.
protected boolean isChildCollectionValid(PartProblemReporter reporter, Iterable<? extends Part> collection, boolean checkNotEmpty, boolean checkValid, boolean checkNameUniqueness, boolean checkObjectUniqueness, boolean checkIdentityUniqueness)
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.
true
if all conditions are ok.public boolean isPartValid(PartProblemReporter reporter)
reportProblem(org.openpermis.policy.PartProblemReporter, org.openpermis.policy.PartProblemReporter.ProblemMessage, java.lang.Object...)
to avoid having to deal with null
reporters.reporter
- the problem reporter to use, may be null
.BasicPart
,
Part.isValid(PartProblemReporter)
,
reportProblem(org.openpermis.policy.PartProblemReporter, org.openpermis.policy.PartProblemReporter.ProblemMessage, java.lang.Object...)
protected void appendPartDetails(StringBuilder sb)
appendDetails(StringBuilder, String, Object)
to guarantee proper formatting.sb
- the string builder to add the details to.BasicPart
,
appendDetails(StringBuilder, String, Object)
protected String getSerialNumberString()
The default implementation simply returns null
.
protected void notifyIdentityChange(URI oldIdentity, URI newIdentity)
The default implementation does nothing.
oldIdentity
- the old identity.newIdentity
- the new identity.protected void notifyNameChange(String oldName, String newName)
The default implementation does nothing.
oldName
- the old name.newName
- the new name.protected String getSimpleClassName()
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)
.
protected final boolean hasPartIdentity()
Identifiable
.
true
if this part is a Identifiable
.public final boolean isIdentityValid(PartProblemReporter reporter)
The identity portion is only checked if this part hasPartIdentity()
.
true
if the identity portion of this part is valid or this part
does not implement the mix-in interface Identifiable
.public final URI getIdentity()
public final void setIdentity(URI identity)
identity
- the new identity URI of this part to set.protected final boolean hasPartName()
Nameable
.
true
if this part is a Nameable
.public final boolean isNameValid(PartProblemReporter reporter)
The name portion is only checked if this part hasPartName()
.
true
if the name portion of this part is valid or this part
does not implement the mix-in interface Nameable
.public final String getName()
public final void setName(String name)
name
- the new name of this part.public final boolean isValid(PartProblemReporter reporter)
Part
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.
isValid
in interface Part
reporter
- optional callback where violiations are reported, may be null
if the caller is not interested in details about the violations.
true
if the part and all parts contained are valid,
false
if this part or at least one part contained are invalid.public final boolean equals(Object obj)
Part
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.
equals
in interface Part
equals
in class Object
obj
- the policy part to compare this policy part to.Part.hashCode()
public final int hashCode()
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.
hashCode
in interface Part
hashCode
in class Object
Part.equals(Object)
public final String toString()
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.
toString
in interface Part
toString
in class Object
Object.toString()
|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
PERMIS Role Based Access Control 0.3.0 (Build 14)
2009/05/08 09:06:10
Copyright (c) 2002-2007 Ergon Informatik AG