com.pnp.xfeature.data
Class ModelParser

java.lang.Object
  extended by com.pnp.xfeature.data.ModelParser

public class ModelParser
extends java.lang.Object

A set of static methods used to parse the XML file (in its DOM tree representation) and thus extract the necessary data.

Author:
Kamil Ekstein, created on 16.11.2004, extended in March 2005 by Ondrej Rohlik

Field Summary
static java.lang.String FMTLC_DEFAULTMODELNAME
          Deprecated.  
static int NOT_A_NODE_DISPLAY_TYPE
           
static int XFEATURE_DISPLAYTYPE_CARDINALITY
           
static int XFEATURE_DISPLAYTYPE_NODE
           
static int XFEATURE_DISPLAYTYPE_NONE
           
static int XFEATURE_DISPLAYTYPE_PROPERTY
           
static int XFEATURE_DISPLAYTYPE_PROPERTYSET
           
static int XFEATURE_DISPLAYTYPE_ROOT
           
 
Constructor Summary
ModelParser()
           
 
Method Summary
static void addRequiredCardinalityAndPropertySets(FeatureDiagramModel diagram, org.w3c.dom.Node parent)
           
static java.util.List getAvailableNodeChildren(org.w3c.dom.Node node, org.w3c.dom.Document metaModel)
          Returns a list of possible child nodes of the given node according to the entries in the metaModel
static org.w3c.dom.Node getDisplayModelEntryFor(org.w3c.dom.Document displayModel, java.lang.String node)
          Returns the node from the display model XML file that describes how to display the node (figurable, i.e. node, property, propertyset)
static java.lang.String getDisplayModelProperty(org.w3c.dom.Document displayModel, java.lang.String displayFormat, java.lang.String node, java.lang.String property)
          Returns the given display model property of the given feature model node, i.e. the font, line width, etc.
static java.util.List getDisplayNodeNames(org.w3c.dom.Document metamodel)
          Returns a list of names of nodes that can be displayed on a canvas of the editor, i.e. nodes, properties, property sets, and cardinalities The list has doubled size, every second element is the parent property set (or an empty string if the parent is not a property set)
static java.util.List getDisplayNodes(org.w3c.dom.Document metamodel)
          Returns a list of nodes that can be displayed on a canvas of the editor, i.e. nodes, properties, property sets, and cardinalities
static java.util.List getElementChildren(org.w3c.dom.Node element)
          Returns a list of elements children that have the passed name
static java.util.List getElementChildrenByName(org.w3c.dom.Node element, java.lang.String name)
          Returns a list of elements children that have the passed name
static long getElementId(org.w3c.dom.Node element)
          returns the element's unique ID - a positive integer
static java.util.List getElementsThat(org.w3c.dom.Document document, java.lang.String tag, java.lang.String attr, java.lang.String value)
          Returns a list of those elements from document that have the given tag and their attribute attr equals to value
static java.util.List getFigurativeNodes(org.w3c.dom.Document metamodel)
          Returns a list of nodes (xml) that can be drawn to canvas as a selectable, editable, moveable, etc. feature model nodes
static java.util.List getChildrenThat(java.util.List list, org.w3c.dom.Node node, java.lang.String name)
          Returns a list of node's child nodes that have the given name
static int getIndentCount(org.w3c.dom.Node node)
          Tells what is the depth of this node in DOM model
static java.lang.String getMetamodelElementDisplayType(org.w3c.dom.Node node)
          Reads the display type from the given metamodel node, i.e. returns node, property, propertyset, and cardinality
static int getMetamodelElementDisplayTypeConstant(java.lang.String s)
          Transforms the string to constant
static org.w3c.dom.Node getMetamodelEntryFor(org.w3c.dom.Document metamodel, java.lang.String node)
          Returns the metamodel xml element describing the meta characteristics of the given node
static java.lang.String getMetamodelFilename(org.w3c.dom.Document dom)
          Analyses the document in order to find the metamodel link i.e. the filename where the appropriate metamodel is saved.
static java.lang.String getMetamodelFilename(java.lang.String loc)
          Extracts the path to the meta model from Schema location string.
