KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdlextui > template > SoapBindingPostProcessor


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 package org.netbeans.modules.xml.wsdlextui.template;
21
22 import java.util.Collection JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 import org.netbeans.modules.xml.wsdl.model.Binding;
27 import org.netbeans.modules.xml.wsdl.model.BindingFault;
28 import org.netbeans.modules.xml.wsdl.model.BindingInput;
29 import org.netbeans.modules.xml.wsdl.model.BindingOperation;
30 import org.netbeans.modules.xml.wsdl.model.BindingOutput;
31 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
32 import org.netbeans.modules.xml.wsdl.model.Port;
33 import org.netbeans.modules.xml.wsdl.model.Service;
34 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
35 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPAddress;
36 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBinding;
37 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBody;
38 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPFault;
39
40 /**
41  *
42  * @author radval
43  */

44 public class SoapBindingPostProcessor {
45     
46     private String JavaDoc mWsdlTargetNamespace;
47     
48     private static final String JavaDoc SOAP_LOCATION_PPREFIX = "http://localhost:18181/";
49     
50     /** Creates a new instance of SoapBindingPostProcessor */
51     public SoapBindingPostProcessor() {
52     }
53     
54     public void postProcess(String JavaDoc wsdlTargetNamespace, Port port) {
55         this.mWsdlTargetNamespace = wsdlTargetNamespace;
56         
57         List JavaDoc<ExtensibilityElement> ees = port.getExtensibilityElements();
58         Iterator JavaDoc<ExtensibilityElement> it = ees.iterator();
59         
60         while(it.hasNext()) {
61             ExtensibilityElement ee = it.next();
62             if(ee instanceof SOAPAddress) {
63                 SOAPAddress soapAddress = (SOAPAddress) ee;
64                 WSDLComponent parent = port.getParent();
65                 if(parent != null && parent instanceof Service) {
66                     Service service = (Service) parent;
67                     soapAddress.setLocation(SOAP_LOCATION_PPREFIX + service.getName() + "/" + port.getName() );
68                 }
69             }
70         }
71     }
72     
73     public void postProcess(String JavaDoc wsdlTargetNamespace, Binding binding) {
74         this.mWsdlTargetNamespace = wsdlTargetNamespace;
75         
76         SOAPBinding.Style style = null;
77         
78         List JavaDoc<ExtensibilityElement> ee = binding.getExtensibilityElements();
79         Iterator JavaDoc<ExtensibilityElement> it = ee.iterator();
80         while(it.hasNext()) {
81             ExtensibilityElement e = it.next();
82             if(e instanceof SOAPBinding) {
83                 SOAPBinding sBinding = (SOAPBinding) e;
84                 style = sBinding.getStyle();
85                 break;
86             }
87         }
88         
89         if(style != null) {
90             Collection JavaDoc<BindingOperation> bOps = binding.getBindingOperations();
91             Iterator JavaDoc<BindingOperation> itBops = bOps.iterator();
92             while(itBops.hasNext()) {
93                 BindingOperation op = itBops.next();
94                 processBindingOperation(style, op);
95             }
96         }
97     }
98     
99     private void processBindingOperation(SOAPBinding.Style style, BindingOperation bindingOperation) {
100         BindingInput bIn = bindingOperation.getBindingInput();
101         if (bIn != null) {
102             processBindingOperationInput(style, bIn);
103         }
104         
105         BindingOutput bOut = bindingOperation.getBindingOutput();
106         if (bOut != null) {
107             processBindingOperationOutput(style, bOut);
108         }
109         
110         Collection JavaDoc<BindingFault> bFaults = bindingOperation.getBindingFaults();
111         if (bFaults != null && !bFaults.isEmpty()) {
112             Iterator JavaDoc<BindingFault> it = bFaults.iterator();
113             while(it.hasNext()) {
114                 BindingFault bFault = it.next();
115                 processBindingOperationFault(style, bFault);
116             }
117         }
118     }
119     
120     
121     private void processBindingOperationInput(SOAPBinding.Style style, BindingInput bIn) {
122         if(style.equals(SOAPBinding.Style.RPC)) {
123             List JavaDoc<ExtensibilityElement> eeList = bIn.getExtensibilityElements();
124             Iterator JavaDoc<ExtensibilityElement> it = eeList.iterator();
125             while(it.hasNext()) {
126                 ExtensibilityElement ee = it.next();
127                 if(ee instanceof SOAPBody) {
128                     SOAPBody sBody = (SOAPBody) ee;
129                     sBody.setNamespace(mWsdlTargetNamespace);
130                 }
131             }
132         }
133     }
134     
135     private void processBindingOperationOutput(SOAPBinding.Style style, BindingOutput bOut ) {
136         if(style.equals(SOAPBinding.Style.RPC)) {
137             List JavaDoc<ExtensibilityElement> eeList = bOut.getExtensibilityElements();
138             Iterator JavaDoc<ExtensibilityElement> it = eeList.iterator();
139             while(it.hasNext()) {
140                 ExtensibilityElement ee = it.next();
141                 if(ee instanceof SOAPBody) {
142                     SOAPBody sBody = (SOAPBody) ee;
143                     sBody.setNamespace(mWsdlTargetNamespace);
144                 }
145             }
146         }
147     }
148     
149     private void processBindingOperationFault(SOAPBinding.Style style, BindingFault bFault) {
150         
151             List JavaDoc<ExtensibilityElement> eeList = bFault.getExtensibilityElements();
152             Iterator JavaDoc<ExtensibilityElement> it = eeList.iterator();
153             while(it.hasNext()) {
154                 ExtensibilityElement ee = it.next();
155                 if(ee instanceof SOAPFault) {
156                     SOAPFault sFault = (SOAPFault) ee;
157                     sFault.setName(bFault.getName());
158                     if(style.equals(SOAPBinding.Style.RPC)) {
159                         sFault.setNamespace(mWsdlTargetNamespace);
160                     }
161                 }
162             }
163         
164     }
165     
166 }
167
Popular Tags