Powered by SmartDoc

Reference to elementRules and hedgeRules

RefElementHedge.rlx
<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "relaxCore.dtd">
<module>

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

  <elementRule role="RefElementHedge">
    <sequence>
      <ref label="TargetElement"/>
      <ref label="TargetHedge"/>
    </sequence>
  </elementRule>

  <tag name="ref" role="RefElementHedge">
  </tag>

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

  <tag name="target" role="TargetElement">
  </tag>

  <hedgeRule label="TargetHedge">
    <sequence>
      <element name="one" type="byte"/>
      <element name="two" type="short"/>
    </sequence>
  </hedgeRule>

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

/**
 * <b>RefElementHedge</b> is generated by Relaxer based on RefElementHedge.rlx.
 * This class is derived from:
 * 
 * <!-- for programmer
 * <elementRule role="RefElementHedge">
 *   <sequence>
 *     <ref label="TargetElement"/>
 *     <ref label="TargetHedge"/>
 *   </sequence>
 * </elementRule>
 * 
 * <tag name="ref" role="RefElementHedge"/>
 * -->
 * <!-- for javadoc -->
 * <pre> &lt;elementRule role="RefElementHedge"&gt;
 *   &lt;sequence&gt;
 *     &lt;ref label="TargetElement"/&gt;
 *     &lt;ref label="TargetHedge"/&gt;
 *   &lt;/sequence&gt;
 * &lt;/elementRule&gt;
 * &lt;tag name="ref" role="RefElementHedge"/&gt;
 * </pre>
 *
 * @version RefElementHedge.rlx (Tue Aug 01 23:45:44 JST 2000)
 * @author  Relaxer 0.10.1b (by ASAMI@Yokohama)
 */
public class RefElementHedge implements java.io.Serializable {
    private int target;
    private byte one;
    private short two;

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

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

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

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

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

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

    /**
     * Initializes the <code>RefElementHedge</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());
        one = URelaxer.getElementPropertyAsByte(stack.popElement());
        two = URelaxer.getElementPropertyAsShort(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);
        URelaxer.setElementPropertyByByte(element, "one", one);
        URelaxer.setElementPropertyByShort(element, "two", two);
        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;
    }

    /**
     * Gets the byte property <b>one</b>.
     *
     * @return byte
     */
    public final byte getOne() {
        return (one);
    }

    /**
     * Sets the byte property <b>one</b>.
     *
     * @param one
     */
    public final void setOne(byte one) {
        this.one = one;
    }

    /**
     * Gets the short property <b>two</b>.
     *
     * @return short
     */
    public final short getTwo() {
        return (two);
    }

    /**
     * Sets the short property <b>two</b>.
     *
     * @param two
     */
    public final void setTwo(short two) {
        this.two = two;
    }

    /**
     * Tests if a Element <code>element</code> is valid
     * for the <code>RefElementHedge</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);
        }
        child = target.popElement();
        if (child == null) {
            return (false);
        }
        if (!"one".equals(child.getTagName())) {
            return (false);
        }
        child = target.popElement();
        if (child == null) {
            return (false);
        }
        if (!"two".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>RefElementHedge</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>RefElementHedge</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);
        }
    }
}