viper.api.impl
Class ConfigImpl

java.lang.Object
  extended byviper.api.impl.EventfulNodeHelper
      extended byviper.api.impl.ConfigImpl
All Implemented Interfaces:
java.lang.Cloneable, Config, Config.Edit, EventfulNode, Node, TransactionalNode, XmlVisibleNode

public class ConfigImpl
extends EventfulNodeHelper
implements Config, java.lang.Cloneable, XmlVisibleNode, EventfulNode, Config.Edit

Implements the Config interface of the viper.api, including all standard extensions. This means that it is editable, serializable to xml, and can take event listeners.


Nested Class Summary
static class ConfigImpl.DescNameChangeEvent
           
static class ConfigImpl.DescNameChangeUndoable
           
static class ConfigImpl.DescTypeChangeUndoable
           
 
Nested classes inherited from class viper.api.Config
Config.Edit
 
Nested classes inherited from class viper.api.extensions.TransactionalNode
TransactionalNode.Transaction
 
Field Summary
 
Fields inherited from class viper.api.impl.EventfulNodeHelper
childNodeType, notifyingListeners
 
Fields inherited from interface viper.api.Config
CONTENT, FILE, OBJECT
 
Constructor Summary
ConfigImpl(java.lang.String name, int type)
          Constructs a new descriptor class definition, with the given class name and type.
 
Method Summary
 java.lang.Object clone()
          Returns a copy of this node, unconnected to the parent, but with copies of the attribute config nodes.
 AttrConfig createAttrConfig(java.lang.String name, java.lang.String type, boolean dynamic, java.lang.Object def, AttrValueWrapper params)
          Note that this will not check the case of the type or the name, or check for spaces.
 boolean equals(java.lang.Object o)
          Checks to see that this descriptor class definition describes the same type of descriptor objects as the referenced object.
 AttrConfig getAttrConfig(java.lang.String name)
          Gets a specific attribute configuration.
 int getAttrConfigIndex(AttrConfig ac)
          Gets the index of the given config.
 java.util.Collection getAttrConfigs()
          Gets the configuration of each attribute attached to this descriptor.
 java.util.Iterator getAttributeConfigs()
          Gets the configuration of each attribute attached to this descriptor.
 Node getChild(int i)
          Gets the ith child.
 java.util.Iterator getChildren()
          Gets all the Node children of this Node.
 java.lang.String getDescName()
          Get the name of the descriptor.
 int getDescType()
          Get the descriptor type.
 Config.Edit getEditor()
          Gets an editor object for this node.
protected  java.util.logging.Logger getLogger()
           
 int getNumberOfChildren()
          Gets the count of children attached to this node.
 Node getParent()
          Gets the parent node.
 org.w3c.dom.Element getXMLFormat(org.w3c.dom.Document root)
          Get a new XML Element node representing this Node.
 boolean hasAttrConfig(java.lang.String name)
          Checks to see that a descriptor has an attribute with the given name.
 boolean hasChild(Node n)
          Checks to see if this node has the specified node among its children.
 int hashCode()
          Since there can only be one of a given type/name pair, this only returns the hash of the name and type.
protected  void helpSetChild(int i, Node n, TransactionalNode.Transaction t, boolean insert)
          Replace the child at index i with the given node.
 int indexOf(Node n)
          Gets the index of the given child node.
protected  void postHelpSetChild(int i, Node n, TransactionalNode.Transaction t, boolean insert)
          Invoked after the event has been generated for the corresponding helpSetChild call.
 void printConfig(java.io.PrintWriter pw)
          Old skool print config; exports the data in the old gtf format.
 void setDescName(java.lang.String str)
          Set the descriptor name.
 void setDescType(int i)
          Set the descriptor type.
 java.lang.String toString()
          Returns a old school gtf representation of the descriptor config.
 
Methods inherited from class viper.api.impl.EventfulNodeHelper
addChild, addChild, addNodeListener, begin, fireMajorNodeChanged, fireMinorNodeChanged, fireNodeChanged, getRoot, hasListeners, isNotifyingListeners, isWriteLocked, removeChild, removeChild, removeChild, removeNodeListener, setChild
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface viper.api.Node
addChild, getRoot, removeChild, removeChild, setChild
 
Methods inherited from interface viper.api.extensions.EventfulNode
addNodeListener, fireMajorNodeChanged, fireMinorNodeChanged, fireNodeChanged, isNotifyingListeners, removeNodeListener
 

