Reference to labels -- occurs='?'
- RELAX: zero or one times
- Java: "Integer" (which can be null) rather than "int"
RefZeroMore.rlx
<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "relaxCore.dtd">
<module>
<interface>
<export label="RefZeroOne"/>
</interface>
<elementRule role="RefZeroOne">
<ref label="Target" occurs="?"/>
</elementRule>
<tag name="ref" role="RefZeroOne">
</tag>
<elementRule role="Target" type="int">
</elementRule>
<tag name="target" role="Target">
</tag>
</module>
RefZeroMore.java
import org.w3c.dom.*;
/**
* <b>RefZeroOne</b> is generated by Relaxer based on RefZeroOne.rlx.
* This class is derived from:
*
* <!-- for programmer
* <elementRule role="RefZeroOne">
* <ref label="Target" occurs="?"/>
* </elementRule>
*
* <tag name="ref" role="RefZeroOne"/>
* -->
* <!-- for javadoc -->
* <pre> <elementRule role="RefZeroOne">
* <ref label="Target" occurs="?"/>
* </elementRule>
* <tag name="ref" role="RefZeroOne"/>
* </pre>
*
* @version RefZeroOne.rlx (Mon Jul 31 06:00:10 JST 2000)
* @author Relaxer 0.10 (by ASAMI@Yokohama)
*/
public class RefZeroOne implements java.io.Serializable {
private Integer target;
/**
* Creates a <code>RefZeroOne</code>.
*
*/
public RefZeroOne() {
}
/**
* Creates a <code>RefZeroOne</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 RefZeroOne(RStack stack) {
setup(stack);
}
/**
* Creates a <code>RefZeroOne</code> by the Document <code>doc</code>.
*
* @param doc
*/
public RefZeroOne(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Creates a <code>RefZeroOne</code> by the Element <code>element</code>.
*
* @param element
*/
public RefZeroOne(Element element) {
setup(element);
}
/**
* Initializes the <code>RefZeroOne</code> by the Document <code>doc</code>.
*
* @param doc
*/
public void setup(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Initializes the <code>RefZeroOne</code> by the Element <code>element</code>.
*
* @param element
*/
public void setup(Element element) {
init(element);
}
/**
* Initializes the <code>RefZeroOne</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 = URelaxer.getElementPropertyAsIntByStack(stack, "target");
}
/**
* 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;
if (target != null) {
URelaxer.setElementPropertyByInt(element, "target", target);
}
parent.appendChild(element);
}
/**
* Gets the Integer property <b>target</b>.
*
* @return Integer
*/
public final Integer getTarget() {
return (target);
}
/**
* Sets the Integer property <b>target</b>.
*
* @param target
*/
public final void setTarget(Integer target) {
this.target = target;
}
/**
* Tests if a Element <code>element</code> is valid
* for the <code>RefZeroOne</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;
child = target.peekElement();
if (child != null) {
if ("target".equals(child.getTagName())) {
target.popElement();
}
}
if (!target.isEmptyElement()) {
return (false);
}
return (true);
}
/**
* Tests if elements contained in a Stack <code>stack</code>
* is valid for the <code>RefZeroOne</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>RefZeroOne</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);
}
}
}