src/share/jaxws_classes/com/sun/xml/internal/ws/db/DatabindingImpl.java

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

ohair@286 1 /*
ohair@286 2 * Copyright (c) 1997, 2011, 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.db;
ohair@286 27
ohair@286 28 import java.io.IOException;
ohair@286 29 import java.io.InputStream;
ohair@286 30 import java.io.OutputStream;
ohair@286 31 import java.lang.reflect.Method;
ohair@286 32 import java.util.HashMap;
ohair@286 33 import java.util.Map;
ohair@286 34
ohair@286 35 import javax.xml.namespace.QName;
ohair@286 36 import javax.xml.ws.WebServiceFeature;
ohair@286 37
ohair@286 38 import com.sun.xml.internal.org.jvnet.ws.message.MessageContext;
ohair@286 39
ohair@286 40 import com.sun.xml.internal.ws.api.databinding.EndpointCallBridge;
ohair@286 41 import com.sun.xml.internal.ws.api.databinding.JavaCallInfo;
ohair@286 42 import com.sun.xml.internal.ws.api.databinding.WSDLGenInfo;
ohair@286 43 import com.sun.xml.internal.ws.api.databinding.Databinding;
ohair@286 44 import com.sun.xml.internal.ws.api.databinding.DatabindingConfig;
ohair@286 45 import com.sun.xml.internal.ws.api.databinding.ClientCallBridge;
ohair@286 46 import com.sun.xml.internal.ws.api.message.Message;
ohair@286 47 import com.sun.xml.internal.ws.api.message.Packet;
ohair@286 48 import com.sun.xml.internal.ws.api.model.MEP;
ohair@286 49 import com.sun.xml.internal.ws.api.model.SEIModel;
ohair@286 50 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
ohair@286 51 import com.sun.xml.internal.ws.api.pipe.Codec;
ohair@286 52 import com.sun.xml.internal.ws.api.pipe.ContentType;
ohair@286 53 import com.sun.xml.internal.ws.binding.BindingImpl;
ohair@286 54 import com.sun.xml.internal.ws.client.sei.StubAsyncHandler;
ohair@286 55 import com.sun.xml.internal.ws.client.sei.StubHandler;
ohair@286 56 import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
ohair@286 57 import com.sun.xml.internal.ws.model.JavaMethodImpl;
ohair@286 58 import com.sun.xml.internal.ws.model.RuntimeModeler;
ohair@286 59 import com.sun.xml.internal.ws.server.sei.TieHandler;
ohair@286 60 import com.sun.xml.internal.ws.util.QNameMap;
ohair@286 61 import com.sun.xml.internal.ws.wsdl.ActionBasedOperationSignature;
ohair@286 62 import com.sun.xml.internal.ws.wsdl.DispatchException;
ohair@286 63 import com.sun.xml.internal.ws.wsdl.OperationDispatcher;
ohair@286 64
ohair@286 65 /**
ohair@286 66 * WsRuntimeImpl is the databinding processor built on SEIModel
ohair@286 67 *
ohair@286 68 * @author shih-chang.chen@oracle.com
ohair@286 69 */
ohair@286 70 public class DatabindingImpl implements Databinding, com.sun.xml.internal.org.jvnet.ws.databinding.Databinding {
ohair@286 71
ohair@286 72 AbstractSEIModelImpl seiModel;
ohair@286 73 Map<Method, StubHandler> stubHandlers;
ohair@286 74 QNameMap<TieHandler> wsdlOpMap = new QNameMap<TieHandler>();
ohair@286 75 Map<Method, TieHandler> tieHandlers = new HashMap<Method, TieHandler>();
ohair@286 76 OperationDispatcher operationDispatcher;
ohair@286 77 OperationDispatcher operationDispatcherNoWsdl;
ohair@286 78 boolean clientConfig = false;
ohair@286 79 Codec codec;
ohair@286 80
ohair@286 81 public DatabindingImpl(DatabindingProviderImpl p, DatabindingConfig config) {
ohair@286 82 RuntimeModeler modeler = new RuntimeModeler(config);
ohair@286 83 modeler.setClassLoader(config.getClassLoader());
ohair@286 84 seiModel = modeler.buildRuntimeModel();
ohair@286 85 WSDLPort wsdlport = config.getWsdlPort();
ohair@286 86 clientConfig = isClientConfig(config);
ohair@286 87 if ( clientConfig ) initStubHandlers();
ohair@286 88 seiModel.setDatabinding(this);
ohair@286 89 if (wsdlport != null) freeze(wsdlport);
ohair@286 90 if (operationDispatcher == null) operationDispatcherNoWsdl = new OperationDispatcher(null, seiModel.getWSBinding(), seiModel);
ohair@286 91 // if(!clientConfig) {
ohair@286 92 for(JavaMethodImpl jm: seiModel.getJavaMethods()) if (!jm.isAsync()) {
ohair@286 93 TieHandler th = new TieHandler(jm, seiModel.getWSBinding());
ohair@286 94 wsdlOpMap.put(jm.getOperationQName(), th);
ohair@286 95 tieHandlers.put(th.getMethod(), th);
ohair@286 96 }
ohair@286 97 // }
ohair@286 98 }
ohair@286 99
ohair@286 100 //TODO isClientConfig
ohair@286 101 private boolean isClientConfig(DatabindingConfig config) {
ohair@286 102 if (config.getContractClass() == null) return false;
ohair@286 103 if (!config.getContractClass().isInterface()) return false;
ohair@286 104 return (config.getEndpointClass() == null || config.getEndpointClass().isInterface());
ohair@286 105 }
ohair@286 106 //TODO fix freeze
ohair@286 107 public synchronized void freeze(WSDLPort port) {
ohair@286 108 if (clientConfig) return;
ohair@286 109 if (operationDispatcher != null) return;
ohair@286 110 operationDispatcher = (port == null) ? null : new OperationDispatcher(port, seiModel.getWSBinding(), seiModel);
ohair@286 111 }
ohair@286 112
ohair@286 113 public SEIModel getModel() {
ohair@286 114 return seiModel;
ohair@286 115 }
ohair@286 116 //Refactored from SEIStub
ohair@286 117 private void initStubHandlers() {
ohair@286 118 stubHandlers = new HashMap<Method, StubHandler>();
ohair@286 119 Map<ActionBasedOperationSignature, JavaMethodImpl> syncs = new HashMap<ActionBasedOperationSignature, JavaMethodImpl>();
ohair@286 120 // fill in methodHandlers.
ohair@286 121 // first fill in sychronized versions
ohair@286 122 for (JavaMethodImpl m : seiModel.getJavaMethods()) {
ohair@286 123 if (!m.getMEP().isAsync) {
ohair@286 124 StubHandler handler = new StubHandler(m);
ohair@286 125 syncs.put(m.getOperationSignature(), m);
ohair@286 126 stubHandlers.put(m.getMethod(), handler);
ohair@286 127 }
ohair@286 128 }
ohair@286 129 for (JavaMethodImpl jm : seiModel.getJavaMethods()) {
ohair@286 130 JavaMethodImpl sync = syncs.get(jm.getOperationSignature());
ohair@286 131 if (jm.getMEP() == MEP.ASYNC_CALLBACK || jm.getMEP() == MEP.ASYNC_POLL) {
ohair@286 132 Method m = jm.getMethod();
ohair@286 133 StubAsyncHandler handler = new StubAsyncHandler(jm, sync);
ohair@286 134 stubHandlers.put(m, handler);
ohair@286 135 }
ohair@286 136 }
ohair@286 137 }
ohair@286 138
ohair@286 139 public QName resolveOperationQName(Packet req) throws DispatchException {
ohair@286 140 return (operationDispatcher != null)?
ohair@286 141 operationDispatcher.getWSDLOperationQName(req):
ohair@286 142 operationDispatcherNoWsdl.getWSDLOperationQName(req);
ohair@286 143 }
ohair@286 144
ohair@286 145 public JavaCallInfo deserializeRequest(Packet req) {
ohair@286 146 JavaCallInfo call = new JavaCallInfo();
ohair@286 147 try {
ohair@286 148 QName wsdlOp = resolveOperationQName(req);
ohair@286 149 TieHandler tie = wsdlOpMap.get(wsdlOp);
ohair@286 150 call.setMethod(tie.getMethod());
ohair@286 151 Object[] args = tie.readRequest(req.getMessage());
ohair@286 152 call.setParameters(args);
ohair@286 153 } catch (DispatchException e) {
ohair@286 154 call.setException(e);
ohair@286 155 }
ohair@286 156 return call;
ohair@286 157 }
ohair@286 158
ohair@286 159 public JavaCallInfo deserializeResponse(Packet res, JavaCallInfo call) {
ohair@286 160 StubHandler stubHandler = stubHandlers.get(call.getMethod());
ohair@286 161 try {
ohair@286 162 return stubHandler.readResponse(res, call);
ohair@286 163 } catch (Throwable e) {
ohair@286 164 call.setException(e);
ohair@286 165 return call;
ohair@286 166 }
ohair@286 167 }
ohair@286 168
ohair@286 169 public WebServiceFeature[] getFeatures() {
ohair@286 170 // TODO Auto-generated method stub
ohair@286 171 return null;
ohair@286 172 }
ohair@286 173
ohair@286 174 public Packet serializeRequest(JavaCallInfo call) {
ohair@286 175 StubHandler stubHandler = stubHandlers.get(call.getMethod());
ohair@286 176 return stubHandler.createRequestPacket(call);
ohair@286 177 }
ohair@286 178
ohair@286 179 public Packet serializeResponse(JavaCallInfo call) {
ohair@286 180 Method method = call.getMethod();
ohair@286 181 Message message = null;
ohair@286 182 if (method != null) {
ohair@286 183 TieHandler th = tieHandlers.get(method);
ohair@286 184 if (th != null) {
ohair@286 185 return th.serializeResponse(call);
ohair@286 186 }
ohair@286 187 }
ohair@286 188 if (call.getException() instanceof DispatchException) {
ohair@286 189 message = ((DispatchException)call.getException()).fault;
ohair@286 190 }
ohair@286 191 Packet response = new Packet();
ohair@286 192 response.setMessage(message);
ohair@286 193 return response;
ohair@286 194 }
ohair@286 195
ohair@286 196 public ClientCallBridge getClientBridge(Method method) {
ohair@286 197 return stubHandlers.get(method);
ohair@286 198 }
ohair@286 199
ohair@286 200
ohair@286 201 public void generateWSDL(WSDLGenInfo info) {
ohair@286 202 com.sun.xml.internal.ws.wsdl.writer.WSDLGenerator wsdlGen = new com.sun.xml.internal.ws.wsdl.writer.WSDLGenerator(
ohair@286 203 seiModel,
ohair@286 204 info.getWsdlResolver(),
ohair@286 205 seiModel.getWSBinding(),
ohair@286 206 info.getContainer(), seiModel.getEndpointClass(),
ohair@286 207 info.isInlineSchemas(),
ohair@286 208 info.getExtensions());
ohair@286 209 wsdlGen.doGeneration();
ohair@286 210 }
ohair@286 211
ohair@286 212 public EndpointCallBridge getEndpointBridge(Packet req) throws DispatchException {
ohair@286 213 QName wsdlOp = resolveOperationQName(req);
ohair@286 214 return wsdlOpMap.get(wsdlOp);
ohair@286 215 }
ohair@286 216
ohair@286 217
ohair@286 218 Codec getCodec() {
ohair@286 219 if (codec == null) codec = ((BindingImpl)seiModel.getWSBinding()).createCodec();
ohair@286 220 return codec;
ohair@286 221 }
ohair@286 222
ohair@286 223 public ContentType encode( Packet packet, OutputStream out ) throws IOException {
ohair@286 224 return getCodec().encode(packet, out);
ohair@286 225 }
ohair@286 226
ohair@286 227 public void decode( InputStream in, String ct, Packet p ) throws IOException{
ohair@286 228 getCodec().decode(in, ct, p);
ohair@286 229 }
ohair@286 230
ohair@286 231 public com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo createJavaCallInfo(Method method, Object[] args) {
ohair@286 232 return new JavaCallInfo(method, args);
ohair@286 233 }
ohair@286 234
ohair@286 235 public MessageContext serializeRequest(com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo call) {
ohair@286 236 return serializeRequest((JavaCallInfo)call);
ohair@286 237 }
ohair@286 238
ohair@286 239 public com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo deserializeResponse(
ohair@286 240 MessageContext message, com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo call) {
ohair@286 241 return deserializeResponse((Packet)message, (JavaCallInfo)call);
ohair@286 242 }
ohair@286 243
ohair@286 244 public com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo deserializeRequest(MessageContext message) {
ohair@286 245 return deserializeRequest((Packet)message);
ohair@286 246 }
ohair@286 247
ohair@286 248 public MessageContext serializeResponse(com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo call) {
ohair@286 249 return serializeResponse((JavaCallInfo)call);
ohair@286 250 }
ohair@286 251 }

mercurial