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>listenersprotected Map<String,Property>propertiesThe properties of this element.ElementprototypeThe prototype of this element. -
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidaccept(Visitor visitor)Accept a visitor.voidacceptSafe(Visitor visitor)Like to accept(), but cannot throw an Exception.voidaddListener(EventListener l)Adds an event listener.Objectclone()Returns a deep clone of the element.ColorgetColor()Returns the value of the color property.CommandManagergetCommandManager()Get the command managerDocumentgetDocument()Returns the document of this element.PropertygetLocalProperty(String name)Returns the property of the given name.ElementgetParent()Returns the parent element.Set<Map.Entry<String,Property>>getProperties()Get the properties stored in this element.PropertygetProperty(String name)Returns the property of the given name.ObjectgetPropertyValue(String name)Returns the value of the property of the given name.ElementgetPrototype()Returns the prototype.ElementgetPrototypeFromParent(Element parent)Return the proper prototype for this element stored in the parent.AbstractTemplategetTemplate()Returns the template of this element.intgetX()Returns the value of the x property.String[]getXMLLabelKinds()Returns possible XML label kinds this element supports.StringgetXPath()Computes the full path to this elementStringgetXPathTag()Computes the local tag of the XPath address.intgetY()Returns the value of the y property.booleanhasFlag(String property)Returns the value of a boolean property.voidimportInto(Element parent)Imports the tree rooted at this element into the prototype structure of the given parent.booleanisPropertyLocal(String name)Returns true if the property of the given name has a local value.voidremoveListener(EventListener l)Removes an event listener.voidsetCommandManager(CommandManager commandManager)Set the command managervoidsetProperties(Object[] properties)PropertysetProperty(String name, Object value)Sets and returns the given property.voidsetPropertyFromPath(String path, Object value)Set the given property from pathvoidsetPrototype(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:
clonein 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:
-