cb.petal
Class PetalObject

java.lang.Object
  |
  +--cb.petal.PetalObject
All Implemented Interfaces:
java.lang.Cloneable, PetalNode, java.io.Serializable
Direct Known Subclasses:
ActionTime, Attribute, Compartment, Defaults, Design, Event, ExternalDoc, FocusOfControl, Font, ItemLabel, Label, Mechanism, Parameter, Petal, QuidObject, SegLabel, SemanticInfo, View

public abstract class PetalObject
extends java.lang.Object
implements PetalNode

Super class for all petal objects which have a list of properties. Unfortunately, property names may occur multiply. This can happen, e.g., if there are multiple notes attached to a class. Thus it is not implemented with a HashMap as one might think.

Version:
$Id: PetalObject.java,v 1.25 2001/07/17 14:38:36 dahm Exp $
Author:
M. Dahm
See Also:
Serialized Form

Field Summary
static java.util.ArrayList EMPTY
           
protected  java.util.ArrayList params
           
 
Constructor Summary
protected PetalObject(PetalNode parent, java.lang.String name, java.util.ArrayList params)
           
protected PetalObject(PetalNode parent, java.lang.String name, java.util.Collection params)
           
protected PetalObject(java.lang.String name)
           
 
Method Summary
abstract  void accept(Visitor v)
           
 int addProperty(java.lang.String name, PetalNode value)
          Add a property (which may already exist, Petal files allow to define properties multiply).
protected  void addToList(java.lang.String prop_name, java.lang.String list_name, PetalObject o)
          Add object to some given list and create the list if necessary.
 java.lang.Object clone()
           
 void defineProperty(java.lang.String name, boolean value)
          Override property if exists already or add it if not.
 void defineProperty(java.lang.String name, double value)
          Override property if exists already or add it if not.
 void defineProperty(java.lang.String name, int value)
          Override property if exists already or add it if not.
 int defineProperty(java.lang.String name, PetalNode value)
          Override property if exists already or add it if not.
 void defineProperty(java.lang.String name, java.lang.String value)
          Override property if exists already or add it if not.
 boolean equals(Object o)
           
 int getChildCount()
           
 java.lang.String getKind()
           
 java.lang.String getLongestName()
           
 java.lang.String getName()
           
 java.util.ArrayList getNames()
           
 int getNoProperties()
           
 java.util.ArrayList getParameterList()
           
 PetalNode getParent()
           
 java.util.ArrayList getProperties(java.lang.String name)
           
 PetalNode getProperty(int i)
           
 PetalNode getProperty(java.lang.String name)
           
 boolean getPropertyAsBoolean(java.lang.String name)
           
 double getPropertyAsFloat(java.lang.String name)
           
 int getPropertyAsInteger(java.lang.String name)
           
 java.lang.String getPropertyAsString(java.lang.String name)
           
 java.util.ArrayList getPropertyList()
           
 java.lang.String getPropertyName(PetalNode value)
          This method uses the strict indexOf method to find the value.
 java.lang.Object[][] getPropertyTuples()
           
 java.lang.String getQualifiedName()
          Get fully qualified name for an object that must implement the Named interface and is contained by further Named objects.
 PetalFile getRoot()
           
 int indexOf(PetalNode value)
          This method is strict in that it does not use equals() to search the list of properties but ==, since values, in particular literals may occur more than once.
 void init()
          Perform any initial actions after all properties have been set up.
 void moveProperty(int from, int to)
          Move property within list of properties, i.e.
protected  void removeFromList(java.lang.String prop_name, PetalObject o)
          Remove object from some given list.
 void removeProperty(int index)
          Remove property at given index
 void removeProperty(java.lang.String name)
          Remove property with given name
 void setName(java.lang.String n)
           
 void setParameterList(java.util.ArrayList params)
           
 void setParent(PetalNode p)
           
 void setProperty(int i, java.lang.String name, PetalNode value)
          Override property at i, value's "parent" reference points to this object afterwards
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final java.util.ArrayList EMPTY

params

protected java.util.ArrayList params
Constructor Detail

PetalObject

protected PetalObject(PetalNode parent,
                      java.lang.String name,
                      java.util.ArrayList params)
Parameters:
parent - node in the petal tree, either another PetalObject or PetalFile
name - of the object, e.g., "ClassCategory"
params - list of parameters, e.g., "Class" "Logical View::templates::Class"

PetalObject

protected PetalObject(PetalNode parent,
                      java.lang.String name,
                      java.util.Collection params)
Parameters:
parent - node in the petal tree, either another PetalObject or PetalFile
name - of the object, e.g., "ClassCategory"
params - list of parameters, e.g., "Class" "Logical View::templates::Class"

