src/share/jaxws_classes/com/sun/xml/internal/ws/policy/PolicyMap.java

Thu, 12 Oct 2017 19:44:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 19:44:07 +0800
changeset 760
e530533619ec
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2010, 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.policy;
aoqi@0 27
aoqi@0 28 import com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages;
aoqi@0 29 import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
aoqi@0 30 import java.util.ArrayList;
aoqi@0 31 import java.util.Collection;
aoqi@0 32 import java.util.HashMap;
aoqi@0 33 import java.util.Iterator;
aoqi@0 34 import java.util.LinkedList;
aoqi@0 35 import java.util.List;
aoqi@0 36 import java.util.Map;
aoqi@0 37 import java.util.NoSuchElementException;
aoqi@0 38 import java.util.Set;
aoqi@0 39 import javax.xml.namespace.QName;
aoqi@0 40
aoqi@0 41 /**
aoqi@0 42 * A PolicyMap holds all policies for a scope.
aoqi@0 43 *
aoqi@0 44 * This map is modeled around WSDL 1.1 policy scopes according to WS-PolicyAttachment. The map holds an information about
aoqi@0 45 * every scope for service, endpoint, operation, and input/output/fault message. It also provide accessibility methods for
aoqi@0 46 * computing and obtaining effective policy on each scope.
aoqi@0 47 *
aoqi@0 48 * TODO: rename createWsdlMessageScopeKey to createWsdlInputOutputMessageScopeKey
aoqi@0 49 *
aoqi@0 50 * @author Fabian Ritzmann
aoqi@0 51 */
aoqi@0 52 public final class PolicyMap implements Iterable<Policy> {
aoqi@0 53 private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyMap.class);
aoqi@0 54
aoqi@0 55 private static final PolicyMapKeyHandler serviceKeyHandler = new PolicyMapKeyHandler() {
aoqi@0 56 public boolean areEqual(final PolicyMapKey key1, final PolicyMapKey key2) {
aoqi@0 57 return key1.getService().equals(key2.getService());
aoqi@0 58 }
aoqi@0 59
aoqi@0 60 public int generateHashCode(final PolicyMapKey key) {
aoqi@0 61 int result = 17;
aoqi@0 62
aoqi@0 63 result = 37 * result + key.getService().hashCode();
aoqi@0 64
aoqi@0 65 return result;
aoqi@0 66 }
aoqi@0 67 };
aoqi@0 68
aoqi@0 69 private static final PolicyMapKeyHandler endpointKeyHandler = new PolicyMapKeyHandler() {
aoqi@0 70 public boolean areEqual(final PolicyMapKey key1, final PolicyMapKey key2) {
aoqi@0 71 boolean retVal = true;
aoqi@0 72
aoqi@0 73 retVal = retVal && key1.getService().equals(key2.getService());
aoqi@0 74 retVal = retVal && ((key1.getPort() == null) ? key2.getPort() == null : key1.getPort().equals(key2.getPort()));
aoqi@0 75
aoqi@0 76 return retVal;
aoqi@0 77 }
aoqi@0 78
aoqi@0 79 public int generateHashCode(final PolicyMapKey key) {
aoqi@0 80 int result = 17;
aoqi@0 81
aoqi@0 82 result = 37 * result + key.getService().hashCode();
aoqi@0 83 result = 37 * result + ((key.getPort() == null) ? 0 : key.getPort().hashCode());
aoqi@0 84
aoqi@0 85 return result;
aoqi@0 86 }
aoqi@0 87 };
aoqi@0 88
aoqi@0 89 private static final PolicyMapKeyHandler operationAndInputOutputMessageKeyHandler = new PolicyMapKeyHandler() {
aoqi@0 90 // we use the same algorithm to handle operation and input/output message keys
aoqi@0 91
aoqi@0 92 public boolean areEqual(final PolicyMapKey key1, final PolicyMapKey key2) {
aoqi@0 93 boolean retVal = true;
aoqi@0 94
aoqi@0 95 retVal = retVal && key1.getService().equals(key2.getService());
aoqi@0 96 retVal = retVal && ((key1.getPort() == null) ? key2.getPort() == null : key1.getPort().equals(key2.getPort()));
aoqi@0 97 retVal = retVal && ((key1.getOperation() == null) ? key2.getOperation() == null : key1.getOperation().equals(key2.getOperation()));
aoqi@0 98
aoqi@0 99 return retVal;
aoqi@0 100 }
aoqi@0 101
aoqi@0 102 public int generateHashCode(final PolicyMapKey key) {
aoqi@0 103 int result = 17;
aoqi@0 104
aoqi@0 105 result = 37 * result + key.getService().hashCode();
aoqi@0 106 result = 37 * result + ((key.getPort() == null) ? 0 : key.getPort().hashCode());
aoqi@0 107 result = 37 * result + ((key.getOperation() == null) ? 0 : key.getOperation().hashCode());
aoqi@0 108
aoqi@0 109 return result;
aoqi@0 110 }
aoqi@0 111 };
aoqi@0 112
aoqi@0 113 private static final PolicyMapKeyHandler faultMessageHandler = new PolicyMapKeyHandler() {
aoqi@0 114 public boolean areEqual(final PolicyMapKey key1, final PolicyMapKey key2) {
aoqi@0 115 boolean retVal = true;
aoqi@0 116
aoqi@0 117 retVal = retVal && key1.getService().equals(key2.getService());
aoqi@0 118 retVal = retVal && ((key1.getPort() == null) ? key2.getPort() == null : key1.getPort().equals(key2.getPort()));
aoqi@0 119 retVal = retVal && ((key1.getOperation() == null) ? key2.getOperation() == null : key1.getOperation().equals(key2.getOperation()));
aoqi@0 120 retVal = retVal && ((key1.getFaultMessage() == null) ? key2.getFaultMessage() == null : key1.getFaultMessage().equals(key2.getFaultMessage()));
aoqi@0 121
aoqi@0 122 return retVal;
aoqi@0 123 }
aoqi@0 124
aoqi@0 125 public int generateHashCode(final PolicyMapKey key) {
aoqi@0 126 int result = 17;
aoqi@0 127
aoqi@0 128 result = 37 * result + key.getService().hashCode();
aoqi@0 129 result = 37 * result + ((key.getPort() == null) ? 0 : key.getPort().hashCode());
aoqi@0 130 result = 37 * result + ((key.getOperation() == null) ? 0 : key.getOperation().hashCode());
aoqi@0 131 result = 37 * result + ((key.getFaultMessage() == null) ? 0 : key.getFaultMessage().hashCode());
aoqi@0 132
aoqi@0 133 return result;
aoqi@0 134 }
aoqi@0 135 };
aoqi@0 136
aoqi@0 137
aoqi@0 138 static enum ScopeType {
aoqi@0 139 SERVICE,
aoqi@0 140 ENDPOINT,
aoqi@0 141 OPERATION,
aoqi@0 142 INPUT_MESSAGE,
aoqi@0 143 OUTPUT_MESSAGE,
aoqi@0 144 FAULT_MESSAGE
aoqi@0 145 }
aoqi@0 146
aoqi@0 147 private static final class ScopeMap implements Iterable<Policy> {
aoqi@0 148 private final Map<PolicyMapKey, PolicyScope> internalMap = new HashMap<PolicyMapKey, PolicyScope>();
aoqi@0 149 private final PolicyMapKeyHandler scopeKeyHandler;
aoqi@0 150 private final PolicyMerger merger;
aoqi@0 151
aoqi@0 152 ScopeMap(final PolicyMerger merger, final PolicyMapKeyHandler scopeKeyHandler) {
aoqi@0 153 this.merger = merger;
aoqi@0 154 this.scopeKeyHandler = scopeKeyHandler;
aoqi@0 155 }
aoqi@0 156
aoqi@0 157 Policy getEffectivePolicy(final PolicyMapKey key) throws PolicyException {
aoqi@0 158 final PolicyScope scope = internalMap.get(createLocalCopy(key));
aoqi@0 159 return (scope == null) ? null : scope.getEffectivePolicy(merger);
aoqi@0 160 }
aoqi@0 161
aoqi@0 162 void putSubject(final PolicyMapKey key, final PolicySubject subject) {
aoqi@0 163 final PolicyMapKey localKey = createLocalCopy(key);
aoqi@0 164 final PolicyScope scope = internalMap.get(localKey);
aoqi@0 165 if (scope == null) {
aoqi@0 166 final List<PolicySubject> list = new LinkedList<PolicySubject>();
aoqi@0 167 list.add(subject);
aoqi@0 168 internalMap.put(localKey, new PolicyScope(list));
aoqi@0 169 } else {
aoqi@0 170 scope.attach(subject);
aoqi@0 171 }
aoqi@0 172 }
aoqi@0 173
aoqi@0 174 void setNewEffectivePolicy(final PolicyMapKey key, final Policy newEffectivePolicy) {
aoqi@0 175 // we add this policy map as a subject, because there is nothing reasonable we could add there, since
aoqi@0 176 // this is an artificial policy subject
aoqi@0 177 final PolicySubject subject = new PolicySubject(key, newEffectivePolicy);
aoqi@0 178
aoqi@0 179 final PolicyMapKey localKey = createLocalCopy(key);
aoqi@0 180 final PolicyScope scope = internalMap.get(localKey);
aoqi@0 181 if (scope == null) {
aoqi@0 182 final List<PolicySubject> list = new LinkedList<PolicySubject>();
aoqi@0 183 list.add(subject);
aoqi@0 184 internalMap.put(localKey, new PolicyScope(list));
aoqi@0 185 } else {
aoqi@0 186 scope.dettachAllSubjects();
aoqi@0 187 scope.attach(subject);
aoqi@0 188 }
aoqi@0 189 }
aoqi@0 190
aoqi@0 191 Collection<PolicyScope> getStoredScopes() {
aoqi@0 192 return internalMap.values();
aoqi@0 193 }
aoqi@0 194
aoqi@0 195 Set<PolicyMapKey> getAllKeys() {
aoqi@0 196 return internalMap.keySet();
aoqi@0 197 }
aoqi@0 198
aoqi@0 199 private PolicyMapKey createLocalCopy(final PolicyMapKey key) {
aoqi@0 200 if (key == null) {
aoqi@0 201 throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0045_POLICY_MAP_KEY_MUST_NOT_BE_NULL()));
aoqi@0 202 }
aoqi@0 203
aoqi@0 204 final PolicyMapKey localKeyCopy = new PolicyMapKey(key);
aoqi@0 205 localKeyCopy.setHandler(scopeKeyHandler);
aoqi@0 206
aoqi@0 207 return localKeyCopy;
aoqi@0 208 }
aoqi@0 209
aoqi@0 210 public Iterator<Policy> iterator() {
aoqi@0 211 return new Iterator<Policy> () {
aoqi@0 212 private final Iterator<PolicyMapKey> keysIterator = internalMap.keySet().iterator();
aoqi@0 213
aoqi@0 214 public boolean hasNext() {
aoqi@0 215 return keysIterator.hasNext();
aoqi@0 216 }
aoqi@0 217
aoqi@0 218 public Policy next() {
aoqi@0 219 final PolicyMapKey key = keysIterator.next();
aoqi@0 220 try {
aoqi@0 221 return getEffectivePolicy(key);
aoqi@0 222 } catch (PolicyException e) {
aoqi@0 223 throw LOGGER.logSevereException(new IllegalStateException(LocalizationMessages.WSP_0069_EXCEPTION_WHILE_RETRIEVING_EFFECTIVE_POLICY_FOR_KEY(key), e));
aoqi@0 224 }
aoqi@0 225 }
aoqi@0 226
aoqi@0 227 public void remove() {
aoqi@0 228 throw LOGGER.logSevereException(new UnsupportedOperationException(LocalizationMessages.WSP_0034_REMOVE_OPERATION_NOT_SUPPORTED()));
aoqi@0 229 }
aoqi@0 230 };
aoqi@0 231 }
aoqi@0 232
aoqi@0 233 public boolean isEmpty() {
aoqi@0 234 return internalMap.isEmpty();
aoqi@0 235 }
aoqi@0 236
aoqi@0 237 @Override
aoqi@0 238 public String toString() {
aoqi@0 239 return internalMap.toString();
aoqi@0 240 }
aoqi@0 241 }
aoqi@0 242
aoqi@0 243 private static final PolicyMerger merger = PolicyMerger.getMerger();
aoqi@0 244
aoqi@0 245 private final ScopeMap serviceMap = new ScopeMap(merger, serviceKeyHandler);
aoqi@0 246 private final ScopeMap endpointMap = new ScopeMap(merger, endpointKeyHandler);
aoqi@0 247 private final ScopeMap operationMap = new ScopeMap(merger, operationAndInputOutputMessageKeyHandler);
aoqi@0 248 private final ScopeMap inputMessageMap = new ScopeMap(merger, operationAndInputOutputMessageKeyHandler);
aoqi@0 249 private final ScopeMap outputMessageMap = new ScopeMap(merger, operationAndInputOutputMessageKeyHandler);
aoqi@0 250 private final ScopeMap faultMessageMap = new ScopeMap(merger, faultMessageHandler);
aoqi@0 251
aoqi@0 252 /**
aoqi@0 253 * This constructor is private to prevent direct instantiation from outside of the class
aoqi@0 254 */
aoqi@0 255 private PolicyMap() {
aoqi@0 256 // nothing to initialize
aoqi@0 257 }
aoqi@0 258
aoqi@0 259 /**
aoqi@0 260 * Creates new policy map instance and connects provided collection of policy map mutators to the created policy map.
aoqi@0 261 *
aoqi@0 262 * @param mutators collection of mutators that should be connected to the newly created map.
aoqi@0 263 * @return new policy map instance (mutable via provided collection of mutators).
aoqi@0 264 */
aoqi@0 265 public static PolicyMap createPolicyMap(final Collection<? extends PolicyMapMutator> mutators) {
aoqi@0 266 final PolicyMap result = new PolicyMap();
aoqi@0 267
aoqi@0 268 if (mutators != null && !mutators.isEmpty()) {
aoqi@0 269 for (PolicyMapMutator mutator : mutators) {
aoqi@0 270 mutator.connect(result);
aoqi@0 271 }
aoqi@0 272 }
aoqi@0 273
aoqi@0 274 return result;
aoqi@0 275 }
aoqi@0 276
aoqi@0 277 public Policy getServiceEffectivePolicy(final PolicyMapKey key) throws PolicyException {
aoqi@0 278 return serviceMap.getEffectivePolicy(key);
aoqi@0 279 }
aoqi@0 280
aoqi@0 281 public Policy getEndpointEffectivePolicy(final PolicyMapKey key) throws PolicyException {
aoqi@0 282 return endpointMap.getEffectivePolicy(key);
aoqi@0 283 }
aoqi@0 284
aoqi@0 285 public Policy getOperationEffectivePolicy(final PolicyMapKey key) throws PolicyException {
aoqi@0 286 return operationMap.getEffectivePolicy(key);
aoqi@0 287 }
aoqi@0 288
aoqi@0 289 public Policy getInputMessageEffectivePolicy(final PolicyMapKey key) throws PolicyException {
aoqi@0 290 return inputMessageMap.getEffectivePolicy(key);
aoqi@0 291 }
aoqi@0 292
aoqi@0 293 public Policy getOutputMessageEffectivePolicy(final PolicyMapKey key) throws PolicyException {
aoqi@0 294 return outputMessageMap.getEffectivePolicy(key);
aoqi@0 295 }
aoqi@0 296
aoqi@0 297 public Policy getFaultMessageEffectivePolicy(final PolicyMapKey key) throws PolicyException {
aoqi@0 298 return faultMessageMap.getEffectivePolicy(key);
aoqi@0 299 }
aoqi@0 300
aoqi@0 301 /**
aoqi@0 302 * Returns all service scope keys stored in this policy map
aoqi@0 303 *
aoqi@0 304 * @return collection of service scope policy map keys stored in the map.
aoqi@0 305 */
aoqi@0 306 public Collection<PolicyMapKey> getAllServiceScopeKeys() {
aoqi@0 307 return serviceMap.getAllKeys();
aoqi@0 308 }
aoqi@0 309
aoqi@0 310 /**
aoqi@0 311 * Returns all endpoint scope keys stored in this policy map
aoqi@0 312 *
aoqi@0 313 * @return collection of endpoint scope policy map keys stored in the map.
aoqi@0 314 */
aoqi@0 315 public Collection<PolicyMapKey> getAllEndpointScopeKeys() {
aoqi@0 316 return endpointMap.getAllKeys();
aoqi@0 317 }
aoqi@0 318
aoqi@0 319 /**
aoqi@0 320 * Returns all operation scope keys stored in this policy map
aoqi@0 321 *
aoqi@0 322 * @return collection of operation scope policy map keys stored in the map.
aoqi@0 323 */
aoqi@0 324 public Collection<PolicyMapKey> getAllOperationScopeKeys() {
aoqi@0 325 return operationMap.getAllKeys();
aoqi@0 326 }
aoqi@0 327
aoqi@0 328 /**
aoqi@0 329 * Returns all input message scope keys stored in this policy map
aoqi@0 330 *
aoqi@0 331 * @return collection of input message scope policy map keys stored in the map.
aoqi@0 332 */
aoqi@0 333 public Collection<PolicyMapKey> getAllInputMessageScopeKeys() {
aoqi@0 334 return inputMessageMap.getAllKeys();
aoqi@0 335 }
aoqi@0 336
aoqi@0 337 /**
aoqi@0 338 * Returns all output message scope keys stored in this policy map
aoqi@0 339 *
aoqi@0 340 * @return collection of output message scope policy map keys stored in the map.
aoqi@0 341 */
aoqi@0 342 public Collection<PolicyMapKey> getAllOutputMessageScopeKeys() {
aoqi@0 343 return outputMessageMap.getAllKeys();
aoqi@0 344 }
aoqi@0 345
aoqi@0 346 /**
aoqi@0 347 * Returns all fault message scope keys stored in this policy map
aoqi@0 348 *
aoqi@0 349 * @return collection of input message scope policy map keys stored in the map.
aoqi@0 350 */
aoqi@0 351 public Collection<PolicyMapKey> getAllFaultMessageScopeKeys() {
aoqi@0 352 return faultMessageMap.getAllKeys();
aoqi@0 353 }
aoqi@0 354
aoqi@0 355 /**
aoqi@0 356 * Places new subject into policy map under the scope identified by it's type and policy map key.
aoqi@0 357 *
aoqi@0 358 * @param scopeType the type of the scope the subject belongs to
aoqi@0 359 * @param key a policy map key to be used to store the subject
aoqi@0 360 * @param subject actual policy subject to be stored in the policy map
aoqi@0 361 *
aoqi@0 362 * @throw IllegalArgumentException in case the scope type is not recognized.
aoqi@0 363 */
aoqi@0 364 void putSubject(final ScopeType scopeType, final PolicyMapKey key, final PolicySubject subject) {
aoqi@0 365 switch (scopeType) {
aoqi@0 366 case SERVICE:
aoqi@0 367 serviceMap.putSubject(key, subject);
aoqi@0 368 break;
aoqi@0 369 case ENDPOINT:
aoqi@0 370 endpointMap.putSubject(key, subject);
aoqi@0 371 break;
aoqi@0 372 case OPERATION:
aoqi@0 373 operationMap.putSubject(key, subject);
aoqi@0 374 break;
aoqi@0 375 case INPUT_MESSAGE:
aoqi@0 376 inputMessageMap.putSubject(key, subject);
aoqi@0 377 break;
aoqi@0 378 case OUTPUT_MESSAGE:
aoqi@0 379 outputMessageMap.putSubject(key, subject);
aoqi@0 380 break;
aoqi@0 381 case FAULT_MESSAGE:
aoqi@0 382 faultMessageMap.putSubject(key, subject);
aoqi@0 383 break;
aoqi@0 384 default:
aoqi@0 385 throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0002_UNRECOGNIZED_SCOPE_TYPE(scopeType)));
aoqi@0 386 }
aoqi@0 387 }
aoqi@0 388
aoqi@0 389 /**
aoqi@0 390 * Replaces current effective policy on given scope (identified by a {@code key} parameter) with the new efective
aoqi@0 391 * policy provided as a second input parameter. If no policy was defined for the presented key, the new policy is simply
aoqi@0 392 * stored with the key.
aoqi@0 393 *
aoqi@0 394 * @param scopeType the type of the scope the subject belongs to. Must not be {@code null}.
aoqi@0 395 * @param key identifier of the scope the effective policy should be replaced with the new one. Must not be {@code null}.
aoqi@0 396 * @param newEffectivePolicy the new policy to replace the old effective policy of the scope. Must not be {@code null}.
aoqi@0 397 *
aoqi@0 398 * @throw IllegalArgumentException in case any of the input parameters is {@code null}
aoqi@0 399 * or in case the scope type is not recognized.
aoqi@0 400 */
aoqi@0 401 void setNewEffectivePolicyForScope(final ScopeType scopeType, final PolicyMapKey key, final Policy newEffectivePolicy) throws IllegalArgumentException {
aoqi@0 402 if (scopeType == null || key == null || newEffectivePolicy == null) {
aoqi@0 403 throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0062_INPUT_PARAMS_MUST_NOT_BE_NULL()));
aoqi@0 404 }
aoqi@0 405
aoqi@0 406 switch (scopeType) {
aoqi@0 407 case SERVICE :
aoqi@0 408 serviceMap.setNewEffectivePolicy(key, newEffectivePolicy);
aoqi@0 409 break;
aoqi@0 410 case ENDPOINT :
aoqi@0 411 endpointMap.setNewEffectivePolicy(key, newEffectivePolicy);
aoqi@0 412 break;
aoqi@0 413 case OPERATION :
aoqi@0 414 operationMap.setNewEffectivePolicy(key, newEffectivePolicy);
aoqi@0 415 break;
aoqi@0 416 case INPUT_MESSAGE :
aoqi@0 417 inputMessageMap.setNewEffectivePolicy(key, newEffectivePolicy);
aoqi@0 418 break;
aoqi@0 419 case OUTPUT_MESSAGE :
aoqi@0 420 outputMessageMap.setNewEffectivePolicy(key, newEffectivePolicy);
aoqi@0 421 break;
aoqi@0 422 case FAULT_MESSAGE :
aoqi@0 423 faultMessageMap.setNewEffectivePolicy(key, newEffectivePolicy);
aoqi@0 424 break;
aoqi@0 425 default:
aoqi@0 426 throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0002_UNRECOGNIZED_SCOPE_TYPE(scopeType)));
aoqi@0 427 }
aoqi@0 428 }
aoqi@0 429
aoqi@0 430 /**
aoqi@0 431 * Returns all policy subjects contained by this map.
aoqi@0 432 *
aoqi@0 433 * @return All policy subjects contained by this map
aoqi@0 434 */
aoqi@0 435 public Collection<PolicySubject> getPolicySubjects() {
aoqi@0 436 final List<PolicySubject> subjects = new LinkedList<PolicySubject>();
aoqi@0 437 addSubjects(subjects, serviceMap);
aoqi@0 438 addSubjects(subjects, endpointMap);
aoqi@0 439 addSubjects(subjects, operationMap);
aoqi@0 440 addSubjects(subjects, inputMessageMap);
aoqi@0 441 addSubjects(subjects, outputMessageMap);
aoqi@0 442 addSubjects(subjects, faultMessageMap);
aoqi@0 443 return subjects;
aoqi@0 444 }
aoqi@0 445
aoqi@0 446 /*
aoqi@0 447 * TODO: reconsider this QUICK HACK
aoqi@0 448 */
aoqi@0 449 public boolean isInputMessageSubject(final PolicySubject subject) {
aoqi@0 450 for (PolicyScope scope : inputMessageMap.getStoredScopes()) {
aoqi@0 451 if (scope.getPolicySubjects().contains(subject)) {
aoqi@0 452 return true;
aoqi@0 453 }
aoqi@0 454 }
aoqi@0 455 return false;
aoqi@0 456 }
aoqi@0 457
aoqi@0 458 /*
aoqi@0 459 * TODO: reconsider this QUICK HACK
aoqi@0 460 */
aoqi@0 461 public boolean isOutputMessageSubject(final PolicySubject subject) {
aoqi@0 462 for (PolicyScope scope : outputMessageMap.getStoredScopes()) {
aoqi@0 463 if (scope.getPolicySubjects().contains(subject)) {
aoqi@0 464 return true;
aoqi@0 465 }
aoqi@0 466 }
aoqi@0 467 return false;
aoqi@0 468 }
aoqi@0 469
aoqi@0 470
aoqi@0 471 /*
aoqi@0 472 * TODO: reconsider this QUICK HACK
aoqi@0 473 */
aoqi@0 474 public boolean isFaultMessageSubject(final PolicySubject subject) {
aoqi@0 475 for (PolicyScope scope : faultMessageMap.getStoredScopes()) {
aoqi@0 476 if (scope.getPolicySubjects().contains(subject)) {
aoqi@0 477 return true;
aoqi@0 478 }
aoqi@0 479 }
aoqi@0 480 return false;
aoqi@0 481 }
aoqi@0 482
aoqi@0 483
aoqi@0 484 /**
aoqi@0 485 * Returns true if this map contains no key - policy pairs
aoqi@0 486 *
aoqi@0 487 * A null object key or policy constitutes a non-empty map.
aoqi@0 488 *
aoqi@0 489 * @return true if this map contains no key - policy pairs
aoqi@0 490 */
aoqi@0 491 public boolean isEmpty() {
aoqi@0 492 return serviceMap.isEmpty() && endpointMap.isEmpty() &&
aoqi@0 493 operationMap.isEmpty() && inputMessageMap.isEmpty() &&
aoqi@0 494 outputMessageMap.isEmpty() && faultMessageMap.isEmpty();
aoqi@0 495 }
aoqi@0 496
aoqi@0 497
aoqi@0 498 /**
aoqi@0 499 * Add all subjects in the given map to the collection
aoqi@0 500 *
aoqi@0 501 * @param subjects A collection that should hold subjects. The new subjects are added to the collection. Must not be {@code null}.
aoqi@0 502 * @param scopeMap A scope map that holds policy scopes. The subjects are retrieved from the scope objects.
aoqi@0 503 */
aoqi@0 504 private void addSubjects(final Collection<PolicySubject> subjects, final ScopeMap scopeMap) {
aoqi@0 505 for (PolicyScope scope : scopeMap.getStoredScopes()) {
aoqi@0 506 final Collection<PolicySubject> scopedSubjects = scope.getPolicySubjects();
aoqi@0 507 subjects.addAll(scopedSubjects);
aoqi@0 508 }
aoqi@0 509 }
aoqi@0 510
aoqi@0 511 /**
aoqi@0 512 * Creates a service policy scope <emph>locator</emph> object, that serves as a access key into
aoqi@0 513 * a {@code PolicyMap} where actual service policy scope for given service can be retrieved.
aoqi@0 514 *
aoqi@0 515 * @param service qualified name of the service. Must not be {@code null}.
aoqi@0 516 * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}.
aoqi@0 517 */
aoqi@0 518 public static PolicyMapKey createWsdlServiceScopeKey(final QName service) throws IllegalArgumentException {
aoqi@0 519 if (service == null) {
aoqi@0 520 throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0031_SERVICE_PARAM_MUST_NOT_BE_NULL()));
aoqi@0 521 }
aoqi@0 522 return new PolicyMapKey(service, null, null, serviceKeyHandler);
aoqi@0 523 }
aoqi@0 524
aoqi@0 525 /**
aoqi@0 526 * Creates an endpoint policy scope <emph>locator</emph> object, that serves as a access key into
aoqi@0 527 * a {@code PolicyMap} where actual endpoint policy scope for given endpoint can be retrieved.
aoqi@0 528 *
aoqi@0 529 * @param service qualified name of the service. Must not be {@code null}.
aoqi@0 530 * @param port qualified name of the endpoint. Must not be {@code null}.
aoqi@0 531 * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}.
aoqi@0 532 */
aoqi@0 533 public static PolicyMapKey createWsdlEndpointScopeKey(final QName service, final QName port) throws IllegalArgumentException {
aoqi@0 534 if (service == null || port == null) {
aoqi@0 535 throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0033_SERVICE_AND_PORT_PARAM_MUST_NOT_BE_NULL(service, port)));
aoqi@0 536 }
aoqi@0 537 return new PolicyMapKey(service, port, null, endpointKeyHandler);
aoqi@0 538 }
aoqi@0 539
aoqi@0 540 /**
aoqi@0 541 * Creates an operation policy scope <emph>locator</emph> object, that serves as a access key into
aoqi@0 542 * a {@code PolicyMap} where actual operation policy scope for given bound operation can be retrieved.
aoqi@0 543 *
aoqi@0 544 * @param service qualified name of the service. Must not be {@code null}.
aoqi@0 545 * @param port qualified name of the endpoint. Must not be {@code null}.
aoqi@0 546 * @param operation qualified name of the operation. Must not be {@code null}.
aoqi@0 547 * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}.
aoqi@0 548 */
aoqi@0 549 public static PolicyMapKey createWsdlOperationScopeKey(final QName service, final QName port, final QName operation) throws IllegalArgumentException {
aoqi@0 550 return createOperationOrInputOutputMessageKey(service, port, operation);
aoqi@0 551 }
aoqi@0 552
aoqi@0 553 /**
aoqi@0 554 * Creates an input/output message policy scope <emph>locator</emph> object identified by a bound operation, that serves as a
aoqi@0 555 * access key into {@code PolicyMap} where actual input/output message policy scope for given input message of a bound operation
aoqi@0 556 * can be retrieved.
aoqi@0 557 * <p/>
aoqi@0 558 * The method returns a key that is compliant with <emph>WSDL 1.1 Basic Profile Specification</emph>, according to which there
aoqi@0 559 * should be no two operations with the same name in a single port type definition.
aoqi@0 560 *
aoqi@0 561 * @param service qualified name of the service. Must not be {@code null}.
aoqi@0 562 * @param port qualified name of the endpoint. Must not be {@code null}.
aoqi@0 563 * @param operation qualified name of the operation. Must not be {@code null}.
aoqi@0 564 * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}.
aoqi@0 565 *
aoqi@0 566 */
aoqi@0 567 public static PolicyMapKey createWsdlMessageScopeKey(final QName service, final QName port, final QName operation) throws IllegalArgumentException {
aoqi@0 568 return createOperationOrInputOutputMessageKey(service, port, operation);
aoqi@0 569 }
aoqi@0 570
aoqi@0 571 /**
aoqi@0 572 * Creates a fault message policy scope <emph>locator</emph> object identified by a bound operation, that serves as a
aoqi@0 573 * access key into {@code PolicyMap} where the actual fault message policy scope for one of the faults of a bound operation
aoqi@0 574 * can be retrieved.
aoqi@0 575 * <p/>
aoqi@0 576 * The method returns a key that is compliant with the <emph>WSDL 1.1 Basic Profile Specification</emph>, according to which there
aoqi@0 577 * should be no two operations with the same name in a single port type definition.
aoqi@0 578 *
aoqi@0 579 * @param service qualified name of the service. Must not be {@code null}.
aoqi@0 580 * @param port qualified name of the endpoint. Must not be {@code null}.
aoqi@0 581 * @param operation qualified name of the operation. Must not be {@code null}.
aoqi@0 582 * @param fault qualified name of the fault. Do not confuse this with the name of the actual message. This parameter
aoqi@0 583 * takes the wsdl:binding/wsdl:operation/wsdl:fault name and not the wsdl:message name. Must not be {@code null}.
aoqi@0 584 * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}.
aoqi@0 585 *
aoqi@0 586 */
aoqi@0 587 public static PolicyMapKey createWsdlFaultMessageScopeKey(final QName service, final QName port, final QName operation, final QName fault) throws IllegalArgumentException {
aoqi@0 588 if (service == null || port == null || operation == null || fault == null) {
aoqi@0 589 throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0030_SERVICE_PORT_OPERATION_FAULT_MSG_PARAM_MUST_NOT_BE_NULL(service, port, operation, fault)));
aoqi@0 590 }
aoqi@0 591
aoqi@0 592 return new PolicyMapKey(service, port, operation, fault, faultMessageHandler);
aoqi@0 593 }
aoqi@0 594
aoqi@0 595 private static PolicyMapKey createOperationOrInputOutputMessageKey(final QName service, final QName port, final QName operation) {
aoqi@0 596 if (service == null || port == null || operation == null) {
aoqi@0 597 throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0029_SERVICE_PORT_OPERATION_PARAM_MUST_NOT_BE_NULL(service, port, operation)));
aoqi@0 598 }
aoqi@0 599
aoqi@0 600 return new PolicyMapKey(service, port, operation, operationAndInputOutputMessageKeyHandler);
aoqi@0 601 }
aoqi@0 602
aoqi@0 603 @Override
aoqi@0 604 public String toString(){
aoqi@0 605 // TODO
aoqi@0 606 final StringBuffer result = new StringBuffer();
aoqi@0 607 if(null!=this.serviceMap) {
aoqi@0 608 result.append("\nServiceMap=").append(this.serviceMap);
aoqi@0 609 }
aoqi@0 610 if(null!=this.endpointMap) {
aoqi@0 611 result.append("\nEndpointMap=").append(this.endpointMap);
aoqi@0 612 }
aoqi@0 613 if(null!=this.operationMap) {
aoqi@0 614 result.append("\nOperationMap=").append(this.operationMap);
aoqi@0 615 }
aoqi@0 616 if(null!=this.inputMessageMap) {
aoqi@0 617 result.append("\nInputMessageMap=").append(this.inputMessageMap);
aoqi@0 618 }
aoqi@0 619 if(null!=this.outputMessageMap) {
aoqi@0 620 result.append("\nOutputMessageMap=").append(this.outputMessageMap);
aoqi@0 621 }
aoqi@0 622 if(null!=this.faultMessageMap) {
aoqi@0 623 result.append("\nFaultMessageMap=").append(this.faultMessageMap);
aoqi@0 624 }
aoqi@0 625 return result.toString();
aoqi@0 626 }
aoqi@0 627
aoqi@0 628 public Iterator<Policy> iterator() {
aoqi@0 629 return new Iterator<Policy> () {
aoqi@0 630 private final Iterator<Iterator<Policy>> mainIterator;
aoqi@0 631 private Iterator<Policy> currentScopeIterator;
aoqi@0 632
aoqi@0 633 { // instance initialization
aoqi@0 634 final Collection<Iterator<Policy>> scopeIterators = new ArrayList<Iterator<Policy>>(6);
aoqi@0 635 scopeIterators.add(serviceMap.iterator());
aoqi@0 636 scopeIterators.add(endpointMap.iterator());
aoqi@0 637 scopeIterators.add(operationMap.iterator());
aoqi@0 638 scopeIterators.add(inputMessageMap.iterator());
aoqi@0 639 scopeIterators.add(outputMessageMap.iterator());
aoqi@0 640 scopeIterators.add(faultMessageMap.iterator());
aoqi@0 641
aoqi@0 642 mainIterator = scopeIterators.iterator();
aoqi@0 643 currentScopeIterator = mainIterator.next();
aoqi@0 644 }
aoqi@0 645
aoqi@0 646 public boolean hasNext() {
aoqi@0 647 while (!currentScopeIterator.hasNext()) {
aoqi@0 648 if (mainIterator.hasNext()) {
aoqi@0 649 currentScopeIterator = mainIterator.next();
aoqi@0 650 } else {
aoqi@0 651 return false;
aoqi@0 652 }
aoqi@0 653 }
aoqi@0 654
aoqi@0 655 return true;
aoqi@0 656 }
aoqi@0 657
aoqi@0 658 public Policy next() {
aoqi@0 659 if (hasNext()) {
aoqi@0 660 return currentScopeIterator.next();
aoqi@0 661 }
aoqi@0 662 throw LOGGER.logSevereException(new NoSuchElementException(LocalizationMessages.WSP_0054_NO_MORE_ELEMS_IN_POLICY_MAP()));
aoqi@0 663 }
aoqi@0 664
aoqi@0 665 public void remove() {
aoqi@0 666 throw LOGGER.logSevereException(new UnsupportedOperationException(LocalizationMessages.WSP_0034_REMOVE_OPERATION_NOT_SUPPORTED()));
aoqi@0 667 }
aoqi@0 668 };
aoqi@0 669 }
aoqi@0 670
aoqi@0 671 }

mercurial