|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ercato.core.xml.XOperator
public class XOperator
XOperator is a class implementing a simple algebra between XML documents.
Copyright notice: © 2004-2009 Living Pages Research GmbH, Munich, Germany.
URL: living-pages.de
XOperations are normally defined for entire documents. Additionally, operations are offered to be applied to elements where this is convenient, too.
The following relations should all hold true (all expressions must be read left to right!):
Operations "+", "-" and "==0" are implemented accordingly.
The main intention is to consider a and b as two documents playing different roles:
The sum a + b of both documents can be considered a more specific version of the more general base, the difference a - b between documents can be regarded the difference set of how a is more specific than b.
A special case is when a and b are completely unrelated: Then a + b and a - b both return a which is in accordance with above equations and a consequence of equation (3).
The following special markup in documents a and b is available to fine-tune how this class works:
Namespaces recognized:
abbreviation: | xml namespace: |
erc | http://ercato.com/xmlns/ErcatoCore |
Deriving document markup (the left side, "a"):
attribute: | description: |
erc:inherit="expand" | The attributes and child elements are all considered additional. |
erc:inherit="match" | The attributes and child elements are compared to b. When they can be matched, the content of both will be merged where additional content in b goes first. |
erc:inherit="matchtext" | Same as "match", but the value of text nodes is now considered significant in deciding a match. |
erc:inherit="override" | Corresponding content in b will be overridden. |
erc:inherit="delete" | Corresponding content in b will be deleted. In order to mark a single attribute rather than an entire element for deletion, it may be given a value of 'erc:inherit=delete'. |
erc:inherit="none" | Content in a is unrelated to content in b. However, the algorithm may ignore this relationship if it can compute a match. |
erc:inherit="auto" | Correspondance is computed automatically. This is the default. A node in a is regarded as matching a node in b if it has compatible position and a does not lack structure of b. |
erc:inherit-tag="'name'" | Sometimes, it is necessary to expand a tag by a tag with a different tagname, eg., if a tagname represents sort of typename. This is possible by providing the tagname in b as 'name'. Namespaces must be equal. Note that this rule is ignored if no matching tag with 'name' can be found! |
Base document markup (the right side, "b"):
attribute: | description: |
erc:inherited-as="scalar" | The element with given tagname exists only once and may be matched by tagname. |
erc:inherited-as="option" | The element with given tagname exists at most once and may be matched by tagname. |
erc:inherited-as="vector" | The element with given tagname is position-independent and serves as base for any element with same tagname which may therefore be matched by tagname too. |
erc:name="'name'" | The element with given tagname and name 'name' exists only once and may be matched by those. Note that the property 'erc:name' (ie., its namespace and its attribute name) is configurable. |
Note that "base document markup" is not contained in the difference and "deriving document markup" is not contained in the sum.
A trivial example may clarify the above.
Assume derived document a looks like:
<account xmlns:erc="http://ercato.com/xmlns/ErcatoCore"> <erc:id>example</erc:id> <balance>4365</balance> </account>
Assume base document b looks like:
<account xmlns:erc="http://ercato.com/xmlns/ErcatoCore"> <erc:id/> <balance unit="Euro"/> </account>
Assume you compute the addition (a + b) with the following setting of: xop.setDefaultInherit (CORRESPONDS);
,
you should obtain:
<account xmlns:erc="http://ercato.com/xmlns/ErcatoCore"> <erc:id>example</erc:id> <balance unit="Euro">4365</balance> </account>
Note that this example defines the erc: namespace too. Enjoy!
Field Summary | |
---|---|
static short |
AUTOMATIC
No possible return value of howRelates. |
static short |
CORRESPONDS
Possible return value of howRelates. |
static short |
DELETES
Possible return value of howRelates. |
static short |
EQUALS
Possible return value of howRelates. |
static java.lang.String |
ERCNS
|
static java.lang.String |
ERCPP
|
static short |
EXPANDS
Possible return value of howRelates. |
protected static short |
IA_BYNAME
|
protected static short |
IA_COPY
|
protected static short |
IA_IGNORED
|
protected static short |
IA_PLAIN
|
protected static short |
IA_SCALAR
|
protected static short |
IA_TEXT
|
protected static short |
IA_VECTOR
|
static short |
MATCHTEXT
No possible return value of howRelates. |
protected static short |
NULL
Impossible internal value for dummy tests. |
static short |
OVERRIDES
Possible return value of howRelates. |
static short |
UNRELATED
Possible return value of howRelates. |
Constructor Summary | |
---|---|
XOperator()
|
Method Summary | |
---|---|
org.w3c.dom.Document |
addition(org.w3c.dom.Document a,
org.w3c.dom.Document b)
'may_return_a' defaults to false - a document different to 'a' is always returned. |
org.w3c.dom.Document |
addition(org.w3c.dom.Document a,
org.w3c.dom.Document b,
boolean may_return_a)
addition computes the sum of two documents a and b. |
org.w3c.dom.Element[] |
addition(org.w3c.dom.Element a,
org.w3c.dom.Element b,
org.w3c.dom.Document doc)
addition computes the sum of two elements a and b. |
protected org.w3c.dom.Element[] |
addition0(org.w3c.dom.Element a,
org.w3c.dom.Element b,
org.w3c.dom.Document dom,
short abrel)
|
protected short |
classifyBaseElement(org.w3c.dom.Element b)
|
protected short |
classifyDerivedElement(org.w3c.dom.Element a)
|
static short |
classifyInherit(org.w3c.dom.Element a,
short default_read_inherit)
|
org.w3c.dom.Document |
difference(org.w3c.dom.Document a,
org.w3c.dom.Document b)
'may_return_a' defaults to false - a document different to 'a' is always returned. |
org.w3c.dom.Document |
difference(org.w3c.dom.Document a,
org.w3c.dom.Document b,
boolean may_return_a)
difference computes the difference between two documents a and b. |
org.w3c.dom.Element |
difference(org.w3c.dom.Element a,
org.w3c.dom.Element b,
org.w3c.dom.Document doc)
difference computes the difference between two elements a and b. |
protected org.w3c.dom.Element |
difference0(org.w3c.dom.Element a,
org.w3c.dom.Element b,
org.w3c.dom.Document dom,
short abrel)
|
short |
getDefaultInheritOnDiff()
|
short |
getDefaultInheritOnRead()
|
protected static java.lang.String |
getMatchingName(org.w3c.dom.Element a)
|
short |
howRelates(org.w3c.dom.Node a,
org.w3c.dom.Node b)
howRelates computes the relationship between two nodes a and b in two separate documents. |
protected short |
howRelates0(org.w3c.dom.Element a,
org.w3c.dom.Node b)
|
boolean |
isNull(org.w3c.dom.Document a)
isNull computes whether a document may be considered zero. |
static void |
removeElement(org.w3c.dom.Element e)
removeElement removes an element in its Document together with surrounding whitespace. |
void |
setDefaultInherit(short inherit)
Sets the default inherit property when no annotation is found at an element. |
void |
setMatchingName(java.lang.String namespace,
java.lang.String attrname)
Configures the rule by which xml elements are matched by name. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String ERCNS
public static final java.lang.String ERCPP
public static final short EQUALS
public static final short EXPANDS
public static final short OVERRIDES
public static final short DELETES
public static final short CORRESPONDS
public static final short MATCHTEXT
public static final short UNRELATED
public static final short AUTOMATIC
protected static final short NULL
protected static final short IA_PLAIN
protected static final short IA_BYNAME
protected static final short IA_SCALAR
protected static final short IA_VECTOR
protected static final short IA_TEXT
protected static final short IA_COPY
protected static final short IA_IGNORED
Constructor Detail |
---|
public XOperator()
Method Detail |
---|
public void setDefaultInherit(short inherit)
public short getDefaultInheritOnRead()
public short getDefaultInheritOnDiff()
public void setMatchingName(java.lang.String namespace, java.lang.String attrname)
namespace
- the namespace of the attribute name or its enclosing element (defaults to ERCNS, null namespace is allowed).attrname
- the name of the attribute (defaults to "name").public short howRelates(org.w3c.dom.Node a, org.w3c.dom.Node b)
a
- a node in the derived document.b
- a node in the base document.
public org.w3c.dom.Document difference(org.w3c.dom.Document a, org.w3c.dom.Document b, boolean may_return_a)
a
- the derived document.b
- the base document.may_return_a
- boolean whether it is allowed to return 'a' rather than a copy of 'a' where this is an option.
public org.w3c.dom.Document difference(org.w3c.dom.Document a, org.w3c.dom.Document b)
public org.w3c.dom.Element difference(org.w3c.dom.Element a, org.w3c.dom.Element b, org.w3c.dom.Document doc)
a
- an element in the derived document.b
- an element in the base document.doc
- document to become the owner document of the difference-element.
public org.w3c.dom.Document addition(org.w3c.dom.Document a, org.w3c.dom.Document b, boolean may_return_a)
a
- the derived document.b
- the base document.may_return_a
- boolean whether it is allowed to return 'a' rather than a copy of 'a' where this is an option.
public org.w3c.dom.Document addition(org.w3c.dom.Document a, org.w3c.dom.Document b)
public org.w3c.dom.Element[] addition(org.w3c.dom.Element a, org.w3c.dom.Element b, org.w3c.dom.Document doc)
a
- an element in the derived document.b
- an element in the base document.doc
- document to become the owner document of the addition-elements.
public boolean isNull(org.w3c.dom.Document a)
a
- the difference of both, or any document.
public static void removeElement(org.w3c.dom.Element e)
e
- The Element to be removed.public static short classifyInherit(org.w3c.dom.Element a, short default_read_inherit)
protected final short classifyDerivedElement(org.w3c.dom.Element a)
protected static java.lang.String getMatchingName(org.w3c.dom.Element a)
protected final short classifyBaseElement(org.w3c.dom.Element b)
protected final org.w3c.dom.Element[] addition0(org.w3c.dom.Element a, org.w3c.dom.Element b, org.w3c.dom.Document dom, short abrel)
protected final org.w3c.dom.Element difference0(org.w3c.dom.Element a, org.w3c.dom.Element b, org.w3c.dom.Document dom, short abrel)
protected final short howRelates0(org.w3c.dom.Element a, org.w3c.dom.Node b)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |