src/share/jaxws_classes/com/sun/xml/internal/ws/binding/WebServiceFeatureList.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 408
b0610cd08440
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, 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.binding;
ohair@286 27
ohair@286 28 import com.sun.istack.internal.NotNull;
ohair@286 29 import com.sun.istack.internal.Nullable;
ohair@286 30 import com.sun.xml.internal.ws.api.BindingID;
alanb@368 31 import com.sun.xml.internal.ws.api.FeatureListValidator;
alanb@368 32 import com.sun.xml.internal.ws.api.FeatureListValidatorAnnotation;
ohair@286 33 import com.sun.xml.internal.ws.api.ImpliesWebServiceFeature;
ohair@286 34 import com.sun.xml.internal.ws.api.SOAPVersion;
ohair@286 35 import com.sun.xml.internal.ws.api.WSBinding;
ohair@286 36 import com.sun.xml.internal.ws.api.WSFeatureList;
ohair@286 37 import com.sun.xml.internal.ws.api.FeatureConstructor;
ohair@286 38 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
ohair@286 39 import com.sun.xml.internal.ws.api.model.wsdl.WSDLFeaturedObject;
ohair@286 40 import com.sun.xml.internal.ws.model.RuntimeModelerException;
ohair@286 41 import com.sun.xml.internal.ws.model.wsdl.WSDLPortImpl;
ohair@286 42 import com.sun.xml.internal.ws.resources.ModelerMessages;
ohair@286 43 import com.sun.xml.internal.bind.util.Which;
ohair@286 44
ohair@286 45 import javax.xml.ws.RespectBinding;
ohair@286 46 import javax.xml.ws.RespectBindingFeature;
ohair@286 47 import javax.xml.ws.WebServiceException;
ohair@286 48 import javax.xml.ws.WebServiceFeature;
ohair@286 49 import javax.xml.ws.soap.Addressing;
ohair@286 50 import javax.xml.ws.soap.AddressingFeature;
ohair@286 51 import javax.xml.ws.soap.MTOM;
ohair@286 52 import javax.xml.ws.soap.MTOMFeature;
ohair@286 53 import javax.xml.ws.spi.WebServiceFeatureAnnotation;
ohair@286 54
alanb@368 55 import com.oracle.webservices.internal.api.EnvelopeStyleFeature;
ohair@286 56
ohair@286 57 import java.lang.annotation.Annotation;
ohair@286 58 import java.lang.reflect.InvocationTargetException;
ohair@286 59 import java.lang.reflect.Method;
ohair@286 60 import java.lang.reflect.Constructor;
ohair@286 61 import java.util.*;
ohair@286 62 import java.util.logging.Logger;
ohair@286 63
ohair@286 64 /**
ohair@286 65 * Represents a list of {@link WebServiceFeature}s that has bunch of utility
ohair@286 66 * methods pertaining to web service features.
ohair@286 67 *
ohair@286 68 * @author Rama Pulavarthi
ohair@286 69 */
ohair@286 70 public final class WebServiceFeatureList extends AbstractMap<Class<? extends WebServiceFeature>, WebServiceFeature> implements WSFeatureList {
ohair@286 71 public static WebServiceFeatureList toList(Iterable<WebServiceFeature> features) {
ohair@286 72 if (features instanceof WebServiceFeatureList)
ohair@286 73 return (WebServiceFeatureList) features;
ohair@286 74 WebServiceFeatureList w = new WebServiceFeatureList();
ohair@286 75 if (features != null)
ohair@286 76 w.addAll(features);
ohair@286 77 return w;
ohair@286 78 }
ohair@286 79
ohair@286 80 private Map<Class<? extends WebServiceFeature>, WebServiceFeature> wsfeatures = new HashMap<Class<? extends WebServiceFeature>, WebServiceFeature>();
alanb@368 81 private boolean isValidating = false;
ohair@286 82
ohair@286 83 public WebServiceFeatureList() {
ohair@286 84 }
ohair@286 85
ohair@286 86 /**
ohair@286 87 * Delegate to this parent if non-null.
ohair@286 88 */
ohair@286 89 private @Nullable
ohair@286 90 WSDLFeaturedObject parent;
ohair@286 91
ohair@286 92 public WebServiceFeatureList(@NotNull WebServiceFeature... features) {
ohair@286 93 if (features != null) {
ohair@286 94 for (WebServiceFeature f : features) {
alanb@368 95 addNoValidate(f);
alanb@368 96 }
alanb@368 97 }
alanb@368 98 }
alanb@368 99
alanb@368 100 public void validate() {
alanb@368 101 if (!isValidating) {
alanb@368 102 isValidating = true;
alanb@368 103
alanb@368 104 // validation
alanb@368 105 for (WebServiceFeature ff : this) {
alanb@368 106 validate(ff);
alanb@368 107 }
alanb@368 108 }
alanb@368 109 }
alanb@368 110
alanb@368 111 private void validate(WebServiceFeature feature) {
alanb@368 112 // run validation
alanb@368 113 FeatureListValidatorAnnotation fva = feature.getClass().getAnnotation(FeatureListValidatorAnnotation.class);
alanb@368 114 if (fva != null) {
alanb@368 115 Class<? extends FeatureListValidator> beanClass = fva.bean();
alanb@368 116 try {
alanb@368 117 FeatureListValidator validator = beanClass.newInstance();
alanb@368 118 validator.validate(this);
alanb@368 119 } catch (InstantiationException e) {
alanb@368 120 throw new WebServiceException(e);
alanb@368 121 } catch (IllegalAccessException e) {
alanb@368 122 throw new WebServiceException(e);
ohair@286 123 }
ohair@286 124 }
ohair@286 125 }
ohair@286 126
ohair@286 127 public WebServiceFeatureList(WebServiceFeatureList features) {
ohair@286 128 if (features != null) {
ohair@286 129 wsfeatures.putAll(features.wsfeatures);
ohair@286 130 parent = features.parent;
alanb@368 131 isValidating = features.isValidating;
ohair@286 132 }
ohair@286 133 }
ohair@286 134
ohair@286 135 /**
ohair@286 136 * Creates a list by reading featuers from the annotation on a class.
ohair@286 137 */
ohair@286 138 public WebServiceFeatureList(@NotNull Class<?> endpointClass) {
ohair@286 139 parseAnnotations(endpointClass);
ohair@286 140 }
ohair@286 141
ohair@286 142 /**
ohair@286 143 * Adds the corresponding features to the list for feature annotations(i.e
ohair@286 144 * which have {@link WebServiceFeatureAnnotation} meta annotation)
ohair@286 145 *
ohair@286 146 * @param annIt collection of annotations(that can have non-feature annotations)
ohair@286 147 */
ohair@286 148 public void parseAnnotations(Iterable<Annotation> annIt) {
ohair@286 149 for(Annotation ann : annIt) {
ohair@286 150 WebServiceFeature feature = getFeature(ann);
ohair@286 151 if (feature != null) {
ohair@286 152 add(feature);
ohair@286 153 }
ohair@286 154 }
ohair@286 155 }
ohair@286 156
ohair@286 157 /**
ohair@286 158 * Returns a corresponding feature for a feature annotation(i.e which has
ohair@286 159 * {@link WebServiceFeatureAnnotation} meta annotation)
ohair@286 160 *
ohair@286 161 * @return corresponding feature for the annotation
ohair@286 162 * null, if the annotation is nota feature annotation
ohair@286 163 */
ohair@286 164 public static WebServiceFeature getFeature(Annotation a) {
ohair@286 165 WebServiceFeature ftr = null;
ohair@286 166 if (!(a.annotationType().isAnnotationPresent(WebServiceFeatureAnnotation.class))) {
ohair@286 167 ftr = null;
ohair@286 168 } else if (a instanceof Addressing) {
ohair@286 169 Addressing addAnn = (Addressing) a;
ohair@286 170 try {
ohair@286 171 ftr = new AddressingFeature(addAnn.enabled(), addAnn.required(),addAnn.responses());
ohair@286 172 } catch(NoSuchMethodError e) {
ohair@286 173 //throw error. We can't default to Responses.ALL as we dont know if the user has not used 2.2 annotation with responses.
ohair@286 174 throw new RuntimeModelerException(ModelerMessages.RUNTIME_MODELER_ADDRESSING_RESPONSES_NOSUCHMETHOD(toJar(Which.which(Addressing.class))));
ohair@286 175 }
ohair@286 176 } else if (a instanceof MTOM) {
ohair@286 177 MTOM mtomAnn = (MTOM) a;
ohair@286 178 ftr = new MTOMFeature(mtomAnn.enabled(), mtomAnn.threshold());
ohair@286 179 } else if (a instanceof RespectBinding) {
ohair@286 180 RespectBinding rbAnn = (RespectBinding) a;
ohair@286 181 ftr = new RespectBindingFeature(rbAnn.enabled());
ohair@286 182 } else {
ohair@286 183 ftr = getWebServiceFeatureBean(a);
ohair@286 184 }
ohair@286 185 return ftr;
ohair@286 186 }
ohair@286 187
ohair@286 188 /**
ohair@286 189 *
ohair@286 190 * @param endpointClass web service impl class
ohair@286 191 */
ohair@286 192 public void parseAnnotations(Class<?> endpointClass) {
ohair@286 193 for (Annotation a : endpointClass.getAnnotations()) {
ohair@286 194 WebServiceFeature ftr = getFeature(a);
ohair@286 195 if (ftr != null) {
ohair@286 196 if (ftr instanceof MTOMFeature) {
ohair@286 197 // check conflict with @BindingType
ohair@286 198 BindingID bindingID = BindingID.parse(endpointClass);
ohair@286 199 MTOMFeature bindingMtomSetting = bindingID.createBuiltinFeatureList().get(MTOMFeature.class);
ohair@286 200 if (bindingMtomSetting != null && bindingMtomSetting.isEnabled() ^ ftr.isEnabled()) {
ohair@286 201 throw new RuntimeModelerException(
ohair@286 202 ModelerMessages.RUNTIME_MODELER_MTOM_CONFLICT(bindingID, ftr.isEnabled()));
ohair@286 203 }
ohair@286 204 }
ohair@286 205 add(ftr);
ohair@286 206 }
ohair@286 207 }
ohair@286 208 }
ohair@286 209
ohair@286 210 /**
ohair@286 211 * Given the URL String inside jar, returns the URL to the jar itself.
ohair@286 212 */
ohair@286 213 private static String toJar(String url) {
ohair@286 214 if(!url.startsWith("jar:"))
ohair@286 215 return url;
ohair@286 216 url = url.substring(4); // cut off jar:
ohair@286 217 return url.substring(0,url.lastIndexOf('!')); // cut off everything after '!'
ohair@286 218 }
ohair@286 219
ohair@286 220 private static WebServiceFeature getWebServiceFeatureBean(Annotation a) {
ohair@286 221 WebServiceFeatureAnnotation wsfa = a.annotationType().getAnnotation(WebServiceFeatureAnnotation.class);
ohair@286 222 Class<? extends WebServiceFeature> beanClass = wsfa.bean();
ohair@286 223 WebServiceFeature bean;
ohair@286 224
ohair@286 225 Constructor ftrCtr = null;
ohair@286 226 String[] paramNames = null;
ohair@286 227 for (Constructor con : beanClass.getConstructors()) {
ohair@286 228 FeatureConstructor ftrCtrAnn = (FeatureConstructor) con.getAnnotation(FeatureConstructor.class);
ohair@286 229 if (ftrCtrAnn != null) {
ohair@286 230 if (ftrCtr == null) {
ohair@286 231 ftrCtr = con;
ohair@286 232 paramNames = ftrCtrAnn.value();
ohair@286 233 } else {
ohair@286 234 throw new WebServiceException(
ohair@286 235 ModelerMessages.RUNTIME_MODELER_WSFEATURE_MORETHANONE_FTRCONSTRUCTOR(a, beanClass));
ohair@286 236 }
ohair@286 237 }
ohair@286 238 }
ohair@286 239 if (ftrCtr == null) {
ohair@286 240 bean = getWebServiceFeatureBeanViaBuilder(a, beanClass);
ohair@286 241 if (bean != null) {
ohair@286 242 return bean;
ohair@286 243 } else {
ohair@286 244 throw new WebServiceException(
ohair@286 245 ModelerMessages.RUNTIME_MODELER_WSFEATURE_NO_FTRCONSTRUCTOR(a, beanClass));
ohair@286 246 }
ohair@286 247 }
ohair@286 248 if (ftrCtr.getParameterTypes().length != paramNames.length) {
ohair@286 249 throw new WebServiceException(
ohair@286 250 ModelerMessages.RUNTIME_MODELER_WSFEATURE_ILLEGAL_FTRCONSTRUCTOR(a, beanClass));
ohair@286 251 }
ohair@286 252
ohair@286 253 try {
ohair@286 254 Object[] params = new Object[paramNames.length];
ohair@286 255 for (int i = 0; i < paramNames.length; i++) {
ohair@286 256 Method m = a.annotationType().getDeclaredMethod(paramNames[i]);
ohair@286 257 params[i] = m.invoke(a);
ohair@286 258 }
ohair@286 259 bean = (WebServiceFeature) ftrCtr.newInstance(params);
ohair@286 260 } catch (Exception e) {
ohair@286 261 throw new WebServiceException(e);
ohair@286 262 }
ohair@286 263 return bean;
ohair@286 264 }
ohair@286 265
ohair@286 266 private static WebServiceFeature getWebServiceFeatureBeanViaBuilder(
ohair@286 267 final Annotation annotation,
ohair@286 268 final Class<? extends WebServiceFeature> beanClass)
ohair@286 269 {
ohair@286 270 try {
ohair@286 271 final Method featureBuilderMethod = beanClass.getDeclaredMethod("builder");
ohair@286 272 final Object builder = featureBuilderMethod.invoke(beanClass);
ohair@286 273 final Method buildMethod = builder.getClass().getDeclaredMethod("build");
ohair@286 274
ohair@286 275 for (Method builderMethod : builder.getClass().getDeclaredMethods()) {
ohair@286 276 if (!builderMethod.equals(buildMethod)) {
ohair@286 277 final String methodName = builderMethod.getName();
ohair@286 278 final Method annotationMethod = annotation.annotationType().getDeclaredMethod(methodName);
ohair@286 279 final Object annotationFieldValue = annotationMethod.invoke(annotation);
ohair@286 280 final Object[] arg = { annotationFieldValue };
alanb@368 281 if (skipDuringOrgJvnetWsToComOracleWebservicesPackageMove(builderMethod, annotationFieldValue)) {
alanb@368 282 continue;
alanb@368 283 }
ohair@286 284 builderMethod.invoke(builder, arg);
ohair@286 285 }
ohair@286 286 }
ohair@286 287
ohair@286 288 final Object result = buildMethod.invoke(builder);
ohair@286 289 if (result instanceof WebServiceFeature) {
ohair@286 290 return (WebServiceFeature) result;
ohair@286 291 } else {
ohair@286 292 throw new WebServiceException("Not a WebServiceFeature: " + result);
ohair@286 293 }
ohair@286 294 } catch (final NoSuchMethodException e) {
ohair@286 295 return null;
ohair@286 296 } catch (final IllegalAccessException e) {
ohair@286 297 throw new WebServiceException(e);
ohair@286 298 } catch (final InvocationTargetException e) {
ohair@286 299 throw new WebServiceException(e);
ohair@286 300 }
ohair@286 301 }
ohair@286 302
alanb@368 303 // TODO this will be removed after package move is complete.
alanb@368 304 private static boolean skipDuringOrgJvnetWsToComOracleWebservicesPackageMove(
alanb@368 305 final Method builderMethod,
alanb@368 306 final Object annotationFieldValue)
alanb@368 307 {
alanb@368 308 final Class<?> annotationFieldValueClass = annotationFieldValue.getClass();
alanb@368 309 if (! annotationFieldValueClass.isEnum()) {
alanb@368 310 return false;
alanb@368 311 }
alanb@368 312 final Class<?>[] builderMethodParameterTypes = builderMethod.getParameterTypes();
alanb@368 313 if (builderMethodParameterTypes.length != 1) {
alanb@368 314 throw new WebServiceException("expected only 1 parameter");
alanb@368 315 }
alanb@368 316 final String builderParameterTypeName = builderMethodParameterTypes[0].getName();
alanb@368 317 if (! builderParameterTypeName.startsWith("com.oracle.webservices.internal.test.features_annotations_enums.apinew") &&
alanb@368 318 ! builderParameterTypeName.startsWith("com.oracle.webservices.internal.api")) {
alanb@368 319 return false;
alanb@368 320 }
alanb@368 321 return false;
alanb@368 322 }
alanb@368 323
ohair@286 324 public Iterator<WebServiceFeature> iterator() {
ohair@286 325 if (parent != null)
ohair@286 326 return new MergedFeatures(parent.getFeatures());
ohair@286 327 return wsfeatures.values().iterator();
ohair@286 328 }
ohair@286 329
ohair@286 330 public @NotNull
ohair@286 331 WebServiceFeature[] toArray() {
ohair@286 332 if (parent != null)
ohair@286 333 return new MergedFeatures(parent.getFeatures()).toArray();
ohair@286 334 return wsfeatures.values().toArray(new WebServiceFeature[] {});
ohair@286 335 }
ohair@286 336
ohair@286 337 public boolean isEnabled(@NotNull Class<? extends WebServiceFeature> feature) {
ohair@286 338 WebServiceFeature ftr = get(feature);
ohair@286 339 return ftr != null && ftr.isEnabled();
ohair@286 340 }
ohair@286 341
ohair@286 342 public boolean contains(@NotNull Class<? extends WebServiceFeature> feature) {
ohair@286 343 WebServiceFeature ftr = get(feature);
ohair@286 344 return ftr != null;
ohair@286 345 }
ohair@286 346
ohair@286 347 public @Nullable
ohair@286 348 <F extends WebServiceFeature> F get(@NotNull Class<F> featureType) {
ohair@286 349 WebServiceFeature f = featureType.cast(wsfeatures.get(featureType));
ohair@286 350 if (f == null && parent != null) {
ohair@286 351 return parent.getFeatures().get(featureType);
ohair@286 352 }
ohair@286 353 return (F) f;
ohair@286 354 }
ohair@286 355
ohair@286 356 /**
ohair@286 357 * Adds a feature to the list if it's not already added.
ohair@286 358 */
ohair@286 359 public void add(@NotNull WebServiceFeature f) {
alanb@368 360 if(addNoValidate(f) && isValidating)
alanb@368 361 validate(f);
alanb@368 362 }
alanb@368 363
alanb@368 364 private boolean addNoValidate(@NotNull WebServiceFeature f) {
ohair@286 365 if (!wsfeatures.containsKey(f.getClass())) {
ohair@286 366 wsfeatures.put(f.getClass(), f);
ohair@286 367
ohair@286 368 if (f instanceof ImpliesWebServiceFeature)
ohair@286 369 ((ImpliesWebServiceFeature) f).implyFeatures(this);
alanb@368 370
alanb@368 371 return true;
ohair@286 372 }
alanb@368 373
alanb@368 374 return false;
ohair@286 375 }
ohair@286 376
ohair@286 377 /**
ohair@286 378 * Adds features to the list if it's not already added.
ohair@286 379 */
ohair@286 380 public void addAll(@NotNull Iterable<WebServiceFeature> list) {
ohair@286 381 for (WebServiceFeature f : list)
ohair@286 382 add(f);
ohair@286 383 }
ohair@286 384
ohair@286 385 /**
ohair@286 386 * Sets MTOM feature, overriding any existing feature. This is necessary for compatibility
ohair@286 387 * with the existing {@link SOAPBinding.setMTOMEnabled}.
ohair@286 388 * @param b if MTOM will be enabled
ohair@286 389 */
ohair@286 390 void setMTOMEnabled(boolean b) {
ohair@286 391 wsfeatures.put(MTOMFeature.class, new MTOMFeature(b));
ohair@286 392 }
ohair@286 393
ohair@286 394 public boolean equals(Object other) {
ohair@286 395 if (!(other instanceof WebServiceFeatureList))
ohair@286 396 return false;
ohair@286 397
ohair@286 398 WebServiceFeatureList w = (WebServiceFeatureList) other;
ohair@286 399 return wsfeatures.equals(w.wsfeatures) && (parent == w.parent);
ohair@286 400 }
ohair@286 401
ohair@286 402 public String toString() {
ohair@286 403 return wsfeatures.toString();
ohair@286 404 }
ohair@286 405
ohair@286 406 /**
ohair@286 407 * Merges the extra features that are not already set on binding.
ohair@286 408 * i.e, if a feature is set already on binding through some other API
ohair@286 409 * the corresponding wsdlFeature is not set.
ohair@286 410 *
ohair@286 411 * @param features Web Service features that need to be merged with already configured features.
ohair@286 412 * @param reportConflicts If true, checks if the feature setting in WSDL (wsdl extension or
ohair@286 413 * policy configuration) conflicts with feature setting in Deployed Service and
ohair@286 414 * logs warning if there are any conflicts.
ohair@286 415 */
ohair@286 416 public void mergeFeatures(@NotNull Iterable<WebServiceFeature> features, boolean reportConflicts) {
ohair@286 417 for (WebServiceFeature wsdlFtr : features) {
ohair@286 418 if (get(wsdlFtr.getClass()) == null) {
ohair@286 419 add(wsdlFtr);
ohair@286 420 } else if (reportConflicts) {
ohair@286 421 if (isEnabled(wsdlFtr.getClass()) != wsdlFtr.isEnabled()) {
ohair@286 422 LOGGER.warning(ModelerMessages.RUNTIME_MODELER_FEATURE_CONFLICT(
ohair@286 423 get(wsdlFtr.getClass()), wsdlFtr));
ohair@286 424 }
ohair@286 425 }
ohair@286 426 }
ohair@286 427 }
ohair@286 428
ohair@286 429 public void mergeFeatures(WebServiceFeature[] features, boolean reportConflicts) {
ohair@286 430 for (WebServiceFeature wsdlFtr : features) {
ohair@286 431 if (get(wsdlFtr.getClass()) == null) {
ohair@286 432 add(wsdlFtr);
ohair@286 433 } else if (reportConflicts) {
ohair@286 434 if (isEnabled(wsdlFtr.getClass()) != wsdlFtr.isEnabled()) {
ohair@286 435 LOGGER.warning(ModelerMessages.RUNTIME_MODELER_FEATURE_CONFLICT(
ohair@286 436 get(wsdlFtr.getClass()), wsdlFtr));
ohair@286 437 }
ohair@286 438 }
ohair@286 439 }
ohair@286 440 }
ohair@286 441
ohair@286 442 /**
ohair@286 443 * Extracts features from {@link WSDLPortImpl#getFeatures()}. Extra features
ohair@286 444 * that are not already set on binding. i.e, if a feature is set already on
ohair@286 445 * binding through someother API the coresponding wsdlFeature is not set.
ohair@286 446 *
ohair@286 447 * @param wsdlPort
ohair@286 448 * WSDLPort model
ohair@286 449 * @param honorWsdlRequired
ohair@286 450 * If this is true add WSDL Feature only if wsd:Required=true In
ohair@286 451 * SEI case, it should be false In Provider case, it should be
ohair@286 452 * true
ohair@286 453 * @param reportConflicts
ohair@286 454 * If true, checks if the feature setting in WSDL (wsdl extension
ohair@286 455 * or policy configuration) colflicts with feature setting in
ohair@286 456 * Deployed Service and logs warning if there are any conflicts.
ohair@286 457 */
ohair@286 458 public void mergeFeatures(@NotNull WSDLPort wsdlPort,
ohair@286 459 boolean honorWsdlRequired, boolean reportConflicts) {
ohair@286 460 if (honorWsdlRequired && !isEnabled(RespectBindingFeature.class))
ohair@286 461 return;
ohair@286 462 if (!honorWsdlRequired) {
ohair@286 463 addAll(wsdlPort.getFeatures());
ohair@286 464 return;
ohair@286 465 }
ohair@286 466 // Add only if isRequired returns true, when honorWsdlRequired is true
ohair@286 467 for (WebServiceFeature wsdlFtr : wsdlPort.getFeatures()) {
ohair@286 468 if (get(wsdlFtr.getClass()) == null) {
ohair@286 469 try {
ohair@286 470 // if it is a WSDL Extension , it will have required
ohair@286 471 // attribute
ohair@286 472 Method m = (wsdlFtr.getClass().getMethod("isRequired"));
ohair@286 473 try {
ohair@286 474 boolean required = (Boolean) m.invoke(wsdlFtr);
ohair@286 475 if (required)
ohair@286 476 add(wsdlFtr);
ohair@286 477 } catch (IllegalAccessException e) {
ohair@286 478 throw new WebServiceException(e);
ohair@286 479 } catch (InvocationTargetException e) {
ohair@286 480 throw new WebServiceException(e);
ohair@286 481 }
ohair@286 482 } catch (NoSuchMethodException e) {
ohair@286 483 // this wsdlFtr is not an WSDL extension, just add it
ohair@286 484 add(wsdlFtr);
ohair@286 485 }
ohair@286 486 } else if (reportConflicts) {
ohair@286 487 if (isEnabled(wsdlFtr.getClass()) != wsdlFtr.isEnabled()) {
ohair@286 488 LOGGER.warning(ModelerMessages.RUNTIME_MODELER_FEATURE_CONFLICT(
ohair@286 489 get(wsdlFtr.getClass()), wsdlFtr));
ohair@286 490 }
ohair@286 491
ohair@286 492 }
ohair@286 493 }
ohair@286 494 }
ohair@286 495
ohair@286 496 /**
ohair@286 497 * Set the parent features. Basically the parent feature list will be
ohair@286 498 * overriden by this feature list.
ohair@286 499 */
ohair@286 500 public void setParentFeaturedObject(@NotNull WSDLFeaturedObject parent) {
ohair@286 501 this.parent = parent;
ohair@286 502 }
ohair@286 503
ohair@286 504 public static @Nullable <F extends WebServiceFeature> F getFeature(@NotNull WebServiceFeature[] features,
ohair@286 505 @NotNull Class<F> featureType) {
ohair@286 506 for (WebServiceFeature f : features) {
ohair@286 507 if (f.getClass() == featureType)
ohair@286 508 return (F) f;
ohair@286 509 }
ohair@286 510 return null;
ohair@286 511 }
ohair@286 512
ohair@286 513 /**
ohair@286 514 * A Union of this WebServiceFeatureList and the parent.
ohair@286 515 */
ohair@286 516 private final class MergedFeatures implements Iterator<WebServiceFeature> {
ohair@286 517 private final Stack<WebServiceFeature> features = new Stack<WebServiceFeature>();
ohair@286 518
ohair@286 519 public MergedFeatures(@NotNull WSFeatureList parent) {
ohair@286 520
ohair@286 521 for (WebServiceFeature f : wsfeatures.values()) {
ohair@286 522 features.push(f);
ohair@286 523 }
ohair@286 524
ohair@286 525 for (WebServiceFeature f : parent) {
ohair@286 526 if (!wsfeatures.containsKey(f.getClass())) {
ohair@286 527 features.push(f);
ohair@286 528 }
ohair@286 529 }
ohair@286 530 }
ohair@286 531
ohair@286 532 public boolean hasNext() {
ohair@286 533 return !features.empty();
ohair@286 534 }
ohair@286 535
ohair@286 536 public WebServiceFeature next() {
ohair@286 537 if (!features.empty()) {
ohair@286 538 return features.pop();
ohair@286 539 }
ohair@286 540 throw new NoSuchElementException();
ohair@286 541 }
ohair@286 542
ohair@286 543 public void remove() {
ohair@286 544 if (!features.empty()) {
ohair@286 545 features.pop();
ohair@286 546 }
ohair@286 547 }
ohair@286 548
ohair@286 549 public WebServiceFeature[] toArray() {
ohair@286 550 return features.toArray(new WebServiceFeature[] {});
ohair@286 551 }
ohair@286 552 }
ohair@286 553
ohair@286 554 private static final Logger LOGGER = Logger.getLogger(WebServiceFeatureList.class.getName());
ohair@286 555
ohair@286 556 @Override
ohair@286 557 public Set<java.util.Map.Entry<Class<? extends WebServiceFeature>, WebServiceFeature>> entrySet() {
ohair@286 558 return wsfeatures.entrySet();
ohair@286 559 }
ohair@286 560
ohair@286 561 @Override
ohair@286 562 public WebServiceFeature put(Class<? extends WebServiceFeature> key, WebServiceFeature value) {
ohair@286 563 return wsfeatures.put(key, value);
ohair@286 564 }
ohair@286 565
ohair@286 566 static public SOAPVersion getSoapVersion(WSFeatureList features) {
alanb@368 567 {
alanb@368 568 EnvelopeStyleFeature env = features.get(EnvelopeStyleFeature.class);
alanb@368 569 if (env != null) {
alanb@368 570 return SOAPVersion.from(env);
alanb@368 571 }
alanb@368 572 }
alanb@368 573 com.oracle.webservices.internal.api.EnvelopeStyleFeature env = features.get(com.oracle.webservices.internal.api.EnvelopeStyleFeature.class);
ohair@286 574 return env != null ? SOAPVersion.from(env) : null;
ohair@286 575 }
ohair@286 576
ohair@286 577 static public boolean isFeatureEnabled(Class<? extends WebServiceFeature> type, WebServiceFeature[] features) {
ohair@286 578 WebServiceFeature ftr = getFeature(features, type);
ohair@286 579 return ftr != null && ftr.isEnabled();
ohair@286 580 }
ohair@286 581
ohair@286 582 static public WebServiceFeature[] toFeatureArray(WSBinding binding) {
ohair@286 583 //TODO scchen convert BindingID to WebServiceFeature[]
ohair@286 584 if(!binding.isFeatureEnabled(EnvelopeStyleFeature.class)) {
ohair@286 585 WebServiceFeature[] f = { binding.getSOAPVersion().toFeature() };
ohair@286 586 binding.getFeatures().mergeFeatures(f, false);
ohair@286 587 }
ohair@286 588 return binding.getFeatures().toArray();
ohair@286 589 }
ohair@286 590 }

mercurial