src/share/jaxws_classes/com/sun/xml/internal/ws/binding/WebServiceFeatureList.java

Fri, 04 Oct 2013 16:21:34 +0100

author
mkos
date
Fri, 04 Oct 2013 16:21:34 +0100
changeset 408
b0610cd08440
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar

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

mercurial