Class AbstractFigureFactory

java.lang.Object
org.jhotdraw8.draw.io.AbstractFigureFactory
All Implemented Interfaces:
FigureFactory
Direct Known Subclasses:
DefaultFigureFactory

public abstract class AbstractFigureFactory extends Object implements FigureFactory
AbstractFigureFactory.
Author:
Werner Randelshofer
  • Constructor Details

    • AbstractFigureFactory

      public AbstractFigureFactory()
    • AbstractFigureFactory

      public AbstractFigureFactory(@Nullable org.jhotdraw8.base.converter.IdFactory idFactory)
  • Method Details

    • addConverter

      public <T> void addConverter(MapAccessor<T> key, org.jhotdraw8.base.converter.Converter<T> converter)
      Adds a converter for the specified key.
      Type Parameters:
      T - the type of the value
      Parameters:
      key - the key
      converter - the converter
    • addConverterForType

      public void addConverterForType(Type fullValueType, org.jhotdraw8.base.converter.Converter<?> converter)
      Adds a converter.
      Parameters:
      fullValueType - A value type returned by MapAccessor.getFullValueType();.
      converter - the converter
    • addConverterForType

      public void addConverterForType(Type fullValueType, org.jhotdraw8.base.converter.Converter<?> converter, boolean force)
    • addDefaultValue

      public <T> void addDefaultValue(Class<? extends Figure> figure, MapAccessor<T> acc, T value)
    • addFigure

      public void addFigure(String name, @NonNull Class<? extends Figure> figureClass)
      Adds the provided mappings of XML attribute names from/to Figures.

      figureClass.newInstance() is used to instantiate a figure from a name.

      If a figure with this name has already been added, it will be replaced by this figure.

      Parameters:
      name - The element name
      figureClass - The figure class is used both for instantiation of a new figure and for determining the name of a figure.
    • addFigureAttributeKeys

      public void addFigureAttributeKeys(Class<? extends Figure> f, @NonNull Iterable<MapAccessor<?>> keys)
      Adds the provided keys to the figure.
      Parameters:
      f - the figure
      keys - the keys
    • addFigureKeysAndNames

      public void addFigureKeysAndNames(String figureName, @NonNull Class<? extends Figure> f)
    • addFigureKeysAndNames

      public void addFigureKeysAndNames(String figureName, @NonNull Class<? extends Figure> f, @NonNull Iterable<MapAccessor<?>> keys)
    • addFigureKeysAndNames

      public void addFigureKeysAndNames(Class<? extends Figure> f, @NonNull Collection<MapAccessor<?>> keys)
    • addKey

      public void addKey(Class<? extends Figure> figure, String name, MapAccessor<?> key)
      Adds the provided mapping of XML attribute names from/to MapAccessors.

      The same key can be added more than once.

      Parameters:
      figure - the figure
      name - The attribute name
      key - The key
    • addKeys

      public void addKeys(Class<? extends Figure> f, @NonNull HashMap<String,MapAccessor<?>> keys)
      Adds the provided mapping of XML attribute names from/to MapAccessors.

      The same key can be added more than once.

      Parameters:
      f - The figure
      keys - The mapping from attribute names to keys
    • addNodeListKey

      public void addNodeListKey(Class<? extends Figure> figure, String name, MapAccessor<?> key)
      Adds the provided keys to the figure.
      Parameters:
      figure - the figure
      name - the element name
      key - the keys
    • addSkipAttribute

      public void addSkipAttribute(Class<? extends Figure> figure, String attributeName)
      Adds an attribute to the list of attributes which will be skipped when reading the DOM.
      Parameters:
      figure - the figure class
      attributeName - the attribute name
    • addSkipElement

      public void addSkipElement(String elementName)
      Adds an element to the list of elements which will be skipped when reading the DOM.
      Parameters:
      elementName - the element name
    • addSkipFigure

      public void addSkipFigure(Class<? extends Figure> figure)
      Adds a figure class to the list of Figures which will be skipped when writing the DOM.
      Parameters:
      figure - The figure class
    • checkConverters

      public void checkConverters(boolean throwException, @NonNull Consumer<String> logger) throws IllegalStateException
      Throws:
      IllegalStateException
    • clearAttributeMap

      public void clearAttributeMap()
      Clears the mapping of XML attributes from/to MapAccessors.
    • clearElementMap

      public void clearElementMap()
      Clears the mapping of XML attributes from/to MapAccessors.
    • getKeyByElementName

      public MapAccessor<?> getKeyByElementName(@NonNull Figure f, String elementName) throws IOException
      Description copied from interface: FigureFactory
      Maps an XML element name to a key.
      Specified by:
      getKeyByElementName in interface FigureFactory
      Parameters:
      f - the figure
      elementName - the name
      Returns:
      the key
      Throws:
      IOException - if the factory does not support the name for the specified figure
    • figureAttributeKeys

      public @NonNull Set<MapAccessor<?>> figureAttributeKeys(@NonNull Figure f)
      Description copied from interface: FigureFactory
      Returns all keys for the specified figure which should be converted into element attributes.
      Specified by:
      figureAttributeKeys in interface FigureFactory
      Parameters:
      f - The figure
      Returns:
      an immutable set
    • figureNodeListKeys

      public @NonNull Set<MapAccessor<?>> figureNodeListKeys(@NonNull Figure f)
      Description copied from interface: FigureFactory
      Returns all keys for the specified figure which should be converted into a node list.
      Specified by:
      figureNodeListKeys in interface FigureFactory
      Parameters:
      f - The figure
      Returns:
      an immutable set
    • getElementNameByFigure

      public @Nullable String getElementNameByFigure(@NonNull Figure f) throws IOException
      Description copied from interface: FigureFactory
      Maps a figure to an XML element name.
      Specified by:
      getElementNameByFigure in interface FigureFactory
      Parameters:
      f - the figure
      Returns:
      the name
      Throws:
      IOException - if the factory does not support this figure
    • getDefaultValue

      public <T> T getDefaultValue(@NonNull Figure f, @NonNull MapAccessor<T> key)
      Description copied from interface: FigureFactory
      Returns the default for the key. The default value used for persistent storage may be different from the default value defined in the key.
      Specified by:
      getDefaultValue in interface FigureFactory
      Type Parameters:
      T - The type of the value
      Parameters:
      f - The figure
      key - The key
      Returns:
      the default value
    • getIdFactory

      public @Nullable org.jhotdraw8.base.converter.IdFactory getIdFactory()
    • setIdFactory

      public void setIdFactory(@Nullable org.jhotdraw8.base.converter.IdFactory idFactory)
    • getObjectIdAttribute

      public String getObjectIdAttribute()
      Returns the name of the object id attribute. The object id attribute is used for referencing other objects in the XML file.

      The default value is "oid".

      Specified by:
      getObjectIdAttribute in interface FigureFactory
      Returns:
      name of the object id attribute
    • setObjectIdAttribute

      public void setObjectIdAttribute(String newValue)
      Sets the name of the object id attribute. The object id attribute is used for referencing other objects in the XML file.
      Parameters:
      newValue - name of the object id attribute
    • isDefaultValue

      public <T> boolean isDefaultValue(@NonNull Figure f, @NonNull MapAccessor<T> key, @Nullable T value)
      Description copied from interface: FigureFactory
      Returns true if the specified value is the default for the given key.
      Specified by:
      isDefaultValue in interface FigureFactory
      Type Parameters:
      T - The type of the value
      Parameters:
      f - The figure
      key - The key
      value - the value
      Returns:
      true if the value is the default value
    • getElementNameByKey

      public String getElementNameByKey(@NonNull Figure f, MapAccessor<?> key) throws IOException
      Description copied from interface: FigureFactory
      Maps a key to a XML element name. The name used for persistent storage may be different from the name defined in the key.

      The name can be an empty String "" for the key returned by FigureFactory.figureNodeListKeys(org.jhotdraw8.draw.figure.Figure) if the figure has exactly one node list key. In this case, the node list will be added directly as children to the figure. The name of a node list key must not be equal to the name of a figure, because child figure elements are also added as child elements.

      Specified by:
      getElementNameByKey in interface FigureFactory
      Parameters:
      f - the figure
      key - the key
      Returns:
      The name.
      Throws:
      IOException - if the factory does not support the key for the specified figure
    • getAttributeNameByKey

      public String getAttributeNameByKey(@NonNull Figure f, MapAccessor<?> key) throws IOException
      Description copied from interface: FigureFactory
      Maps a key to a XML attribute name. The name used for persistent storage may be different from the name defined in the key.
      Specified by:
      getAttributeNameByKey in interface FigureFactory
      Parameters:
      f - the figure
      key - the key
      Returns:
      The name.
      Throws:
      IOException - if the factory does not support the key for the specified figure
    • createFigureByElementName

      public @NonNull Figure createFigureByElementName(String elementName) throws IOException
      Description copied from interface: FigureFactory
      Creates a new figure given the name of an XML element.
      Specified by:
      createFigureByElementName in interface FigureFactory
      Parameters:
      elementName - the name
      Returns:
      the figure
      Throws:
      IOException - if the factory does not support this name
    • getKeyByAttributeName

      public @Nullable MapAccessor<?> getKeyByAttributeName(@NonNull Figure f, String attributeName)
      Description copied from interface: FigureFactory
      Maps an XML attribute name to a key.
      Specified by:
      getKeyByAttributeName in interface FigureFactory
      Parameters:
      f - the figure
      attributeName - the name
      Returns:
      the key
    • nodeListToValue

      public <T> @NonNull T nodeListToValue(@NonNull MapAccessor<T> key, @NonNull List<Node> nodeList)
      Description copied from interface: FigureFactory
      Maps a XML node list to a value.

      The node list does not contain elements with a name that conflicts with the names returned by FigureFactory.getElementNameByFigure(org.jhotdraw8.draw.figure.Figure).

      Specified by:
      nodeListToValue in interface FigureFactory
      Type Parameters:
      T - the type of the value
      Parameters:
      key - the key
      nodeList - the nodeList
      Returns:
      the mapped attribute value.
    • removeKey

      public void removeKey(MapAccessor<?> key)
      Globally removes the specified key.
      Parameters:
      key - the key
    • needsIdResolver

      public <T> boolean needsIdResolver(MapAccessor<T> key) throws IOException
      Specified by:
      needsIdResolver in interface FigureFactory
      Throws:
      IOException
    • stringToValue

      public <T> T stringToValue(@NonNull MapAccessor<T> key, @NonNull String string) throws IOException
      Description copied from interface: FigureFactory
      Maps an XML attribute value to a value.
      Specified by:
      stringToValue in interface FigureFactory
      Type Parameters:
      T - the type of the value
      Parameters:
      key - the key
      string - the XML attribute value
      Returns:
      the mapped value
      Throws:
      IOException - if the factory does not support a mapping for the specified key
    • getConverter

      protected <T> @NonNull org.jhotdraw8.base.converter.Converter<T> getConverter(@NonNull MapAccessor<T> key) throws IOException
      Throws:
      IOException
    • valueToNodeList

      public void valueToNodeList(@NonNull MapAccessor<?> key, Object value, @NonNull XMLStreamWriter w) throws XMLStreamException
      Description copied from interface: FigureFactory
      Maps a value to a XML node list.

      The node list may not contain elements with a name that conflicts with the names returned by FigureFactory.getElementNameByFigure(org.jhotdraw8.draw.figure.Figure).

      Specified by:
      valueToNodeList in interface FigureFactory
      Parameters:
      key - the key
      value - the value
      w - the writer for creating the node list.
      Throws:
      XMLStreamException
    • valueToString

      public <T> @NonNull String valueToString(@NonNull MapAccessor<T> key, T value) throws IOException
      Description copied from interface: FigureFactory
      Maps a value to an XML attribute value.
      Specified by:
      valueToString in interface FigureFactory
      Type Parameters:
      T - the type of the value
      Parameters:
      key - the key
      value - the value
      Returns:
      the mapped attribute value
      Throws:
      IOException - if the factory does not support a mapping for the specified key