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:


  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);
       }
  }
 
Additional code (indicated by an ellipsis) is, of course, necessary to do anything useful.
  • Constructor Details

  • Method Details

    • clone

      protected Object clone() throws CloneNotSupportedException
      Creates and returns a copy of this object. This method will throw the exception CloneNotSupportedException if the object is interned.
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException - a clone could not be created
      See Also:
    • getObjectNamer

      protected DefaultObjectNamer<T> 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 interface NamedObjectOps
      Returns:
      true if the object is interned; false if not
    • getName

      public final String getName()
      Get a named object's name.
      Specified by:
      getName in interface NamedObjectOps
      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 interface NamedObjectOps
      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 interface NamedObjectOps
      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 interface NamedObjectOps
      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 interface NamedObjectOps
      Returns:
      true if deletion is pending; false otherwise