Constructor Detail

ConfigImpl

public ConfigImpl(java.lang.String name,
                  int type)
Constructs a new descriptor class definition, with the given class name and type.

Parameters:
name - the name of the class
type - the descriptor type
Method Detail

getParent

public Node getParent()
Description copied from interface: Node
Gets the parent node. Root nodes return null

Specified by:
getParent in interface Node
Returns:
the node's parent
See Also:
Node.getParent()

getChildren

public java.util.Iterator getChildren()
Description copied from interface: Node
Gets all the Node children of this Node.

Specified by:
getChildren in interface Node
Returns:
a java.util.Iterator through all the node's children
See Also:
Node.getChildren()

getChild

public Node getChild(int i)
Description copied from interface: Node
Gets the ith child.

Specified by:
getChild in interface Node
Parameters:
i - the index of the child to get
Returns:
the child
See Also:
Node.getChild(int)

clone

public java.lang.Object clone()
Returns a copy of this node, unconnected to the parent, but with copies of the attribute config nodes.

See Also:
Object.clone()

getDescName

public java.lang.String getDescName()
Description copied from interface: Config
Get the name of the descriptor.

Specified by:
getDescName in interface Config
Returns:
the descriptor name
See Also:
Config.getDescName()

getDescType

public int getDescType()
Description copied from interface: Config
Get the descriptor type.

Specified by:
getDescType in interface Config
Returns:
FILE, OBJECT, or CONTENT
See Also:
Config.getDescType()

getAttrConfigs

public java.util.Collection getAttrConfigs()
Deprecated.  

Description copied from interface: Config
Gets the configuration of each attribute attached to this descriptor. It is preferred to use Config.getAttributeConfigs(), as that allows more freedom in the implementation.

Specified by:
getAttrConfigs in interface Config
Returns:
a (possibly empty) java.util.Collection of AttrConfig objects
See Also:
Config.getAttrConfigs()

equals

public boolean equals(java.lang.Object o)
Checks to see that this descriptor class definition describes the same type of descriptor objects as the referenced object.

See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Since there can only be one of a given type/name pair, this only returns the hash of the name and type. So if you have a hash table that uses multiple Config objects with the same name and type, you might want to subclass this to xor the result with getAttrConfigs().hashCode().

Returns:
getDescType() ^ getDescName().hashCode()

toString

public java.lang.String toString()
Returns a old school gtf representation of the descriptor config.

See Also:
Object.toString()

hasAttrConfig

public boolean hasAttrConfig(java.lang.String name)
Description copied from interface: Config
Checks to see that a descriptor has an attribute with the given name.

Specified by:
hasAttrConfig in interface Config
Parameters:
name - the name of the attribute to check for.
Returns:
true iff an attribute with the specified name may exist in this descriptor.
See Also:
Config.hasAttrConfig(java.lang.String)

getAttrConfigIndex

public int getAttrConfigIndex(AttrConfig ac)
Gets the index of the given config.

Parameters:
ac - the config for check for
Returns:
the index
Throws:
UnknownAttributeTypeException - if the config isn't found

getAttrConfig

public AttrConfig getAttrConfig(java.lang.String name)
Description copied from interface: Config
Gets a specific attribute configuration.

Specified by:
getAttrConfig in interface Config
Parameters:
name - The attribute to get.
Returns:
the configuration for the attribute with the given name
See Also:
Config.getAttrConfig(java.lang.String)

createAttrConfig

public AttrConfig createAttrConfig(java.lang.String name,
                                   java.lang.String type,
                                   boolean dynamic,
                                   java.lang.Object def,
                                   AttrValueWrapper params)
                            throws java.lang.IllegalArgumentException
Note that this will not check the case of the type or the name, or check for spaces.

Specified by:
createAttrConfig in interface Config
Parameters:
name - the name for the new attribute, such as "FaceBox" or "Comment"
type - the datatype to use, such as "http://viper#lvalue" or "bbox"
dynamic - true if the value can change over the life of an instance of a descriptor. Only valid for OBJECT descriptors.
def - a default value
params - any additional parameters that the data type must take, such as possible values for an lvalue
Returns:
the new AttrConfig, already attached to this Config
Throws:
java.lang.IllegalArgumentException - if attaching a dynamic attribute to a FILE or CONTENT Config, type is not a valid datatype, or params does not apply to the datatype
See Also:
Config.createAttrConfig(String, String, boolean, Object, AttrValueWrapper)

