001: /**
002: * org/ozone-db/xml/dom/ElementDeclImpl.java
003: *
004: * The contents of this file are subject to the OpenXML Public
005: * License Version 1.0; you may not use this file except in compliance
006: * with the License. You may obtain a copy of the License at
007: * http://www.openxml.org/license.html
008: *
009: * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
010: * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
011: * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
012: * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
013: * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
014: * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
015: *
016: * The Initial Developer of this code under the License is Assaf Arkin.
017: * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
018: * All Rights Reserved.
019: */
020:
021: /**
022: * Changes for Persistent DOM running with ozone are
023: * Copyright 1999 by SMB GmbH. All rights reserved.
024: */package org.ozoneDB.xml.dom;
025:
026: import org.w3c.dom.*;
027:
028: /**
029: * @version $Revision: 1.1 $ $Date: 2001/12/18 11:03:24 $
030: * @author <a href="mailto:arkin@trendline.co.il">Assaf Arkin</a>
031: * @see org.w3c.dom.Node
032: * @see NodeImpl
033: */
034: public class ElementDeclImpl extends NodeImpl implements
035: ElementDeclProxy {
036:
037: final static long serialVersionUID = 1;
038:
039: public short getNodeType() {
040: return ELEMENT_DECL_NODE;
041: }
042:
043: public String getName() {
044: return getNodeName();
045: }
046:
047: public synchronized boolean equals(Object other) {
048: /*
049: EntityProxy otherX;
050:
051: // Test for node equality (this covers entity name and all its children)
052: // and then test for specific entity qualities.
053: if (super.equals (other)) {
054: otherX = (EntityProxy) other;
055: return (getPublicId ().equals (otherX.getPublicId ()) &&
056: getSystemId ().equals (otherX.getSystemId ()) &&
057: getNotation ().equals (otherX.getNotation ()));
058: }
059: */
060: return false;
061: }
062:
063: /**
064: * Returns true if element is empty. An empty element cannot contain any
065: * children and must be specified with an empty tag, or an opening tag
066: * immediately followed by a closing tag.
067: *
068: * @return True if element is empty
069: */
070: public boolean isEmpty() {
071: return _empty;
072: }
073:
074: /**
075: * Returns true if element may contain any child elements and character data
076: * in any order.
077: *
078: * @return True if element supports any contents
079: */
080: public boolean isAny() {
081: return _any;
082: }
083:
084: /**
085: * Returns true if element contains mixed contents. Mixed contents includes
086: * both elements and character data in any particular order. This option
087: * implies that both {@link #isEmpty} and {@link #isAny} return false.
088: * If all three are false, then contents is subject to exact order.
089: *
090: * @return True if element contains mixed contents
091: */
092: public boolean isMixed() {
093: return _mixed;
094: }
095:
096: /**
097: * Returns true if the opening tag is optional. Even if the opening tag is
098: * missing from the document for this element, the document is still valid.
099: * This option only relates to HTML document, and implies that {@link
100: * #requiresClosingTag} is also true.
101: *
102: * @return True if opening tag is optional
103: */
104: public boolean requiresOpeningTag() {
105: return _optionalOpen;
106: }
107:
108: /**
109: * Returns true if the closing tag is optional. Even if the closing tag is
110: * missing from the document for this element, the document is still valid.
111: * This option only relates to HTML document.
112: *
113: * @return True if closing tag is optional
114: */
115: public boolean requiresClosingTag() {
116: return _optionalClose;
117: }
118:
119: public final Object clone() {
120: ElementDeclProxy clone = null;
121: try {
122: clone = (ElementDeclProxy) database().createObject(
123: ElementDeclImpl.class.getName());
124: ((NodeProxy) clone).init(_ownerDocument, getNodeName(),
125: null, true);
126: cloneInto((NodeProxy) clone, true);
127: } catch (Exception except) {
128: throw new DOMExceptionImpl(DOMExceptionImpl.PDOM_ERR,
129: except.getMessage());
130: }
131: return clone;
132: }
133:
134: public final Node cloneNode(boolean deep) {
135: ElementDeclProxy clone = null;
136: try {
137: clone = (ElementDeclProxy) database().createObject(
138: ElementDeclImpl.class.getName());
139: ((NodeProxy) clone).init(_ownerDocument, getNodeName(),
140: null, true);
141: cloneInto((NodeProxy) clone, deep);
142: } catch (Exception except) {
143: throw new DOMExceptionImpl(DOMExceptionImpl.PDOM_ERR,
144: except.getMessage());
145: }
146: return clone;
147: }
148:
149: /**
150: * Constructor requires owner document, element name and its definition.
151: *
152: * @param owner The owner document
153: * @param name The element name
154: * @param definition The element definition
155: */
156: ElementDeclImpl(DocumentImpl owner, String name, String definition) {
157: this (owner, name, definition, false, false);
158: }
159:
160: /**
161: * Constructor requires owner document, element name and its definition.
162: * The flags for optional opening and closing tag are supported only for
163: * HTML documents.
164: *
165: * @param owner The owner document
166: * @param name The element name
167: * @param definition The element definition
168: * @param optionalOpen The opening tag is optional
169: * @param optionalClose The closing tag is optional
170: */
171: ElementDeclImpl(DocumentImpl owner, String name, String definition,
172: boolean optionalOpen, boolean optionalClose) {
173: super (owner, name, null, true);
174: _optionalOpen = optionalOpen;
175: if (_optionalOpen) {
176: _optionalClose = true;
177: } else {
178: _optionalClose = optionalClose;
179: }
180: if (definition.equals("EMPTY")) {
181: _empty = true;
182: } else if (definition.equals("ANY")) {
183: _any = true;
184: } else {
185: }
186: }
187:
188: private ElementDeclImpl(DocumentImpl owner, String name) {
189: super (owner, name, null, true);
190: }
191:
192: /**
193: * Indicates that the opening tag is optional: even if missing from the
194: * document, the document is still valid. Applies only to HTML documents.
195: * Also implies that {@link #_optionalClose} is true.
196: */
197: private boolean _optionalOpen;
198:
199: /**
200: * Indicates that the closing tag is optional: even if missing from the
201: * document, the document is still valid. Applies only to HTML documents.
202: */
203: private boolean _optionalClose;
204:
205: /**
206: * Indicates that the element is empty.
207: */
208: private boolean _empty;
209:
210: /**
211: * Indicates that the element can contain any child elements of any type
212: * and any order.
213: */
214: private boolean _any;
215:
216: /**
217: * Indicates that the element contains mixed contents. Mixed contents
218: * includes both elements and character data in any particular order.
219: */
220: private boolean _mixed;
221: }
|