package jp.gr.java_conf.abagames.bulletml; import org.w3c.dom.*; import org.xml.sax.*; import java.io.*; import java.net.MalformedURLException; import java.net.URL; import javax.xml.parsers.*; /** * <b>Fire</b> is generated by Relaxer based on bulletml.rlx. * This class is derived from: * * <!-- for programmer * <elementRule role="fire"> * <sequence> * <ref label="direction" occurs="?"/> * <ref label="speed" occurs="?"/> * <hedgeRef label="bulletElm"/> * </sequence> * </elementRule> * * <tag name="fire"> * <attribute name="label" type="string"/> * </tag> * --> * <!-- for javadoc --> * <pre> <elementRule role="fire"> * <sequence> * <ref label="direction" occurs="?"/> * <ref label="speed" occurs="?"/> * <hedgeRef label="bulletElm"/> * </sequence> * </elementRule> * <tag name="fire"> * <attribute name="label" type="string"/> * </tag> * </pre> * * @version bulletml.rlx 0.21 (Sun Jun 03 09:44:34 JST 2001) * @author Relaxer 0.13 (http://www.relaxer.org) */ public class Fire implements java.io.Serializable, IRNSContainer, IRNode, IFireElmChoice, IBulletmlChoice { private RNSContext rNSContext_ = new RNSContext(this); private String label_; private Direction direction_; private Speed speed_; private IBulletElmChoice bulletElm_; private IRNode parentRNode_; /** * Creates a <code>Fire</code>. * */ public Fire() { } /** * Creates a <code>Fire</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 Fire(RStack stack) { setup(stack); } /** * Creates a <code>Fire</code> by the Document <code>doc</code>. * * @param doc */ public Fire(Document doc) { setup(doc.getDocumentElement()); } /** * Creates a <code>Fire</code> by the Element <code>element</code>. * * @param element */ public Fire(Element element) { setup(element); } /** * Creates a <code>Fire</code> by the File <code>file</code>. * * @param file * @exception IOException * @exception SAXException * @exception ParserConfigurationException */ public Fire(File file) throws IOException, SAXException, ParserConfigurationException { setup(file); } /** * Creates a <code>Fire</code> * by the String representation of URI <code>uri</code>. * * @param uri * @exception IOException * @exception SAXException * @exception ParserConfigurationException */ public Fire(String uri) throws IOException, SAXException, ParserConfigurationException { setup(uri); } /** * Creates a <code>Fire</code> by the URL <code>url</code>. * * @param url * @exception IOException * @exception SAXException * @exception ParserConfigurationException */ public Fire(URL url) throws IOException, SAXException, ParserConfigurationException { setup(url); } /** * Creates a <code>Fire</code> by the InputStream <code>in</code>. * * @param in * @exception IOException * @exception SAXException * @exception ParserConfigurationException */ public Fire(InputStream in) throws IOException, SAXException, ParserConfigurationException { setup(in); } /** * Creates a <code>Fire</code> by the InputSource <code>is</code>. * * @param is * @exception IOException * @exception SAXException * @exception ParserConfigurationException */ public Fire(InputSource is) throws IOException, SAXException, ParserConfigurationException { setup(is); } /** * Creates a <code>Fire</code> by the Reader <code>reader</code>. * * @param reader * @exception IOException * @exception SAXException * @exception ParserConfigurationException */ public Fire(Reader reader) throws IOException, SAXException, ParserConfigurationException { setup(reader); } /** * Initializes the <code>Fire</code> by the Document <code>doc</code>. * * @param doc */ public void setup(Document doc) { setup(doc.getDocumentElement()); } /** * Initializes the <code>Fire</code> by the Element <code>element</code>. * * @param element */ public void setup(Element element) { init(element); } /** * Initializes the <code>Fire</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); rNSContext_.declareNamespace(element); label_ = URelaxer.getAttributePropertyAsString(element, "label"); if (Direction.isMatch(stack)) { setDirection(new Direction(stack)); } if (Speed.isMatch(stack)) { setSpeed(new Speed(stack)); } if (Bullet.isMatch(stack)) { setBulletElm(new Bullet(stack)); } else if (BulletRef.isMatch(stack)) { setBulletElm(new BulletRef(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.createElementNS("http://www.asahi-net.or.jp/~cs8k-cyu/bulletml", "fire"); rNSContext_.setupNamespace(element); int size; if (this.label_ != null) { URelaxer.setAttributePropertyByString(element, "label", this.label_); } if (this.direction_ != null) { this.direction_.makeElement(element); } if (this.speed_ != null) { this.speed_.makeElement(element); } this.bulletElm_.makeElement(element); parent.appendChild(element); } /** * Initializes the <code>Fire</code> by the File <code>file</code>. * * @param file * @exception IOException * @exception SAXException * @exception ParserConfigurationException */ public void setup(File file) throws IOException, SAXException, ParserConfigurationException { setup(file.toURL()); } /** * Initializes the <code>Fire</code> * by the String representation of URI <code>uri</code>. * * @param uri * @exception IOException * @exception SAXException * @exception ParserConfigurationException */ public void setup(String uri) throws IOException, SAXException, ParserConfigurationException { setup(UJAXP.getValidDocument(uri)); } /** * Initializes the <code>Fire</code> by the URL <code>url</code>. * * @param url * @exception IOException * @exception SAXException * @exception ParserConfigurationException */ public void setup(URL url) throws IOException, SAXException, ParserConfigurationException { setup(UJAXP.getValidDocument(url)); } /** * Initializes the <code>Fire</code> by the InputStream <code>in</code>. * * @param in * @exception IOException * @exception SAXException * @exception ParserConfigurationException */ public void setup(InputStream in) throws IOException, SAXException, ParserConfigurationException { setup(UJAXP.getValidDocument(in)); } /** * Initializes the <code>Fire</code> by the InputSource <code>is</code>. * * @param is * @exception IOException * @exception SAXException * @exception ParserConfigurationException */ public void setup(InputSource is) throws IOException, SAXException, ParserConfigurationException { setup(UJAXP.getValidDocument(is)); } /** * Initializes the <code>Fire</code> by the Reader <code>reader</code>. * * @param reader * @exception IOException * @exception SAXException * @exception ParserConfigurationException */ public void setup(Reader reader) throws IOException, SAXException, ParserConfigurationException { setup(UJAXP.getValidDocument(reader)); } /** * Creates a DOM document representation of the object. * * @exception ParserConfigurationException * @return Document */ public Document makeDocument() throws ParserConfigurationException { Document doc = UJAXP.makeDocument(); makeElement(doc); return (doc); } /** * Gets the RNSContext property <b>rNSContext</b>. * * @return RNSContext */ public final RNSContext getRNSContext() { return (rNSContext_); } /** * Sets the RNSContext property <b>rNSContext</b>. * * @param rNSContext */ public final void setRNSContext(RNSContext rNSContext) { this.rNSContext_ = rNSContext; } /** * Gets the String property <b>label</b>. * * @return String */ public final String getLabel() { return (label_); } /** * Sets the String property <b>label</b>. * * @param label */ public final void setLabel(String label) { this.label_ = label; } /** * Gets the Direction property <b>direction</b>. * * @return Direction */ public final Direction getDirection() { return (direction_); } /** * Sets the Direction property <b>direction</b>. * * @param direction */ public final void setDirection(Direction direction) { this.direction_ = direction; if (direction != null) { direction.setParentRNode(this); } } /** * Gets the Speed property <b>speed</b>. * * @return Speed */ public final Speed getSpeed() { return (speed_); } /** * Sets the Speed property <b>speed</b>. * * @param speed */ public final void setSpeed(Speed speed) { this.speed_ = speed; if (speed != null) { speed.setParentRNode(this); } } /** * Gets the IBulletElmChoice property <b>bulletElm</b>. * * @return IBulletElmChoice */ public final IBulletElmChoice getBulletElm() { return (bulletElm_); } /** * Sets the IBulletElmChoice property <b>bulletElm</b>. * * @param bulletElm */ public final void setBulletElm(IBulletElmChoice bulletElm) { this.bulletElm_ = bulletElm; if (bulletElm != null) { bulletElm.setParentRNode(this); } } /** * Makes a XML text representation. * * @return String */ public String makeTextDocument() { StringBuffer buffer = new StringBuffer(); makeTextElement(buffer); return (new String(buffer)); } /** * Makes a XML text representation. * * @param buffer */ public void makeTextElement(StringBuffer buffer) { int size; String prefix = rNSContext_.getPrefixByUri("http://www.asahi-net.or.jp/~cs8k-cyu/bulletml"); buffer.append("<"); URelaxer.makeQName(prefix, "fire", buffer); rNSContext_.makeNSMappings(buffer); if (label_ != null) { buffer.append(" "); buffer.append("label"); buffer.append("=\""); buffer.append(URelaxer.escapeAttrQuot(getLabel())); buffer.append("\""); } buffer.append(">"); if (direction_ != null) { direction_.makeTextElement(buffer); } if (speed_ != null) { speed_.makeTextElement(buffer); } bulletElm_.makeTextElement(buffer); buffer.append("</"); URelaxer.makeQName(prefix, "fire", buffer); buffer.append(">"); } /** * Makes a XML text representation. * * @param buffer */ public void makeTextElement(PrintWriter buffer) { int size; String prefix = rNSContext_.getPrefixByUri("http://www.asahi-net.or.jp/~cs8k-cyu/bulletml"); buffer.print("<"); URelaxer.makeQName(prefix, "fire", buffer); rNSContext_.makeNSMappings(buffer); if (label_ != null) { buffer.print(" "); buffer.print("label"); buffer.print("=\""); buffer.print(URelaxer.escapeAttrQuot(getLabel())); buffer.print("\""); } buffer.print(">"); if (direction_ != null) { direction_.makeTextElement(buffer); } if (speed_ != null) { speed_.makeTextElement(buffer); } bulletElm_.makeTextElement(buffer); buffer.print("</"); URelaxer.makeQName(prefix, "fire", buffer); buffer.print(">"); } /** * Gets the IRNode property <b>parentRNode</b>. * * @return IRNode */ public final IRNode getParentRNode() { return (parentRNode_); } /** * Sets the IRNode property <b>parentRNode</b>. * * @param parentRNode */ public final void setParentRNode(IRNode parentRNode) { this.parentRNode_ = parentRNode; } /** * Gets child RNodes. * * @return IRNode[] */ public IRNode[] getRNodes() { java.util.List classNodes = new java.util.ArrayList(); if (direction_ != null) { classNodes.add(direction_); } if (speed_ != null) { classNodes.add(speed_); } classNodes.add(bulletElm_); IRNode[] nodes = new IRNode[classNodes.size()]; return ((IRNode[]) classNodes.toArray(nodes)); } /** * Tests if a Element <code>element</code> is valid * for the <code>Fire</code>. * * @param element * @return boolean */ public static boolean isMatch(Element element) { if (!URelaxer2.isTargetElement(element, "http://www.asahi-net.or.jp/~cs8k-cyu/bulletml", "fire")) { return (false); } RStack target = new RStack(element); Element child; if (Direction.isMatchHungry(target)) { } if (Speed.isMatchHungry(target)) { } if (Bullet.isMatchHungry(target)) { } else if (BulletRef.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>Fire</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>Fire</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); } } }