Powered by SmartDoc

Mixed

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

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

  <elementRule role="Mixed">
    <mixed>
      <ref label="MixedTarget" occurs="*"/>
    </mixed>
  </elementRule>

  <tag name="mixed" role="Mixed">
  </tag>

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

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

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

/**
 * <b>Mixed</b> is generated by Relaxer based on Mixed.rlx.
 * This class is derived from:
 * 
 * <!-- for programmer
 * <elementRule role="Mixed">
 *   <mixed>
 *     <ref label="MixedTarget" occurs="*"/>
 *   </mixed>
 * </elementRule>
 * 
 * <tag name="mixed" role="Mixed"/>
 * -->
 * <!-- for javadoc -->
 * <pre> &lt;elementRule role="Mixed"&gt;
 *   &lt;mixed&gt;
 *     &lt;ref label="MixedTarget" occurs="*"/&gt;
 *   &lt;/mixed&gt;
 * &lt;/elementRule&gt;
 * &lt;tag name="mixed" role="Mixed"/&gt;
 * </pre>
 *
 * @version Mixed.rlx (Wed Aug 02 00:14:58 JST 2000)
 * @author  Relaxer 0.10.1b (by ASAMI@Yokohama)
 */
public class Mixed implements java.io.Serializable {
    // List<IMixedPCDATA>
    private java.util.List pcdata = new java.util.ArrayList();

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

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

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

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

    /**
     * Sets a mixed content by <code>String</code>.
     *
     * @param text
     */
    public void setPcdata(String text) {
        addPcdata(new RString(text));
    }

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

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

    /**
     * Initializes the <code>Mixed</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);
        pcdata.clear();
        while (!stack.isEmpty()) {
            if (RString.isMatch(stack)) {
                addPcdata(new RString(stack));
            } else if (MixedTarget.isMatch(stack)) {
                addPcdata(new MixedTarget(stack));
            } else {
                break;
            }
        }
    }

    /**
     * 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("mixed");
        int size;
        size = pcdata.size();
        for (int i = 0;i < size;i++) {
            IMixedPCDATA value = (IMixedPCDATA)this.pcdata.get(i);
            value.makeElement(element);
        }
        parent.appendChild(element);
    }

    /**
     * Gets the IMixedPCDATA property <b>pcdata</b>.
     *
     * @return IMixedPCDATA[]
     */
    public final IMixedPCDATA[] getPcdata() {
        IMixedPCDATA[] array = new IMixedPCDATA[pcdata.size()];
        return ((IMixedPCDATA[])pcdata.toArray(array));
    }

    /**
     * Sets the IMixedPCDATA property <b>pcdata</b>.
     *
     * @param pcdata
     */
    public final void setPcdata(IMixedPCDATA[] pcdata) {
        this.pcdata.clear();
        this.pcdata.addAll(java.util.Arrays.asList(pcdata));
    }

    /**
     * Adds the IMixedPCDATA property <b>pcdata</b>.
     *
     * @param pcdata
     */
    public final void addPcdata(IMixedPCDATA pcdata) {
        this.pcdata.add(pcdata);
    }

    /**
     * Tests if a Element <code>element</code> is valid
     * for the <code>Mixed</code>.
     *
     * @param element
     * @return boolean
     */
    public static boolean isMatch(Element element) {
        String tagName = element.getTagName();
        if (!"mixed".equals(tagName)) {
            return (false);
        }
        RStack target = new RStack(element);
        Element child;
        while (!target.isEmptyElement()) {
            if (MixedTarget.isMatchHungry(target)) {
            } else {
                break;
            }
        }
        if (!target.isEmptyElement()) {
            return (false);
        }
        return (true);
    }

    /**
     * Tests if elements contained in a Stack <code>stack</code>
     * is valid for the <code>Mixed</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>Mixed</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);
        }
    }
}
IMixedPCDATA.java
import org.w3c.dom.*;

/**
 * <b>IMixedPCDATA</b> is generated by Relaxer based on Mixed.rlx.
 *
 * @version Mixed.rlx (Wed Aug 02 00:14:59 JST 2000)
 * @author  Relaxer 0.10.1b (by ASAMI@Yokohama)
 */
public interface IMixedPCDATA {
    /**
     * Creates a DOM representation of the object.
     * Result is appended to the Node <code>parent</code>.
     *
     * @param parent
     */
    void makeElement(Node parent);
}
MixedTarget.java
import org.w3c.dom.*;

/**
 * <b>MixedTarget</b> is generated by Relaxer based on Mixed.rlx.
 * This class is derived from:
 * 
 * <!-- for programmer
 * <elementRule role="MixedTarget" type="int"/>
 * 
 * <tag name="target" role="MixedTarget"/>
 * -->
 * <!-- for javadoc -->
 * <pre> &lt;elementRule role="MixedTarget" type="int"/&gt;
 * &lt;tag name="target" role="MixedTarget"/&gt;
 * </pre>
 *
 * @version Mixed.rlx (Wed Aug 02 00:14:59 JST 2000)
 * @author  Relaxer 0.10.1b (by ASAMI@Yokohama)
 */
public class MixedTarget implements java.io.Serializable, IMixedPCDATA {
    private int content;

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

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

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

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

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

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

    /**
     * Initializes the <code>MixedTarget</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("target");
        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>MixedTarget</code>.
     *
     * @param element
     * @return boolean
     */
    public static boolean isMatch(Element element) {
        String tagName = element.getTagName();
        if (!"target".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>MixedTarget</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>MixedTarget</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);
        }
    }
}
RString.java
import org.w3c.dom.*;

/**
 * <b>RString</b> is a text container class which is used for mixed.
 *
 * @version Mixed.rlx (Wed Aug 02 00:14:59 JST 2000)
 * @author  Relaxer 0.10.1b (by ASAMI@Yokohama)
 */
public class RString implements java.io.Serializable, IMixedPCDATA {
    private String text;

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

    /**
     * Creates a <code>RString</code> by the String <code>text</code>.
     *
     * @param text
     */
    public RString(String text) {
        this.text = text;
    }

    /**
     * Creates a <code>RString</code> by the Stack <code>stack</code>.
     * This constructor is supposed to be used internallyby the Relaxer system.
     *
     * @param stack
     */
    public RString(RStack stack) {
        setup(stack);
    }

    /**
     * Initializes the <code>RString</code> by the Stack <code>stack</code>
     * that contains Elements.
     * This constructor is supposed to be used internallyby the Relaxer system.
     *
     * @param stack
     */
    public void setup(RStack stack) {
        text = stack.pop().toString();
    }

    /**
     * Creates a DOM representation of the object.
     * Result is appended to the Node <code>parent</code>.
     *
     * @param node
     */
    public void makeElement(Node node) {
        Document doc = node.getOwnerDocument();
        node.appendChild(doc.createTextNode(text));
    }

    /**
     * Gets the text.
     *
     * @return String
     */
    public String getText() {
        return (text);
    }

    /**
     * Sets the text.
     *
     * @param text
     */
    public void setText(String text) {
        this.text = text;
    }

    /**
     * Tests if elements contained in a Stack <code>stack</code>
     * is valid for the <code>RString</code>.
     * This mehtod is supposed to be used internally
     * by the Relaxer system.
     *
     * @param stack
     * @return boolean
     */
    public static boolean isMatch(RStack stack) {
        return (stack.peek() instanceof String);
    }
}