Reference to elementRules and hedgeRules with occurs="*"
- In this example, both a elementRule and a hedgeRule is managed by List because occurs is '*'
RefElementHedgeOccurs.rlx
<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "relaxCore.dtd">
<module>
<interface>
<export label="RefElementHedgeOccurs"/>
</interface>
<elementRule role="RefElementHedgeOccurs">
<sequence>
<ref label="TargetElement" occurs="*"/>
<ref label="TargetHedge" occurs="*"/>
</sequence>
</elementRule>
<tag name="ref" role="RefElementHedgeOccurs">
</tag>
<elementRule role="TargetElement" type="int">
</elementRule>
<tag name="target" role="TargetElement">
</tag>
<hedgeRule label="TargetHedge">
<sequence>
<element name="one" type="byte"/>
<element name="two" type="short"/>
</sequence>
</hedgeRule>
</module>
RefElementHedgeOccurs.java
import org.w3c.dom.*;
/**
* <b>RefElementHedgeOccurs</b> is generated by Relaxer based on RefElementHedgeOccurs.rlx.
* This class is derived from:
*
* <!-- for programmer
* <elementRule role="RefElementHedgeOccurs">
* <sequence>
* <ref label="TargetElement" occurs="*"/>
* <ref label="TargetHedge" occurs="*"/>
* </sequence>
* </elementRule>
*
* <tag name="ref" role="RefElementHedgeOccurs"/>
* -->
* <!-- for javadoc -->
* <pre> <elementRule role="RefElementHedgeOccurs">
* <sequence>
* <ref label="TargetElement" occurs="*"/>
* <ref label="TargetHedge" occurs="*"/>
* </sequence>
* </elementRule>
* <tag name="ref" role="RefElementHedgeOccurs"/>
* </pre>
*
* @version RefElementHedgeOccurs.rlx (Thu Jul 27 08:26:03 JST 2000)
* @author Relaxer 0.10 (by ASAMI@Yokohama)
*/
public class RefElementHedgeOccurs implements java.io.Serializable {
// List<TargetElement>
private java.util.List targetElement = new java.util.ArrayList();
// List<TargetHedge>
private java.util.List targetHedge = new java.util.ArrayList();
/**
* Creates a <code>RefElementHedgeOccurs</code>.
*
*/
public RefElementHedgeOccurs() {
}
/**
* Creates a <code>RefElementHedgeOccurs</code> by the Stack <code>stack</code>
* that contains Elements.
* This constructor is supposed to be used internally
* by the Relaxer system.
*
* @param stack
*/
public RefElementHedgeOccurs(RStack stack) {
setup(stack);
}
/**
* Creates a <code>RefElementHedgeOccurs</code> by the Document <code>doc</code>.
*
* @param doc
*/
public RefElementHedgeOccurs(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Creates a <code>RefElementHedgeOccurs</code> by the Element <code>element</code>.
*
* @param element
*/
public RefElementHedgeOccurs(Element element) {
setup(element);
}
/**
* Initializes the <code>RefElementHedgeOccurs</code> by the Document <code>doc</code>.
*
* @param doc
*/
public void setup(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Initializes the <code>RefElementHedgeOccurs</code> by the Element <code>element</code>.
*
* @param element
*/
public void setup(Element element) {
init(element);
}
/**
* Initializes the <code>RefElementHedgeOccurs</code> by the Stack <code>stack</code>
* that contains Elements.
* This constructor is supposed to be used internally
* by the Relaxer system.
*
* @param stack
*/
public void setup(RStack stack) {
setup(stack.popElement());
}
/**
* @param element
*/
private void init(Element element) {
RStack stack = new RStack(element);
targetElement.clear();
while (!stack.isEmptyElement()) {
if (TargetElement.isMatch(stack)) {
addTargetElement(new TargetElement(stack));
} else {
break;
}
}
targetHedge.clear();
while (!stack.isEmptyElement()) {
TargetHedge node = new TargetHedge(stack);
if (node == null) {
break;
}
addTargetHedge(node);
}
}
/**
* Creates a DOM representation of the object.
* Result is appended to the Node <code>parent</code>.
*
* @param parent
*/
public void makeElement(Node parent) {
Document doc;
if (parent instanceof Document) {
doc = (Document)parent;
} else {
doc = parent.getOwnerDocument();
}
Element element = doc.createElement("ref");
int size;
size = targetElement.size();
for (int i = 0;i < size;i++) {
TargetElement value = (TargetElement)this.targetElement.get(i);
value.makeElement(element);
}
size = targetHedge.size();
for (int i = 0;i < size;i++) {
TargetHedge value = (TargetHedge)this.targetHedge.get(i);
value.makeElement(element);
}
parent.appendChild(element);
}
/**
* Gets the TargetElement property <b>targetElement</b>.
*
* @return TargetElement[]
*/
public final TargetElement[] getTargetElement() {
TargetElement[] array = new TargetElement[targetElement.size()];
return ((TargetElement[])targetElement.toArray(array));
}
/**
* Sets the TargetElement property <b>targetElement</b>.
*
* @param targetElement
*/
public final void setTargetElement(TargetElement[] targetElement) {
this.targetElement.clear();
this.targetElement.addAll(java.util.Arrays.asList(targetElement));
}
/**
* Adds the TargetElement property <b>targetElement</b>.
*
* @param targetElement
*/
public final void addTargetElement(TargetElement targetElement) {
this.targetElement.add(targetElement);
}
/**
* Gets the TargetHedge property <b>targetHedge</b>.
*
* @return TargetHedge[]
*/
public final TargetHedge[] getTargetHedge() {
TargetHedge[] array = new TargetHedge[targetHedge.size()];
return ((TargetHedge[])targetHedge.toArray(array));
}
/**
* Sets the TargetHedge property <b>targetHedge</b>.
*
* @param targetHedge
*/
public final void setTargetHedge(TargetHedge[] targetHedge) {
this.targetHedge.clear();
this.targetHedge.addAll(java.util.Arrays.asList(targetHedge));
}
/**
* Adds the TargetHedge property <b>targetHedge</b>.
*
* @param targetHedge
*/
public final void addTargetHedge(TargetHedge targetHedge) {
this.targetHedge.add(targetHedge);
}
/**
* Tests if a Element <code>element</code> is valid
* for the <code>RefElementHedgeOccurs</code>.
*
* @param element
* @return boolean
*/
public static boolean isMatch(Element element) {
String tagName = element.getTagName();
if (!"ref".equals(tagName)) {
return (false);
}
RStack target = new RStack(element);
Element child;
while (!target.isEmptyElement()) {
if (!TargetElement.isMatchHungry(target)) {
break;
}
}
while (!target.isEmptyElement()) {
if (!TargetHedge.isMatchHungry(target)) {
break;
}
}
if (!target.isEmptyElement()) {
return (false);
}
return (true);
}
/**
* Tests if elements contained in a Stack <code>stack</code>
* is valid for the <code>RefElementHedgeOccurs</code>.
* This mehtod is supposed to be used internally
* by the Relaxer system.
*
* @param stack
* @return boolean
*/
public static boolean isMatch(RStack stack) {
Element element = stack.peekElement();
if (element == null) {
return (false);
}
return (isMatch(element));
}
/**
* Tests if elements contained in a Stack <code>stack</code>
* is valid for the <code>RefElementHedgeOccurs</code>.
* This method consumes the stack contents during matching operation.
* This mehtod is supposed to be used internally
* by the Relaxer system.
*
* @param stack
* @return boolean
*/
public static boolean isMatchHungry(RStack stack) {
Element element = stack.peekElement();
if (element == null) {
return (false);
}
if (isMatch(element)) {
stack.popElement();
return (true);
} else {
return (false);
}
}
}
TargetElement.java
import org.w3c.dom.*;
/**
* <b>TargetElement</b> is generated by Relaxer based on RefElementHedgeOccurs.rlx.
* This class is derived from:
*
* <!-- for programmer
* <elementRule role="TargetElement" type="int"/>
*
* <tag name="target" role="TargetElement"/>
* -->
* <!-- for javadoc -->
* <pre> <elementRule role="TargetElement" type="int"/>
* <tag name="target" role="TargetElement"/>
* </pre>
*
* @version RefElementHedgeOccurs.rlx (Thu Jul 27 08:26:04 JST 2000)
* @author Relaxer 0.10 (by ASAMI@Yokohama)
*/
public class TargetElement implements java.io.Serializable {
private int content;
/**
* Creates a <code>TargetElement</code>.
*
*/
public TargetElement() {
}
/**
* Creates a <code>TargetElement</code> by the Stack <code>stack</code>
* that contains Elements.
* This constructor is supposed to be used internally
* by the Relaxer system.
*
* @param stack
*/
public TargetElement(RStack stack) {
setup(stack);
}
/**
* Creates a <code>TargetElement</code> by the Document <code>doc</code>.
*
* @param doc
*/
public TargetElement(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Creates a <code>TargetElement</code> by the Element <code>element</code>.
*
* @param element
*/
public TargetElement(Element element) {
setup(element);
}
/**
* Initializes the <code>TargetElement</code> by the Document <code>doc</code>.
*
* @param doc
*/
public void setup(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Initializes the <code>TargetElement</code> by the Element <code>element</code>.
*
* @param element
*/
public void setup(Element element) {
init(element);
}
/**
* Initializes the <code>TargetElement</code> by the Stack <code>stack</code>
* that contains Elements.
* This constructor is supposed to be used internally
* by the Relaxer system.
*
* @param stack
*/
public void setup(RStack stack) {
setup(stack.popElement());
}
/**
* @param element
*/
private void init(Element element) {
RStack stack = new RStack(element);
content = URelaxer.getElementPropertyAsInt(element);
}
/**
* Creates a DOM representation of the object.
* Result is appended to the Node <code>parent</code>.
*
* @param parent
*/
public void makeElement(Node parent) {
Document doc;
if (parent instanceof Document) {
doc = (Document)parent;
} else {
doc = parent.getOwnerDocument();
}
Element element = doc.createElement("target");
URelaxer.setElementPropertyByInt(element, content);
int size;
parent.appendChild(element);
}
/**
* Gets the int property <b>content</b>.
*
* @return int
*/
public final int getContent() {
return (content);
}
/**
* Sets the int property <b>content</b>.
*
* @param content
*/
public final void setContent(int content) {
this.content = content;
}
/**
* Tests if a Element <code>element</code> is valid
* for the <code>TargetElement</code>.
*
* @param element
* @return boolean
*/
public static boolean isMatch(Element element) {
String tagName = element.getTagName();
if (!"target".equals(tagName)) {
return (false);
}
RStack target = new RStack(element);
Element child;
if (!target.isEmptyElement()) {
return (false);
}
return (true);
}
/**
* Tests if elements contained in a Stack <code>stack</code>
* is valid for the <code>TargetElement</code>.
* This mehtod is supposed to be used internally
* by the Relaxer system.
*
* @param stack
* @return boolean
*/
public static boolean isMatch(RStack stack) {
Element element = stack.peekElement();
if (element == null) {
return (false);
}
return (isMatch(element));
}
/**
* Tests if elements contained in a Stack <code>stack</code>
* is valid for the <code>TargetElement</code>.
* This method consumes the stack contents during matching operation.
* This mehtod is supposed to be used internally
* by the Relaxer system.
*
* @param stack
* @return boolean
*/
public static boolean isMatchHungry(RStack stack) {
Element element = stack.peekElement();
if (element == null) {
return (false);
}
if (isMatch(element)) {
stack.popElement();
return (true);
} else {
return (false);
}
}
}
TargetHedge.java
import org.w3c.dom.*;
/**
* <b>TargetHedge</b> is generated by Relaxer based on RefElementHedgeOccurs.rlx.
* This class is derived from:
*
* <!-- for programmer
* <hedgeRule label="TargetHedge">
* <sequence>
* <element name="one" type="byte"/>
* <element name="two" type="short"/>
* </sequence>
* </hedgeRule>
* -->
* <!-- for javadoc -->
* <pre> <hedgeRule label="TargetHedge">
* <sequence>
* <element name="one" type="byte"/>
* <element name="two" type="short"/>
* </sequence>
* </hedgeRule>
* </pre>
*
* @version RefElementHedgeOccurs.rlx (Thu Jul 27 08:26:04 JST 2000)
* @author Relaxer 0.10 (by ASAMI@Yokohama)
*/
public class TargetHedge implements java.io.Serializable {
private byte one;
private short two;
/**
* Creates a <code>TargetHedge</code>.
*
*/
public TargetHedge() {
}
/**
* Creates a <code>TargetHedge</code> by the Stack <code>stack</code>
* that contains Elements.
* This constructor is supposed to be used internally
* by the Relaxer system.
*
* @param stack
*/
public TargetHedge(RStack stack) {
setup(stack);
}
/**
* Initializes the <code>TargetHedge</code> by the Stack <code>stack</code>
* that contains Elements.
* This constructor is supposed to be used internally
* by the Relaxer system.
*
* @param stack
*/
public void setup(RStack stack) {
one = URelaxer.getElementPropertyAsByte(stack.popElement());
two = URelaxer.getElementPropertyAsShort(stack.popElement());
}
/**
* Creates a DOM representation of the object.
* Result is appended to the Node <code>parent</code>.
*
* @param parent
*/
public void makeElement(Node parent) {
Document doc = parent.getOwnerDocument();
Element element = (Element)parent;
int size;
URelaxer.setElementPropertyByByte(element, "one", one);
URelaxer.setElementPropertyByShort(element, "two", two);
}
/**
* Gets the byte property <b>one</b>.
*
* @return byte
*/
public final byte getOne() {
return (one);
}
/**
* Sets the byte property <b>one</b>.
*
* @param one
*/
public final void setOne(byte one) {
this.one = one;
}
/**
* Gets the short property <b>two</b>.
*
* @return short
*/
public final short getTwo() {
return (two);
}
/**
* Sets the short property <b>two</b>.
*
* @param two
*/
public final void setTwo(short two) {
this.two = two;
}
/**
* Tests if elements contained in a Stack <code>stack</code>
* is valid for the <code>TargetHedge</code>.
* This mehtod is supposed to be used internally
* by the Relaxer system.
*
* @param stack
* @return boolean
*/
public static boolean isMatch(RStack stack) {
return (isMatchHungry(stack.makeClone()));
}
/**
* Tests if elements contained in a Stack <code>stack</code>
* is valid for the <code>TargetHedge</code>.
* This method consumes the stack contents during matching operation.
* This mehtod is supposed to be used internally
* by the Relaxer system.
*
* @param stack
* @return boolean
*/
public static boolean isMatchHungry(RStack stack) {
RStack target = stack;
Element child;
child = target.popElement();
if (child == null) {
return (false);
}
if (!"one".equals(child.getTagName())) {
return (false);
}
child = target.popElement();
if (child == null) {
return (false);
}
if (!"two".equals(child.getTagName())) {
return (false);
}
return (true);
}
}