Datatypes as contents
- XML: an element containing text only
- RELAX: a reference to a datatype
int
- Java: an instance variable of the type
int
SimpleData.xml
<?xml version="1.0"?>
<SimpleData>100</SimpleData>
SimpleData.rlx
<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "relaxCore.dtd">
<module>
<interface>
<export label="SimpleData"/>
</interface>
<elementRule role="SimpleData" type="int">
</elementRule>
<tag name="SimpleData"/>
</module>
SimpleData.java
import org.w3c.dom.*;
/**
* <b>SimpleData</b> is generated by Relaxer based on SimpleData.rlx.
* This class is derived from:
*
* <!-- for programmer
* <elementRule role="SimpleData" type="int"/>
*
* <tag name="SimpleData"/>
* -->
* <!-- for javadoc -->
* <pre> <elementRule role="SimpleData" type="int"/>
* <tag name="SimpleData"/>
* </pre>
*
* @version SimpleData.rlx (Thu Jul 27 08:07:08 JST 2000)
* @author Relaxer 0.10 (by ASAMI@Yokohama)
*/
public class SimpleData implements java.io.Serializable {
private int content;
/**
* Creates a <code>SimpleData</code>.
*
*/
public SimpleData() {
}
/**
* Creates a <code>SimpleData</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 SimpleData(RStack stack) {
setup(stack);
}
/**
* Creates a <code>SimpleData</code> by the Document <code>doc</code>.
*
* @param doc
*/
public SimpleData(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Creates a <code>SimpleData</code> by the Element <code>element</code>.
*
* @param element
*/
public SimpleData(Element element) {
setup(element);
}
/**
* Initializes the <code>SimpleData</code> by the Document <code>doc</code>.
*
* @param doc
*/
public void setup(Document doc) {
setup(doc.getDocumentElement());
}
/**
* Initializes the <code>SimpleData</code> by the Element <code>element</code>.
*
* @param element
*/
public void setup(Element element) {
init(element);
}
/**
* Initializes the <code>SimpleData</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("SimpleData");
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>SimpleData</code>.
*
* @param element
* @return boolean
*/
public static boolean isMatch(Element element) {
String tagName = element.getTagName();
if (!"SimpleData".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>SimpleData</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>SimpleData</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);
}
}
}