dk.brics.xmlgraph
Class XMLGraph

java.lang.Object
  extended by dk.brics.xmlgraph.XMLGraph
All Implemented Interfaces:
Serializable, Cloneable

public class XMLGraph
extends Object
implements Cloneable, Serializable

XML graph (also known as a Summary Graph).

See Also:
Serialized Form

Constructor Summary
XMLGraph()
          Constructs a new empty XML graph.
 
Method Summary
 void addClosedAttributeGap(String g)
          Adds a gap name to the set of maybe closed attribute gaps.
 void addClosedTemplateGap(String g)
          Adds a gap name to the set of maybe closed template gaps.
 void addNode(Node n)
          Adds a node.
 void addOpenAttributeGap(String g)
          Adds a gap name to the set of maybe open attribute gaps.
 void addOpenTemplateGap(String g)
          Adds a gap name to the set of maybe open template gaps.
 void addRoot(Node n)
          Adds a node as root.
 boolean check(PrintStream err)
          Checks that this XML graph is well-defined using a WelldefinedChecker.
 XMLGraph clone()
          Clones this XML graph.
 Set<Integer> extendWith(XMLGraph xg)
          Extends this XML graph with a copy of the given one.
 Set<String> getClosedAttributeGaps()
          Returns names of all maybe closed attribute gaps.
 Set<String> getClosedTemplateGaps()
          Returns names of all maybe closed template gaps.
 Map<String,String> getGapTypeMap()
          Returns map from gap names to schema types.
 Node getNode(int i)
          Returns node of the given index
 ArrayList<Node> getNodes()
          Returns all nodes in this XML graph.
 Set<String> getOpenAttributeGaps()
          Returns names of all maybe open attribute gaps.
 Set<String> getOpenTemplateGaps()
          Returns names of all maybe open template gaps.
 Set<Integer> getRoots()
          Returns all roots.
 boolean isUnknown()
          Returns true if this XML graph represents unknown XML data.
 boolean merge(XMLGraph xg)
          Merges the given XML graph into this one, resulting in the least upper bound.
<T> void
processNodes(NodeProcessor<T> v)
          Processes all nodes using the given pattern processor.
<T> void
processReachableNodes(NodeProcessor<T> v)
          Processes all reachable nodes using the given pattern processor.
<T> void
processRoots(NodeProcessor<T> v)
          Processes all roots using the given processor
 void removeClosedAttributeGap(String g)
          Removes a gap name from the set of maybe closed attribute gaps.
 void removeClosedTemplateGap(String g)
          Removes a gap name from the set of maybe closed template gaps.
 void removeOpenAttributeGap(String g)
          Removes a gap name from the set of maybe open attribute gaps.
 void removeOpenTemplateGap(String g)
          Removes a gap name from the set of maybe open template gaps.
 void setNode(int index, Node n)
          Replaces a node.
 void setRoots(Set<Integer> roots)
          Sets the roots to the given set.
 void setUnknown()
          Marks this XML graph as representing unknown XML data.
 void sharpen()
          Sharpens this XML graph by removing unreachable edges, element/attribute names, text, and gap presence.
 void simplify()
          Simplifies this XML graph by bypassing single-content choice/sequence/interleave nodes.
 void useFragment(XMLGraphFragment f)
          Sets the roots, gap types, and gap presence according to the given fragment.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLGraph

public XMLGraph()
Constructs a new empty XML graph.

Method Detail

addClosedAttributeGap

public void addClosedAttributeGap(String g)
Adds a gap name to the set of maybe closed attribute gaps.

Parameters:
g - gap name

addClosedTemplateGap

public void addClosedTemplateGap(String g)
Adds a gap name to the set of maybe closed template gaps.

Parameters:
g - gap name

addNode

public void addNode(Node n)
Adds a node.

Parameters:
n - node (not already in the graph)

addOpenAttributeGap

public void addOpenAttributeGap(String g)
Adds a gap name to the set of maybe open attribute gaps.

Parameters:
g - gap name

addOpenTemplateGap

public void addOpenTemplateGap(String g)
Adds a gap name to the set of maybe open template gaps.

Parameters:
g - gap name

addRoot

public void addRoot(Node n)
Adds a node as root.

