Tue, 09 Apr 2013 14:51:13 +0100
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, 2013, 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.InputStream; |
ohair@286 | 29 | import java.net.URL; |
ohair@286 | 30 | import java.util.HashMap; |
ohair@286 | 31 | import java.util.List; |
ohair@286 | 32 | import java.util.Map; |
ohair@286 | 33 | import java.util.Properties; |
ohair@286 | 34 | |
ohair@286 | 35 | import javax.xml.namespace.QName; |
ohair@286 | 36 | import javax.xml.transform.Source; |
ohair@286 | 37 | import javax.xml.ws.WebServiceException; |
ohair@286 | 38 | import javax.xml.ws.WebServiceFeature; |
ohair@286 | 39 | |
ohair@286 | 40 | import org.xml.sax.EntityResolver; |
ohair@286 | 41 | |
alanb@368 | 42 | import com.oracle.webservices.internal.api.databinding.Databinding; |
alanb@368 | 43 | import com.oracle.webservices.internal.api.databinding.Databinding.Builder; |
alanb@368 | 44 | import com.oracle.webservices.internal.api.databinding.WSDLGenerator; |
ohair@286 | 45 | import com.sun.xml.internal.ws.api.BindingID; |
ohair@286 | 46 | import com.sun.xml.internal.ws.api.WSBinding; |
ohair@286 | 47 | import com.sun.xml.internal.ws.api.databinding.DatabindingConfig; |
ohair@286 | 48 | import com.sun.xml.internal.ws.api.databinding.DatabindingFactory; |
alanb@368 | 49 | import com.sun.xml.internal.ws.api.databinding.MetadataReader; |
ohair@286 | 50 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; |
ohair@286 | 51 | import com.sun.xml.internal.ws.spi.db.DatabindingProvider; |
ohair@286 | 52 | import com.sun.xml.internal.ws.util.ServiceFinder; |
ohair@286 | 53 | |
ohair@286 | 54 | /** |
ohair@286 | 55 | * DatabindingFactoryImpl |
ohair@286 | 56 | * |
ohair@286 | 57 | * @author shih-chang.chen@oracle.com |
ohair@286 | 58 | */ |
ohair@286 | 59 | public class DatabindingFactoryImpl extends DatabindingFactory { |
ohair@286 | 60 | |
ohair@286 | 61 | // static final String WsRuntimeFactoryProperties = DatabindingProvider.class.getName() + ".properties"; |
ohair@286 | 62 | static final String WsRuntimeFactoryDefaultImpl = "com.sun.xml.internal.ws.db.DatabindingProviderImpl"; |
ohair@286 | 63 | |
ohair@286 | 64 | protected Map<String, Object> properties = new HashMap<String, Object>(); |
ohair@286 | 65 | protected DatabindingProvider defaultRuntimeFactory; |
ohair@286 | 66 | // protected Map<String, DatabindingProvider> runtimeFactories = new HashMap<String, DatabindingProvider>(); |
ohair@286 | 67 | // protected Properties wsRuntimeFactoryMap; |
ohair@286 | 68 | protected List<DatabindingProvider> providers; |
ohair@286 | 69 | |
ohair@286 | 70 | static private List<DatabindingProvider> providers() { |
ohair@286 | 71 | List<DatabindingProvider> factories = new java.util.ArrayList<DatabindingProvider>(); |
ohair@286 | 72 | for (DatabindingProvider p : ServiceFinder.find(DatabindingProvider.class)) { |
ohair@286 | 73 | factories.add(p); |
ohair@286 | 74 | } |
ohair@286 | 75 | return factories; |
ohair@286 | 76 | } |
ohair@286 | 77 | |
ohair@286 | 78 | public DatabindingFactoryImpl() { |
ohair@286 | 79 | } |
ohair@286 | 80 | |
ohair@286 | 81 | public Map<String, Object> properties() { |
ohair@286 | 82 | return properties; |
ohair@286 | 83 | } |
ohair@286 | 84 | |
ohair@286 | 85 | <T> T property(Class<T> propType, String propName) { |
ohair@286 | 86 | if (propName == null) propName = propType.getName(); |
ohair@286 | 87 | return propType.cast(properties.get(propName)); |
ohair@286 | 88 | } |
ohair@286 | 89 | |
ohair@286 | 90 | public DatabindingProvider provider(DatabindingConfig config) { |
ohair@286 | 91 | String mode = databindingMode(config); |
ohair@286 | 92 | if (providers == null) |
ohair@286 | 93 | providers = providers(); |
ohair@286 | 94 | DatabindingProvider provider = null; |
ohair@286 | 95 | if (providers != null) { |
ohair@286 | 96 | for (DatabindingProvider p : providers) |
ohair@286 | 97 | if (p.isFor(mode)) |
ohair@286 | 98 | provider = p; |
ohair@286 | 99 | } if (provider == null) { |
ohair@286 | 100 | // if (defaultRuntimeFactory == null) { |
ohair@286 | 101 | // defaultRuntimeFactory = |
ohair@286 | 102 | // newRuntimeFactory(WsRuntimeFactoryDefaultImpl); |
ohair@286 | 103 | // } |
ohair@286 | 104 | // provider = defaultRuntimeFactory; |
ohair@286 | 105 | provider = new DatabindingProviderImpl(); |
ohair@286 | 106 | } |
ohair@286 | 107 | return provider; |
ohair@286 | 108 | } |
ohair@286 | 109 | |
ohair@286 | 110 | public Databinding createRuntime(DatabindingConfig config) { |
ohair@286 | 111 | DatabindingProvider provider = provider(config); |
ohair@286 | 112 | return provider.create(config); |
ohair@286 | 113 | } |
ohair@286 | 114 | |
alanb@368 | 115 | public WSDLGenerator createWsdlGen(DatabindingConfig config) { |
ohair@286 | 116 | DatabindingProvider provider = provider(config); |
ohair@286 | 117 | return provider.wsdlGen(config); |
ohair@286 | 118 | } |
ohair@286 | 119 | |
ohair@286 | 120 | // DatabindingProvider newRuntimeFactory(String name) { |
ohair@286 | 121 | // ClassLoader classLoader = classLoader(); |
ohair@286 | 122 | // DatabindingProvider factory = null; |
ohair@286 | 123 | // try { |
ohair@286 | 124 | // Class cls = (classLoader != null) ? classLoader.loadClass(name) : Class.forName(name); |
ohair@286 | 125 | // factory = DatabindingProvider.class.cast(cls.newInstance()); |
ohair@286 | 126 | // } catch (Exception e) { |
ohair@286 | 127 | // throw new DatabindingException("Unknown DatabindingFactory: " + name, e); |
ohair@286 | 128 | // } |
ohair@286 | 129 | // factory.init(properties); |
ohair@286 | 130 | // return factory; |
ohair@286 | 131 | // } |
ohair@286 | 132 | |
ohair@286 | 133 | String databindingMode(DatabindingConfig config) { |
ohair@286 | 134 | // if ( config.getOverrideMappingInfo() != null && |
ohair@286 | 135 | // config.getOverrideMappingInfo().getDatabindingMode() != null) |
ohair@286 | 136 | // return config.getOverrideMappingInfo().getDatabindingMode(); |
ohair@286 | 137 | // if ( config.getDefaultMappingInfo() != null && |
ohair@286 | 138 | // config.getDefaultMappingInfo().getDatabindingMode() != null) |
ohair@286 | 139 | // return config.getDefaultMappingInfo().getDatabindingMode(); |
ohair@286 | 140 | |
ohair@286 | 141 | if ( config.getMappingInfo() != null && |
ohair@286 | 142 | config.getMappingInfo().getDatabindingMode() != null) |
ohair@286 | 143 | return config.getMappingInfo().getDatabindingMode(); |
ohair@286 | 144 | if ( config.getFeatures() != null) for (WebServiceFeature f : config.getFeatures()) { |
alanb@368 | 145 | if (f instanceof com.oracle.webservices.internal.api.databinding.DatabindingModeFeature) { |
alanb@368 | 146 | com.oracle.webservices.internal.api.databinding.DatabindingModeFeature dmf = (com.oracle.webservices.internal.api.databinding.DatabindingModeFeature) f; |
ohair@286 | 147 | return dmf.getMode(); |
ohair@286 | 148 | } |
ohair@286 | 149 | } |
ohair@286 | 150 | return null; |
ohair@286 | 151 | } |
ohair@286 | 152 | |
ohair@286 | 153 | ClassLoader classLoader() { |
ohair@286 | 154 | ClassLoader classLoader = property(ClassLoader.class, null); |
ohair@286 | 155 | if (classLoader == null) classLoader = Thread.currentThread().getContextClassLoader(); |
ohair@286 | 156 | return classLoader; |
ohair@286 | 157 | } |
ohair@286 | 158 | |
ohair@286 | 159 | Properties loadPropertiesFile(String fileName) { |
ohair@286 | 160 | ClassLoader classLoader = classLoader(); |
ohair@286 | 161 | Properties p = new Properties(); |
ohair@286 | 162 | try { |
ohair@286 | 163 | InputStream is = null; |
ohair@286 | 164 | if (classLoader == null) { |
ohair@286 | 165 | is = ClassLoader.getSystemResourceAsStream(fileName); |
ohair@286 | 166 | } else { |
ohair@286 | 167 | is = classLoader.getResourceAsStream(fileName); |
ohair@286 | 168 | } |
ohair@286 | 169 | if (is != null) { |
ohair@286 | 170 | p.load(is); |
ohair@286 | 171 | } |
ohair@286 | 172 | } catch (Exception e) { |
ohair@286 | 173 | throw new WebServiceException(e); |
ohair@286 | 174 | } |
ohair@286 | 175 | return p; |
ohair@286 | 176 | } |
ohair@286 | 177 | |
ohair@286 | 178 | public Builder createBuilder(Class<?> contractClass, Class<?> endpointClass) { |
ohair@286 | 179 | return new ConfigBuilder(this, contractClass, endpointClass); |
ohair@286 | 180 | } |
ohair@286 | 181 | |
ohair@286 | 182 | static class ConfigBuilder implements Builder { |
ohair@286 | 183 | DatabindingConfig config; |
ohair@286 | 184 | DatabindingFactoryImpl factory; |
ohair@286 | 185 | |
ohair@286 | 186 | ConfigBuilder(DatabindingFactoryImpl f, Class<?> contractClass, Class<?> implBeanClass) { |
ohair@286 | 187 | factory = f; |
ohair@286 | 188 | config = new DatabindingConfig(); |
ohair@286 | 189 | config.setContractClass(contractClass); |
ohair@286 | 190 | config.setEndpointClass(implBeanClass); |
ohair@286 | 191 | } |
ohair@286 | 192 | public Builder targetNamespace(String targetNamespace) { |
ohair@286 | 193 | config.getMappingInfo().setTargetNamespace(targetNamespace); |
ohair@286 | 194 | return this; |
ohair@286 | 195 | } |
ohair@286 | 196 | public Builder serviceName(QName serviceName) { |
ohair@286 | 197 | config.getMappingInfo().setServiceName(serviceName); |
ohair@286 | 198 | return this; |
ohair@286 | 199 | } |
ohair@286 | 200 | public Builder portName(QName portName) { |
ohair@286 | 201 | config.getMappingInfo().setPortName(portName); |
ohair@286 | 202 | return this; |
ohair@286 | 203 | } |
ohair@286 | 204 | public Builder wsdlURL(URL wsdlURL) { |
ohair@286 | 205 | config.setWsdlURL(wsdlURL); |
ohair@286 | 206 | return this; |
ohair@286 | 207 | } |
ohair@286 | 208 | public Builder wsdlSource(Source wsdlSource) { |
ohair@286 | 209 | config.setWsdlSource(wsdlSource); |
ohair@286 | 210 | return this; |
ohair@286 | 211 | } |
ohair@286 | 212 | public Builder entityResolver(EntityResolver entityResolver) { |
ohair@286 | 213 | config.setEntityResolver(entityResolver); |
ohair@286 | 214 | return this; |
ohair@286 | 215 | } |
ohair@286 | 216 | public Builder classLoader(ClassLoader classLoader) { |
ohair@286 | 217 | config.setClassLoader(classLoader); |
ohair@286 | 218 | return this; |
ohair@286 | 219 | } |
ohair@286 | 220 | public Builder feature(WebServiceFeature... f) { |
ohair@286 | 221 | config.setFeatures(f); |
ohair@286 | 222 | return this; |
ohair@286 | 223 | } |
ohair@286 | 224 | public Builder property(String name, Object value) { |
ohair@286 | 225 | config.properties().put(name, value); |
ohair@286 | 226 | if (isfor(BindingID.class, name, value)) { |
ohair@286 | 227 | config.getMappingInfo().setBindingID((BindingID)value); |
ohair@286 | 228 | } |
ohair@286 | 229 | if (isfor(WSBinding.class, name, value)) { |
ohair@286 | 230 | config.setWSBinding((WSBinding)value); |
ohair@286 | 231 | } |
ohair@286 | 232 | if (isfor(WSDLPort.class, name, value)) { |
ohair@286 | 233 | config.setWsdlPort((WSDLPort)value); |
ohair@286 | 234 | } |
alanb@368 | 235 | if (isfor(MetadataReader.class, name, value)) { |
alanb@368 | 236 | config.setMetadataReader((MetadataReader)value); |
alanb@368 | 237 | } |
ohair@286 | 238 | return this; |
ohair@286 | 239 | } |
ohair@286 | 240 | boolean isfor(Class<?> type, String name, Object value) { |
ohair@286 | 241 | return type.getName().equals(name) && type.isInstance(value); |
ohair@286 | 242 | } |
ohair@286 | 243 | |
alanb@368 | 244 | public com.oracle.webservices.internal.api.databinding.Databinding build() { |
ohair@286 | 245 | return factory.createRuntime(config); |
ohair@286 | 246 | } |
alanb@368 | 247 | public com.oracle.webservices.internal.api.databinding.WSDLGenerator createWSDLGenerator() { |
ohair@286 | 248 | return factory.createWsdlGen(config); |
ohair@286 | 249 | } |
ohair@286 | 250 | } |
ohair@286 | 251 | } |