KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > visitor > FindReferencedVisitor


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.wsdl.model.visitor;
21
22 import org.netbeans.modules.xml.wsdl.model.Binding;
23 import org.netbeans.modules.xml.wsdl.model.Definitions;
24 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
25 import org.netbeans.modules.xml.wsdl.model.Message;
26 import org.netbeans.modules.xml.wsdl.model.NotificationOperation;
27 import org.netbeans.modules.xml.wsdl.model.OneWayOperation;
28 import org.netbeans.modules.xml.wsdl.model.Part;
29 import org.netbeans.modules.xml.wsdl.model.Port;
30 import org.netbeans.modules.xml.wsdl.model.PortType;
31 import org.netbeans.modules.xml.wsdl.model.ReferenceableWSDLComponent;
32 import org.netbeans.modules.xml.wsdl.model.RequestResponseOperation;
33 import org.netbeans.modules.xml.wsdl.model.Service;
34 import org.netbeans.modules.xml.wsdl.model.SolicitResponseOperation;
35 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
36
37 /**
38  *
39  * @author Nam Nguyen
40  */

41 public class FindReferencedVisitor<T extends ReferenceableWSDLComponent> extends DefaultVisitor {
42     private Class JavaDoc<T> type;
43     private String JavaDoc localName;
44     private T referenced = null;
45     private Definitions root;
46     
47     /** Creates a new instance of FindReferencedVisitor */
48     public FindReferencedVisitor(Definitions root) {
49         this.root = root;
50     }
51     
52     public T find(String JavaDoc localName, Class JavaDoc<T> type) {
53         this.type = type;
54         this.localName = localName;
55         visitChildren(root);
56         return referenced;
57     }
58
59     public void visit(Binding c) {
60         checkReference(c, true); //extensible
61
}
62
63     public void visit(Message c) { //extensible
64
checkReference(c, true);
65     }
66
67     public void visit(PortType c) { //extensible
68
checkReference(c, true);
69     }
70     
71     public void visit(RequestResponseOperation op){
72         checkReference(op, true);
73     }
74     
75     public void visit(OneWayOperation op){
76         checkReference(op, true);
77     }
78     
79     
80     public void visit(NotificationOperation op){
81         checkReference(op, true);
82     }
83     
84     public void visit(SolicitResponseOperation op){
85         checkReference(op, true);
86     }
87
88     public void visit(Service s){
89         checkReference(s, true);
90     }
91     
92     public void visit(Port p){
93         checkReference(p, true);
94     }
95     
96     public void visit(Part part){
97         checkReference(part, true);
98     }
99     
100     public void visit(ExtensibilityElement c) {
101         if (c instanceof ReferenceableWSDLComponent) {
102             checkReference(ReferenceableWSDLComponent.class.cast(c), true);
103         }
104         visitChildren(c);
105     }
106
107     private void checkReference(ReferenceableWSDLComponent c, boolean checkChildren) {
108          if (type.isAssignableFrom(c.getClass()) && c.getName() != null &&
109                  c.getName().equals(localName)) {
110              referenced = type.cast(c);
111              return;
112          } else if (checkChildren) {
113              visitChildren(c);
114          }
115     }
116     
117     private void visitChildren(WSDLComponent c) {
118         for (WSDLComponent child : c.getChildren()) {
119            if (referenced != null) { // before start each visit
120
return;
121            }
122             child.accept(this);
123         }
124     }
125     
126 }
127
Popular Tags