KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > refactoring > ui > DisplayInfoVisitor


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
20 /*
21  * DisplayInfoVisitor.java
22  *
23  * Created on October 27, 2005, 6:51 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.refactoring.ui;
30
31 import java.text.MessageFormat JavaDoc;
32 import java.util.List JavaDoc;
33 import org.netbeans.modules.xml.schema.model.ComplexContent;
34 import org.netbeans.modules.xml.schema.model.ComplexContentRestriction;
35 import org.netbeans.modules.xml.schema.model.ComplexExtension;
36 import org.netbeans.modules.xml.schema.model.ElementReference;
37 import org.netbeans.modules.xml.schema.model.GlobalAttribute;
38 import org.netbeans.modules.xml.schema.model.GlobalAttributeGroup;
39 import org.netbeans.modules.xml.schema.model.GlobalComplexType;
40 import org.netbeans.modules.xml.schema.model.GlobalElement;
41 import org.netbeans.modules.xml.schema.model.GlobalGroup;
42 import org.netbeans.modules.xml.schema.model.GlobalSimpleType;
43 import org.netbeans.modules.xml.schema.model.GlobalType;
44 import org.netbeans.modules.xml.schema.model.LocalAttribute;
45 import org.netbeans.modules.xml.schema.model.LocalComplexType;
46 import org.netbeans.modules.xml.schema.model.LocalElement;
47 import org.netbeans.modules.xml.schema.model.LocalSimpleType;
48 import org.netbeans.modules.xml.schema.model.Redefine;
49 import org.netbeans.modules.xml.schema.model.Schema;
50 import org.netbeans.modules.xml.schema.model.Sequence;
51 import org.netbeans.modules.xml.schema.model.SimpleContent;
52 import org.netbeans.modules.xml.schema.model.SimpleContentRestriction;
53 import org.netbeans.modules.xml.schema.model.SimpleExtension;
54 import org.netbeans.modules.xml.schema.model.SimpleTypeRestriction;
55 import org.netbeans.modules.xml.schema.model.Union;
56 import org.netbeans.modules.xml.schema.model.visitor.DefaultSchemaVisitor;
57 import org.netbeans.modules.xml.xam.Component;
58 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
59 import org.netbeans.modules.xml.xam.Named;
60 import org.openide.ErrorManager;
61 import org.openide.util.NbBundle;
62
63 /**
64  *
65  * @author Jeri Lockhart
66  */

