src/share/jaxws_classes/com/sun/xml/internal/ws/server/sei/EndpointResponseMessageBuilder.java

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
equal deleted inserted replaced
366:8c0b6bccfe47 368:0989ad8c0860
1 /* 1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
141 /** 141 /**
142 * Abstracts away the {@link Holder} handling when touching method arguments. 142 * Abstracts away the {@link Holder} handling when touching method arguments.
143 */ 143 */
144 protected final ValueGetter[] getters; 144 protected final ValueGetter[] getters;
145 145
146 /**
147 * How does each wrapped parameter binds to XML?
148 */
149 protected XMLBridge[] parameterBridges;
150
151 /**
152 * Used for error diagnostics.
153 */
154 protected List<ParameterImpl> children;
155
146 protected Wrapped(WrapperParameter wp, SOAPVersion soapVersion) { 156 protected Wrapped(WrapperParameter wp, SOAPVersion soapVersion) {
147 super(wp.getXMLBridge(), soapVersion); 157 super(wp.getXMLBridge(), soapVersion);
148 158
149 List<ParameterImpl> children = wp.getWrapperChildren(); 159 children = wp.getWrapperChildren();
150 160
151 indices = new int[children.size()]; 161 indices = new int[children.size()];
152 getters = new ValueGetter[children.size()]; 162 getters = new ValueGetter[children.size()];
153 for( int i=0; i<indices.length; i++ ) { 163 for( int i=0; i<indices.length; i++ ) {
154 ParameterImpl p = children.get(i); 164 ParameterImpl p = children.get(i);
155 indices[i] = p.getIndex(); 165 indices[i] = p.getIndex();
156 getters[i] = ValueGetter.get(p); 166 getters[i] = ValueGetter.get(p);
157 } 167 }
158 } 168 }
169
170 /**
171 * Packs a bunch of arguments intoa {@link WrapperComposite}.
172 */
173 WrapperComposite buildWrapperComposite(Object[] methodArgs, Object returnValue) {
174 WrapperComposite cs = new WrapperComposite();
175 cs.bridges = parameterBridges;
176 cs.values = new Object[parameterBridges.length];
177
178 // fill in wrapped parameters from methodArgs
179 for( int i=indices.length-1; i>=0; i-- ) {
180 Object v;
181 if (indices[i] == -1) {
182 v = getters[i].get(returnValue);
183 } else {
184 v = getters[i].get(methodArgs[indices[i]]);
185 }
186 if(v==null) {
187 throw new WebServiceException("Method Parameter: "+
188 children.get(i).getName() +" cannot be null. This is BP 1.1 R2211 violation.");
189 }
190 cs.values[i] = v;
191 }
192
193 return cs;
194 }
159 } 195 }
160 196
161 /** 197 /**
162 * Used to create a payload JAXB object by wrapping 198 * Used to create a payload JAXB object by wrapping
163 * multiple parameters into one "wrapper bean". 199 * multiple parameters into one "wrapper bean".
172 208
173 /** 209 /**
174 * Wrapper bean. 210 * Wrapper bean.
175 */ 211 */
176 private final Class wrapper; 212 private final Class wrapper;
213 private boolean dynamicWrapper;
177 214
178 /** 215 /**
179 * Needed to get wrapper instantiation method. 216 * Needed to get wrapper instantiation method.
180 */ 217 */
181 private BindingContext bindingContext; 218 private BindingContext bindingContext;
184 * Creates a {@link EndpointResponseMessageBuilder} from a {@link WrapperParameter}. 221 * Creates a {@link EndpointResponseMessageBuilder} from a {@link WrapperParameter}.
185 */ 222 */
186 public DocLit(WrapperParameter wp, SOAPVersion soapVersion) { 223 public DocLit(WrapperParameter wp, SOAPVersion soapVersion) {
187 super(wp, soapVersion); 224 super(wp, soapVersion);
188 bindingContext = wp.getOwner().getBindingContext(); 225 bindingContext = wp.getOwner().getBindingContext();
189
190 wrapper = (Class)wp.getXMLBridge().getTypeInfo().type; 226 wrapper = (Class)wp.getXMLBridge().getTypeInfo().type;
191 227 dynamicWrapper = WrapperComposite.class.equals(wrapper);
192 List<ParameterImpl> children = wp.getWrapperChildren(); 228 children = wp.getWrapperChildren();
193 229 parameterBridges = new XMLBridge[children.size()];
194 accessors = new PropertyAccessor[children.size()]; 230 accessors = new PropertyAccessor[children.size()];
195 for( int i=0; i<accessors.length; i++ ) { 231 for( int i=0; i<accessors.length; i++ ) {
196 ParameterImpl p = children.get(i); 232 ParameterImpl p = children.get(i);
197 QName name = p.getName(); 233 QName name = p.getName();
198 try { 234 if (dynamicWrapper) {
199 accessors[i] = p.getOwner().getBindingContext().getElementPropertyAccessor( 235 parameterBridges[i] = children.get(i).getInlinedRepeatedElementBridge();
200 wrapper, name.getNamespaceURI(), name.getLocalPart() ); 236 if (parameterBridges[i] == null) parameterBridges[i] = children.get(i).getXMLBridge();
201 } catch (JAXBException e) { 237 } else {
202 throw new WebServiceException( // TODO: i18n 238 try {
203 wrapper+" do not have a property of the name "+name,e); 239 accessors[i] = (dynamicWrapper) ? null :
240 p.getOwner().getBindingContext().getElementPropertyAccessor(
241 wrapper, name.getNamespaceURI(), name.getLocalPart() );
242 } catch (JAXBException e) {
243 throw new WebServiceException( // TODO: i18n
244 wrapper+" do not have a property of the name "+name,e);
245 }
204 } 246 }
205 } 247 }
206 248
207 } 249 }
208 250
209 /** 251 /**
210 * Packs a bunch of arguments into a {@link WrapperComposite}. 252 * Packs a bunch of arguments into a {@link WrapperComposite}.
211 */ 253 */
212 Object build(Object[] methodArgs, Object returnValue) { 254 Object build(Object[] methodArgs, Object returnValue) {
255 if (dynamicWrapper) return buildWrapperComposite(methodArgs, returnValue);
213 try { 256 try {
214 //Object bean = wrapper.newInstance(); 257 //Object bean = wrapper.newInstance();
215 Object bean = bindingContext.newWrapperInstace(wrapper); 258 Object bean = bindingContext.newWrapperInstace(wrapper);
216 259
217 // fill in wrapped parameters from methodArgs 260 // fill in wrapped parameters from methodArgs
249 * <p> 292 * <p>
250 * This is used for rpc/lit, as we don't have a wrapper bean for it. 293 * This is used for rpc/lit, as we don't have a wrapper bean for it.
251 * (TODO: Why don't we have a wrapper bean for this, when doc/lit does!?) 294 * (TODO: Why don't we have a wrapper bean for this, when doc/lit does!?)
252 */ 295 */
253 public final static class RpcLit extends Wrapped { 296 public final static class RpcLit extends Wrapped {
254 /**
255 * How does each wrapped parameter binds to XML?
256 */
257 private final XMLBridge[] parameterBridges;
258
259 /**
260 * Used for error diagnostics.
261 */
262 private final List<ParameterImpl> children;
263 297
264 /** 298 /**
265 * Creates a {@link EndpointResponseMessageBuilder} from a {@link WrapperParameter}. 299 * Creates a {@link EndpointResponseMessageBuilder} from a {@link WrapperParameter}.
266 */ 300 */
267 public RpcLit(WrapperParameter wp, SOAPVersion soapVersion) { 301 public RpcLit(WrapperParameter wp, SOAPVersion soapVersion) {
268 super(wp, soapVersion); 302 super(wp, soapVersion);
269 // we'll use CompositeStructure to pack requests 303 // we'll use CompositeStructure to pack requests
270 assert wp.getTypeInfo().type==WrapperComposite.class; 304 assert wp.getTypeInfo().type==WrapperComposite.class;
271 305
272 this.children = wp.getWrapperChildren();
273
274 parameterBridges = new XMLBridge[children.size()]; 306 parameterBridges = new XMLBridge[children.size()];
275 for( int i=0; i<parameterBridges.length; i++ ) 307 for( int i=0; i<parameterBridges.length; i++ )
276 parameterBridges[i] = children.get(i).getXMLBridge(); 308 parameterBridges[i] = children.get(i).getXMLBridge();
277 } 309 }
278 310
279 /** 311 /**
280 * Packs a bunch of arguments intoa {@link WrapperComposite}. 312 * Packs a bunch of arguments intoa {@link WrapperComposite}.
281 */ 313 */
282 WrapperComposite build(Object[] methodArgs, Object returnValue) { 314 Object build(Object[] methodArgs, Object returnValue) {
283 WrapperComposite cs = new WrapperComposite(); 315 return buildWrapperComposite(methodArgs, returnValue);
284 cs.bridges = parameterBridges;
285 cs.values = new Object[parameterBridges.length];
286
287 // fill in wrapped parameters from methodArgs
288 for( int i=indices.length-1; i>=0; i-- ) {
289 Object v;
290 if (indices[i] == -1) {
291 v = getters[i].get(returnValue);
292 } else {
293 v = getters[i].get(methodArgs[indices[i]]);
294 }
295 if(v==null) {
296 throw new WebServiceException("Method Parameter: "+
297 children.get(i).getName() +" cannot be null. This is BP 1.1 R2211 violation.");
298 }
299 cs.values[i] = v;
300 }
301
302 return cs;
303 } 316 }
304 } 317 }
305 } 318 }

mercurial