static java.lang.String getModelName(org.w3c.dom.Document dom)
          Reads the name of the model, i.e. the name attr of the root .xfm file element
static java.lang.String getNodeAttribute(org.w3c.dom.Node node, java.lang.String attribute)
          Reads the given attribute of the node if available
static org.w3c.dom.Node getNodeCardinality(org.w3c.dom.Document metaModel, org.w3c.dom.Node node)
          Returns the cardinality for the passed node
static java.lang.String getNodeDisplayType(org.w3c.dom.Document metaModel, org.w3c.dom.Node node)
          Returns the display type (see above getMetamodelElementDisplayType) for the passed node according to the metaModel
static java.lang.String getNodeChildValue(org.w3c.dom.Document metamodel, org.w3c.dom.Node node, java.lang.String description)
          Returns the value of the value attribute of the given child of node.
static int getNodePosition(org.w3c.dom.Node parent, long id)
          Returns an position index within the parent of node with id id
static int getNodePosition(org.w3c.dom.Node parent, org.w3c.dom.Node node)
          Traverse the list of child nodes of the "parent" naode and returns an index of "node" node.
static org.w3c.dom.Node getNodePropertySet(org.w3c.dom.Document metaModel, org.w3c.dom.Node node, java.lang.String name)
          Returns the property set node for of the given name for the passed node
static java.lang.String getParentPropertySetIfAny(org.w3c.dom.Document metamodel, org.w3c.dom.Node node)
          Returns name of a property set that is a parent node of specified property node
static java.lang.String getPropertyDefaultValue(org.w3c.dom.Node node)
          Reads the display type from the given metamodel node, i.e. returns node, property, propertyset, and cardinality
static java.util.List getPropertyNodes(org.w3c.dom.Document metamodel)
          Returns a list of nodes (xml) that are properties of a feature model node
static org.w3c.dom.Node getPropertySet(org.w3c.dom.Node parentNode, java.lang.String propertySet)
          Returns property set DOM node specified by name
static int getPropertySetIndex(org.w3c.dom.Node parentNode, org.w3c.dom.Node propertySetNode, org.w3c.dom.Document metamodelDocument)
          Return the position of the parameter among the other parameters of the same type.
static org.w3c.dom.Node getSequence(org.w3c.dom.Document metamodel, java.lang.String nodeName)
          Return the sequence node for the passed node name from the metamodel
static org.w3c.dom.Node getSubElementByTagName(org.w3c.dom.Node node, java.lang.String subElementName)
          Scans the recursive structure of the given node and returns the sub-node given by subElementName path (using '/' as a delimiter - see getNodeChildValue())
static java.lang.String getTooltip(org.w3c.dom.Document metaModel, org.w3c.dom.Node node)
          searches given node for ShortDescription descendant and returns its content to be later displayed to the user as a tool tip
static org.w3c.dom.xpath.XPathResult getXPathResult(org.w3c.dom.Node node, java.lang.String xPath)
          uses the org.w3c.dom.xpath pacakge to query a DOM Documents with XPath expressions
static java.lang.String getXPathValueApache(org.w3c.dom.Document document, java.lang.String xPath)
          Get value of the node specified by an XPath.
static boolean isCardinalityNode(org.w3c.dom.Node node)
          Checks wheather a node is a cardinality node
static boolean isCorrectNodeType(org.w3c.dom.Node node, java.lang.String type)
          Checks wheather a node is a node, property, or property setnode
static boolean isPropertyNode(org.w3c.dom.Node node)
          Checks wheather a node is a property node
static boolean isPropertySetNode(org.w3c.dom.Node node)
          Checks wheather a node is a property set node
static java.lang.String removeIndex(java.lang.String s)
          Return the string where index in brackets e.g. "(3)" is removed.
static boolean setGlobalConstraintValue(FeatureDiagramModel diagram, java.lang.String description, java.lang.String value)
          The same as getNodeChildValue but the value is stored to the appropriate attribute of the given node