67 public class DisplayInfoVisitor extends DefaultSchemaVisitor {
68     
69     private DisplayInfo info;
70     private static final String JavaDoc EMPTY_STRING = ""; // NOI18N
71

72     /** Creates a new instance of DisplayInfoVisitor */
73     public DisplayInfoVisitor() {
74         
75     }
76     
77     public DisplayInfo getDisplayInfo(Component comp){
78         info = new DisplayInfo();
79         if (comp instanceof Named){
80             info.setName(((Named)comp).getName());
81         }
82         if (comp instanceof GlobalSimpleType){
83             visit((GlobalSimpleType)comp);
84         } else if (comp instanceof GlobalComplexType){
85             visit((GlobalComplexType)comp);
86         } else if (comp instanceof LocalComplexType){
87             visit((LocalComplexType)comp);
88         } else if (comp instanceof GlobalElement){
89             visit((GlobalElement)comp);
90         } else if (comp instanceof LocalElement){
91             visit((LocalElement)comp);
92         } else if (comp instanceof Sequence){
93             visit((Sequence)comp);
94         } else if (comp instanceof ComplexContent){
95             visit((ComplexContent)comp);
96         } else if (comp instanceof SimpleContentRestriction){
97             visit((SimpleContentRestriction)comp);
98         } else if (comp instanceof ComplexContentRestriction){
99             visit((ComplexContentRestriction)comp);
100         } else if (comp instanceof SimpleContent){
101             visit((SimpleContent)comp);
102         } else if (comp instanceof ComplexExtension){
103             visit((ComplexExtension)comp);
104         } else if (comp instanceof SimpleExtension){
105             visit((SimpleExtension)comp);
106         } else if (comp instanceof SimpleTypeRestriction){
107             visit((SimpleTypeRestriction)comp);
108         } else if (comp instanceof LocalSimpleType){
109             visit((LocalSimpleType)comp);
110         } else if (comp instanceof GlobalAttribute){
111             visit((GlobalAttribute)comp);
112         } else if (comp instanceof GlobalAttributeGroup){
113             visit((GlobalAttributeGroup)comp);
114         } else if (comp instanceof GlobalGroup){
115             visit((GlobalGroup)comp);
116         } else if (comp instanceof LocalAttribute){
117             visit((LocalAttribute)comp);
118         } else if (comp instanceof ElementReference){
119             visit((ElementReference)comp);
120         } else if (comp instanceof Union){
121             visit((Union)comp);
122         } else if (comp instanceof Schema){
123             visit((Schema)comp);
124         } else if (comp instanceof Redefine){
125             visit((Redefine)comp);
126         } else {
127             ErrorManager.getDefault().log(ErrorManager.WARNING,
128                     "DisplayInfoVisitor unrecognized type "
129                     + comp==null?"":comp.getClass().toString()); //NOI18N
130
}
131         return info;
132         
133     }
134     
135     @Override JavaDoc
136             public void visit(GlobalSimpleType gst) {
137         super.visit(gst);
138         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
139                 "LBL_Global_Simple_Type"));
140     }
141     
142     
143     @Override JavaDoc
144             public void visit(GlobalElement ge) {
145         
146         super.visit(ge);
147         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
148                 "LBL_Global_Element"));
149         
150         NamedComponentReference type = ge.getType();
151         if (type != null){
152             GlobalType gt = ge.getType().get();
153             // TODO Replace this workaround for CR 6373793
154
info.setElementType(gt==null?
155                 NbBundle.getMessage(DisplayInfoVisitor.class,"LBL_Undetermined_Type")
156                 :gt.getName());
157         }
158         
159     }
160     
161     
162     @Override JavaDoc
163             public void visit(GlobalComplexType gct) {
164         
165         super.visit(gct);
166         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
167                 "LBL_Global_Complex_Type"));
168     }
169     
170     @Override JavaDoc
171             public void visit(LocalElement le) {
172         
173         super.visit(le);
174         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
175                 "LBL_Local_Element"));
176         
177         NamedComponentReference type = le.getType();
178         if (type != null){
179             GlobalType gt = le.getType().get();
180             // TODO Replace this workaround for CR 6373793
181
info.setElementType(gt==null?
182                 NbBundle.getMessage(DisplayInfoVisitor.class,"LBL_Undetermined_Type")
183                 :gt.getName());
184         }
185     }
186     
187     @Override JavaDoc
188             public void visit(Sequence s) {
189         
190         super.visit(s);
191         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
192                 "LBL_Sequence"));
193     }
194     
195     @Override JavaDoc
196             public void visit(LocalComplexType type) {
197         
198         super.visit(type);
199         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
200                 "LBL_Local_Complex_Type"));
201     }
202     
203     @Override JavaDoc
204             public void visit(ComplexContent cc) {
205         
206         super.visit(cc);
207         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
208                 "LBL_ComplexContent"));
209     }
210     
211     @Override JavaDoc
212             public void visit(SimpleContentRestriction scr) {
213         
214         super.visit(scr);
215         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
216                 "LBL_SimpleContentRestriction"));
217     }
218     
219     @Override JavaDoc
220             public void visit(ComplexContentRestriction ccr) {
221         
222         super.visit(ccr);
223         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
224                 "LBL_ComplexContentRestriction"));
225     }
226     
227     @Override JavaDoc
228             public void visit(SimpleContent sc) {
229         
230         super.visit(sc);
231         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
232                 "LBL_SimpleContent"));
233     }
234     
235     @Override JavaDoc
236             public void visit(ComplexExtension ce) {
237         
238         super.visit(ce);
239         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
240                 "LBL_ComplexExtension"));
241     }
242     
243     @Override JavaDoc
244             public void visit(SimpleExtension se) {
245         
246         super.visit(se);
247         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
248                 "LBL_SimpleExtension"));
249     }
250     
251     @Override JavaDoc
252             public void visit(SimpleTypeRestriction str) {
253         
254         super.visit(str);
255         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
256                 "LBL_SimpleTypeRestriction"));
257     }
258     
259     @Override JavaDoc
260             public void visit(LocalSimpleType type) {
261         
262         super.visit(type);
263         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
264                 "LBL_LocalSimpleType"));
265     }
266     
267     @Override JavaDoc
268             public void visit(GlobalAttribute ga) {
269         
270         super.visit(ga);
271         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
272                 "LBL_GlobalAttribute"));
273         
274         NamedComponentReference type = ga.getType();
275         if (type != null){
276             GlobalType gt = ga.getType().get();
277             // TODO Replace this workaround for CR 6373793
278
info.setElementType(gt==null?
279                 NbBundle.getMessage(DisplayInfoVisitor.class,"LBL_Undetermined_Type")
280                 :gt.getName());
281         }
282     }
283     
284     @Override JavaDoc
285             public void visit(GlobalAttributeGroup gag) {
286         
287         super.visit(gag);
288         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
289                 "LBL_GlobalAttributeGroup"));
290     }
291     
292     @Override JavaDoc
293             public void visit(GlobalGroup gd) {
294         
295         super.visit(gd);
296         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
297                 "LBL_GlobalGroup"));
298     }
299     
300     @Override JavaDoc
301             public void visit(LocalAttribute la) {
302         
303         super.visit(la);
304         info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
305                 "LBL_LocalAttribute"));
306         
307         NamedComponentReference type = la.getType();
308         if (type != null){
309             GlobalType gt = la.getType().get();
310             // TODO Replace this workaround for CR 6373793
311
info.setElementType(gt==null?
312                 NbBundle.getMessage(DisplayInfoVisitor.class,"LBL_Undetermined_Type")
313                 :gt.getName());
314         }
315     }
316     
317     public void visit(ElementReference er) {
318         super.visit(er);
319         // has no name
320
info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
321                 "LBL_Local_Element"));
322         
323         info.setElementType(NbBundle.getMessage(DisplayInfoVisitor.class,
324                 "LBL_Global_Element"));
325         
326         NamedComponentReference<GlobalElement> ref =
327                     er.getRef();
328             if (ref != null){
329                 info.setName(MessageFormat.format(NbBundle.getMessage(
330                         DisplayInfoVisitor.class,
331                         "LBL_References_Ref"),
332                         new Object JavaDoc[] {ref.getQName().getLocalPart()}));
333             }
334                 
335                  
336                         
337     }
338      
339     public void visit(Schema schema) {
340         super.visit(schema);
341         // has no name
342
info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
343                 "LBL_Schema"));
344         
345        info.setName(schema.getTargetNamespace());
346                 
347                  
348                         
349     }
350      
351     public void visit(Union union) {
352         super.visit(union);
353         // has no name
354
info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
355                 "LBL_Union"));
356         
357         List JavaDoc<NamedComponentReference<GlobalSimpleType>> members =
358                 union.getMemberTypes();
359         StringBuffer JavaDoc names = new StringBuffer JavaDoc(NbBundle.getMessage(DisplayInfoVisitor.class,
360                 "LBL_Union_Members"));
361         names.append(" "); //NOI18N
362
if (members.size() < 1){
363             names.append(NbBundle.getMessage(DisplayInfoVisitor.class,
364                 "LBL_Union_Members_None"));
365         }
366         else {
367             for (NamedComponentReference n:members){
368                 names.append(n.getQName().toString());
369                 names.append(" ");//NOI18N
370
}
371         }
372         // Named Members: TypeA TypeB TypeC
373
// Named Members: [none]
374
info.setName(names.toString());
375                         
376     }
377     
378      
379     public void visit(Redefine redefine) {
380         super.visit(redefine);
381         // has no name
382
info.setCompType(NbBundle.getMessage(DisplayInfoVisitor.class,
383                 "LBL_Redefine"));
384         
385         info.setName(NbBundle.getMessage(DisplayInfoVisitor.class,
386                 "LBL_Redefinition"));
387                         
388     }
389     
390     
391     public static class DisplayInfo {
392         
393         private String JavaDoc name = EMPTY_STRING;
394         private String JavaDoc compType = EMPTY_STRING;
395         private String JavaDoc elementType = EMPTY_STRING;
396         
397         
398         public DisplayInfo() {
399             
400         }
401         
402         /**
403          * Getter for property name.
404          * @return Value of property name.
405          */

406         public String JavaDoc getName() {
407             
408             return this.name;
409         }
410         
411         /**
412          * Setter for property name.
413          * @param name New value of property name.
414          */

415         public void setName(String JavaDoc name) {
416             if (name == null ){
417                 name = EMPTY_STRING;
418             }
419             
420             this.name = name;
421         }
422         
423         
424         /**
425          * Getter for property compType.
426          * @return Value of property compType.
427          */

428         public String JavaDoc getCompType() {
429             
430             return this.compType;
431         }
432         
433         /**
434          * Setter for property compType.
435          * @param compType New value of property compType.
436          */

437         public void setCompType(String JavaDoc compType) {
438             if (compType == null ){
439                 compType = EMPTY_STRING;
440             }
441             
442             this.compType = compType;
443         }
444         
445         
446         /**
447          * The type of the GlobalElement, LocalElement, GlobalAttribute, or LocalAttribute
448          * Getter for property elementType.
449          * @return Value of property elementType.
450          */

451         public String JavaDoc getElementType() {
452             
453             return this.elementType;
454         }
455         
456         /**
457          * The type of the GlobalElement, LocalElement, GlobalAttribute, or LocalAttribute
458          * @param elementType New value of property elementType.
459          */

460         public void setElementType(String JavaDoc elementType) {
461             if (elementType == null ){
462                 elementType = EMPTY_STRING;
463             }
464             
465             this.elementType = elementType;
466         }
467         
468     }
469     
470     
471 }
472
Popular Tags