KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > impl > AXIComponentCreator


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.axi.impl;
20
21 import org.netbeans.modules.xml.axi.AXIComponent;
22 import org.netbeans.modules.xml.axi.AXIComponentFactory;
23 import org.netbeans.modules.xml.axi.Attribute;
24 import org.netbeans.modules.xml.axi.Compositor;
25 import org.netbeans.modules.xml.axi.ContentModel;
26 import org.netbeans.modules.xml.axi.Element;
27 import org.netbeans.modules.xml.schema.model.*;
28
29 /**
30  * This is a visitor, which visits a specified schema component
31  * and creates an AXI component. Not every schema component will
32  * have a corresponding AXI component. The things we care in AXI
33  * are, element, attribute, compositor, references and schema constructs
34  * that will yield these as children.
35  *
36  * @author Samaresh (Samaresh.Panda@Sun.Com)
37  */

38 public class AXIComponentCreator extends AbstractModelBuilder {
39
40     /**
41      * Creates a new instance of AXIComponentCreator
42      */

43     public AXIComponentCreator(AXIModelImpl model) {
44         super(model);
45         factory = model.getComponentFactory();
46     }
47
48     /**
49      * Create an AXI component from a schema component.
50      */

51     AXIComponent createNew(SchemaComponent schemaComponent) {
52         schemaComponent.accept(this);
53         
54         return newAXIComponent;
55     }
56     
57     /**
58      * Visit Schema.
59      */

60     public void visit(Schema schema) {
61         newAXIComponent = new AXIDocumentImpl(model, schema);
62     }
63     
64     /**
65      * Visit AnyElement.
66      */

67     public void visit(AnyElement schemaComponent) {
68         org.netbeans.modules.xml.axi.AnyElement element = factory.
69                 createAnyElement(schemaComponent);
70         Util.updateAnyElement(element);
71         newAXIComponent = element;
72     }
73     
74     /**
75      * Visit AnyAttribute.
76      */

77     public void visit(AnyAttribute schemaComponent) {
78         org.netbeans.modules.xml.axi.AnyAttribute attribute = factory.
79                 createAnyAttribute(schemaComponent);
80         Util.updateAnyAttribute(attribute);
81         newAXIComponent = attribute;
82     }
83     
84     /**
85      * Visit GlobalElement.
86      */

87     public void visit(GlobalElement schemaComponent) {
88         if(!model.fromSameSchemaModel(schemaComponent)) {
89             newAXIComponent = model.lookupFromOtherModel(schemaComponent);
90             return;
91         }
92         
93         Element element = factory.createElement(schemaComponent);
94         Util.updateGlobalElement(element);
95         newAXIComponent = element;
96     }
97     
98     /**
99      * Visit LocalElement.
100      */

101     public void visit(LocalElement component) {
102         Element element = factory.createElement(component);
103         Util.updateLocalElement(element);
104         newAXIComponent = element;
105     }
106     
107     /**
108      * Visit ElementReference.
109      */

110     public void visit(ElementReference component) {
111         SchemaComponent originalElement = component.getRef().get();
112         if(originalElement == null)
113             return;
114         AXIComponent referent = null;
115         if(!model.fromSameSchemaModel(originalElement)) {
116             referent = model.lookupFromOtherModel(originalElement);
117         } else {
118             referent = model.lookup(originalElement);
119         }
120         assert (referent != null);
121         Element element = factory.createElementReference(component, (Element)referent);
122         Util.updateElementReference(element);
123         newAXIComponent = element;
124     }
125     
126     /**
127      * Visit GlobalAttribute.
128      */

129     public void visit(GlobalAttribute schemaComponent) {
130         if(!model.fromSameSchemaModel(schemaComponent)) {
131             newAXIComponent = model.lookupFromOtherModel(schemaComponent);
132             return;
133         }
134         Attribute attribute = factory.createAttribute(schemaComponent);
135         Util.updateGlobalAttribute(attribute);
136         newAXIComponent = attribute;
137     }
138     
139     /**
140      * Visit LocalAttribute.
141      */

142     public void visit(LocalAttribute component) {
143         Attribute attribute = factory.createAttribute(component);
144         Util.updateLocalAttribute(attribute);
145         newAXIComponent = attribute;
146     }
147     
148     /**
149      * Visit AttributeReference.
150      */

151     public void visit(AttributeReference component) {
152         SchemaComponent originalElement = component.getRef().get();
153         if(originalElement == null)
154             return;
155         AXIComponent referent = null;
156         if(!model.fromSameSchemaModel(originalElement)) {
157             referent = model.lookupFromOtherModel(originalElement);
158         } else {
159             referent = model.lookup(originalElement);
160         }
161         assert(referent != null);
162         Attribute attribute = factory.createAttributeReference(component,
163                 (Attribute)referent);
164         Util.updateAttributeReference(attribute);
165         newAXIComponent = attribute;
166     }
167     
168     /**
169      * Visit Sequence.
170      */

171     public void visit(Sequence component) {
172         Compositor compositor = factory.createSequence(component);
173         Util.updateCompositor(compositor);
174         newAXIComponent = compositor;
175     }
176     
177     /**
178      * Visit Choice.
179      */

180     public void visit(Choice component) {
181         Compositor compositor = factory.createChoice(component);
182         Util.updateCompositor(compositor);
183         newAXIComponent = compositor;
184     }
185     
186     /**
187      * Visit All.
188      */

189     public void visit(All component) {
190         Compositor compositor = factory.createAll(component);
191         Util.updateCompositor(compositor);
192         newAXIComponent = compositor;
193     }
194     
195     /**
196      * Visit GlobalGroup.
197      */

198     public void visit(GlobalGroup schemaComponent) {
199         if(!model.fromSameSchemaModel(schemaComponent)) {
200             newAXIComponent = model.lookupFromOtherModel(schemaComponent);
201             return;
202         }
203         ContentModel cm = factory.createContentModel(schemaComponent);
204         Util.updateContentModel(cm);
205         newAXIComponent = cm;
206     }
207     
208     /**
209      * Visit GroupReference.
210      */

211     public void visit(GroupReference component) {
212         SchemaComponent sc = component.getRef().get();
213         if(sc == null)
214             return;
215         AXIComponent referent = new AXIComponentCreator(model).
216                 createNew(sc);
217         newAXIComponent = referent;
218     }
219     
220     /**
221      * Visit AttributeGroup.
222      */

223     public void visit(GlobalAttributeGroup schemaComponent) {
224         if(!model.fromSameSchemaModel(schemaComponent)) {
225             newAXIComponent = model.lookupFromOtherModel(schemaComponent);
226             return;
227         }
228         ContentModel cm = factory.createContentModel(schemaComponent);
229         Util.updateContentModel(cm);
230         newAXIComponent = cm;
231     }
232     
233     /**
234      * Visit AttributeGroupReference.
235      */

236     public void visit(AttributeGroupReference component) {
237         SchemaComponent sc = component.getGroup().get();
238         if(sc == null)
239             return;
240         AXIComponent referent = new AXIComponentCreator(model).
241                 createNew(sc);
242         newAXIComponent = referent;
243     }
244         
245     /**
246      * Visit GlobalComplexType.
247      */

248     public void visit(GlobalComplexType schemaComponent) {
249         if(!model.fromSameSchemaModel(schemaComponent)) {
250             newAXIComponent = model.lookupFromOtherModel(schemaComponent);
251             return;
252         }
253         ContentModel cm = factory.createContentModel(schemaComponent);
254         Util.updateContentModel(cm);
255         newAXIComponent = cm;
256     }
257             
258     public void visit(LocalComplexType component) {
259     }
260     public void visit(ComplexContent component) {
261     }
262     public void visit(SimpleContent component) {
263     }
264     public void visit(SimpleExtension component) {
265     }
266     public void visit(ComplexExtension component) {
267     }
268
269     ////////////////////////////////////////////////////////////////////
270
////////////////////////// member variables ////////////////////////
271
////////////////////////////////////////////////////////////////////
272
/**
273      * Newly created component.
274      */

275     private AXIComponent newAXIComponent;
276     private AXIComponentFactory factory;
277 }
278
279
Popular Tags