Reference to labels -- occurs='*'
- RELAX: zero or more times
- Java: as in the previous example
RefZeroMore.rlx
<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "relaxCore.dtd">
<module>
<interface>
<export label="RefZeroMore"/>
</interface>
<elementRule role="RefZeroMore">
<ref label="Target" occurs="*"/>
</elementRule>
<tag name="ref" role="RefZeroMore">
</tag>
<elementRule role="Target" type="int">
</elementRule>
<tag name="target" role="Target">
</tag>
</module>
RefZeroMore.java
import org.w3c.dom.*;
/**
* <b>RefZeroMore</b> is generated by Relaxer based on RefZeroMore.rlx.
* This class is derived from:
*
* <!-- for programmer
* <elementRule role="RefZeroMore">
* <ref label="Target" occurs="*"/>
* </elementRule>
*
* <tag name="ref" role="RefZeroMore"/>
* -->
* <!-- for javadoc -->
* <pre> <elementRule role="RefZeroMore">
* <ref label="Target" occurs="*"/>
* </elementRule>
* <tag name="ref" role="RefZeroMore"/>
* </pre>
*
* @version RefZeroMore.rlx (Mon Jul 31 06:00:24 JST 2000)
* @author Relaxer 0.10 (by ASAMI@Yokohama)
*/
public class RefZeroMore implements java.io.Serializable {
// List<Target>
private java.util.List target = new java.util.ArrayList();
/**
* Creates a <code>RefZeroMore</code>.
*
*/
public RefZeroMore() {
}
/**
* Creates a <code>RefZeroMore</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 RefZeroMore(RStack stack) {
setup(stack);
}
/**
* Creates a <code>RefZeroMore</code> by the Document <code>doc</code>.
*
* @param doc
*/
public RefZeroMore(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Creates a <code>RefZeroMore</code> by the Element <code>element</code>.
*
* @param element
*/
public RefZeroMore(Element element) {
setup(element);
}
/**
* Initializes the <code>RefZeroMore</code> by the Document <code>doc</code>.
*
* @param doc
*/
public void setup(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Initializes the <code>RefZeroMore</code> by the Element <code>element</code>.
*
* @param element
*/
public void setup(Element element) {
init(element);
}
/**
* Initializes the <code>RefZeroMore</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);
target.clear();
while (!stack.isEmptyElement()) {
if (Target.isMatch(stack)) {
addTarget(new Target(stack));
} else {
break;
}
}
}
/**
* 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 = target.size();
for (int i = 0;i < size;i++) {
Target value = (Target)this.target.get(i);
value.makeElement(element);
}
parent.appendChild(element);
}
/**
* Gets the Target property <b>target</b>.
*
* @return Target[]
*/
public final Target[] getTarget() {
Target[] array = new Target[target.size()];
return ((Target[])target.toArray(array));
}
/**
* Sets the Target property <b>target</b>.
*
* @param target
*/
public final void setTarget(Target[] target) {
this.target.clear();
this.target.addAll(java.util.Arrays.asList(target));
}
/**
* Adds the Target property <b>target</b>.
*
* @param target
*/
public final void addTarget(Target target) {
this.target.add(target);
}
/**
* Tests if a Element <code>element</code> is valid
* for the <code>RefZeroMore</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 (!Target.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>RefZeroMore</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>RefZeroMore</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);
}
}
}