Class SimpleIdFactory

java.lang.Object
org.jhotdraw8.base.converter.SimpleIdFactory
All Implemented Interfaces:
IdFactory, IdResolver, IdSupplier

public class SimpleIdFactory extends Object implements IdFactory
SimpleIdFactory.
Author:
Werner Randelshofer
  • Constructor Details

    • SimpleIdFactory

      public SimpleIdFactory()
  • Method Details

    • reset

      public void reset()
      Description copied from interface: IdFactory
      Clears all ids.
      Specified by:
      reset in interface IdFactory
    • createId

      public @Nullable String createId(Object object)
      Description copied from interface: IdFactory
      Creates an id for the specified object. If the object already has an id, then that id is returned.
      Specified by:
      createId in interface IdFactory
      Parameters:
      object - the object
      Returns:
      the id
    • getId

      public String getId(Object object)
      Description copied from interface: IdSupplier
      Gets an id for the specified object. Returns null if the object has no id.
      Specified by:
      getId in interface IdSupplier
      Parameters:
      object - the object
      Returns:
      the id
    • setDocumentHome

      public void setDocumentHome(@Nullable URI documentHome)
      Specified by:
      setDocumentHome in interface IdFactory
    • relativize

      public @NonNull URI relativize(@NonNull URI uri)
      Description copied from interface: IdSupplier
      Relativize the given URI, so that it can be used for storage in a file.

      In the internal representation of a drawing, we store all URIs with absolute paths.

      In the external representation of a drawing, we try to store all URIs relative to the home folder of the document (document home).

      Specified by:
      relativize in interface IdSupplier
      Parameters:
      uri - an internal URI (typically an absolute path)
      Returns:
      an external URI (typically relative to document home)
    • getObject

      public Object getObject(String id)
      Description copied from interface: IdResolver
      Gets the object for the specified id. Returns null if the id has no object.
      Specified by:
      getObject in interface IdResolver
      Parameters:
      id - the id or null
      Returns:
      the object if present
    • absolutize

      public @NonNull URI absolutize(@NonNull URI uri)
      Description copied from interface: IdResolver
      Absolutize the given external URI, so that it can be used inside of a drawing (e.g. to access data from the URI).

      In the internal representation of a drawing, we store all URIs with absolute paths.

      In the external representation of a drawing, we try to store all URIs relative to the home folder of the document (document home).

      Specified by:
      absolutize in interface IdResolver
      Parameters:
      uri - an external URI (typically relative to document home)
      Returns:
      an internal URI (typically an absolute path)
    • putIdAndObject

      public Object putIdAndObject(@NonNull String id, @NonNull Object object)
      Description copied from interface: IdFactory
      Puts the id and the object for mapping between them.

      If the object already has an id, the old id is replaced.

      Specified by:
      putIdAndObject in interface IdFactory
      Parameters:
      id - the id
      object - the object
      Returns:
      the object that previously was assigned to this id
    • putIdToObject

      public Object putIdToObject(@NonNull String id, @NonNull Object object)
      Description copied from interface: IdFactory
      Puts the id for mapping to the specified object.
      Specified by:
      putIdToObject in interface IdFactory
      Parameters:
      id - the id
      object - the object
      Returns:
      the object that previously was assigned to this id
    • createId

      public String createId(Object object, @Nullable String prefix)
      Description copied from interface: IdFactory
      Creates an id for the specified object. If the object already has an id, then that id is returned.
      Specified by:
      createId in interface IdFactory
      Parameters:
      object - the object
      prefix - the desired prefix for the id
      Returns:
      the id
    • createId

      public @Nullable String createId(@NonNull Object object, @Nullable String prefix, @Nullable String suggestedId)
      Description copied from interface: IdFactory
      Creates an id for the specified object. If the object already has an id, then that id is returned. If the object has no id and the suggestedId has not been assigned to an object yet, then the suggestedId is used.
      Specified by:
      createId in interface IdFactory
      Parameters:
      object - the object
      prefix - the prefix used to create a new id, if the suggested id is taken
      suggestedId - the suggested id
      Returns:
      the id
    • getUriResolver

      public @NonNull UriResolver getUriResolver()
    • setUriResolver

      public void setUriResolver(@NonNull UriResolver uriResolver)