Choice
- RELAX : <choice> captures "|" of DTDs.
- Java: contains an interface "IChoiceContent", which is implemented by "Target1" and "Target2"
Choice.rlx
<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "relaxCore.dtd">
<module>
<interface>
<export label="Choice"/>
</interface>
<elementRule role="Choice">
<choice>
<ref label="Target1" occurs="*"/>
<ref label="Target2" occurs="*"/>
</choice>
</elementRule>
<tag name="choice" role="Choice">
</tag>
<elementRule role="Target1" type="int">
</elementRule>
<tag name="target1" role="Target1">
</tag>
<elementRule role="Target2" type="boolean">
</elementRule>
<tag name="target2" role="Target2">
</tag>
</module>
Choice.java
import org.w3c.dom.*;
/**
* <b>Choice</b> is generated by Relaxer based on choice.rlx.
* This class is derived from:
*
* <!-- for programmer
* <elementRule role="Choice">
* <choice>
* <ref label="Target1" occurs="*"/>
* <ref label="Target2" occurs="*"/>
* </choice>
* </elementRule>
*
* <tag name="choice" role="Choice"/>
* -->
* <!-- for javadoc -->
* <pre> <elementRule role="Choice">
* <choice>
* <ref label="Target1" occurs="*"/>
* <ref label="Target2" occurs="*"/>
* </choice>
* </elementRule>
* <tag name="choice" role="Choice"/>
* </pre>
*
* @version choice.rlx (Thu Jul 27 08:34:10 JST 2000)
* @author Relaxer 0.10 (by ASAMI@Yokohama)
*/
public class Choice implements java.io.Serializable {
private IChoiceContent content;
/**
* Creates a <code>Choice</code>.
*
*/
public Choice() {
}
/**
* Creates a <code>Choice</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 Choice(RStack stack) {
setup(stack);
}
/**
* Creates a <code>Choice</code> by the Document <code>doc</code>.
*
* @param doc
*/
public Choice(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Creates a <code>Choice</code> by the Element <code>element</code>.
*
* @param element
*/
public Choice(Element element) {
setup(element);
}
/**
* Initializes the <code>Choice</code> by the Document <code>doc</code>.
*
* @param doc
*/
public void setup(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Initializes the <code>Choice</code> by the Element <code>element</code>.
*
* @param element
*/
public void setup(Element element) {
init(element);
}
/**
* Initializes the <code>Choice</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);
if (Target1.isMatch(stack)) {
setContent(new Target1(stack));
} else if (Target2.isMatch(stack)) {
setContent(new Target2(stack));
} else {
throw (new IllegalArgumentException());
}
}
/**
* 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("choice");
int size;
content.makeElement(element);
parent.appendChild(element);
}
/**
* Gets the IChoiceContent property <b>content</b>.
*
* @return IChoiceContent
*/
public final IChoiceContent getContent() {
return (content);
}
/**
* Sets the IChoiceContent property <b>content</b>.
*
* @param content
*/
public final void setContent(IChoiceContent content) {
this.content = content;
}
/**
* Tests if a Element <code>element</code> is valid
* for the <code>Choice</code>.
*
* @param element
* @return boolean
*/
public static boolean isMatch(Element element) {
String tagName = element.getTagName();
if (!"choice".equals(tagName)) {
return (false);
}
RStack target = new RStack(element);
Element child;
if (Target1.isMatchHungry(target)) {
} else if (Target2.isMatchHungry(target)) {
} else {
return (false);
}
if (!target.isEmptyElement()) {
return (false);
}
return (true);
}
/**
* Tests if elements contained in a Stack <code>stack</code>
* is valid for the <code>Choice</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>Choice</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);
}
}
}
IChoiceContent.java
import org.w3c.dom.*;
/**
* <b>IChoiceContent</b> is generated by Relaxer based on choice.rlx.
*
* @version choice.rlx (Thu Jul 27 08:34:10 JST 2000)
* @author Relaxer 0.10 (by ASAMI@Yokohama)
*/
public interface IChoiceContent {
/**
* Creates a DOM representation of the object.
* Result is appended to the Node <code>parent</code>.
*
* @param parent
*/
void makeElement(Node parent);
}
Target1.java
import org.w3c.dom.*;
/**
* <b>Target1</b> is generated by Relaxer based on Mixed.rlx.
* This class is derived from:
*
* <!-- for programmer
* <elementRule role="Target1" type="int"/>
*
* <tag name="target1" role="Target1"/>
* -->
* <!-- for javadoc -->
* <pre> <elementRule role="Target1" type="int"/>
* <tag name="target1" role="Target1"/>
* </pre>
*
* @version Mixed.rlx (Thu Jul 27 08:37:16 JST 2000)
* @author Relaxer 0.10 (by ASAMI@Yokohama)
*/
public class Target1 implements java.io.Serializable, IMixedPCDATA {
private int content;
/**
* Creates a <code>Target1</code>.
*
*/
public Target1() {
}
/**
* Creates a <code>Target1</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 Target1(RStack stack) {
setup(stack);
}
/**
* Creates a <code>Target1</code> by the Document <code>doc</code>.
*
* @param doc
*/
public Target1(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Creates a <code>Target1</code> by the Element <code>element</code>.
*
* @param element
*/
public Target1(Element element) {
setup(element);
}
/**
* Initializes the <code>Target1</code> by the Document <code>doc</code>.
*
* @param doc
*/
public void setup(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Initializes the <code>Target1</code> by the Element <code>element</code>.
*
* @param element
*/
public void setup(Element element) {
init(element);
}
/**
* Initializes the <code>Target1</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("target1");
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>Target1</code>.
*
* @param element
* @return boolean
*/
public static boolean isMatch(Element element) {
String tagName = element.getTagName();
if (!"target1".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>Target1</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>Target1</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);
}
}
}
Target2.java
import org.w3c.dom.*;
/**
* <b>Target2</b> is generated by Relaxer based on Mixed.rlx.
* This class is derived from:
*
* <!-- for programmer
* <elementRule role="Target2" type="boolean"/>
*
* <tag name="target2" role="Target2"/>
* -->
* <!-- for javadoc -->
* <pre> <elementRule role="Target2" type="boolean"/>
* <tag name="target2" role="Target2"/>
* </pre>
*
* @version Mixed.rlx (Thu Jul 27 08:37:16 JST 2000)
* @author Relaxer 0.10 (by ASAMI@Yokohama)
*/
public class Target2 implements java.io.Serializable, IMixedPCDATA {
private boolean content;
/**
* Creates a <code>Target2</code>.
*
*/
public Target2() {
}
/**
* Creates a <code>Target2</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 Target2(RStack stack) {
setup(stack);
}
/**
* Creates a <code>Target2</code> by the Document <code>doc</code>.
*
* @param doc
*/
public Target2(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Creates a <code>Target2</code> by the Element <code>element</code>.
*
* @param element
*/
public Target2(Element element) {
setup(element);
}
/**
* Initializes the <code>Target2</code> by the Document <code>doc</code>.
*
* @param doc
*/
public void setup(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Initializes the <code>Target2</code> by the Element <code>element</code>.
*
* @param element
*/
public void setup(Element element) {
init(element);
}
/**
* Initializes the <code>Target2</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.getElementPropertyAsBoolean(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("target2");
URelaxer.setElementPropertyByBoolean(element, content);
int size;
parent.appendChild(element);
}
/**
* Gets the boolean property <b>content</b>.
*
* @return boolean
*/
public final boolean getContent() {
return (content);
}
/**
* Sets the boolean property <b>content</b>.
*
* @param content
*/
public final void setContent(boolean content) {
this.content = content;
}
/**
* Tests if a Element <code>element</code> is valid
* for the <code>Target2</code>.
*
* @param element
* @return boolean
*/
public static boolean isMatch(Element element) {
String tagName = element.getTagName();
if (!"target2".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>Target2</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>Target2</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);
}
}
}