Package com.uppaal.model.core2
Class Element
java.lang.Object
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
Fields Modifier and Type Field Description List<EventListener>
listeners
protected Map<String,Property>
properties
The properties of this element.Element
prototype
The prototype of this element. -
Constructor Summary
-
Method Summary
Modifier and Type Method Description 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.CommandManager
getCommandManager()
Get the command managerDocument
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.String[]
getXMLLabelKinds()
Returns possible XML label kinds this element supports.String
getXPath()
Computes the full path to this elementString
getXPathTag()
Computes the local tag of the XPath address.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
setCommandManager(CommandManager commandManager)
Set the command managervoid
setProperties(Object[] properties)
Property
setProperty(String name, Object value)
Sets and returns the given property.void
setPropertyFromPath(String path, Object value)
Set the given property from pathvoid
setPrototype(Element prototype)
Sets the prototype of this element to the given argument.
-
Field Details
-
listeners
-
prototype
The prototype of this element. -
properties
The properties of this element. For speed we maintain a map of properties. This might be null if there are no properties.
-
-
Constructor Details
-
Element
Constructor- Parameters:
prototype
- - the prototype
-
-
Method Details
-
isPropertyLocal
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
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
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
Returns the value of the property of the given name. This value might be inherited from the prototype.- Parameters:
name
- - The property name- Returns:
- The property
-
hasFlag
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 typeInteger
.- Returns:
- The x value
-
getY
public int getY()Returns the value of the y property. The value of the y property must be of typeInteger
.- Returns:
- The y value
-
getColor
Returns the value of the color property. The value of the color property must be of typeColor
.- Returns:
- The color
-
setProperty
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 namevalue
- - The property value- Returns:
- The property object
-
setPropertyFromPath
Set the given property from path- Parameters:
path
- - The path of the propertyvalue
- - The property value
-
setProperties
-
getProperties
Get the properties stored in this element. The properties of the prototype are not included.- Returns:
- The properties set
-
getParent
Returns the parent element.- Returns:
- The parent element
-
addListener
Adds an event listener.- Parameters:
l
- - the event listener
-
removeListener
Removes an event listener.- Parameters:
l
- - The event listener
-
accept
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
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
Returns the prototype.- Returns:
- The property element
-
getDocument
Returns the document of this element.- Returns:
- The document object
-
getTemplate
Returns the template of this element.- Returns:
- The template
-
clone
Returns a deep clone of the element. All properties are cloned. The clone has no parent and no prototype.- Overrides:
clone
in classObject
- Returns:
- The clone object
- Throws:
CloneNotSupportedException
- the object cannot be cloned.
-
getPrototypeFromParent
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
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
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
Get the command manager- Returns:
- the commandManager
-
setCommandManager
Set the command manager- Parameters:
commandManager
- - The commandManager to set
-
getXPathTag
Computes the local tag of the XPath address. Needs to be overwritten by concrete instances- Returns:
- local address of this element
-
getXPath
Computes the full path to this element- Returns:
-
getXMLLabelKinds
Returns possible XML label kinds this element supports.- Returns:
-