001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.xml.axi;
042:
043: import java.util.List;
044: import java.util.Set;
045: import org.netbeans.modules.xml.axi.impl.AXIModelBuilder;
046: import org.netbeans.modules.xml.axi.impl.Util;
047: import org.netbeans.modules.xml.axi.visitor.AXIVisitor;
048: import org.netbeans.modules.xml.schema.model.Form;
049: import org.netbeans.modules.xml.schema.model.GlobalElement;
050: import org.netbeans.modules.xml.schema.model.Schema;
051: import org.netbeans.modules.xml.schema.model.SchemaComponent;
052:
053: /**
054: * Root of the AXI tree.
055: *
056: * @author Samaresh (Samaresh.Panda@Sun.Com)
057: */
058: public abstract class AXIDocument extends AXIComponent {
059:
060: /**
061: * Creates a new instance of AXIDocument.
062: */
063: public AXIDocument(AXIModel model) {
064: super (model);
065: }
066:
067: /**
068: * Creates a new instance of AXIDocument
069: */
070: public AXIDocument(AXIModel model, SchemaComponent schemaComponent) {
071: super (model, schemaComponent);
072: }
073:
074: /**
075: * Allow visitor.
076: */
077: public void accept(AXIVisitor visitor) {
078: visitor.visit(this );
079: }
080:
081: /**
082: * Convenient method to return the top level elements.
083: */
084: public List<Element> getElements() {
085: return getChildren(Element.class);
086: }
087:
088: /**
089: * Convenient method to return the top level attributes.
090: */
091: public List<Attribute> getAttributes() {
092: return getChildren(Attribute.class);
093: }
094:
095: /**
096: * Returns a list of ContentModels used in this schema document.
097: */
098: public List<ContentModel> getContentModels() {
099: return getChildren(ContentModel.class);
100: }
101:
102: /**
103: * Adds a ContentModel to the document.
104: */
105: public void addContentModel(ContentModel contentModel) {
106: appendChild(ContentModel.PROP_CONTENT_MODEL, contentModel);
107: }
108:
109: /**
110: * Removes a ContentModel from the document.
111: */
112: public void removeContentModel(ContentModel contentModel) {
113: removeChild(ContentModel.PROP_CONTENT_MODEL, contentModel);
114: }
115:
116: /**
117: * Adds an Element as its child.
118: */
119: public void addElement(Element element) {
120: appendChild(Element.PROP_ELEMENT, element);
121: }
122:
123: /**
124: * Removes an Element.
125: */
126: public void removeElement(Element element) {
127: removeChild(Element.PROP_ELEMENT, element);
128: }
129:
130: /**
131: * Returns the namespace, this component belongs to.
132: */
133: public String getTargetNamespace() {
134: return namespace;
135: }
136:
137: /**
138: * Sets the fixed value.
139: */
140: public void setTargetNamespace(String value) {
141: String oldValue = getTargetNamespace();
142: if ((oldValue == null && value == null)
143: || (oldValue != null && oldValue.equals(value))) {
144: return;
145: }
146: this .namespace = value;
147: firePropertyChangeEvent(PROP_TARGET_NAMESPACE, oldValue, value);
148: }
149:
150: public void setVersion(String value) {
151: String oldValue = getVersion();
152: if ((oldValue == null && value == null)
153: || (oldValue != null && oldValue.equals(value))) {
154: return;
155: }
156: this .version = value;
157: firePropertyChangeEvent(PROP_VERSION, oldValue, value);
158: }
159:
160: public String getVersion() {
161: return version;
162: }
163:
164: public void setLanguage(String value) {
165: String oldValue = getLanguage();
166: if ((oldValue == null && value == null)
167: || (oldValue != null && oldValue.equals(value))) {
168: return;
169: }
170: this .language = value;
171: firePropertyChangeEvent(PROP_LANGUAGE, oldValue, value);
172: }
173:
174: public String getLanguage() {
175: return language;
176: }
177:
178: //TODO
179: // public void setFinalDefault(Set<Final> value) {
180: // Set<Final> oldValue = getFinalDefault();
181: // if( (oldValue == null && value == null) ||
182: // (oldValue != null && oldValue.equals(value)) ) {
183: // return;
184: // }
185: // this.finalDefault = value;
186: // firePropertyChangeEvent(PROP_FINAL_DEFAULT, oldValue, value);
187: // }
188: //
189: // public Set<Final> getFinalDefault() {
190: // return finalDefault;
191: // }
192:
193: public void setElementFormDefault(Form value) {
194: Form oldValue = getElementFormDefault();
195: if ((oldValue == null && value == null)
196: || (oldValue != null && oldValue.equals(value))) {
197: return;
198: }
199: this .elementFormDefault = value;
200: firePropertyChangeEvent(PROP_ELEMENT_FORM_DEFAULT, oldValue,
201: value);
202: }
203:
204: public Form getElementFormDefault() {
205: return elementFormDefault;
206: }
207:
208: public void setAttributeFormDefault(Form value) {
209: Form oldValue = getAttributeFormDefault();
210: if ((oldValue == null && value == null)
211: || (oldValue != null && oldValue.equals(value))) {
212: return;
213: }
214: this .attributeFormDefault = value;
215: firePropertyChangeEvent(PROP_ATTRIBUTE_FORM_DEFAULT, oldValue,
216: value);
217: }
218:
219: public Form getAttributeFormDefault() {
220: return attributeFormDefault;
221: }
222:
223: public void setSchemaDesignPattern(SchemaGenerator.Pattern value) {
224: SchemaGenerator.Pattern oldValue = getSchemaDesignPattern();
225: if ((oldValue == null && value == null)
226: || (oldValue != null && oldValue == value)) {
227: return;
228: }
229: if (getModel() != null)
230: getModel().setSchemaDesignPattern(value);
231: firePropertyChangeEvent(PROP_SCHEMA_DESIGN_PATTERN, oldValue,
232: value);
233: }
234:
235: public SchemaGenerator.Pattern getSchemaDesignPattern() {
236: return getModel() != null ? getModel().getSchemaDesignPattern()
237: : null;
238: }
239:
240: private String namespace;
241: private String version;
242: private String language;
243: private Form attributeFormDefault;
244: private Form elementFormDefault;
245:
246: public static final String PROP_TARGET_NAMESPACE = "targetNamespace"; // NOI18N
247: public static final String PROP_LANGUAGE = "language"; // NOI18N
248: public static final String PROP_VERSION = "version"; // NOI18N
249: public static final String PROP_ATTRIBUTE_FORM_DEFAULT = "attributeFormDefault"; // NOI18N
250: public static final String PROP_ELEMENT_FORM_DEFAULT = "elementFormDefault"; // NOI18N
251: public static final String PROP_SCHEMA_DESIGN_PATTERN = "schemaDesignPattern"; // NOI18N
252: }
|