Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.ws.db; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.io.InputStream; |
aoqi@0 | 29 | import java.net.URL; |
aoqi@0 | 30 | import java.util.HashMap; |
aoqi@0 | 31 | import java.util.List; |
aoqi@0 | 32 | import java.util.Map; |
aoqi@0 | 33 | import java.util.Properties; |
aoqi@0 | 34 | |
aoqi@0 | 35 | import javax.xml.namespace.QName; |
aoqi@0 | 36 | import javax.xml.transform.Source; |
aoqi@0 | 37 | import javax.xml.ws.WebServiceException; |
aoqi@0 | 38 | import javax.xml.ws.WebServiceFeature; |
aoqi@0 | 39 | |
aoqi@0 | 40 | import org.xml.sax.EntityResolver; |
aoqi@0 | 41 | |
aoqi@0 | 42 | import com.oracle.webservices.internal.api.databinding.Databinding; |
aoqi@0 | 43 | import com.oracle.webservices.internal.api.databinding.Databinding.Builder; |
aoqi@0 | 44 | import com.oracle.webservices.internal.api.databinding.WSDLGenerator; |
aoqi@0 | 45 | import com.oracle.webservices.internal.api.databinding.DatabindingModeFeature; |
aoqi@0 | 46 | import com.sun.xml.internal.ws.api.BindingID; |
aoqi@0 | 47 | import com.sun.xml.internal.ws.api.WSBinding; |
aoqi@0 | 48 | import com.sun.xml.internal.ws.api.databinding.DatabindingConfig; |
aoqi@0 | 49 | import com.sun.xml.internal.ws.api.databinding.DatabindingFactory; |
aoqi@0 | 50 | import com.sun.xml.internal.ws.api.databinding.MetadataReader; |
aoqi@0 | 51 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; |
aoqi@0 | 52 | import com.sun.xml.internal.ws.spi.db.DatabindingProvider; |
aoqi@0 | 53 | import com.sun.xml.internal.ws.util.ServiceFinder; |
aoqi@0 | 54 | |
aoqi@0 | 55 | /** |
aoqi@0 | 56 | * DatabindingFactoryImpl |
aoqi@0 | 57 | * |
aoqi@0 | 58 | * @author shih-chang.chen@oracle.com |
aoqi@0 | 59 | */ |
aoqi@0 | 60 | public class DatabindingFactoryImpl extends DatabindingFactory { |
aoqi@0 | 61 | |
aoqi@0 | 62 | static final String WsRuntimeFactoryDefaultImpl = "com.sun.xml.internal.ws.db.DatabindingProviderImpl"; |
aoqi@0 | 63 | |
aoqi@0 | 64 | protected Map<String, Object> properties = new HashMap<String, Object>(); |
aoqi@0 | 65 | protected DatabindingProvider defaultRuntimeFactory; |
aoqi@0 | 66 | protected List<DatabindingProvider> providers; |
aoqi@0 | 67 | |
aoqi@0 | 68 | static private List<DatabindingProvider> providers() { |
aoqi@0 | 69 | List<DatabindingProvider> factories = new java.util.ArrayList<DatabindingProvider>(); |
aoqi@0 | 70 | for (DatabindingProvider p : ServiceFinder.find(DatabindingProvider.class)) { |
aoqi@0 | 71 | factories.add(p); |
aoqi@0 | 72 | } |
aoqi@0 | 73 | return factories; |
aoqi@0 | 74 | } |
aoqi@0 | 75 | |
aoqi@0 | 76 | public DatabindingFactoryImpl() { |
aoqi@0 | 77 | } |
aoqi@0 | 78 | |
aoqi@0 | 79 | public Map<String, Object> properties() { |
aoqi@0 | 80 | return properties; |
aoqi@0 | 81 | } |
aoqi@0 | 82 | |
aoqi@0 | 83 | <T> T property(Class<T> propType, String propName) { |
aoqi@0 | 84 | if (propName == null) propName = propType.getName(); |
aoqi@0 | 85 | return propType.cast(properties.get(propName)); |
aoqi@0 | 86 | } |
aoqi@0 | 87 | |
aoqi@0 | 88 | public DatabindingProvider provider(DatabindingConfig config) { |
aoqi@0 | 89 | String mode = databindingMode(config); |
aoqi@0 | 90 | if (providers == null) |
aoqi@0 | 91 | providers = providers(); |
aoqi@0 | 92 | DatabindingProvider provider = null; |
aoqi@0 | 93 | if (providers != null) { |
aoqi@0 | 94 | for (DatabindingProvider p : providers) |
aoqi@0 | 95 | if (p.isFor(mode)) |
aoqi@0 | 96 | provider = p; |
aoqi@0 | 97 | } if (provider == null) { |
aoqi@0 | 98 | provider = new DatabindingProviderImpl(); |
aoqi@0 | 99 | } |
aoqi@0 | 100 | return provider; |
aoqi@0 | 101 | } |
aoqi@0 | 102 | |
aoqi@0 | 103 | public Databinding createRuntime(DatabindingConfig config) { |
aoqi@0 | 104 | DatabindingProvider provider = provider(config); |
aoqi@0 | 105 | return provider.create(config); |
aoqi@0 | 106 | } |
aoqi@0 | 107 | |
aoqi@0 | 108 | public WSDLGenerator createWsdlGen(DatabindingConfig config) { |
aoqi@0 | 109 | DatabindingProvider provider = provider(config); |
aoqi@0 | 110 | return provider.wsdlGen(config); |
aoqi@0 | 111 | } |
aoqi@0 | 112 | |
aoqi@0 | 113 | String databindingMode(DatabindingConfig config) { |
aoqi@0 | 114 | if ( config.getMappingInfo() != null && |
aoqi@0 | 115 | config.getMappingInfo().getDatabindingMode() != null) |
aoqi@0 | 116 | return config.getMappingInfo().getDatabindingMode(); |
aoqi@0 | 117 | if ( config.getFeatures() != null) for (WebServiceFeature f : config.getFeatures()) { |
aoqi@0 | 118 | if (f instanceof DatabindingModeFeature) { |
aoqi@0 | 119 | DatabindingModeFeature dmf = (DatabindingModeFeature) f; |
aoqi@0 | 120 | config.properties().putAll(dmf.getProperties()); |
aoqi@0 | 121 | return dmf.getMode(); |
aoqi@0 | 122 | } |
aoqi@0 | 123 | } |
aoqi@0 | 124 | return null; |
aoqi@0 | 125 | } |
aoqi@0 | 126 | |
aoqi@0 | 127 | ClassLoader classLoader() { |
aoqi@0 | 128 | ClassLoader classLoader = property(ClassLoader.class, null); |
aoqi@0 | 129 | if (classLoader == null) classLoader = Thread.currentThread().getContextClassLoader(); |
aoqi@0 | 130 | return classLoader; |
aoqi@0 | 131 | } |
aoqi@0 | 132 | |
aoqi@0 | 133 | Properties loadPropertiesFile(String fileName) { |
aoqi@0 | 134 | ClassLoader classLoader = classLoader(); |
aoqi@0 | 135 | Properties p = new Properties(); |
aoqi@0 | 136 | try { |
aoqi@0 | 137 | InputStream is = null; |
aoqi@0 | 138 | if (classLoader == null) { |
aoqi@0 | 139 | is = ClassLoader.getSystemResourceAsStream(fileName); |
aoqi@0 | 140 | } else { |
aoqi@0 | 141 | is = classLoader.getResourceAsStream(fileName); |
aoqi@0 | 142 | } |
aoqi@0 | 143 | if (is != null) { |
aoqi@0 | 144 | p.load(is); |
aoqi@0 | 145 | } |
aoqi@0 | 146 | } catch (Exception e) { |
aoqi@0 | 147 | throw new WebServiceException(e); |
aoqi@0 | 148 | } |
aoqi@0 | 149 | return p; |
aoqi@0 | 150 | } |
aoqi@0 | 151 | |
aoqi@0 | 152 | public Builder createBuilder(Class<?> contractClass, Class<?> endpointClass) { |
aoqi@0 | 153 | return new ConfigBuilder(this, contractClass, endpointClass); |
aoqi@0 | 154 | } |
aoqi@0 | 155 | |
aoqi@0 | 156 | static class ConfigBuilder implements Builder { |
aoqi@0 | 157 | DatabindingConfig config; |
aoqi@0 | 158 | DatabindingFactoryImpl factory; |
aoqi@0 | 159 | |
aoqi@0 | 160 | ConfigBuilder(DatabindingFactoryImpl f, Class<?> contractClass, Class<?> implBeanClass) { |
aoqi@0 | 161 | factory = f; |
aoqi@0 | 162 | config = new DatabindingConfig(); |
aoqi@0 | 163 | config.setContractClass(contractClass); |
aoqi@0 | 164 | config.setEndpointClass(implBeanClass); |
aoqi@0 | 165 | } |
aoqi@0 | 166 | public Builder targetNamespace(String targetNamespace) { |
aoqi@0 | 167 | config.getMappingInfo().setTargetNamespace(targetNamespace); |
aoqi@0 | 168 | return this; |
aoqi@0 | 169 | } |
aoqi@0 | 170 | public Builder serviceName(QName serviceName) { |
aoqi@0 | 171 | config.getMappingInfo().setServiceName(serviceName); |
aoqi@0 | 172 | return this; |
aoqi@0 | 173 | } |
aoqi@0 | 174 | public Builder portName(QName portName) { |
aoqi@0 | 175 | config.getMappingInfo().setPortName(portName); |
aoqi@0 | 176 | return this; |
aoqi@0 | 177 | } |
aoqi@0 | 178 | public Builder wsdlURL(URL wsdlURL) { |
aoqi@0 | 179 | config.setWsdlURL(wsdlURL); |
aoqi@0 | 180 | return this; |
aoqi@0 | 181 | } |
aoqi@0 | 182 | public Builder wsdlSource(Source wsdlSource) { |
aoqi@0 | 183 | config.setWsdlSource(wsdlSource); |
aoqi@0 | 184 | return this; |
aoqi@0 | 185 | } |
aoqi@0 | 186 | public Builder entityResolver(EntityResolver entityResolver) { |
aoqi@0 | 187 | config.setEntityResolver(entityResolver); |
aoqi@0 | 188 | return this; |
aoqi@0 | 189 | } |
aoqi@0 | 190 | public Builder classLoader(ClassLoader classLoader) { |
aoqi@0 | 191 | config.setClassLoader(classLoader); |
aoqi@0 | 192 | return this; |
aoqi@0 | 193 | } |
aoqi@0 | 194 | public Builder feature(WebServiceFeature... f) { |
aoqi@0 | 195 | config.setFeatures(f); |
aoqi@0 | 196 | return this; |
aoqi@0 | 197 | } |
aoqi@0 | 198 | public Builder property(String name, Object value) { |
aoqi@0 | 199 | config.properties().put(name, value); |
aoqi@0 | 200 | if (isfor(BindingID.class, name, value)) { |
aoqi@0 | 201 | config.getMappingInfo().setBindingID((BindingID)value); |
aoqi@0 | 202 | } |
aoqi@0 | 203 | if (isfor(WSBinding.class, name, value)) { |
aoqi@0 | 204 | config.setWSBinding((WSBinding)value); |
aoqi@0 | 205 | } |
aoqi@0 | 206 | if (isfor(WSDLPort.class, name, value)) { |
aoqi@0 | 207 | config.setWsdlPort((WSDLPort)value); |
aoqi@0 | 208 | } |
aoqi@0 | 209 | if (isfor(MetadataReader.class, name, value)) { |
aoqi@0 | 210 | config.setMetadataReader((MetadataReader)value); |
aoqi@0 | 211 | } |
aoqi@0 | 212 | return this; |
aoqi@0 | 213 | } |
aoqi@0 | 214 | boolean isfor(Class<?> type, String name, Object value) { |
aoqi@0 | 215 | return type.getName().equals(name) && type.isInstance(value); |
aoqi@0 | 216 | } |
aoqi@0 | 217 | |
aoqi@0 | 218 | public com.oracle.webservices.internal.api.databinding.Databinding build() { |
aoqi@0 | 219 | return factory.createRuntime(config); |
aoqi@0 | 220 | } |
aoqi@0 | 221 | public com.oracle.webservices.internal.api.databinding.WSDLGenerator createWSDLGenerator() { |
aoqi@0 | 222 | return factory.createWsdlGen(config); |
aoqi@0 | 223 | } |
aoqi@0 | 224 | } |
aoqi@0 | 225 | } |