static boolean setNodeChildValue(org.w3c.dom.Document metamodel, org.w3c.dom.Node node, java.lang.String description, java.lang.String value)
          The same as getNodeChildValue but the value is stored to the appropriate attribute of the given node
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FMTLC_DEFAULTMODELNAME

public static final java.lang.String FMTLC_DEFAULTMODELNAME
Deprecated. 
See Also:
Constant Field Values

XFEATURE_DISPLAYTYPE_NONE

public static final int XFEATURE_DISPLAYTYPE_NONE
See Also:
Constant Field Values

XFEATURE_DISPLAYTYPE_CARDINALITY

public static final int XFEATURE_DISPLAYTYPE_CARDINALITY
See Also:
Constant Field Values

XFEATURE_DISPLAYTYPE_NODE

public static final int XFEATURE_DISPLAYTYPE_NODE
See Also:
Constant Field Values

XFEATURE_DISPLAYTYPE_PROPERTY

public static final int XFEATURE_DISPLAYTYPE_PROPERTY
See Also:
Constant Field Values

XFEATURE_DISPLAYTYPE_PROPERTYSET

public static final int XFEATURE_DISPLAYTYPE_PROPERTYSET
See Also:
Constant Field Values

XFEATURE_DISPLAYTYPE_ROOT

public static final int XFEATURE_DISPLAYTYPE_ROOT
See Also:
Constant Field Values

NOT_A_NODE_DISPLAY_TYPE

public static final int NOT_A_NODE_DISPLAY_TYPE
See Also:
Constant Field Values
Constructor Detail

ModelParser

public ModelParser()
Method Detail

getModelName

public static java.lang.String getModelName(org.w3c.dom.Document dom)
Reads the name of the model, i.e. the name attr of the root .xfm file element


getMetamodelFilename

public static java.lang.String getMetamodelFilename(org.w3c.dom.Document dom)
Analyses the document in order to find the metamodel link i.e. the filename where the appropriate metamodel is saved. Attribute "xsi:schemaLocation" is assumed to contain a namespace and path to the *.xfmm file. The namespace is removed from the attribute value. The rest is the path.

Parameters:
dom -
Returns:
metamodel filename

getMetamodelFilename

public static java.lang.String getMetamodelFilename(java.lang.String loc)
Extracts the path to the meta model from Schema location string.

Parameters:
dom -
Returns:
meta-model filename

getElementsThat

public static java.util.List getElementsThat(org.w3c.dom.Document document,
                                             java.lang.String tag,
                                             java.lang.String attr,
                                             java.lang.String value)
Returns a list of those elements from document that have the given tag and their attribute attr equals to value


getNodeAttribute

public static java.lang.String getNodeAttribute(org.w3c.dom.Node node,
                                                java.lang.String attribute)
Reads the given attribute of the node if available


getDisplayModelEntryFor

public static org.w3c.dom.Node getDisplayModelEntryFor(org.w3c.dom.Document displayModel,
                                                       java.lang.String node)
Returns the node from the display model XML file that describes how to display the node (figurable, i.e. node, property, propertyset)


getDisplayModelProperty

public static java.lang.String getDisplayModelProperty(org.w3c.dom.Document displayModel,
                                                       java.lang.String displayFormat,
                                                       java.lang.String node,
                                                       java.lang.String property)
Returns the given display model property of the given feature model node, i.e. the font, line width, etc. Used mainly in FeatureNodeModel class.


getNodeChildValue

public static java.lang.String getNodeChildValue(org.w3c.dom.Document metamodel,
                                                 org.w3c.dom.Node node,
                                                 java.lang.String description)
Returns the value of the value attribute of the given child of node. The appropriate child is adressed by description string - '/' slash char means a delimiter of node path, e.g. "NameText/FontStyle" means the value attr of ...


setNodeChildValue

public static boolean setNodeChildValue(org.w3c.dom.Document metamodel,
                                        org.w3c.dom.Node node,
                                        java.lang.String description,
                                        java.lang.String value)
The same as getNodeChildValue but the value is stored to the appropriate attribute of the given node


getDisplayNodeNames

