Class Element

  • All Implemented Interfaces:
    Serializable, Cloneable
    Direct Known Subclasses:
    Node, Property, PrototypeDocument

    public class Element
    extends Object
    implements Cloneable, Serializable
    Base class for elements. An element has a set of named properties. A prototype based inheritance mechanism is used. If properties cannot be be resolved directly, the prototype is consulted. This is important to remember when setting properties on properties: If you obtain a property A with getProperty() of an element E and then use setProperty() on A to set another property B, then it might be the case that A was in fact a property of the prototype! Elements have a parent, although they do not themself have the necessary machinery to be arranged in a tree structure. For that the Node class should be used instead. Finally, elements support the basic infrastructure to register listeners (observers).
    See Also:
    Serialized Form
    • Field Detail

      • prototype

        public Element prototype
        The prototype of this element.
      • properties

        protected Map<String,​Property> properties
        The properties of this element. For speed we maintain a map of properties. This might be null if there are no properties.
    • Constructor Detail

      • Element

        public Element​(Element prototype)
        Constructor
        Parameters:
        prototype - - the prototype
    • Method Detail

      • isPropertyLocal

        public boolean isPropertyLocal​(String name)
        Returns true if the property of the given name has a local value. Returns false if the property is inherited from the prototype.
        Parameters:
        name - -The property name
        Returns:
        properties - the properties contains the name
      • getProperty

        public Property getProperty​(String name)
        Returns the property of the given name. This property might be inherited from the prototype.
        Parameters:
        name - - The property name
        Returns:
        property - The founded property
      • getLocalProperty

        public Property getLocalProperty​(String name)
        Returns the property of the given name. If the element only inherits the property, then null is returned.
        Parameters:
        name - - the property name
        Returns:
        The property
      • getPropertyValue

        public <T> T getPropertyValue​(String name)
        Returns the value of the property of the given name.This value might be inherited from the prototype.
        Type Parameters:
        T - the checked type of the value
        Parameters:
        name - - The property name
        Returns:
        The property
      • hasFlag

        public boolean hasFlag​(String property)
        Returns the value of a boolean property.
        Parameters:
        property - - The property
        Returns:
        True - Has flag
      • getX

        public int getX()
        Returns the value of the x property. The value of the x property must be of type Integer.
        Returns:
        The x value
      • getY

        public int getY()
        Returns the value of the y property. The value of the y property must be of type Integer.
        Returns:
        The y value
      • getColor

        public Color getColor()
        Returns the value of the color property. The value of the color property must be of type Color.
        Returns:
        The color
      • setProperty

        public Property setProperty​(String name,
                                    Object value)
        Sets and returns the given property. If value is null, then the property is removed (hence in the future getProperty() will return the prototypical value). If the property is new, then it will be created - the prototype of the property will be the corresponding property of the prototype of the element.
        Parameters:
        name - - The property name
        value - - The property value
        Returns:
        The property object
      • setPropertyFromPath

        public void setPropertyFromPath​(String path,
                                        Object value)
        Set the given property from path
        Parameters:
        path - - The path of the property
        value - - The property value
      • setProperties

        public void setProperties​(Object[] properties)
      • getProperties

        public Set<Map.Entry<String,​Property>> getProperties()
        Get the properties stored in this element. The properties of the prototype are not included.
        Returns:
        The properties set
      • getParent

        public Element getParent()
        Returns the parent element.
        Returns:
        The parent element
      • addListener

        public void addListener​(EventListener l)
        Adds an event listener.
        Parameters:
        l - - the event listener
      • removeListener

        public void removeListener​(EventListener l)
        Removes an event listener.
        Parameters:
        l - - The event listener
      • accept

        public void accept​(Visitor visitor)
                    throws Exception
        Accept a visitor. This method is specialized in every subclass. Part of the visitor pattern.
        Parameters:
        visitor - - The visitor
        Throws:
        Exception - the visitor threw an exception.
      • acceptSafe

        public void acceptSafe​(Visitor visitor)
        Like to accept(), but cannot throw an Exception. If the visitor throws an exception, the program will fail with an assertion error.
        Parameters:
        visitor - - The visitor
      • getPrototype

        public Element getPrototype()
        Returns the prototype.
        Returns:
        The property element
      • getDocument

        public Document getDocument()
        Returns the document of this element.
        Returns:
        The document object
      • getTemplate

        public AbstractTemplate getTemplate()
        Returns the template of this element.
        Returns:
        The template
      • getPrototypeFromParent

        public Element getPrototypeFromParent​(Element parent)
        Return the proper prototype for this element stored in the parent. This is used by importInto().
        Parameters:
        parent - - The parent element
        Returns:
        - The property
      • importInto

        public void importInto​(Element parent)
        Imports the tree rooted at this element into the prototype structure of the given parent. This method does not actually insert this element into the parent.
        Parameters:
        parent - - The parent element
      • setPrototype

        public void setPrototype​(Element prototype)
        Sets the prototype of this element to the given argument. It also recursively reimports all properties by calling importInto(this) (thus resetting the prototype structure throughout the tree).
        Parameters:
        prototype - - The property element
      • getCommandManager

        public CommandManager getCommandManager()
        Get the command manager
        Returns:
        the commandManager
      • setCommandManager

        public void setCommandManager​(CommandManager commandManager)
        Set the command manager
        Parameters:
        commandManager - - The commandManager to set
      • getXPathTag

        public String getXPathTag()
        Computes the local tag of the XPath address. Needs to be overwritten by concrete instances
        Returns:
        local address of this element
      • getXPath

        public String getXPath()
        Computes the full path to this element
        Returns:
      • getXMLLabelKinds

        public String[] getXMLLabelKinds()
        Returns possible XML label kinds this element supports.
        Returns: