KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CreateAddSchemaElementActionVisitor.java
22  *
23  * Created on April 10, 2006, 5:01 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.List JavaDoc;
33 import java.util.Stack JavaDoc;
34
35 import org.netbeans.modules.xml.schema.model.Element;
36 import org.netbeans.modules.xml.schema.model.GlobalElement;
37 import org.netbeans.modules.xml.schema.model.LocalElement;
38 import org.netbeans.modules.xml.schema.model.TypeContainer;
39
40
41 /**
42  *
43  * @author radval
44  */

45 public class CreateAddSchemaElementActionVisitor extends AbstractXSDVisitor {
46     
47     private List JavaDoc<Element> mElements = new ArrayList JavaDoc<Element>();
48     
49     private Stack JavaDoc<Element> mStack = new Stack JavaDoc<Element>();
50     
51     /** Creates a new instance of CreateAddSchemaElementActionVisitor */
52     public CreateAddSchemaElementActionVisitor() {
53     }
54     
55     public List JavaDoc<Element> getElements() {
56         return this.mElements;
57     }
58     
59     public void visit(GlobalElement ge) {
60         createAction(ge);
61         
62         
63     }
64    
65     public void visit(LocalElement le) {
66          createAction(le);
67     }
68     
69     private void createAction(Element e) {
70         //empty is false meaning this is not top most element where we started this traversal
71
//and there we are only one level down. (ie looking element inside element)
72
if(!mStack.empty() && mStack.size() == 1) {
73             this.mElements.add(e);
74         } else {
75             mStack.push(e);
76             visitTypeContainer((TypeContainer) e);
77             mStack.pop();
78         }
79     }
80 }
81
Popular Tags