References to Labels -- Simple
- XML: an element containing a child element "Target".
- RELAX: a reference to a label "Target"
- Java: a simple variable due to optimization
Ref.rlx
<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "relaxCore.dtd">
<module>
<interface>
<export label="Ref"/>
</interface>
<elementRule role="Ref">
<ref label="Target"/>
</elementRule>
<tag name="ref" role="Ref">
</tag>
<elementRule role="Target" type="int">
</elementRule>
<tag name="target" role="Target">
</tag>
</module>
Ref.java
import org.w3c.dom.*;
/**
* <b>Ref</b> is generated by Relaxer based on Ref.rlx.
* This class is derived from:
*
* <!-- for programmer
* <elementRule role="Ref">
* <ref label="Target"/>
* </elementRule>
*
* <tag name="ref" role="Ref"/>
* -->
* <!-- for javadoc -->
* <pre> <elementRule role="Ref">
* <ref label="Target"/>
* </elementRule>
* <tag name="ref" role="Ref"/>
* </pre>
*
* @version Ref.rlx (Tue Aug 01 23:55:06 JST 2000)
* @author Relaxer 0.10.1b (by ASAMI@Yokohama)
*/
public class Ref implements java.io.Serializable {
private int target;
/**
* Creates a <code>Ref</code>.
*
*/
public Ref() {
}
/**
* Creates a <code>Ref</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 Ref(RStack stack) {
setup(stack);
}
/**
* Creates a <code>Ref</code> by the Document <code>doc</code>.
*
* @param doc
*/
public Ref(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Creates a <code>Ref</code> by the Element <code>element</code>.
*
* @param element
*/
public Ref(Element element) {
setup(element);
}
/**
* Initializes the <code>Ref</code> by the Document <code>doc</code>.
*
* @param doc
*/
public void setup(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Initializes the <code>Ref</code> by the Element <code>element</code>.
*
* @param element
*/
public void setup(Element element) {
init(element);
}
/**
* Initializes the <code>Ref</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.getElementPropertyAsInt(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;
if (parent instanceof Document) {
doc = (Document)parent;
} else {
doc = parent.getOwnerDocument();
}
Element element = doc.createElement("ref");
int size;
URelaxer.setElementPropertyByInt(element, "target", target);
parent.appendChild(element);
}
/**
* Gets the int property <b>target</b>.
*
* @return int
*/
public final int getTarget() {
return (target);
}
/**
* Sets the int property <b>target</b>.
*
* @param target
*/
public final void setTarget(int target) {
this.target = target;
}
/**
* Tests if a Element <code>element</code> is valid
* for the <code>Ref</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.popElement();
if (child == null) {
return (false);
}
if (!"target".equals(child.getTagName())) {
return (false);
}
if (!target.isEmptyElement()) {
return (false);
}
return (true);
}
/**
* Tests if elements contained in a Stack <code>stack</code>
* is valid for the <code>Ref</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>Ref</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);
}
}
}