public static java.util.List getDisplayNodeNames(org.w3c.dom.Document metamodel)
Returns a list of names of nodes that can be displayed on a canvas of the editor, i.e. nodes, properties, property sets, and cardinalities The list has doubled size, every second element is the parent property set (or an empty string if the parent is not a property set)


getDisplayNodes

public static java.util.List getDisplayNodes(org.w3c.dom.Document metamodel)
Returns a list of nodes that can be displayed on a canvas of the editor, i.e. nodes, properties, property sets, and cardinalities


getParentPropertySetIfAny

public static java.lang.String getParentPropertySetIfAny(org.w3c.dom.Document metamodel,
                                                         org.w3c.dom.Node node)
Returns name of a property set that is a parent node of specified property node

Parameters:
metamodel -
node - property node

getPropertyNodes

public static java.util.List getPropertyNodes(org.w3c.dom.Document metamodel)
Returns a list of nodes (xml) that are properties of a feature model node


getFigurativeNodes

public static java.util.List getFigurativeNodes(org.w3c.dom.Document metamodel)
Returns a list of nodes (xml) that can be drawn to canvas as a selectable, editable, moveable, etc. feature model nodes


getMetamodelEntryFor

public static org.w3c.dom.Node getMetamodelEntryFor(org.w3c.dom.Document metamodel,
                                                    java.lang.String node)
Returns the metamodel xml element describing the meta characteristics of the given node


getChildrenThat

public static java.util.List getChildrenThat(java.util.List list,
                                             org.w3c.dom.Node node,
                                             java.lang.String name)
Returns a list of node's child nodes that have the given name


getMetamodelElementDisplayType

public static java.lang.String getMetamodelElementDisplayType(org.w3c.dom.Node node)
Reads the display type from the given metamodel node, i.e. returns node, property, propertyset, and cardinality


getPropertyDefaultValue

public static java.lang.String getPropertyDefaultValue(org.w3c.dom.Node node)
Reads the display type from the given metamodel node, i.e. returns node, property, propertyset, and cardinality


getMetamodelElementDisplayTypeConstant

public static int getMetamodelElementDisplayTypeConstant(java.lang.String s)
Transforms the string to constant

Returns:
constant XFEATURE_DISPLAYTYPE_*

getNodeDisplayType

public static java.lang.String getNodeDisplayType(org.w3c.dom.Document metaModel,
                                                  org.w3c.dom.Node node)
Returns the display type (see above getMetamodelElementDisplayType) for the passed node according to the metaModel


getNodeCardinality

public static org.w3c.dom.Node getNodeCardinality(org.w3c.dom.Document metaModel,
                                                  org.w3c.dom.Node node)
Returns the cardinality for the passed node


isCardinalityNode

public static boolean isCardinalityNode(org.w3c.dom.Node node)
Checks wheather a node is a cardinality node


getNodePropertySet

public static org.w3c.dom.Node getNodePropertySet(org.w3c.dom.Document metaModel,
                                                  org.w3c.dom.Node node,
                                                  java.lang.String name)
Returns the property set node for of the given name for the passed node


isPropertySetNode

public static boolean isPropertySetNode(org.w3c.dom.Node node)
Checks wheather a node is a property set node


isPropertyNode

public static boolean isPropertyNode(org.w3c.dom.Node node)
Checks wheather a node is a property node


isCorrectNodeType

public static boolean isCorrectNodeType(org.w3c.dom.Node node,
                                        java.lang.String type)
Checks wheather a node is a node, property, or property setnode


getAvailableNodeChildren

public static java.util.List getAvailableNodeChildren(org.w3c.dom.Node node,
                                                      org.w3c.dom.Document metaModel)
Returns a list of possible child nodes of the given node according to the entries in the metaModel


getElementChildrenByName

public static java.util.List getElementChildrenByName(org.w3c.dom.Node element,
                                                      java.lang.String name)
Returns a list of elements children that have the passed name


getSubElementByTagName

public static org.w3c.dom.Node getSubElementByTagName(org.w3c.dom.Node node,
                                                      java.lang.String subElementName)
Scans the recursive structure of the given node and returns the sub-node given by subElementName path (using '/' as a delimiter - see getNodeChildValue())


