src/share/jaxws_classes/com/sun/xml/internal/ws/client/sei/SEIMethodHandler.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.xml.internal.ws.client.sei;
ohair@286 27
ohair@286 28 import com.sun.xml.internal.ws.api.message.Message;
ohair@286 29 import com.sun.xml.internal.ws.model.CheckedExceptionImpl;
ohair@286 30 import com.sun.xml.internal.ws.model.JavaMethodImpl;
ohair@286 31 import com.sun.xml.internal.ws.model.ParameterImpl;
ohair@286 32 import com.sun.xml.internal.ws.model.WrapperParameter;
ohair@286 33
ohair@286 34 import javax.xml.namespace.QName;
ohair@286 35 import java.util.ArrayList;
ohair@286 36 import java.util.HashMap;
ohair@286 37 import java.util.List;
ohair@286 38 import java.util.Map;
ohair@286 39
ohair@286 40 /**
ohair@286 41 * {@link com.sun.xml.internal.ws.client.sei.MethodHandler} that handles synchronous method invocations.
ohair@286 42 *
ohair@286 43 * <p>
ohair@286 44 * This class mainly performs the following two tasks:
ohair@286 45 * <ol>
ohair@286 46 * <li>Accepts Object[] that represents arguments for a Java method,
ohair@286 47 * and creates {@link com.sun.xml.internal.ws.message.jaxb.JAXBMessage} that represents a request message.
ohair@286 48 * <li>Takes a {@link com.sun.xml.internal.ws.api.message.Message] that represents a response,
ohair@286 49 * and extracts the return value (and updates {@link javax.xml.ws.Holder }s.)
ohair@286 50 * </ol>
ohair@286 51 *
ohair@286 52 * <h2>Creating {@link com.sun.xml.internal.ws.message.jaxb.JAXBMessage }</h2>
ohair@286 53 * <p>
ohair@286 54 * At the construction time, we prepare {@link com.sun.xml.internal.ws.client.sei.BodyBuilder} and {@link com.sun.xml.internal.ws.client.sei.MessageFiller}s
ohair@286 55 * that know how to move arguments into a {@link com.sun.xml.internal.ws.api.message.Message }.
ohair@286 56 * Some arguments go to the payload, some go to headers, still others go to attachments.
ohair@286 57 *
ohair@286 58 * @author Kohsuke Kawaguchi
ohair@286 59 * @author Jitendra Kotamraju
ohair@286 60 */
ohair@286 61 abstract class SEIMethodHandler extends MethodHandler {
ohair@286 62
ohair@286 63 // these objects together create a message from method parameters
ohair@286 64 private BodyBuilder bodyBuilder;
ohair@286 65 private MessageFiller[] inFillers;
ohair@286 66
ohair@286 67 protected String soapAction;
ohair@286 68
ohair@286 69 protected boolean isOneWay;
ohair@286 70
ohair@286 71 protected JavaMethodImpl javaMethod;
ohair@286 72
ohair@286 73 protected Map<QName, CheckedExceptionImpl> checkedExceptions;
ohair@286 74
ohair@286 75 SEIMethodHandler(SEIStub owner) {
ohair@286 76 super(owner, null);
ohair@286 77 }
ohair@286 78
ohair@286 79 SEIMethodHandler(SEIStub owner, JavaMethodImpl method) {
ohair@286 80 super(owner, null);
ohair@286 81
ohair@286 82 //keep all the CheckedException model for the detail qname
ohair@286 83 this.checkedExceptions = new HashMap<QName, CheckedExceptionImpl>();
ohair@286 84 for(CheckedExceptionImpl ce : method.getCheckedExceptions()){
ohair@286 85 checkedExceptions.put(ce.getBond().getTypeInfo().tagName, ce);
ohair@286 86 }
ohair@286 87 //If a non-"" soapAction is specified, wsa:action the SOAPAction
ohair@286 88 if(method.getInputAction() != null && !method.getBinding().getSOAPAction().equals("") ) {
ohair@286 89 this.soapAction = method.getInputAction();
ohair@286 90 } else {
ohair@286 91 this.soapAction = method.getBinding().getSOAPAction();
ohair@286 92 }
ohair@286 93 this.javaMethod = method;
ohair@286 94
ohair@286 95 {// prepare objects for creating messages
ohair@286 96 List<ParameterImpl> rp = method.getRequestParameters();
ohair@286 97
alanb@368 98 BodyBuilder tmpBodyBuilder = null;
ohair@286 99 List<MessageFiller> fillers = new ArrayList<MessageFiller>();
ohair@286 100
ohair@286 101 for (ParameterImpl param : rp) {
ohair@286 102 ValueGetter getter = getValueGetterFactory().get(param);
ohair@286 103
ohair@286 104 switch(param.getInBinding().kind) {
ohair@286 105 case BODY:
ohair@286 106 if(param.isWrapperStyle()) {
ohair@286 107 if(param.getParent().getBinding().isRpcLit())
alanb@368 108 tmpBodyBuilder = new BodyBuilder.RpcLit((WrapperParameter)param, owner.soapVersion, getValueGetterFactory());
ohair@286 109 else
alanb@368 110 tmpBodyBuilder = new BodyBuilder.DocLit((WrapperParameter)param, owner.soapVersion, getValueGetterFactory());
ohair@286 111 } else {
alanb@368 112 tmpBodyBuilder = new BodyBuilder.Bare(param, owner.soapVersion, getter);
ohair@286 113 }
ohair@286 114 break;
ohair@286 115 case HEADER:
ohair@286 116 fillers.add(new MessageFiller.Header(
ohair@286 117 param.getIndex(),
ohair@286 118 param.getXMLBridge(),
ohair@286 119 getter ));
ohair@286 120 break;
ohair@286 121 case ATTACHMENT:
ohair@286 122 fillers.add(MessageFiller.AttachmentFiller.createAttachmentFiller(param, getter));
ohair@286 123 break;
ohair@286 124 case UNBOUND:
ohair@286 125 break;
ohair@286 126 default:
ohair@286 127 throw new AssertionError(); // impossible
ohair@286 128 }
ohair@286 129 }
ohair@286 130
alanb@368 131 if(tmpBodyBuilder==null) {
ohair@286 132 // no parameter binds to body. we create an empty message
ohair@286 133 switch(owner.soapVersion) {
ohair@286 134 case SOAP_11:
alanb@368 135 tmpBodyBuilder = BodyBuilder.EMPTY_SOAP11;
ohair@286 136 break;
ohair@286 137 case SOAP_12:
alanb@368 138 tmpBodyBuilder = BodyBuilder.EMPTY_SOAP12;
ohair@286 139 break;
ohair@286 140 default:
ohair@286 141 throw new AssertionError();
ohair@286 142 }
ohair@286 143 }
ohair@286 144
alanb@368 145 this.bodyBuilder = tmpBodyBuilder;
ohair@286 146 this.inFillers = fillers.toArray(new MessageFiller[fillers.size()]);
ohair@286 147 }
ohair@286 148
ohair@286 149 this.isOneWay = method.getMEP().isOneWay();
ohair@286 150 }
ohair@286 151
ohair@286 152 ResponseBuilder buildResponseBuilder(JavaMethodImpl method, ValueSetterFactory setterFactory) {
ohair@286 153 // prepare objects for processing response
ohair@286 154 List<ParameterImpl> rp = method.getResponseParameters();
ohair@286 155 List<ResponseBuilder> builders = new ArrayList<ResponseBuilder>();
ohair@286 156
ohair@286 157 for( ParameterImpl param : rp ) {
ohair@286 158 ValueSetter setter;
ohair@286 159 switch(param.getOutBinding().kind) {
ohair@286 160 case BODY:
ohair@286 161 if(param.isWrapperStyle()) {
ohair@286 162 if(param.getParent().getBinding().isRpcLit())
ohair@286 163 builders.add(new ResponseBuilder.RpcLit((WrapperParameter)param, setterFactory));
ohair@286 164 else
ohair@286 165 builders.add(new ResponseBuilder.DocLit((WrapperParameter)param, setterFactory));
ohair@286 166 } else {
ohair@286 167 setter = setterFactory.get(param);
ohair@286 168 builders.add(new ResponseBuilder.Body(param.getXMLBridge(),setter));
ohair@286 169 }
ohair@286 170 break;
ohair@286 171 case HEADER:
ohair@286 172 setter = setterFactory.get(param);
ohair@286 173 builders.add(new ResponseBuilder.Header(owner.soapVersion, param, setter));
ohair@286 174 break;
ohair@286 175 case ATTACHMENT:
ohair@286 176 setter = setterFactory.get(param);
ohair@286 177 builders.add(ResponseBuilder.AttachmentBuilder.createAttachmentBuilder(param, setter));
ohair@286 178 break;
ohair@286 179 case UNBOUND:
ohair@286 180 setter = setterFactory.get(param);
ohair@286 181 builders.add(new ResponseBuilder.NullSetter(setter,
ohair@286 182 ResponseBuilder.getVMUninitializedValue(param.getTypeInfo().type)));
ohair@286 183 break;
ohair@286 184 default:
ohair@286 185 throw new AssertionError();
ohair@286 186 }
ohair@286 187 }
ohair@286 188 ResponseBuilder rb;
ohair@286 189 switch(builders.size()) {
ohair@286 190 case 0:
ohair@286 191 rb = ResponseBuilder.NONE;
ohair@286 192 break;
ohair@286 193 case 1:
ohair@286 194 rb = builders.get(0);
ohair@286 195 break;
ohair@286 196 default:
ohair@286 197 rb = new ResponseBuilder.Composite(builders);
ohair@286 198 }
ohair@286 199 return rb;
ohair@286 200 }
ohair@286 201
ohair@286 202
ohair@286 203 /**
ohair@286 204 * Creates a request {@link com.sun.xml.internal.ws.message.jaxb.JAXBMessage} from method arguments.
ohair@286 205 * @param args proxy invocation arguments
ohair@286 206 * @return Message for the arguments
ohair@286 207 */
ohair@286 208 Message createRequestMessage(Object[] args) {
ohair@286 209 Message msg = bodyBuilder.createMessage(args);
ohair@286 210
ohair@286 211 for (MessageFiller filler : inFillers)
ohair@286 212 filler.fillIn(args,msg);
ohair@286 213
ohair@286 214 return msg;
ohair@286 215 }
ohair@286 216
ohair@286 217 abstract ValueGetterFactory getValueGetterFactory();
ohair@286 218
ohair@286 219 }

mercurial