~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to xml/axi/src/org/netbeans/modules/xml/axi/AXIDocument.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
package org.netbeans.modules.xml.axi;
 
42
 
 
43
import java.util.List;
 
44
import java.util.Set;
 
45
import org.netbeans.modules.xml.axi.impl.AXIModelBuilder;
 
46
import org.netbeans.modules.xml.axi.impl.Util;
 
47
import org.netbeans.modules.xml.axi.visitor.AXIVisitor;
 
48
import org.netbeans.modules.xml.schema.model.Form;
 
49
import org.netbeans.modules.xml.schema.model.GlobalElement;
 
50
import org.netbeans.modules.xml.schema.model.Schema;
 
51
import org.netbeans.modules.xml.schema.model.SchemaComponent;
 
52
 
 
53
/**
 
54
 * Root of the AXI tree.
 
55
 *
 
56
 * @author Samaresh (Samaresh.Panda@Sun.Com)
 
57
 */
 
58
public abstract class AXIDocument extends AXIComponent {
 
59
    
 
60
    /**
 
61
     * Creates a new instance of AXIDocument.
 
62
     */
 
63
    public AXIDocument(AXIModel model) {
 
64
        super(model);
 
65
    }
 
66
    
 
67
    /**
 
68
     * Creates a new instance of AXIDocument
 
69
     */
 
70
    public AXIDocument(AXIModel model, SchemaComponent schemaComponent) {
 
71
        super(model, schemaComponent);
 
72
    }
 
73
        
 
74
    /**
 
75
     * Allow visitor.
 
76
     */
 
77
    public void accept(AXIVisitor visitor) {
 
78
        visitor.visit(this);
 
79
    }
 
80
    
 
81
    /**
 
82
     * Convenient method to return the top level elements.
 
83
     */
 
84
    public List<Element> getElements() {
 
85
        return getChildren(Element.class);
 
86
    }
 
87
    
 
88
    /**
 
89
     * Convenient method to return the top level attributes.
 
90
     */
 
91
    public List<Attribute> getAttributes() {
 
92
        return getChildren(Attribute.class);
 
93
    }    
 
94
    
 
95
    /**
 
96
     * Returns a list of ContentModels used in this schema document.
 
97
     */
 
98
    public List<ContentModel> getContentModels() {
 
99
        return getChildren(ContentModel.class);
 
100
    }
 
101
    
 
102
        
 
103
    /**
 
104
     * Adds a ContentModel to the document.
 
105
     */
 
106
    public void addContentModel(ContentModel contentModel) {
 
107
        appendChild(ContentModel.PROP_CONTENT_MODEL, contentModel);
 
108
    }
 
109
        
 
110
    /**
 
111
     * Removes a ContentModel from the document.
 
112
     */
 
113
    public void removeContentModel(ContentModel contentModel) {
 
114
        removeChild(ContentModel.PROP_CONTENT_MODEL, contentModel);
 
115
    }
 
116
    
 
117
    /**
 
118
     * Adds an Element as its child.
 
119
     */
 
120
    public void addElement(Element element) {
 
121
        appendChild(Element.PROP_ELEMENT, element);
 
122
    }
 
123
        
 
124
    /**
 
125
     * Removes an Element.
 
126
     */
 
127
    public void removeElement(Element element) {
 
128
        removeChild(Element.PROP_ELEMENT, element);
 
129
    }    
 
130
 
 
131
    /**
 
132
     * Returns the namespace, this component belongs to.
 
133
     */
 
134
    public String getTargetNamespace() {
 
135
        return namespace;
 
136
    }
 
137
    
 
138
    /**
 
139
     * Sets the fixed value.
 
140
     */
 
141
    public void setTargetNamespace(String value) {
 
142
        String oldValue = getTargetNamespace();
 
143
        if( (oldValue == null && value == null) ||
 
144
                (oldValue != null && oldValue.equals(value)) ) {
 
145
            return;
 
146
        }
 
147
        this.namespace = value;
 
148
        firePropertyChangeEvent(PROP_TARGET_NAMESPACE, oldValue, value);
 
149
    }
 
150
        
 
151
    public void setVersion(String value) {
 
152
        String oldValue = getVersion();
 
153
        if( (oldValue == null && value == null) ||
 
154
                (oldValue != null && oldValue.equals(value)) ) {
 
155
            return;
 
156
        }
 
157
        this.version = value;
 
158
        firePropertyChangeEvent(PROP_VERSION, oldValue, value);
 
159
    }
 
160
    
 
161
    public String getVersion() {
 
162
        return version;
 
163
    }
 
164
    
 
165
    public void setLanguage(String value) {
 
166
        String oldValue = getLanguage();
 
167
        if( (oldValue == null && value == null) ||
 
168
                (oldValue != null && oldValue.equals(value)) ) {
 
169
            return;
 
170
        }
 
171
        this.language = value;
 
172
        firePropertyChangeEvent(PROP_LANGUAGE, oldValue, value);
 
173
    }
 
174
    
 
175
    public String getLanguage() {
 
176
        return language;
 
177
    }
 
178
    
 
179
    //TODO
 
180
//    public void setFinalDefault(Set<Final> value) {
 
181
//        Set<Final> oldValue = getFinalDefault();
 
182
//        if( (oldValue == null && value == null) ||
 
183
//                (oldValue != null && oldValue.equals(value)) ) {
 
184
//            return;
 
185
//        }
 
186
//        this.finalDefault = value;
 
187
//        firePropertyChangeEvent(PROP_FINAL_DEFAULT, oldValue, value);
 
188
//    }
 
189
//    
 
190
//    public Set<Final> getFinalDefault() {
 
191
//        return finalDefault;
 
192
//    }
 
193
    
 
194
    public void setElementFormDefault(Form value) {
 
195
        Form oldValue = getElementFormDefault();
 
196
        if( (oldValue == null && value == null) ||
 
197
                (oldValue != null && oldValue.equals(value)) ) {
 
198
            return;
 
199
        }
 
200
        this.elementFormDefault = value;
 
201
        firePropertyChangeEvent(PROP_ELEMENT_FORM_DEFAULT, oldValue, 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, value);          
 
216
    }
 
217
    
 
218
    public Form getAttributeFormDefault() {
 
219
        return attributeFormDefault;
 
220
    }
 
221
        
 
222
    public void setSchemaDesignPattern(SchemaGenerator.Pattern value) {
 
223
        SchemaGenerator.Pattern oldValue = getSchemaDesignPattern();
 
224
        if( (oldValue == null && value == null) ||
 
225
                (oldValue != null && oldValue == value) ) {
 
226
            return;
 
227
        }
 
228
        if(getModel() != null)
 
229
                        getModel().setSchemaDesignPattern(value);
 
230
        firePropertyChangeEvent(PROP_SCHEMA_DESIGN_PATTERN, oldValue, value);
 
231
    }
 
232
    
 
233
    public SchemaGenerator.Pattern getSchemaDesignPattern() {
 
234
        return getModel()!=null?getModel().getSchemaDesignPattern():null;
 
235
    }   
 
236
        
 
237
    private String namespace;
 
238
    private String version;
 
239
    private String language;
 
240
    private Form attributeFormDefault;
 
241
    private Form elementFormDefault;    
 
242
    
 
243
    public static final String PROP_TARGET_NAMESPACE  = "targetNamespace"; // NOI18N
 
244
    public static final String PROP_LANGUAGE  = "language"; // NOI18N
 
245
    public static final String PROP_VERSION  = "version"; // NOI18N
 
246
    public static final String PROP_ATTRIBUTE_FORM_DEFAULT  = "attributeFormDefault"; // NOI18N
 
247
    public static final String PROP_ELEMENT_FORM_DEFAULT  = "elementFormDefault"; // NOI18N
 
248
    public static final String PROP_SCHEMA_DESIGN_PATTERN = "schemaDesignPattern"; // NOI18N
 
249
}