getSequence

public static org.w3c.dom.Node getSequence(org.w3c.dom.Document metamodel,
                                           java.lang.String nodeName)
Return the sequence node for the passed node name from the metamodel


getElementChildren

public static java.util.List getElementChildren(org.w3c.dom.Node element)
Returns a list of elements children that have the passed name


getElementId

public static long getElementId(org.w3c.dom.Node element)
returns the element's unique ID - a positive integer


getNodePosition

public static int getNodePosition(org.w3c.dom.Node parent,
                                  long id)
Returns an position index within the parent of node with id id


getNodePosition

public static int getNodePosition(org.w3c.dom.Node parent,
                                  org.w3c.dom.Node node)
Traverse the list of child nodes of the "parent" naode and returns an index of "node" node.

Parameters:
parent - the parent node
node - the searched node
Returns:
index or -1 if not found

getPropertySet

public static org.w3c.dom.Node getPropertySet(org.w3c.dom.Node parentNode,
                                              java.lang.String propertySet)
Returns property set DOM node specified by name

Parameters:
parentNode - node that contains a property set
propertySet - property set name
Returns:
DOM Node element with the property set or null if not found

getPropertySetIndex

public static int getPropertySetIndex(org.w3c.dom.Node parentNode,
                                      org.w3c.dom.Node propertySetNode,
                                      org.w3c.dom.Document metamodelDocument)
Return the position of the parameter among the other parameters of the same type. The index of the first sub node is 1 (not 0). If 0 is returned thatn there the parent node doesn't have such a child node.

Parameters:
propertySetNode - node to be searched in the list of
Returns:
index of the child node among the other child nodes of the same type.

removeIndex

public static java.lang.String removeIndex(java.lang.String s)
Return the string where index in brackets e.g. "(3)" is removed.

Parameters:
s - string that may have index at the end e.g. "Attrirute(2)"
Returns:
string withou the index in brackets e.g. "Attribute"

addRequiredCardinalityAndPropertySets

public static void addRequiredCardinalityAndPropertySets(FeatureDiagramModel diagram,
                                                         org.w3c.dom.Node parent)

getTooltip

public static java.lang.String getTooltip(org.w3c.dom.Document metaModel,
                                          org.w3c.dom.Node node)
searches given node for ShortDescription descendant and returns its content to be later displayed to the user as a tool tip

Parameters:
metaModel - reference to the meta-model of the current feature model
node - the node for which tool tip string is requested
Returns:

getXPathValueApache

public static java.lang.String getXPathValueApache(org.w3c.dom.Document document,
                                                   java.lang.String xPath)
                                            throws org.w3c.dom.xpath.XPathException
Get value of the node specified by an XPath.

Parameters:
document - Document to get node value of.
xPath - XPath to select single node value (e.g. "/root/data/value[1]/text()")
Returns:
Result of xPath (the node's value) or null if failed.
Throws:
org.w3c.dom.xpath.XPathException - if XPath result object is not of type XPathResult.
See Also:
XPath Tutorial

getXPathResult

public static org.w3c.dom.xpath.XPathResult getXPathResult(org.w3c.dom.Node node,
                                                           java.lang.String xPath)
                                                    throws org.w3c.dom.xpath.XPathException
uses the org.w3c.dom.xpath pacakge to query a DOM Documents with XPath expressions

Parameters:
node - context node
xPath - XPath expression
Returns:
an object of org.w3c.dom.xpath.XPathResult.ORDERED_NODE_ITERATOR_TYPE type
Throws:
org.w3c.dom.xpath.XPathException

setGlobalConstraintValue

public static boolean setGlobalConstraintValue(FeatureDiagramModel diagram,
                                               java.lang.String description,
                                               java.lang.String value)
The same as getNodeChildValue but the value is stored to the appropriate attribute of the given node


getIndentCount

public static int getIndentCount(org.w3c.dom.Node node)
Tells what is the depth of this node in DOM model

Returns:
depth of node


Copyright © 2004 - 2008 ETH Zurich and P&P Software GmbH, All Rights Reserved.