Module org.bzdev.obnaming
Package org.bzdev.obnaming
Class DefaultNamedObject<T extends DefaultNamedObject<T>>
java.lang.Object
org.bzdev.obnaming.DefaultNamedObject<T>
- All Implemented Interfaces:
NamedObjectOps
public class DefaultNamedObject<T extends DefaultNamedObject<T>>
extends Object
implements NamedObjectOps
Default implementation for named objects.
The default implementation is a bare-bones implementation
suitable for simple applications.
The type parameter T is the subclass of DefaultNamedObject that
will be used as the common superclass for all named objects that
the corresponding object namer will recognize.
As an example, to create an object namer, a named object, and a factory for the named object, one would define the following classes:
Additional code (indicated by an ellipsis) is, of course, necessary to do anything useful.abstract public class OurNamedObject extends DefaultNamedObject<OurNamedObject> { ... protected OurNamedObject(OurObjectNamer namer, String name, boolean intern) { super(namer, name, intern); ... } } public class OurObjectNamer extends DefaultObjectNamer<OurNamedObject> { ... public OurObjectNamer() { super(OurNamedObject.class); } } abstract public class OurObjectFactory<OBJ extends OurNamedObject> extends DefaultNOFactory<OurObjectNamer,OurNamedObject,OBJ> { ... protected OurObjectFactory(OurObjectNamer namer) { super(namer); } }
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultNamedObject
(DefaultObjectNamer<T> namer, String name, boolean intern) Constructor for interned objects. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Determine if this named object can be deleted.protected Object
clone()
Creates and returns a copy of this object.final boolean
delete()
Delete an object.final boolean
Determine if an object is being deleted.final String
getName()
Get a named object's name.protected DefaultObjectNamer<T>
Get a named object's object namer.final boolean
Determine if an object has been deleted.boolean
Determine if an object is interned in a object namer's tables.protected void
onDelete()
Complete the actions necessary to delete a named object.
-
Constructor Details
-
DefaultNamedObject
public DefaultNamedObject(DefaultObjectNamer<T> namer, String name, boolean intern) throws IllegalArgumentException Constructor for interned objects. These objects can be looked up by name using the methods inObjectNamer
.- Parameters:
namer
- the object namername
- the name of the object; null for an automatically generated nameintern
- true if the object can be looked up by using the methods inDefaultObjectNamer
; false otherwise.- Throws:
IllegalArgumentException
- typically means a name is already in use- See Also:
-
-
Method Details
-
clone
Creates and returns a copy of this object. This method will throw the exception CloneNotSupportedException if the object is interned.- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
- a clone could not be created- See Also:
-
getObjectNamer
Get a named object's object namer.- Returns:
- the object namer
-
isInterned
public boolean isInterned()Determine if an object is interned in a object namer's tables.- Specified by:
isInterned
in interfaceNamedObjectOps
- Returns:
- true if the object is interned; false if not
-
getName
Get a named object's name.- Specified by:
getName
in interfaceNamedObjectOps
- Returns:
- the name of the object
-
canDelete
public boolean canDelete()Determine if this named object can be deleted. A named object can be deleted if the method delete has not been called and if the object is not in a state that prevents the object from being deleted. Subclasses that override this method must call canDelete() for their superclasses and return false if the superclass' canDelete method returns false. The default method returns true if delete() has not been called and returned true.- Specified by:
canDelete
in interfaceNamedObjectOps
- Returns:
- true if this object can be deleted; false otherwise
-
onDelete
protected void onDelete()Complete the actions necessary to delete a named object. A subclass that overrides this method must call super.onDelete() at some point to complete the object deletion. This may not be within the onDelete method of the subclass if the deletion must be delayed for some reason (e.g., until some processing that is in progress has been completed). Once called, the object will be removed from the object-namer's tables and the object will be marked as deleted, so in general cleanup actions by a subclass should occur before it calls super.onDelete(). -
delete
public final boolean delete()Delete an object. An object can only be deleted once. If this method returns true, the object (if interned) will have been removed from the object namer tables.- Specified by:
delete
in interfaceNamedObjectOps
- Returns:
- true if the deletion request was accepted; false otherwise
-
isDeleted
public final boolean isDeleted()Determine if an object has been deleted. An object is deleted if the method delete() has been called and returned true.- Specified by:
isDeleted
in interfaceNamedObjectOps
- Returns:
- true if deleted; false otherwise
-
deletePending
public final boolean deletePending()Determine if an object is being deleted. An deletion is pending if the method delete() has been called and returned true but the deletion has not been completed.- Specified by:
deletePending
in interfaceNamedObjectOps
- Returns:
- true if deletion is pending; false otherwise
-