KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > extensions > soap > impl > SOAPComponentUpdater


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 package org.netbeans.modules.xml.wsdl.model.extensions.soap.impl;
20
21 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPAddress;
22 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBinding;
23 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBody;
24 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPComponent;
25 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPFault;
26 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPHeader;
27 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPHeaderFault;
28 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPOperation;
29 import org.netbeans.modules.xml.xam.Component;
30 import org.netbeans.modules.xml.xam.ComponentUpdater;
31 import org.netbeans.modules.xml.xam.ComponentUpdater.Operation;
32 import org.netbeans.modules.xml.xam.ComponentUpdater.Query;
33
34 /**
35  *
36  * @author Nam Nguyen
37  */

38 public class SOAPComponentUpdater implements ComponentUpdater<SOAPComponent>, Query<SOAPComponent>, SOAPComponent.Visitor {
39     private SOAPComponent parent;
40     private Operation operation;
41     private boolean canAdd;
42     
43     /** Creates a new instance of SOAPComponentUpdater */
44     public SOAPComponentUpdater() {
45     }
46     
47     public boolean canAdd(SOAPComponent target, Component child) {
48         if (!(child instanceof SOAPComponent)) return false;
49         update(target, (SOAPComponent) child, null);
50         return canAdd;
51     }
52
53     public void update(SOAPComponent target, SOAPComponent child, Operation operation) {
54         update(target, child, -1, operation);
55     }
56
57     
58     public void update(SOAPComponent target, SOAPComponent child, int index, Operation operation) {
59         parent = target;
60         this.operation = operation;
61         child.accept(this);
62     }
63
64     public void visit(SOAPOperation child) {
65         //not child of a SOAPComponent
66
if (operation == null) {
67             canAdd = false;
68         }
69     }
70
71     public void visit(SOAPBinding child) {
72         //not child of a SOAPComponent
73
if (operation == null) {
74             canAdd = false;
75         }
76     }
77
78     public void visit(SOAPHeader child) {
79         //not child of a SOAPComponent
80
if (operation == null) {
81             canAdd = false;
82         }
83     }
84
85     public void visit(SOAPBody child) {
86         //not child of a SOAPComponent
87
if (operation == null) {
88             canAdd = false;
89         }
90     }
91
92     public void visit(SOAPFault child) {
93         //not child of a SOAPComponent
94
if (operation == null) {
95             canAdd = false;
96         }
97     }
98
99     public void visit(SOAPHeaderFault child) {
100         SOAPHeader target = (SOAPHeader) parent;
101         if (operation == Operation.ADD) {
102             target.addSOAPHeaderFault(child);
103         } else if (operation == Operation.REMOVE) {
104             target.removeSOAPHeaderFault(child);
105         } else if (operation == null) {
106             canAdd = true;
107         }
108     }
109
110     public void visit(SOAPAddress child) {
111         //not child of a SOAPComponent
112
if (operation == null) {
113             canAdd = false;
114         }
115     }
116     
117 }
118
Popular Tags