1 /**********************************************************************
2 * EJOEBindingSerializer.java
3 * created on 13.07.2006 by netseeker
4 * $Source$
5 * $Date$
6 * $Revision$
7 *
8 * ====================================================================
9 *
10 * Copyright 2006 netseeker aka Michael Manske
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 * ====================================================================
24 *
25 * This file is part of the EJOE framework.
26 * For more information on the author, please see
27 * <http://www.manskes.de/>.
28 *
29 *********************************************************************/
30
31 package de.netseeker.ejoe.ext.wsif.wsdl;
32
33 import java.io.Serializable;
34
35 import javax.wsdl.extensions.ExtensibilityElement;
36 import javax.wsdl.extensions.ExtensionDeserializer;
37 import javax.wsdl.extensions.ExtensionRegistry;
38 import javax.wsdl.extensions.ExtensionSerializer;
39 import javax.xml.namespace.QName;
40
41 import org.apache.wsif.logging.Trc;
42 import org.apache.wsif.wsdl.extensions.java.JavaOperation;
43
44 import com.ibm.wsdl.Constants;
45 import com.ibm.wsdl.util.StringUtils;
46 import com.ibm.wsdl.util.xml.DOMUtils;
47
48 /***
49 * WSDL (un-)marshaller for the EJOE WSDL binding extensions
50 *
51 * @author netseeker
52 * @since 0.3.9.1
53 */
54 public class EJOEBindingSerializer implements ExtensionSerializer, ExtensionDeserializer, Serializable
55 {
56 private static final long serialVersionUID = 1L;
57
58 public void marshall( Class parentType, QName elementType, javax.wsdl.extensions.ExtensibilityElement extension,
59 java.io.PrintWriter pw, javax.wsdl.Definition def,
60 javax.wsdl.extensions.ExtensionRegistry extReg ) throws javax.wsdl.WSDLException
61 {
62
63 Trc.entry( this, parentType, elementType, extension, pw, def, extReg );
64
65 if ( extension == null )
66 {
67 Trc.exit();
68 return;
69 }
70
71 if ( extension instanceof EJOEBinding )
72 {
73 pw.print( " <ejoe:binding" );
74
75 Boolean required = extension.getRequired();
76 if ( required != null )
77 {
78 DOMUtils.printQualifiedAttribute( Constants.Q_ATTR_REQUIRED, required.toString(), def, pw );
79 }
80
81 pw.println( "/>" );
82 }
83 else if ( extension instanceof EJOEOperation )
84 {
85 EJOEOperation ejoeOperation = (EJOEOperation) extension;
86 pw.print( " <ejoe:operation" );
87
88 if ( ejoeOperation.getInvocationType() != null )
89 {
90 DOMUtils.printAttribute( "invocationType", ejoeOperation.getInvocationType(), pw );
91 }
92
93 if ( ejoeOperation.getClassName() != null )
94 {
95 DOMUtils.printAttribute( "className", ejoeOperation.getClassName(), pw );
96 }
97
98 if ( ejoeOperation.getMethodName() != null )
99 {
100 DOMUtils.printAttribute( "methodName", ejoeOperation.getMethodName(), pw );
101 }
102
103 if ( ejoeOperation.getParameterOrder() != null )
104 {
105 DOMUtils.printAttribute( "parameterOrder",
106 StringUtils.getNMTokens( ejoeOperation.getParameterOrder() ), pw );
107 }
108
109 if ( ejoeOperation.getReturnPart() != null )
110 {
111 DOMUtils.printAttribute( "returnPart", ejoeOperation.getReturnPart(), pw );
112 }
113
114 Boolean required = extension.getRequired();
115 if ( required != null )
116 {
117 DOMUtils.printQualifiedAttribute( Constants.Q_ATTR_REQUIRED, required.toString(), def, pw );
118 }
119
120 pw.println( "/>" );
121 }
122 else if ( extension instanceof EJOEAddress )
123 {
124 EJOEAddress ejoeaAddress = (EJOEAddress) extension;
125 pw.print( " <ejoe:address" );
126
127 if ( ejoeaAddress.getEjoeServerURL() != null )
128 {
129 DOMUtils.printAttribute( "ejoeServerURL", ejoeaAddress.getEjoeServerURL(), pw );
130 }
131
132 if ( ejoeaAddress.getAdapterClass() != null )
133 {
134 DOMUtils.printAttribute( "classPath", ejoeaAddress.getAdapterClass(), pw );
135 }
136
137 DOMUtils.printAttribute( "useCompression", Boolean.toString( ejoeaAddress.getUseCompression() ), pw );
138
139 DOMUtils.printAttribute( "usePersistentConnection", Boolean.toString( ejoeaAddress
140 .getUsePersistentConnection() ), pw );
141
142 DOMUtils.printAttribute( "usePersistentConnection", Boolean.toString( ejoeaAddress
143 .getUsePersistentConnection() ), pw );
144
145 if ( ejoeaAddress.getTimeout() > 0 )
146 DOMUtils.printAttribute( "timeout", String.valueOf( ejoeaAddress.getTimeout() ), pw );
147
148 Boolean required = extension.getRequired();
149 if ( required != null )
150 {
151 DOMUtils.printQualifiedAttribute( Constants.Q_ATTR_REQUIRED, required.toString(), def, pw );
152 }
153
154 pw.println( "/>" );
155 }
156 Trc.exit();
157 }
158
159 /***
160 * Registers the serializer.
161 */
162 public void registerSerializer( ExtensionRegistry registry )
163 {
164 Trc.entry( this, registry );
165
166 registry.registerSerializer( javax.wsdl.Binding.class, EJOEBindingConstants.Q_ELEM_EJOE_BINDING, this );
167 registry.registerDeserializer( javax.wsdl.Binding.class, EJOEBindingConstants.Q_ELEM_EJOE_BINDING, this );
168 registry.mapExtensionTypes( javax.wsdl.Binding.class, EJOEBindingConstants.Q_ELEM_EJOE_BINDING,
169 EJOEBinding.class );
170
171
172 registry.registerSerializer( javax.wsdl.BindingOperation.class, EJOEBindingConstants.Q_ELEM_EJOE_OPERATION,
173 this );
174 registry.registerDeserializer( javax.wsdl.BindingOperation.class, EJOEBindingConstants.Q_ELEM_EJOE_OPERATION,
175 this );
176
177 registry.mapExtensionTypes( javax.wsdl.BindingOperation.class, EJOEBindingConstants.Q_ELEM_EJOE_OPERATION,
178 JavaOperation.class );
179
180 registry.registerSerializer( javax.wsdl.Port.class, EJOEBindingConstants.Q_ELEM_EJOE_ADDRESS, this );
181
182 registry.registerDeserializer( javax.wsdl.Port.class, EJOEBindingConstants.Q_ELEM_EJOE_ADDRESS, this );
183
184 registry.mapExtensionTypes( javax.wsdl.Port.class, EJOEBindingConstants.Q_ELEM_EJOE_ADDRESS, EJOEAddress.class );
185 Trc.exit();
186 }
187
188 public ExtensibilityElement unmarshall( Class parentType, javax.xml.namespace.QName elementType,
189 org.w3c.dom.Element el, javax.wsdl.Definition def,
190 javax.wsdl.extensions.ExtensionRegistry extReg )
191 throws javax.wsdl.WSDLException
192 {
193 Trc.entry( this, parentType, elementType, el, def, extReg );
194
195
196
197 javax.wsdl.extensions.ExtensibilityElement returnValue = null;
198 String tmp = null;
199
200 if ( EJOEBindingConstants.Q_ELEM_EJOE_BINDING.equals( elementType ) )
201 {
202 EJOEBinding javaBinding = new EJOEBinding();
203 Trc.exit( javaBinding );
204 return javaBinding;
205 }
206 else if ( EJOEBindingConstants.Q_ELEM_EJOE_OPERATION.equals( elementType ) )
207 {
208 EJOEOperation ejoeOperation = new EJOEOperation();
209
210 tmp = DOMUtils.getAttribute( el, "invocationType" );
211 if ( tmp != null )
212 {
213 ejoeOperation.setInvocationType( tmp );
214 }
215
216 tmp = DOMUtils.getAttribute( el, "className" );
217 if ( tmp != null )
218 {
219 ejoeOperation.setClassName( tmp );
220 }
221
222 tmp = DOMUtils.getAttribute( el, "methodName" );
223 if ( tmp != null )
224 {
225 ejoeOperation.setMethodName( tmp );
226 }
227
228 tmp = DOMUtils.getAttribute( el, "parameterOrder" );
229 if ( tmp != null )
230 {
231 ejoeOperation.setParameterOrder( tmp );
232 }
233
234 tmp = DOMUtils.getAttribute( el, "returnPart" );
235 if ( tmp != null )
236 {
237 ejoeOperation.setReturnPart( tmp );
238 }
239 Trc.exit( ejoeOperation );
240 return ejoeOperation;
241 }
242 else if ( EJOEBindingConstants.Q_ELEM_EJOE_ADDRESS.equals( elementType ) )
243 {
244 EJOEAddress ejoeAddress = new EJOEAddress();
245
246 tmp = DOMUtils.getAttribute( el, "ejoeServerURL" );
247 if ( tmp != null )
248 {
249 ejoeAddress.setEjoeServerURL( tmp );
250 }
251
252 tmp = DOMUtils.getAttribute( el, "adapterClass" );
253 if ( tmp != null )
254 {
255 ejoeAddress.setAdapterClass( tmp );
256 }
257
258 tmp = DOMUtils.getAttribute( el, "useCompression" );
259 if ( tmp != null )
260 {
261 ejoeAddress.setUseCompression( Boolean.valueOf( tmp ).booleanValue() );
262 }
263
264 tmp = DOMUtils.getAttribute( el, "usePersistentConnection" );
265 if ( tmp != null )
266 {
267 ejoeAddress.setUsePersistentConnection( Boolean.valueOf( tmp ).booleanValue() );
268 }
269
270 tmp = DOMUtils.getAttribute( el, "timeout" );
271 if ( tmp != null )
272 {
273 ejoeAddress.setTimeout( Integer.parseInt( tmp ) );
274 }
275
276 Trc.exit( ejoeAddress );
277 return ejoeAddress;
278 }
279 Trc.exit( returnValue );
280 return returnValue;
281 }
282
283 }