com.uppaal.model.core2
Class Element

java.lang.Object
  extended by com.uppaal.model.core2.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 Summary
 List<EventListener> listeners
           
protected  Map<String,Property> properties
          The properties of this element.
 Element prototype
          The prototype of this element.
 
Constructor Summary
Element(Element prototype)
           
 
Method Summary
 void accept(Visitor visitor)
          Accept a visitor.
 void acceptSafe(Visitor visitor)
          Like to accept(), but cannot throw an Exception.
 void addListener(EventListener l)
          Adds an event listener.
 Object clone()
          Returns a deep clone of the element.
 Color getColor()
          Returns the value of the color property.
 Document getDocument()
          Returns the document of this element.
 Property getLocalProperty(String name)
          Returns the property of the given name.
 Element getParent()
          Returns the parent element.
 Set<Map.Entry<String,Property>> getProperties()
          Get the properties stored in this element.
 Property getProperty(String name)
          Returns the property of the given name.
 Object getPropertyValue(String name)
          Returns the value of the property of the given name.
 Element getPrototype()
          Returns the prototype.
 Element getPrototypeFromParent(Element parent)
          Return the proper prototype for this element stored in the parent.
 AbstractTemplate getTemplate()
          Returns the template of this element.
 int getX()
          Returns the value of the x property.
 int getY()
          Returns the value of the y property.
 boolean hasFlag(String property)
          Returns the value of a boolean property.
 void importInto(Element parent)
          Imports the tree rooted at this element into the prototype structure of the given parent.
 boolean isPropertyLocal(String name)
          Returns true if the property of the given name has a local value.
 void removeListener(EventListener l)
          Removes an event listener.
 void setProperties(Object[] properties)
           
 Property setProperty(String name, Object value)
          Sets and returns the given property.
 void setPropertyFromPath(String path, Object value)
           
 void setPrototype(Element prototype)
          Sets the prototype of this element to the given argument.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

public List<EventListener> listeners

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)
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.


getProperty

public Property getProperty(String name)
Returns the property of the given name. This property might be inherited from the prototype.


getLocalProperty

public Property getLocalProperty(String name)
Returns the property of the given name. If the element only inherits the property, then null is returned.


getPropertyValue

public Object getPropertyValue(String name)
Returns the value of the property of the given name. This value might be inherited from the prototype.


hasFlag

public boolean hasFlag(String property)
Returns the value of a boolean property.


getX

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


getY

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


getColor

public Color getColor()
Returns the value of the color property. The value of the color property must be of type 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.


setPropertyFromPath

public void setPropertyFromPath(String path,
                                Object 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.


getParent

public Element getParent()
Returns the parent element.


addListener

public void addListener(EventListener l)
Adds an event listener.


removeListener

public void removeListener(EventListener l)
Removes an event listener.


accept

public void accept(Visitor visitor)
            throws Exception
Accept a visitor. This method is specialised in every subclass. Part of the visitor pattern.

Throws:
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.


getPrototype

public Element getPrototype()
Returns the prototype.


getDocument

public Document getDocument()
Returns the document of this element.


getTemplate

public AbstractTemplate getTemplate()
Returns the template of this element.


clone

public Object clone()
             throws CloneNotSupportedException
Returns a deep clone of the element. All properties are cloned. The clone has no parent and no prototype.

Overrides:
clone in class Object
Throws:
CloneNotSupportedException

getPrototypeFromParent

public Element getPrototypeFromParent(Element parent)
Return the proper prototype for this element stored in the parent. This is used by importInto().


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.


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).



Copyright © 2012 Uppsala University and Aalborg University. All Rights Reserved.