PetalObject

protected PetalObject(java.lang.String name)
Parameters:
name - of the object, e.g., "ClassCategory"
Method Detail

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object
Returns:
shallow copy of object, do not forget to assign a new quid if you want to use it within the same model.

equals

public boolean equals(Object o)
Returns:
true if the name and all properties are equal without regarding the order of the properties.

init

public void init()
Perform any initial actions after all properties have been set up. Called by PetalParser when all properties have been defined or when a new object created by the user is added to the model.

setParent

public void setParent(PetalNode p)

getParent

public PetalNode getParent()

getKind

public java.lang.String getKind()
Specified by:
getKind in interface PetalNode

setName

public void setName(java.lang.String n)

getName

public java.lang.String getName()

getRoot

public final PetalFile getRoot()
Returns:
top-level root node of this model

setProperty

public final void setProperty(int i,
                              java.lang.String name,
                              PetalNode value)
Override property at i, value's "parent" reference points to this object afterwards

addProperty

public final int addProperty(java.lang.String name,
                             PetalNode value)
Add a property (which may already exist, Petal files allow to define properties multiply).
Returns:
index of property

indexOf

public final int indexOf(PetalNode value)
This method is strict in that it does not use equals() to search the list of properties but ==, since values, in particular literals may occur more than once.

getPropertyName

public final java.lang.String getPropertyName(PetalNode value)
This method uses the strict indexOf method to find the value.

getNoProperties

public int getNoProperties()
Returns:
number of properties

getChildCount

public int getChildCount()
Specified by:
getChildCount in interface PetalNode
Returns:
number of properties

defineProperty

public final int defineProperty(java.lang.String name,
                                PetalNode value)
Override property if exists already or add it if not.
Returns:
index of property

getProperty

public final PetalNode getProperty(int i)
Returns:
property at given index

getProperty

public final PetalNode getProperty(java.lang.String name)
Returns:
first occurrence of property name

defineProperty

public final void defineProperty(java.lang.String name,
                                 java.lang.String value)
Override property if exists already or add it if not.

getPropertyAsString

public java.lang.String getPropertyAsString(java.lang.String name)
Returns:
given property, or null if it doesn't exist.

getPropertyAsInteger

public int getPropertyAsInteger(java.lang.String name)
Returns:
given property, or Integer.MIN_VALUE if it doesn't exist.

defineProperty

public void defineProperty(java.lang.String name,
                           int value)
Override property if exists already or add it if not.

getPropertyAsBoolean

public boolean getPropertyAsBoolean(java.lang.String name)
Returns:
given property, or false if it doesn't exist.

defineProperty

public void defineProperty(java.lang.String name,
                           boolean value)
Override property if exists already or add it if not.

getPropertyAsFloat

public double getPropertyAsFloat(java.lang.String name)
Returns:
given property, or Double.MIN_VALUE if it doesn't exist.

defineProperty

public void defineProperty(java.lang.String name,
                           double value)
Override property if exists already or add it if not.

removeProperty

public void removeProperty(java.lang.String name)
Remove property with given name

removeProperty

public void removeProperty(int index)
Remove property at given index

moveProperty

public void moveProperty(int from,
                         int to)
Move property within list of properties, i.e. change order.

getLongestName

public java.lang.String getLongestName()
Returns:
the longest name in names list, needed for indentation issues

getProperties

public java.util.ArrayList getProperties(java.lang.String name)
Returns:
all properties with key "name"

getNames

public java.util.ArrayList getNames()
Returns:
all property names

getPropertyList

public java.util.ArrayList getPropertyList()
Returns:
all property values

getPropertyTuples

public java.lang.Object[][] getPropertyTuples()
Returns:
array of properties, where obj[i][0] == name and obj[i][1] == property

getParameterList

public java.util.ArrayList getParameterList()

setParameterList

public void setParameterList(java.util.ArrayList params)

addToList

protected void addToList(java.lang.String prop_name,
                         java.lang.String list_name,
                         PetalObject o)
Add object to some given list and create the list if necessary.

removeFromList

protected void removeFromList(java.lang.String prop_name,
                              PetalObject o)
Remove object from some given list.

getQualifiedName

public java.lang.String getQualifiedName()
Get fully qualified name for an object that must implement the Named interface and is contained by further Named objects. Typical nesting of an objectis (Design .. (ClassCategory ... (Class ...)))
Returns:
String like "Logical View::University::Professor"
See Also:
Named, Class, UseCase

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

accept

public abstract void accept(Visitor v)
Specified by:
accept in interface PetalNode