Interface FigureFactory

All Known Implementing Classes:
AbstractFigureFactory, DefaultFigureFactory

public interface FigureFactory
FigureFactory.
Author:
Werner Randelshofer
  • Method Details

    • getElementNameByFigure

      @Nullable String getElementNameByFigure(Figure f) throws IOException
      Maps a figure to an XML element name.
      Parameters:
      f - the figure
      Returns:
      the name
      Throws:
      IOException - if the factory does not support this figure
    • createFigureByElementName

      Figure createFigureByElementName(String elementName) throws IOException
      Creates a new figure given the name of an XML element.
      Parameters:
      elementName - the name
      Returns:
      the figure
      Throws:
      IOException - if the factory does not support this name
    • getAttributeNameByKey

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

      @Nullable MapAccessor<?> getKeyByAttributeName(Figure f, String name)
      Maps an XML attribute name to a key.
      Parameters:
      f - the figure
      name - the name
      Returns:
      the key
    • getElementNameByKey

      String getElementNameByKey(Figure f, MapAccessor<?> key) throws IOException
      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 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.

      Parameters:
      f - the figure
      key - the key
      Returns:
      The name.
      Throws:
      IOException - if the factory does not support the key for the specified figure
    • getKeyByElementName

      MapAccessor<?> getKeyByElementName(Figure f, String name) throws IOException
      Maps an XML element name to a key.
      Parameters:
      f - the figure
      name - the name
      Returns:
      the key
      Throws:
      IOException - if the factory does not support the name for the specified figure
    • valueToString

      <T> String valueToString(MapAccessor<T> key, T value) throws IOException
      Maps a value to an XML attribute value.
      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
    • valueToNodeList

      void valueToNodeList(MapAccessor<?> key, Object value, XMLStreamWriter w) throws XMLStreamException
      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 getElementNameByFigure(org.jhotdraw8.draw.figure.Figure).

      Parameters:
      key - the key
      value - the value
      w - the writer for creating the node list.
      Throws:
      XMLStreamException
    • nodeListToValue

      <T> @Nullable T nodeListToValue(MapAccessor<T> key, List<Node> nodeList)
      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 getElementNameByFigure(org.jhotdraw8.draw.figure.Figure).

      Type Parameters:
      T - the type of the value
      Parameters:
      key - the key
      nodeList - the nodeList
      Returns:
      the mapped attribute value.
    • stringToValue

      <T> @Nullable T stringToValue(MapAccessor<T> key, String cdata) throws IOException
      Maps an XML attribute value to a value.
      Type Parameters:
      T - the type of the value
      Parameters:
      key - the key
      cdata - the XML attribute value
      Returns:
      the mapped value
      Throws:
      IOException - if the factory does not support a mapping for the specified key
    • needsIdResolver

      <T> boolean needsIdResolver(MapAccessor<T> key) throws IOException
      Throws:
      IOException
    • getDefaultValue

      <T> @Nullable T getDefaultValue(Figure f, MapAccessor<T> key)
      Returns the default for the key. The default value used for persistent storage may be different from the default value defined in the key.
      Type Parameters:
      T - The type of the value
      Parameters:
      f - The figure
      key - The key
      Returns:
      the default value
    • isDefaultValue

      default <T> boolean isDefaultValue(Figure f, MapAccessor<T> key, @Nullable T value)
      Returns true if the specified value is the default for the given key.
      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
    • figureAttributeKeys

      Set<MapAccessor<?>> figureAttributeKeys(Figure f)
      Returns all keys for the specified figure which should be converted into element attributes.
      Parameters:
      f - The figure
      Returns:
      an immutable set
    • figureNodeListKeys

      Set<MapAccessor<?>> figureNodeListKeys(Figure f)
      Returns all keys for the specified figure which should be converted into a node list.
      Parameters:
      f - The figure
      Returns:
      an immutable set
    • toExternalDrawing

      default Drawing toExternalDrawing(Drawing internal)
      Creates an external representation of the drawing.

      Note: this method must not change the provided internal drawing.

      The default implementation returns the same drawing.

      Parameters:
      internal - an internal representation of the drawing
      Returns:
      An external representation of the drawing.
    • fromExternalDrawing

      default Drawing fromExternalDrawing(Drawing external)
      Creates an internal representation of the drawing.

      Note: this method may change the provided external drawing.

      The default implementation returns the same drawing.

      Parameters:
      external - an external representation of the drawing
      Returns:
      An internal representation of the drawing.
    • getStylesheetsKey

      default MapAccessor<ImmutableList<URI>> getStylesheetsKey()
      Returns the stylesheets keys.
      Returns:
      The stylesheets key of the Drawing object. Return null if stylesheets shall not be supported. The default implementation returns Drawing.AUTHOR_STYLESHEETS.
    • getObjectIdAttribute

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