Package com.uppaal.model.core2
Class Element
- java.lang.Object
-
- com.uppaal.model.core2.Element
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
- Direct Known Subclasses:
Node,Property,PrototypeDocument
public class Element extends java.lang.Object implements java.lang.Cloneable, java.io.SerializableBase 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 java.util.List<EventListener>listenersprotected java.util.Map<java.lang.String,Property>propertiesThe properties of this element.ElementprototypeThe prototype of this element.
-
Method Summary
All Methods Instance Methods Concrete Methods 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.java.lang.Objectclone()Returns a deep clone of the element.java.awt.ColorgetColor()Returns the value of the color property.CommandManagergetCommandManager()Get the command managerDocumentgetDocument()Returns the document of this element.PropertygetLocalProperty(java.lang.String name)Returns the property of the given name.ElementgetParent()Returns the parent element.java.util.Set<java.util.Map.Entry<java.lang.String,Property>>getProperties()Get the properties stored in this element.PropertygetProperty(java.lang.String name)Returns the property of the given name.java.lang.ObjectgetPropertyValue(java.lang.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.java.lang.String[]getXMLLabelKinds()Returns possible XML label kinds this element supports.java.lang.StringgetXPath()Computes the full path to this elementjava.lang.StringgetXPathTag()Computes the local tag of the XPath address.intgetY()Returns the value of the y property.booleanhasFlag(java.lang.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(java.lang.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(java.lang.Object[] properties)PropertysetProperty(java.lang.String name, java.lang.Object value)Sets and returns the given property.voidsetPropertyFromPath(java.lang.String path, java.lang.Object value)Set the given property from pathvoidsetPrototype(Element prototype)Sets the prototype of this element to the given argument.
-
-
-
Field Detail
-
listeners
public java.util.List<EventListener> listeners
-
prototype
public Element prototype
The prototype of this element.
-
properties
protected java.util.Map<java.lang.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(java.lang.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(java.lang.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(java.lang.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 java.lang.Object getPropertyValue(java.lang.String name)
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
public boolean hasFlag(java.lang.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 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
public java.awt.Color getColor()
Returns the value of the color property. The value of the color property must be of typeColor.- Returns:
- The color
-
setProperty
public Property setProperty(java.lang.String name, java.lang.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 namevalue- - The property value- Returns:
- The property object
-
setPropertyFromPath
public void setPropertyFromPath(java.lang.String path, java.lang.Object value)Set the given property from path- Parameters:
path- - The path of the propertyvalue- - The property value
-
setProperties
public void setProperties(java.lang.Object[] properties)
-
getProperties
public java.util.Set<java.util.Map.Entry<java.lang.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 java.lang.Exception
Accept a visitor. This method is specialized in every subclass. Part of the visitor pattern.- Parameters:
visitor- - The visitor- Throws:
java.lang.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
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionReturns a deep clone of the element. All properties are cloned. The clone has no parent and no prototype.- Overrides:
clonein classjava.lang.Object- Returns:
- The clone object
- Throws:
java.lang.CloneNotSupportedException- the object cannot be cloned.
-
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 java.lang.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 java.lang.String getXPath()
Computes the full path to this element- Returns:
-
getXMLLabelKinds
public java.lang.String[] getXMLLabelKinds()
Returns possible XML label kinds this element supports.- Returns:
-
-