KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.ArrayList JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.modules.xml.schema.model.All;
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.Choice;
30 import org.netbeans.modules.xml.schema.model.ComplexContentRestriction;
31 import org.netbeans.modules.xml.schema.model.ComplexTypeDefinition;
32 import org.netbeans.modules.xml.schema.model.GlobalComplexType;
33 import org.netbeans.modules.xml.schema.model.LocalAttribute;
34 import org.netbeans.modules.xml.schema.model.LocalGroupDefinition;
35 import org.netbeans.modules.xml.schema.model.SchemaComponent;
36 import org.netbeans.modules.xml.schema.model.Sequence;
37 import org.netbeans.modules.xml.schema.model.visitor.SchemaVisitor;
38 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
39
40 import org.w3c.dom.Element JavaDoc;
41 /**
42  *
43  * @author rico
44  */

45 public class ComplexContentRestrictionImpl extends SchemaComponentImpl implements ComplexContentRestriction{
46     
47     /** Creates a new instance of ComplexContentRestrictionImpl */
48     protected ComplexContentRestrictionImpl(SchemaModelImpl model) {
49     this(model, createNewComponent(SchemaElements.RESTRICTION, model));
50     }
51     
52     public ComplexContentRestrictionImpl(SchemaModelImpl model, Element JavaDoc el){
53     super(model,el);
54     }
55     
56     /**
57      *
58      *
59      */

60     public Class JavaDoc<? extends SchemaComponent> getComponentType() {
61     return ComplexContentRestriction.class;
62     }
63     
64     public void setBase(NamedComponentReference<GlobalComplexType> type) {
65     setAttribute(BASE_PROPERTY, SchemaAttributes.BASE, type);
66     //setAttribute(SchemaAttributes.BASE, type.getRawURI());
67
}
68     
69     public NamedComponentReference<GlobalComplexType> getBase() {
70     return resolveGlobalReference(GlobalComplexType.class, SchemaAttributes.BASE);
71     }
72     
73     public void addAttributeGroupReference(AttributeGroupReference ref) {
74     List JavaDoc<Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>>();
75     list.add(Annotation.class);
76     list.add(ComplexTypeDefinition.class);
77     
78     addAfter(ATTRIBUTE_GROUP_REFERENCE_PROPERTY, ref, list);
79     }
80     
81     public void removeAttributeGroupReference(AttributeGroupReference ref) {
82     removeChild(ATTRIBUTE_GROUP_REFERENCE_PROPERTY, ref);
83     }
84     
85     public Collection JavaDoc<AttributeGroupReference> getAttributeGroupReferences() {
86     return getChildren(AttributeGroupReference.class);
87     }
88     
89     public void setDefinition(ComplexTypeDefinition definition) {
90     Collection JavaDoc<Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>>();
91     list.add(Annotation.class);
92     setChild(ComplexTypeDefinition.class,
93         DEFINITION_CHANGED_PROPERTY, definition, list);
94     }
95     
96     public ComplexTypeDefinition getDefinition() {
97     Collection JavaDoc<ComplexTypeDefinition> elements = getChildren(ComplexTypeDefinition.class);
98     if(!elements.isEmpty()){
99         return elements.iterator().next();
100     }
101     return null;
102     }
103     
104     public void addLocalAttribute(LocalAttribute attr) {
105     List JavaDoc<Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>>();
106     list.add(Annotation.class);
107     list.add(ComplexTypeDefinition.class);
108     
109     addAfter(LOCAL_ATTRIBUTE_PROPERTY, attr, list);
110     }
111     
112     public void removeLocalAttribute(LocalAttribute attr) {
113     removeChild(LOCAL_ATTRIBUTE_PROPERTY, attr);
114     }
115     
116     public Collection JavaDoc<LocalAttribute> getLocalAttributes() {
117     return getChildren(LocalAttribute.class);
118     }
119     
120      public void addAttributeReference(AttributeReference attr) {
121     List JavaDoc<Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>>();
122     list.add(Annotation.class);
123     list.add(ComplexTypeDefinition.class);
124     
125     addAfter(LOCAL_ATTRIBUTE_PROPERTY, attr, list);
126     }
127     
128     public void removeAttributeReference(AttributeReference attr) {
129     removeChild(LOCAL_ATTRIBUTE_PROPERTY, attr);
130     }
131     
132     public Collection JavaDoc<AttributeReference> getAttributeReferences() {
133     return getChildren(AttributeReference.class);
134     }
135     
136     public void setAnyAttribute(AnyAttribute attr) {
137     Collection JavaDoc<Class JavaDoc<? extends SchemaComponent>> list = new ArrayList JavaDoc<Class JavaDoc<? extends SchemaComponent>>();
138     list.add(Annotation.class);
139     list.add(LocalGroupDefinition.class);
140     list.add(All.class);
141     list.add(Choice.class);
142     list.add(Sequence.class);
143     setChild(AnyAttribute.class, ANY_ATTRIBUTE_PROPERTY, attr, list);
144     }
145     
146     public AnyAttribute getAnyAttribute() {
147     Collection JavaDoc<AnyAttribute> elements = getChildren(AnyAttribute.class);
148     if(!elements.isEmpty()){
149         return elements.iterator().next();
150     }
151     //TODO should we throw exception if there is no definition?
152
return null;
153     }
154     
155     /**
156      * Visitor providing
157      */

158     public void accept(SchemaVisitor visitor) {
159     visitor.visit(this);
160     }
161 }
162
Popular Tags