KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > schema > visitor > SchemaElementAttributeFinderVisitor


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  * SchemaElementAttributeFinderVisitor.java
22  *
23  * Created on April 10, 2006, 3:19 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.wsdl.ui.schema.visitor;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.List JavaDoc;
34
35 import org.netbeans.modules.xml.schema.model.All;
36 import org.netbeans.modules.xml.schema.model.Attribute;
37 import org.netbeans.modules.xml.schema.model.Choice;
38 import org.netbeans.modules.xml.schema.model.Element;
39 import org.netbeans.modules.xml.schema.model.GlobalAttribute;
40 import org.netbeans.modules.xml.schema.model.GlobalElement;
41 import org.netbeans.modules.xml.schema.model.GroupReference;
42 import org.netbeans.modules.xml.schema.model.LocalAttribute;
43 import org.netbeans.modules.xml.schema.model.LocalElement;
44 import org.netbeans.modules.xml.schema.model.Sequence;
45 import org.netbeans.modules.xml.schema.model.Attribute.Use;
46
47 /**
48  *
49  * @author radval
50  */

51 public class SchemaElementAttributeFinderVisitor extends AbstractXSDVisitor {
52     
53     private List JavaDoc<Attribute> mAttrList = new ArrayList JavaDoc<Attribute>();
54     
55     private HashMap JavaDoc<String JavaDoc, Attribute> mAttrMap = new HashMap JavaDoc<String JavaDoc, Attribute>();
56     
57     private boolean noProhibited = false;
58     
59     
60     private Element mElement = null;
61     /** Creates a new instance of SchemaElementAttributeFinderVisitor */
62     public SchemaElementAttributeFinderVisitor(Element elem) {
63         mElement = elem;
64     }
65     
66     public SchemaElementAttributeFinderVisitor(Element elem, boolean noProhibited) {
67         mElement = elem;
68         this.noProhibited = noProhibited;
69     }
70     
71     public List JavaDoc<Attribute> getAttributes() {
72         return this.mAttrList;
73     }
74     
75     
76     
77     @Override JavaDoc
78     public void visit(All all) {
79         //Assuming no attributes can be defined at this level for the element (in which we are interested)
80
//dont do anything
81
}
82
83     @Override JavaDoc
84     public void visit(Choice choice) {
85         //Assuming no attributes can be defined at this level for the element (in which we are interested)
86
//dont do anything
87
}
88
89     @Override JavaDoc
90     public void visit(GroupReference gr) {
91         //Assuming no attributes can be defined at this level for the element (in which we are interested)
92
//dont do anything
93
}
94
95     @Override JavaDoc
96     public void visit(Sequence s) {
97         //Assuming no attributes can be defined at this level for the element (in which we are interested)
98
//dont do anything
99
}
100
101     
102     
103     @Override JavaDoc
104     public void visit(GlobalElement ge) {
105         if (ge.equals(mElement)) {
106             super.visit(ge);
107         }
108     }
109
110     @Override JavaDoc
111     public void visit(LocalElement le) {
112         if (le.equals(mElement)) {
113             super.visit(le);
114         }
115     }
116
117     @Override JavaDoc
118     public void visit(LocalAttribute la) {
119
120         if (noProhibited && la.getUse() != null && la.getUse().equals(Use.PROHIBITED)) {
121             //if coming from restriction, removes it.
122
if (mAttrMap.containsKey(la.getName())) {
123                 mAttrList.remove(mAttrMap.remove(la.getName()));
124             }
125             return;
126         }
127         if (!mAttrMap.containsKey(la.getName())) {
128             mAttrMap.put(la.getName(), la);
129             this.mAttrList.add(la);
130         }
131     }
132     
133     @Override JavaDoc
134     public void visit(GlobalAttribute ga) {
135         if (!mAttrMap.containsKey(ga.getName())) {
136             mAttrMap.put(ga.getName(), ga);
137             this.mAttrList.add(ga);
138         }
139     }
140     
141     
142 }
143
Popular Tags