Powered by SmartDoc

Adding attributes

SimpleAttr.xml
<?xml version="1.0"?>

<SimpleAttr data="10">100</SimpleAttr>
SimpleAttr.rlx
<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "relaxCore.dtd">
<module>

  <interface>
    <export label="SimpleAttr"/>
  </interface>

  <elementRule role="SimpleAttr" type="int">
  </elementRule>

  <tag name="SimpleAttr">
    <attribute name="data" type="int"/>
  </tag>

</module>
SimpleAttr.java
import org.w3c.dom.*;

/**
 * <b>SimpleAttr</b> is generated by Relaxer based on SimpleAttr.rlx.
 * This class is derived from:
 * 
 * <!-- for programmer
 * <elementRule role="SimpleAttr" type="int"/>
 * 
 * <tag name="SimpleAttr">
 *   <attribute name="data" type="int"/>
 * </tag>
 * -->
 * <!-- for javadoc -->
 * <pre> &lt;elementRule role="SimpleAttr" type="int"/&gt;
 * &lt;tag name="SimpleAttr"&gt;
 *   &lt;attribute name="data" type="int"/&gt;
 * &lt;/tag&gt;
 * </pre>
 *
 * @version SimpleAttr.rlx (Thu Jul 27 08:09:16 JST 2000)
 * @author  Relaxer 0.10 (by ASAMI@Yokohama)
 */
public class SimpleAttr implements java.io.Serializable {
    private int content;
    private int data;

    /**
     * Creates a <code>SimpleAttr</code>.
     *
     */
    public SimpleAttr() {
    }

    /**
     * Creates a <code>SimpleAttr</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 SimpleAttr(RStack stack) {
        setup(stack);
    }

    /**
     * Creates a <code>SimpleAttr</code> by the Document <code>doc</code>.
     *
     * @param doc
     */
    public SimpleAttr(Document doc) {
        setup(doc.getDocumentElement());
    }

    /**
     * Creates a <code>SimpleAttr</code> by the Element <code>element</code>.
     *
     * @param element
     */
    public SimpleAttr(Element element) {
        setup(element);
    }

    /**
     * Initializes the <code>SimpleAttr</code> by the Document <code>doc</code>.
     *
     * @param doc
     */
    public void setup(Document doc) {
        setup(doc.getDocumentElement());
    }

    /**
     * Initializes the <code>SimpleAttr</code> by the Element <code>element</code>.
     *
     * @param element
     */
    public void setup(Element element) {
        init(element);
    }

    /**
     * Initializes the <code>SimpleAttr</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);
        data = URelaxer.getAttributePropertyAsInt(element, "data");
    }

    /**
     * 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("SimpleAttr");
        URelaxer.setElementPropertyByInt(element, content);
        int size;
        URelaxer.setAttributePropertyByInt(element, "data", data);
        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;
    }

    /**
     * Gets the int property <b>data</b>.
     *
     * @return int
     */
    public final int getData() {
        return (data);
    }

    /**
     * Sets the int property <b>data</b>.
     *
     * @param data
     */
    public final void setData(int data) {
        this.data = data;
    }

    /**
     * Tests if a Element <code>element</code> is valid
     * for the <code>SimpleAttr</code>.
     *
     * @param element
     * @return boolean
     */
    public static boolean isMatch(Element element) {
        String tagName = element.getTagName();
        if (!"SimpleAttr".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>SimpleAttr</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>SimpleAttr</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);
        }
    }
}