KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > model > impl > CommonComplexTypeImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.schema.model.impl;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.modules.xml.schema.model.Annotation;
26 import org.netbeans.modules.xml.schema.model.AnyAttribute;
27 import org.netbeans.modules.xml.schema.model.AttributeGroupReference;
28 import org.netbeans.modules.xml.schema.model.AttributeReference;
29 import org.netbeans.modules.xml.schema.model.ComplexType;
30 import org.netbeans.modules.xml.schema.model.ComplexTypeDefinition;
31 import org.netbeans.modules.xml.schema.model.LocalAttribute;
32 import org.netbeans.modules.xml.schema.model.SchemaComponent;
33 import org.w3c.dom.Element JavaDoc;
34
35
36 /**
37  *
38  * @author rico
39  */

40 public abstract class CommonComplexTypeImpl extends SchemaComponentImpl implements ComplexType{
41     
42     /** Creates a new instance of CommonComplexTypeImpl */
43     public CommonComplexTypeImpl(SchemaModelImpl model, Element JavaDoc el) {
44         super(model, el);
45     }
46     
47     public void setMixed(Boolean JavaDoc mixed) {
48         setAttribute(MIXED_PROPERTY , SchemaAttributes.MIXED, mixed);
49     }
50     
51     public Boolean JavaDoc isMixed() {
52         String JavaDoc s = getAttribute(SchemaAttributes.MIXED);
53         return s == null ? null : Boolean.valueOf(s);
54     }
55     
56     public void addLocalAttribute(LocalAttribute attr) {
57          //If group, sequence, choice, or all is the ComplexTypeDefinition,
58
//the elements must appear in the following order:
59
//1. group | sequence | choice | all
60
//2. attribute | attributeGroup
61
//3. anyAttribute
62
List JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>>();
63         list.add(Annotation.class);
64         list.add(ComplexTypeDefinition.class);
65         addAfter(LOCAL_ATTRIBUTE_PROPERTY, attr, list);
66     }
67     
68     public Collection JavaDoc<LocalAttribute> getLocalAttributes() {
69         return getChildren(LocalAttribute.class);
70     }
71     
72     public void removeLocalAttribute(LocalAttribute attr) {
73         removeChild(LOCAL_ATTRIBUTE_PROPERTY, attr);
74     }
75     
76     public void addAttributeReference(AttributeReference attr) {
77          //If group, sequence, choice, or all is the ComplexTypeDefinition,
78
//the elements must appear in the following order:
79
//1. group | sequence | choice | all
80
//2. attribute | attributeGroup
81
//3. anyAttribute
82
List JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>>();
83         list.add(Annotation.class);
84         list.add(ComplexTypeDefinition.class);
85         addAfter(LOCAL_ATTRIBUTE_PROPERTY, attr, list);
86     }
87     
88     public Collection JavaDoc<AttributeReference> getAttributeReferences() {
89         return getChildren(AttributeReference.class);
90     }
91     
92     public void removeAttributeReference(AttributeReference attr) {
93         removeChild(LOCAL_ATTRIBUTE_PROPERTY, attr);
94     }
95     
96     public void setAnyAttribute(AnyAttribute attr) {
97         //If group, sequence, choice, or all is the ComplexTypeDefinition,
98
//the elements must appear in the following order:
99
//1. group | sequence | choice | all
100
//2. attribute | attributeGroup
101
//3. anyAttribute
102
List JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>>();
103         list.add(Annotation.class);
104         list.add(ComplexTypeDefinition.class);
105         list.add(AttributeGroupReference.class);
106         
107         setChild(AnyAttribute.class, ANY_ATTRIBUTE_PROPERTY, attr, list);
108     }
109     
110     public AnyAttribute getAnyAttribute() {
111         Collection JavaDoc<AnyAttribute> elements = getChildren(AnyAttribute.class);
112         if(!elements.isEmpty()){
113             return elements.iterator().next();
114         }
115         return null;
116     }
117     
118     public void addAttributeGroupReference(AttributeGroupReference ref) {
119         //If group, sequence, choice, or all is the ComplexTypeDefinition,
120
//the elements must appear in the following order:
121
//1. group | sequence | choice | all
122
//2. attribute | attributeGroup
123
//3. anyAttribute
124
List JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<java.lang.Class JavaDoc<? extends SchemaComponent>>();
125         list.add(Annotation.class);
126         list.add(ComplexTypeDefinition.class);
127         addAfter(ATTRIBUTE_GROUP_REFERENCE_PROPERTY, ref, list);
128     }
129     
130     public void removeAttributeGroupReference(AttributeGroupReference ref) {
131         removeChild(ATTRIBUTE_GROUP_REFERENCE_PROPERTY, ref);
132     }
133     
134     public Collection JavaDoc<AttributeGroupReference> getAttributeGroupReferences() {
135         return getChildren(AttributeGroupReference.class);
136     }
137     
138     public void setDefinition(ComplexTypeDefinition content) {
139         //If group, sequence, choice, or all is the ComplexTypeDefinition,
140
//the elements must appear in the following order:
141
//1. group | sequence | choice | all
142
//2. attribute | attributeGroup
143
//3. anyAttribute
144
Collection JavaDoc<Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>>();
145         list.add(Annotation.class);
146         setChild(ComplexTypeDefinition.class, DEFINITION_PROPERTY, content, list);
147     }
148     
149     public ComplexTypeDefinition getDefinition() {
150         Collection JavaDoc<ComplexTypeDefinition> elements = getChildren(ComplexTypeDefinition.class);
151         if(!elements.isEmpty()){
152             return elements.iterator().next();
153         }
154         //TODO should we throw exception if there is no definition?
155
return null;
156     }
157     
158     public boolean getMixedEffective() {
159         Boolean JavaDoc v = isMixed();
160         return v == null ? getMixedDefault() : v;
161     }
162
163     public boolean getMixedDefault() {
164         return false;
165     }
166 }
167
Popular Tags