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

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/db/DatabindingImpl.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,251 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.ws.db;
    1.30 +
    1.31 +import java.io.IOException;
    1.32 +import java.io.InputStream;
    1.33 +import java.io.OutputStream;
    1.34 +import java.lang.reflect.Method;
    1.35 +import java.util.HashMap;
    1.36 +import java.util.Map;
    1.37 +
    1.38 +import javax.xml.namespace.QName;
    1.39 +import javax.xml.ws.WebServiceFeature;
    1.40 +
    1.41 +import com.sun.xml.internal.org.jvnet.ws.message.MessageContext;
    1.42 +
    1.43 +import com.sun.xml.internal.ws.api.databinding.EndpointCallBridge;
    1.44 +import com.sun.xml.internal.ws.api.databinding.JavaCallInfo;
    1.45 +import com.sun.xml.internal.ws.api.databinding.WSDLGenInfo;
    1.46 +import com.sun.xml.internal.ws.api.databinding.Databinding;
    1.47 +import com.sun.xml.internal.ws.api.databinding.DatabindingConfig;
    1.48 +import com.sun.xml.internal.ws.api.databinding.ClientCallBridge;
    1.49 +import com.sun.xml.internal.ws.api.message.Message;
    1.50 +import com.sun.xml.internal.ws.api.message.Packet;
    1.51 +import com.sun.xml.internal.ws.api.model.MEP;
    1.52 +import com.sun.xml.internal.ws.api.model.SEIModel;
    1.53 +import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
    1.54 +import com.sun.xml.internal.ws.api.pipe.Codec;
    1.55 +import com.sun.xml.internal.ws.api.pipe.ContentType;
    1.56 +import com.sun.xml.internal.ws.binding.BindingImpl;
    1.57 +import com.sun.xml.internal.ws.client.sei.StubAsyncHandler;
    1.58 +import com.sun.xml.internal.ws.client.sei.StubHandler;
    1.59 +import com.sun.xml.internal.ws.model.AbstractSEIModelImpl;
    1.60 +import com.sun.xml.internal.ws.model.JavaMethodImpl;
    1.61 +import com.sun.xml.internal.ws.model.RuntimeModeler;
    1.62 +import com.sun.xml.internal.ws.server.sei.TieHandler;
    1.63 +import com.sun.xml.internal.ws.util.QNameMap;
    1.64 +import com.sun.xml.internal.ws.wsdl.ActionBasedOperationSignature;
    1.65 +import com.sun.xml.internal.ws.wsdl.DispatchException;
    1.66 +import com.sun.xml.internal.ws.wsdl.OperationDispatcher;
    1.67 +
    1.68 +/**
    1.69 + * WsRuntimeImpl is the databinding processor built on SEIModel
    1.70 + *
    1.71 + * @author shih-chang.chen@oracle.com
    1.72 + */
    1.73 +public class DatabindingImpl implements Databinding, com.sun.xml.internal.org.jvnet.ws.databinding.Databinding {
    1.74 +
    1.75 +    AbstractSEIModelImpl seiModel;
    1.76 +        Map<Method, StubHandler> stubHandlers;
    1.77 +    QNameMap<TieHandler> wsdlOpMap = new QNameMap<TieHandler>();
    1.78 +        Map<Method, TieHandler> tieHandlers = new HashMap<Method, TieHandler>();
    1.79 +    OperationDispatcher operationDispatcher;
    1.80 +    OperationDispatcher operationDispatcherNoWsdl;
    1.81 +    boolean clientConfig = false;
    1.82 +    Codec codec;
    1.83 +
    1.84 +        public DatabindingImpl(DatabindingProviderImpl p, DatabindingConfig config) {
    1.85 +                RuntimeModeler modeler = new RuntimeModeler(config);
    1.86 +                modeler.setClassLoader(config.getClassLoader());
    1.87 +                seiModel = modeler.buildRuntimeModel();
    1.88 +                WSDLPort wsdlport = config.getWsdlPort();
    1.89 +                clientConfig = isClientConfig(config);
    1.90 +                if ( clientConfig ) initStubHandlers();
    1.91 +                seiModel.setDatabinding(this);
    1.92 +                if (wsdlport != null) freeze(wsdlport);
    1.93 +                if (operationDispatcher == null) operationDispatcherNoWsdl = new OperationDispatcher(null, seiModel.getWSBinding(), seiModel);
    1.94 +//    if(!clientConfig) {
    1.95 +                for(JavaMethodImpl jm: seiModel.getJavaMethods()) if (!jm.isAsync()) {
    1.96 +            TieHandler th = new TieHandler(jm, seiModel.getWSBinding());
    1.97 +            wsdlOpMap.put(jm.getOperationQName(), th);
    1.98 +            tieHandlers.put(th.getMethod(), th);
    1.99 +        }
   1.100 +//    }
   1.101 +        }
   1.102 +
   1.103 +        //TODO isClientConfig
   1.104 +        private boolean isClientConfig(DatabindingConfig config) {
   1.105 +                if (config.getContractClass() == null) return false;
   1.106 +                if (!config.getContractClass().isInterface()) return false;
   1.107 +                return (config.getEndpointClass() == null || config.getEndpointClass().isInterface());
   1.108 +        }
   1.109 +        //TODO fix freeze
   1.110 +        public synchronized void freeze(WSDLPort port) {
   1.111 +                if (clientConfig) return;
   1.112 +                if (operationDispatcher != null) return;
   1.113 +                operationDispatcher = (port == null) ? null : new OperationDispatcher(port, seiModel.getWSBinding(), seiModel);
   1.114 +        }
   1.115 +
   1.116 +        public SEIModel getModel() {
   1.117 +                return seiModel;
   1.118 +        }
   1.119 +//Refactored from SEIStub
   1.120 +    private void initStubHandlers() {
   1.121 +                stubHandlers = new HashMap<Method, StubHandler>();
   1.122 +        Map<ActionBasedOperationSignature, JavaMethodImpl> syncs = new HashMap<ActionBasedOperationSignature, JavaMethodImpl>();
   1.123 +        // fill in methodHandlers.
   1.124 +        // first fill in sychronized versions
   1.125 +        for (JavaMethodImpl m : seiModel.getJavaMethods()) {
   1.126 +            if (!m.getMEP().isAsync) {
   1.127 +                StubHandler handler = new StubHandler(m);
   1.128 +                syncs.put(m.getOperationSignature(), m);
   1.129 +                stubHandlers.put(m.getMethod(), handler);
   1.130 +            }
   1.131 +        }
   1.132 +        for (JavaMethodImpl jm : seiModel.getJavaMethods()) {
   1.133 +            JavaMethodImpl sync = syncs.get(jm.getOperationSignature());
   1.134 +            if (jm.getMEP() == MEP.ASYNC_CALLBACK || jm.getMEP() == MEP.ASYNC_POLL) {
   1.135 +                Method m = jm.getMethod();
   1.136 +                StubAsyncHandler handler = new StubAsyncHandler(jm, sync);
   1.137 +                stubHandlers.put(m, handler);
   1.138 +            }
   1.139 +        }
   1.140 +    }
   1.141 +
   1.142 +    public QName resolveOperationQName(Packet req) throws DispatchException {
   1.143 +        return (operationDispatcher != null)?
   1.144 +                operationDispatcher.getWSDLOperationQName(req):
   1.145 +                operationDispatcherNoWsdl.getWSDLOperationQName(req);
   1.146 +    }
   1.147 +
   1.148 +        public JavaCallInfo deserializeRequest(Packet req) {
   1.149 +                JavaCallInfo call = new JavaCallInfo();
   1.150 +                try {
   1.151 +                        QName wsdlOp = resolveOperationQName(req);
   1.152 +                        TieHandler tie = wsdlOpMap.get(wsdlOp);
   1.153 +                        call.setMethod(tie.getMethod());
   1.154 +                        Object[] args = tie.readRequest(req.getMessage());
   1.155 +                        call.setParameters(args);
   1.156 +                } catch (DispatchException e) {
   1.157 +                        call.setException(e);
   1.158 +                }
   1.159 +                return call;
   1.160 +        }
   1.161 +
   1.162 +        public JavaCallInfo deserializeResponse(Packet res, JavaCallInfo call) {
   1.163 +        StubHandler stubHandler = stubHandlers.get(call.getMethod());
   1.164 +        try {
   1.165 +            return stubHandler.readResponse(res, call);
   1.166 +        } catch (Throwable e) {
   1.167 +            call.setException(e);
   1.168 +            return call;
   1.169 +        }
   1.170 +        }
   1.171 +
   1.172 +        public WebServiceFeature[] getFeatures() {
   1.173 +                // TODO Auto-generated method stub
   1.174 +                return null;
   1.175 +        }
   1.176 +
   1.177 +        public Packet serializeRequest(JavaCallInfo call) {
   1.178 +        StubHandler stubHandler = stubHandlers.get(call.getMethod());
   1.179 +        return stubHandler.createRequestPacket(call);
   1.180 +        }
   1.181 +
   1.182 +        public Packet serializeResponse(JavaCallInfo call) {
   1.183 +                Method method = call.getMethod();
   1.184 +                Message message = null;
   1.185 +                if (method != null) {
   1.186 +                        TieHandler th = tieHandlers.get(method);
   1.187 +                        if (th != null) {
   1.188 +                            return th.serializeResponse(call);
   1.189 +                        }
   1.190 +                }
   1.191 +                if (call.getException() instanceof DispatchException) {
   1.192 +                    message = ((DispatchException)call.getException()).fault;
   1.193 +                }
   1.194 +        Packet response = new Packet();
   1.195 +        response.setMessage(message);
   1.196 +        return response;
   1.197 +        }
   1.198 +
   1.199 +        public ClientCallBridge getClientBridge(Method method) {
   1.200 +                return stubHandlers.get(method);
   1.201 +        }
   1.202 +
   1.203 +
   1.204 +        public void generateWSDL(WSDLGenInfo info) {
   1.205 +            com.sun.xml.internal.ws.wsdl.writer.WSDLGenerator wsdlGen = new com.sun.xml.internal.ws.wsdl.writer.WSDLGenerator(
   1.206 +                    seiModel,
   1.207 +                    info.getWsdlResolver(),
   1.208 +                    seiModel.getWSBinding(),
   1.209 +                    info.getContainer(), seiModel.getEndpointClass(),
   1.210 +                    info.isInlineSchemas(),
   1.211 +                    info.getExtensions());
   1.212 +        wsdlGen.doGeneration();
   1.213 +        }
   1.214 +
   1.215 +        public EndpointCallBridge getEndpointBridge(Packet req) throws DispatchException {
   1.216 +                QName wsdlOp = resolveOperationQName(req);
   1.217 +                return wsdlOpMap.get(wsdlOp);
   1.218 +        }
   1.219 +
   1.220 +
   1.221 +        Codec getCodec() {
   1.222 +                if (codec == null) codec = ((BindingImpl)seiModel.getWSBinding()).createCodec();
   1.223 +                return codec;
   1.224 +        }
   1.225 +
   1.226 +        public ContentType encode( Packet packet, OutputStream out ) throws IOException {
   1.227 +        return getCodec().encode(packet, out);
   1.228 +    }
   1.229 +
   1.230 +        public void decode( InputStream in, String ct, Packet p ) throws IOException{
   1.231 +        getCodec().decode(in, ct, p);
   1.232 +    }
   1.233 +
   1.234 +    public com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo createJavaCallInfo(Method method, Object[] args) {
   1.235 +        return new JavaCallInfo(method, args);
   1.236 +    }
   1.237 +
   1.238 +    public MessageContext serializeRequest(com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo call) {
   1.239 +        return serializeRequest((JavaCallInfo)call);
   1.240 +    }
   1.241 +
   1.242 +    public com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo deserializeResponse(
   1.243 +            MessageContext message, com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo call) {
   1.244 +        return deserializeResponse((Packet)message, (JavaCallInfo)call);
   1.245 +    }
   1.246 +
   1.247 +    public com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo deserializeRequest(MessageContext message) {
   1.248 +        return deserializeRequest((Packet)message);
   1.249 +    }
   1.250 +
   1.251 +    public MessageContext serializeResponse(com.sun.xml.internal.org.jvnet.ws.databinding.JavaCallInfo call) {
   1.252 +        return serializeResponse((JavaCallInfo)call);
   1.253 +    }
   1.254 +}

mercurial