Parameters:
n - node (not already added as a root), ignored if null

check

public boolean check(PrintStream err)
Checks that this XML graph is well-defined using a WelldefinedChecker.

Parameters:
err - print stream for error messages, null if none
Returns:
true if the properties are satisfied

clone

public XMLGraph clone()
Clones this XML graph.

Overrides:
clone in class Object
Returns:
copy of this XML graph (reusing nodes)

extendWith

public Set<Integer> extendWith(XMLGraph xg)
Extends this XML graph with a copy of the given one. The node indices in the copy are all increased by the current number of nodes in this XML graph. The global gap presence, the root set, and the gap types of this XML graph are not modified.

Parameters:
xg - an XML graph
Returns:
set of indices of nodes that correspond to roots in the inserted XML graph

getClosedAttributeGaps

public Set<String> getClosedAttributeGaps()
Returns names of all maybe closed attribute gaps.

Returns:
set of gap names

getClosedTemplateGaps

public Set<String> getClosedTemplateGaps()
Returns names of all maybe closed template gaps.

Returns:
set of gap names

getGapTypeMap

public Map<String,String> getGapTypeMap()
Returns map from gap names to schema types.

Returns:
gap type map

getNode

public Node getNode(int i)
Returns node of the given index

Parameters:
i - node index
Returns:
node

getNodes

public ArrayList<Node> getNodes()
Returns all nodes in this XML graph.

Returns:
list of nodes

getOpenAttributeGaps

public Set<String> getOpenAttributeGaps()
Returns names of all maybe open attribute gaps.

Returns:
set of gap names

getOpenTemplateGaps

public Set<String> getOpenTemplateGaps()
Returns names of all maybe open template gaps.

Returns:
set of gap names

getRoots

public Set<Integer> getRoots()
Returns all roots.

Returns:
set of root indices

isUnknown

public boolean isUnknown()
Returns true if this XML graph represents unknown XML data.


merge

public boolean merge(XMLGraph xg)
              throws IllegalArgumentException
Merges the given XML graph into this one, resulting in the least upper bound. The XML graphs must be compatible meaning that they can only differ in root sets, element and attribute names, text values, choice and gap contents, and gap presence.

Parameters:
xg - XML graph
Returns:
true if this XML graph has changed
Throws:
IllegalArgumentException - if the XML graphs are incompatible

processNodes

public <T> void processNodes(NodeProcessor<T> v)
Processes all nodes using the given pattern processor.

Parameters:
v - node processor

processReachableNodes

public <T> void processReachableNodes(NodeProcessor<T> v)
Processes all reachable nodes using the given pattern processor.

Parameters:
v - node processor

processRoots

public <T> void processRoots(NodeProcessor<T> v)
Processes all roots using the given processor

Parameters:
v - node processor

removeClosedAttributeGap

public void removeClosedAttributeGap(String g)
Removes a gap name from the set of maybe closed attribute gaps.

Parameters:
g - gap name

removeClosedTemplateGap

public void removeClosedTemplateGap(String g)
Removes a gap name from the set of maybe closed template gaps.

Parameters:
g - gap name

removeOpenAttributeGap

public void removeOpenAttributeGap(String g)
Removes a gap name from the set of maybe open attribute gaps.

Parameters:
g - gap name

removeOpenTemplateGap

public void removeOpenTemplateGap(String g)
Removes a gap name from the set of maybe open template gaps.

Parameters:
g - gap name

setNode

public void setNode(int index,
                    Node n)
Replaces a node. This should only be used during construction of initial XML graph.

Parameters:
index - index
n - new node

setRoots

public void setRoots(Set<Integer> roots)
Sets the roots to the given set.

Parameters:
roots - set of root indices

setUnknown

public void setUnknown()
Marks this XML graph as representing unknown XML data.


sharpen

public void sharpen()
Sharpens this XML graph by removing unreachable edges, element/attribute names, text, and gap presence.


simplify

public void simplify()
Simplifies this XML graph by bypassing single-content choice/sequence/interleave nodes.


useFragment

public void useFragment(XMLGraphFragment f)
Sets the roots, gap types, and gap presence according to the given fragment.

Parameters:
f - XML graph fragment (null represents an empty fragment)


Copyright © 2005-2010 Anders Møller.