setDescName

public void setDescName(java.lang.String str)
Description copied from interface: Config.Edit
Set the descriptor name. You can't set it to an already existing name.

Specified by:
setDescName in interface Config.Edit
Parameters:
str - The new descriptor name
See Also:
Config.Edit.setDescName(java.lang.String)

setDescType

public void setDescType(int i)
                 throws java.lang.IllegalArgumentException
Description copied from interface: Config.Edit
Set the descriptor type. This might have dangerous consequences for casting.

Specified by:
setDescType in interface Config.Edit
Parameters:
i - OBJECT, CONTENT, etc.
Throws:
java.lang.IllegalArgumentException
See Also:
Config.Edit.setDescType(int)

printConfig

public void printConfig(java.io.PrintWriter pw)
                 throws java.io.IOException
Old skool print config; exports the data in the old gtf format.

Parameters:
pw - where to put the data
Throws:
java.io.IOException - if there is a problem while writing to the printwriter

getXMLFormat

public org.w3c.dom.Element getXMLFormat(org.w3c.dom.Document root)
Description copied from interface: XmlVisibleNode
Get a new XML Element node representing this Node.

Specified by:
getXMLFormat in interface XmlVisibleNode
Parameters:
root - the DOM Document root to use to generate the necessary elements.
Returns:
a new Element representing this Node
See Also:
XmlVisibleNode.getXMLFormat(org.w3c.dom.Document)

helpSetChild

protected void helpSetChild(int i,
                            Node n,
                            TransactionalNode.Transaction t,
                            boolean insert)
Description copied from class: EventfulNodeHelper
Replace the child at index i with the given node. If insert is set, makes the child at index i the given node and shifts i to i+1, i+1 to i+2, and so on. This should not generate an event.

Specified by:
helpSetChild in class EventfulNodeHelper
Parameters:
i - the index to insert/set
n - the node to insert
t - the transaction associated with the event, if it exists. Otherwise, it is null.
insert - true if the node should be inserted, false if the current node i should be replaced

postHelpSetChild

protected void postHelpSetChild(int i,
                                Node n,
                                TransactionalNode.Transaction t,
                                boolean insert)
Description copied from class: EventfulNodeHelper
Invoked after the event has been generated for the corresponding helpSetChild call. This is useful if you need to order your events. This should not generate an event.

Specified by:
postHelpSetChild in class EventfulNodeHelper
Parameters:
i - the index to insert/set
n - the node to insert
t - the transaction associated with the event, if it exists. Otherwise, it is null.
insert - true if the node should be inserted, false if the current node i should be replaced

getAttributeConfigs

public java.util.Iterator getAttributeConfigs()
Description copied from interface: Config
Gets the configuration of each attribute attached to this descriptor.

Specified by:
getAttributeConfigs in interface Config
Returns:
a (possibly empty) java.util.Iterator of AttrConfig objects
See Also:
Config.getAttributeConfigs()

getNumberOfChildren

public int getNumberOfChildren()
Description copied from interface: Node
Gets the count of children attached to this node.

Specified by:
getNumberOfChildren in interface Node
Returns:
The number of children currently attached to the node
See Also:
Node.getNumberOfChildren()

hasChild

public boolean hasChild(Node n)
Description copied from interface: Node
Checks to see if this node has the specified node among its children.

Specified by:
hasChild in interface Node
Parameters:
n - The node to check for.
Returns:
true if node n is a child of this node
See Also:
Node.hasChild(viper.api.Node)

indexOf

public int indexOf(Node n)
Description copied from interface: Node
Gets the index of the given child node.

Specified by:
indexOf in interface Node
Parameters:
n - The node to search for
Returns:
-1 if node does not have child n
See Also:
Node.indexOf(viper.api.Node)

getEditor

public Config.Edit getEditor()
Description copied from interface: Config
Gets an editor object for this node. Not all implementations of the API will be editable. Those versions should return null for this method.

Specified by:
getEditor in interface Config
Returns:
an editor object for this config.
See Also:
Config.getEditor()

getLogger

protected java.util.logging.Logger getLogger()
Specified by:
getLogger in class EventfulNodeHelper