Source Code Cross Referenced for PolicyMap.java in  » 6.0-JDK-Modules-com.sun » wsit » com » sun » xml » ws » policy » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules com.sun » wsit » com.sun.xml.ws.policy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         * 
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         * 
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common Development
008:         * and Distribution License("CDDL") (collectively, the "License").  You
009:         * may not use this file except in compliance with the License. You can obtain
010:         * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011:         * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
012:         * language governing permissions and limitations under the License.
013:         * 
014:         * When distributing the software, include this License Header Notice in each
015:         * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016:         * Sun designates this particular file as subject to the "Classpath" exception
017:         * as provided by Sun in the GPL Version 2 section of the License file that
018:         * accompanied this code.  If applicable, add the following below the License
019:         * Header, with the fields enclosed by brackets [] replaced by your own
020:         * identifying information: "Portions Copyrighted [year]
021:         * [name of copyright owner]"
022:         * 
023:         * Contributor(s):
024:         * 
025:         * If you wish your version of this file to be governed by only the CDDL or
026:         * only the GPL Version 2, indicate your decision by adding "[Contributor]
027:         * elects to include this software in this distribution under the [CDDL or GPL
028:         * Version 2] license."  If you don't indicate a single choice of license, a
029:         * recipient has the option to distribute your version of this file under
030:         * either the CDDL, the GPL Version 2 or to extend the choice of license to
031:         * its licensees as provided above.  However, if you add GPL Version 2 code
032:         * and therefore, elected the GPL Version 2 license, then the option applies
033:         * only if the new code is made subject to such option by the copyright
034:         * holder.
035:         */
036:
037:        package com.sun.xml.ws.policy;
038:
039:        import com.sun.xml.ws.policy.privateutil.LocalizationMessages;
040:        import com.sun.xml.ws.policy.privateutil.PolicyLogger;
041:        import java.util.ArrayList;
042:        import java.util.Collection;
043:        import java.util.HashMap;
044:        import java.util.Iterator;
045:        import java.util.LinkedList;
046:        import java.util.List;
047:        import java.util.Map;
048:        import java.util.NoSuchElementException;
049:        import java.util.Set;
050:        import javax.xml.namespace.QName;
051:
052:        /**
053:         * A PolicyMap holds all policies for a scope.
054:         *
055:         * This map is modeled around WSDL 1.1 policy scopes according to WS-PolicyAttachment. The map holds an information about
056:         * every scope for service, endpoint, operation, and input/output/fault message. It also provide accessibility methods for
057:         * computing and obtaining effective policy on each scope.
058:         *
059:         * TODO: rename createWsdlMessageScopeKey to createWsdlInputOutputMessageScopeKey
060:         */
061:        public final class PolicyMap implements  Iterable<Policy> {
062:            private static final PolicyLogger LOGGER = PolicyLogger
063:                    .getLogger(PolicyMap.class);
064:
065:            static enum ScopeType {
066:                SERVICE, ENDPOINT, OPERATION, INPUT_MESSAGE, OUTPUT_MESSAGE, FAULT_MESSAGE
067:            }
068:
069:            private static final class ScopeMap implements  Iterable<Policy> {
070:                private final Map<PolicyMapKey, PolicyScope> internalMap = new HashMap<PolicyMapKey, PolicyScope>();
071:                private final PolicyMapKeyHandler scopeKeyHandler;
072:                private final PolicyMerger merger;
073:
074:                ScopeMap(final PolicyMerger merger,
075:                        final PolicyMapKeyHandler scopeKeyHandler) {
076:                    this .merger = merger;
077:                    this .scopeKeyHandler = scopeKeyHandler;
078:                }
079:
080:                Policy getEffectivePolicy(final PolicyMapKey key,
081:                        final Collection<String> namespaces)
082:                        throws PolicyException {
083:                    final PolicyScope scope = internalMap
084:                            .get(createLocalCopy(key));
085:                    return (scope == null) ? null : scope.getEffectivePolicy(
086:                            namespaces, merger);
087:                }
088:
089:                Policy getEffectivePolicy(final PolicyMapKey key)
090:                        throws PolicyException {
091:                    final PolicyScope scope = internalMap
092:                            .get(createLocalCopy(key));
093:                    return (scope == null) ? null : scope
094:                            .getEffectivePolicy(merger);
095:                }
096:
097:                void putSubject(final PolicyMapKey key,
098:                        final PolicySubject subject) {
099:                    final PolicyMapKey localKey = createLocalCopy(key);
100:                    final PolicyScope scope = internalMap.get(localKey);
101:                    if (scope == null) {
102:                        final List<PolicySubject> list = new LinkedList<PolicySubject>();
103:                        list.add(subject);
104:                        internalMap.put(localKey, new PolicyScope(list));
105:                    } else {
106:                        scope.attach(subject);
107:                    }
108:                }
109:
110:                void setNewEffectivePolicy(final PolicyMapKey key,
111:                        final Policy newEffectivePolicy) {
112:                    // we add this policy map as a subject, because there is nothing reasonable we could add there, since
113:                    // this is an artificial policy subject
114:                    final PolicySubject subject = new PolicySubject(key,
115:                            newEffectivePolicy);
116:
117:                    final PolicyMapKey localKey = createLocalCopy(key);
118:                    final PolicyScope scope = internalMap.get(localKey);
119:                    if (scope == null) {
120:                        final List<PolicySubject> list = new LinkedList<PolicySubject>();
121:                        list.add(subject);
122:                        internalMap.put(localKey, new PolicyScope(list));
123:                    } else {
124:                        scope.dettachAllSubjects();
125:                        scope.attach(subject);
126:                    }
127:                }
128:
129:                Collection<PolicyScope> getStoredScopes() {
130:                    return internalMap.values();
131:                }
132:
133:                Set<PolicyMapKey> getAllKeys() {
134:                    return internalMap.keySet();
135:                }
136:
137:                private PolicyMapKey createLocalCopy(final PolicyMapKey key) {
138:                    if (key == null) {
139:                        throw LOGGER
140:                                .logSevereException(new IllegalArgumentException(
141:                                        LocalizationMessages
142:                                                .WSP_0045_POLICY_MAP_KEY_MUST_NOT_BE_NULL()));
143:                    }
144:
145:                    final PolicyMapKey localKeyCopy = new PolicyMapKey(key);
146:                    localKeyCopy.setHandler(scopeKeyHandler);
147:
148:                    return localKeyCopy;
149:                }
150:
151:                public Iterator<Policy> iterator() {
152:                    return new Iterator<Policy>() {
153:                        private final Iterator<PolicyMapKey> keysIterator = internalMap
154:                                .keySet().iterator();
155:
156:                        public boolean hasNext() {
157:                            return keysIterator.hasNext();
158:                        }
159:
160:                        public Policy next() {
161:                            final PolicyMapKey key = keysIterator.next();
162:                            try {
163:                                return getEffectivePolicy(key);
164:                            } catch (PolicyException e) {
165:                                throw LOGGER
166:                                        .logSevereException(new IllegalStateException(
167:                                                LocalizationMessages
168:                                                        .WSP_0069_EXCEPTION_WHILE_RETRIEVING_EFFECTIVE_POLICY_FOR_KEY(key),
169:                                                e));
170:                            }
171:                        }
172:
173:                        public void remove() {
174:                            throw LOGGER
175:                                    .logSevereException(new UnsupportedOperationException(
176:                                            LocalizationMessages
177:                                                    .WSP_0034_REMOVE_OPERATION_NOT_SUPPORTED()));
178:                        }
179:                    };
180:                }
181:
182:                public boolean isEmpty() {
183:                    return internalMap.isEmpty();
184:                }
185:
186:                public String toString() {
187:                    return internalMap.toString();
188:                }
189:            }
190:
191:            private static final PolicyMerger merger = PolicyMerger.getMerger();
192:
193:            private final ScopeMap serviceMap = new ScopeMap(merger,
194:                    new PolicyMapKeyHandler() {
195:                        public boolean areEqual(final PolicyMapKey key1,
196:                                final PolicyMapKey key2) {
197:                            return key1.service.equals(key2.service);
198:                        }
199:
200:                        public int generateHashCode(final PolicyMapKey key) {
201:                            int result = 17;
202:
203:                            result = 37 * result + key.service.hashCode();
204:
205:                            return result;
206:                        }
207:                    });
208:
209:            private final ScopeMap endpointMap = new ScopeMap(merger,
210:                    new PolicyMapKeyHandler() {
211:                        public boolean areEqual(final PolicyMapKey key1,
212:                                final PolicyMapKey key2) {
213:                            boolean retVal = true;
214:
215:                            retVal = retVal
216:                                    && key1.service.equals(key2.service);
217:                            retVal = retVal
218:                                    && ((key1.port == null) ? key2.port == null
219:                                            : key1.port.equals(key2.port));
220:
221:                            return retVal;
222:                        }
223:
224:                        public int generateHashCode(final PolicyMapKey key) {
225:                            int result = 17;
226:
227:                            result = 37 * result + key.service.hashCode();
228:                            result = 37
229:                                    * result
230:                                    + ((key.port == null) ? 0 : key.port
231:                                            .hashCode());
232:
233:                            return result;
234:                        }
235:                    });
236:
237:            private final PolicyMapKeyHandler operationAndInputOutputMessageKeyHandler = new PolicyMapKeyHandler() {
238:                // we use the same algorithm to handle operation and input/output message keys
239:
240:                public boolean areEqual(final PolicyMapKey key1,
241:                        final PolicyMapKey key2) {
242:                    boolean retVal = true;
243:
244:                    retVal = retVal && key1.service.equals(key2.service);
245:                    retVal = retVal
246:                            && ((key1.port == null) ? key2.port == null
247:                                    : key1.port.equals(key2.port));
248:                    retVal = retVal
249:                            && ((key1.operation == null) ? key2.operation == null
250:                                    : key1.operation.equals(key2.operation));
251:
252:                    return retVal;
253:                }
254:
255:                public int generateHashCode(final PolicyMapKey key) {
256:                    int result = 17;
257:
258:                    result = 37 * result + key.service.hashCode();
259:                    result = 37 * result
260:                            + ((key.port == null) ? 0 : key.port.hashCode());
261:                    result = 37
262:                            * result
263:                            + ((key.operation == null) ? 0 : key.operation
264:                                    .hashCode());
265:
266:                    return result;
267:                }
268:            };
269:
270:            private final ScopeMap operationMap = new ScopeMap(merger,
271:                    operationAndInputOutputMessageKeyHandler);
272:            private final ScopeMap inputMessageMap = new ScopeMap(merger,
273:                    operationAndInputOutputMessageKeyHandler);
274:            private final ScopeMap outputMessageMap = new ScopeMap(merger,
275:                    operationAndInputOutputMessageKeyHandler);
276:
277:            private final ScopeMap faultMessageMap = new ScopeMap(merger,
278:                    new PolicyMapKeyHandler() {
279:                        public boolean areEqual(final PolicyMapKey key1,
280:                                final PolicyMapKey key2) {
281:                            boolean retVal = true;
282:
283:                            retVal = retVal
284:                                    && key1.service.equals(key2.service);
285:                            retVal = retVal
286:                                    && ((key1.port == null) ? key2.port == null
287:                                            : key1.port.equals(key2.port));
288:                            retVal = retVal
289:                                    && ((key1.operation == null) ? key2.operation == null
290:                                            : key1.operation
291:                                                    .equals(key2.operation));
292:                            retVal = retVal
293:                                    && ((key1.faultMessage == null) ? key2.faultMessage == null
294:                                            : key1.faultMessage
295:                                                    .equals(key2.faultMessage));
296:
297:                            return retVal;
298:                        }
299:
300:                        public int generateHashCode(final PolicyMapKey key) {
301:                            int result = 17;
302:
303:                            result = 37 * result + key.service.hashCode();
304:                            result = 37
305:                                    * result
306:                                    + ((key.port == null) ? 0 : key.port
307:                                            .hashCode());
308:                            result = 37
309:                                    * result
310:                                    + ((key.operation == null) ? 0
311:                                            : key.operation.hashCode());
312:                            result = 37
313:                                    * result
314:                                    + ((key.faultMessage == null) ? 0
315:                                            : key.faultMessage.hashCode());
316:
317:                            return result;
318:                        }
319:                    });
320:
321:            /**
322:             * This constructor is private to prevent direct instantiation from outside of the class
323:             */
324:            private PolicyMap() {
325:                // nothing to initialize
326:            }
327:
328:            /**
329:             * Creates new policy map instance and connects provided collection of policy map mutators to the created policy map.
330:             *
331:             * @param mutators collection of mutators that should be connected to the newly created map.
332:             * @return new policy map instance (mutable via provided collection of mutators).
333:             */
334:            public static PolicyMap createPolicyMap(
335:                    final Collection<? extends PolicyMapMutator> mutators) {
336:                final PolicyMap result = new PolicyMap();
337:
338:                if (mutators != null && !mutators.isEmpty()) {
339:                    for (PolicyMapMutator mutator : mutators) {
340:                        mutator.connect(result);
341:                    }
342:                }
343:
344:                return result;
345:            }
346:
347:            public Policy getServiceEffectivePolicy(final PolicyMapKey key)
348:                    throws PolicyException {
349:                return serviceMap.getEffectivePolicy(key);
350:            }
351:
352:            public Policy getEndpointEffectivePolicy(final PolicyMapKey key)
353:                    throws PolicyException {
354:                return endpointMap.getEffectivePolicy(key);
355:            }
356:
357:            public Policy getOperationEffectivePolicy(final PolicyMapKey key)
358:                    throws PolicyException {
359:                return operationMap.getEffectivePolicy(key);
360:            }
361:
362:            public Policy getInputMessageEffectivePolicy(final PolicyMapKey key)
363:                    throws PolicyException {
364:                return inputMessageMap.getEffectivePolicy(key);
365:            }
366:
367:            public Policy getOutputMessageEffectivePolicy(final PolicyMapKey key)
368:                    throws PolicyException {
369:                return outputMessageMap.getEffectivePolicy(key);
370:            }
371:
372:            public Policy getFaultMessageEffectivePolicy(final PolicyMapKey key)
373:                    throws PolicyException {
374:                return faultMessageMap.getEffectivePolicy(key);
375:            }
376:
377:            public Policy getServiceEffectivePolicy(final PolicyMapKey key,
378:                    final Collection<String> namespaces) throws PolicyException {
379:                return serviceMap.getEffectivePolicy(key, namespaces);
380:            }
381:
382:            public Policy getEndpointEffectivePolicy(final PolicyMapKey key,
383:                    final Collection<String> namespaces) throws PolicyException {
384:                return endpointMap.getEffectivePolicy(key, namespaces);
385:            }
386:
387:            public Policy getOperationEffectivePolicy(final PolicyMapKey key,
388:                    final Collection<String> namespaces) throws PolicyException {
389:                return operationMap.getEffectivePolicy(key, namespaces);
390:            }
391:
392:            public Policy getInputMessageEffectivePolicy(
393:                    final PolicyMapKey key, final Collection<String> namespaces)
394:                    throws PolicyException {
395:                return inputMessageMap.getEffectivePolicy(key, namespaces);
396:            }
397:
398:            public Policy getOutputMessageEffectivePolicy(
399:                    final PolicyMapKey key, final Collection<String> namespaces)
400:                    throws PolicyException {
401:                return outputMessageMap.getEffectivePolicy(key, namespaces);
402:            }
403:
404:            public Policy getFaultMessageEffectivePolicy(
405:                    final PolicyMapKey key, final Collection<String> namespaces)
406:                    throws PolicyException {
407:                return faultMessageMap.getEffectivePolicy(key, namespaces);
408:            }
409:
410:            /**
411:             * Returns all service scope keys stored in this policy map
412:             *
413:             * @return collection of service scope policy map keys stored in the map.
414:             */
415:            public Collection<PolicyMapKey> getAllServiceScopeKeys() {
416:                return serviceMap.getAllKeys();
417:            }
418:
419:            /**
420:             * Returns all endpoint scope keys stored in this policy map
421:             *
422:             * @return collection of endpoint scope policy map keys stored in the map.
423:             */
424:            public Collection<PolicyMapKey> getAllEndpointScopeKeys() {
425:                return endpointMap.getAllKeys();
426:            }
427:
428:            /**
429:             * Returns all operation scope keys stored in this policy map
430:             *
431:             * @return collection of operation scope policy map keys stored in the map.
432:             */
433:            public Collection<PolicyMapKey> getAllOperationScopeKeys() {
434:                return operationMap.getAllKeys();
435:            }
436:
437:            /**
438:             * Returns all input message scope keys stored in this policy map
439:             *
440:             * @return collection of input message scope policy map keys stored in the map.
441:             */
442:            public Collection<PolicyMapKey> getAllInputMessageScopeKeys() {
443:                return inputMessageMap.getAllKeys();
444:            }
445:
446:            /**
447:             * Returns all output message scope keys stored in this policy map
448:             *
449:             * @return collection of output message scope policy map keys stored in the map.
450:             */
451:            public Collection<PolicyMapKey> getAllOutputMessageScopeKeys() {
452:                return outputMessageMap.getAllKeys();
453:            }
454:
455:            /**
456:             * Returns all fault message scope keys stored in this policy map
457:             *
458:             * @return collection of input message scope policy map keys stored in the map.
459:             */
460:            public Collection<PolicyMapKey> getAllFaultMessageScopeKeys() {
461:                return faultMessageMap.getAllKeys();
462:            }
463:
464:            /**
465:             * Places new subject into policy map under the scope identified by it's type and policy map key.
466:             *
467:             * @param scopeType the type of the scope the subject belongs to
468:             * @param key a policy map key to be used to store the subject
469:             * @param subject actual policy subject to be stored in the policy map
470:             *
471:             * @throw IllegalArgumentException in case the scope type is not recognized.
472:             */
473:            void putSubject(final ScopeType scopeType, final PolicyMapKey key,
474:                    final PolicySubject subject) {
475:                switch (scopeType) {
476:                case SERVICE:
477:                    serviceMap.putSubject(key, subject);
478:                    break;
479:                case ENDPOINT:
480:                    endpointMap.putSubject(key, subject);
481:                    break;
482:                case OPERATION:
483:                    operationMap.putSubject(key, subject);
484:                    break;
485:                case INPUT_MESSAGE:
486:                    inputMessageMap.putSubject(key, subject);
487:                    break;
488:                case OUTPUT_MESSAGE:
489:                    outputMessageMap.putSubject(key, subject);
490:                    break;
491:                case FAULT_MESSAGE:
492:                    faultMessageMap.putSubject(key, subject);
493:                    break;
494:                default:
495:                    throw LOGGER
496:                            .logSevereException(new IllegalArgumentException(
497:                                    LocalizationMessages
498:                                            .WSP_0002_UNRECOGNIZED_SCOPE_TYPE(scopeType)));
499:                }
500:            }
501:
502:            /**
503:             * Replaces current effective policy on given scope (identified by a {@code key} parameter) with the new efective
504:             * policy provided as a second input parameter. If no policy was defined for the presented key, the new policy is simply
505:             * stored with the key.
506:             *
507:             * @param scopeType the type of the scope the subject belongs to. Must not be {@code null}.
508:             * @param key identifier of the scope the effective policy should be replaced with the new one. Must not be {@code null}.
509:             * @param newEffectivePolicy the new policy to replace the old effective policy of the scope. Must not be {@code null}.
510:             *
511:             * @throw IllegalArgumentException in case any of the input parameters is {@code null} 
512:             *        or in case the scope type is not recognized.
513:             */
514:            void setNewEffectivePolicyForScope(final ScopeType scopeType,
515:                    final PolicyMapKey key, final Policy newEffectivePolicy)
516:                    throws IllegalArgumentException {
517:                if (scopeType == null || key == null
518:                        || newEffectivePolicy == null) {
519:                    throw LOGGER
520:                            .logSevereException(new IllegalArgumentException(
521:                                    LocalizationMessages
522:                                            .WSP_0062_INPUT_PARAMS_MUST_NOT_BE_NULL()));
523:                }
524:
525:                switch (scopeType) {
526:                case SERVICE:
527:                    serviceMap.setNewEffectivePolicy(key, newEffectivePolicy);
528:                    break;
529:                case ENDPOINT:
530:                    endpointMap.setNewEffectivePolicy(key, newEffectivePolicy);
531:                    break;
532:                case OPERATION:
533:                    operationMap.setNewEffectivePolicy(key, newEffectivePolicy);
534:                    break;
535:                case INPUT_MESSAGE:
536:                    inputMessageMap.setNewEffectivePolicy(key,
537:                            newEffectivePolicy);
538:                    break;
539:                case OUTPUT_MESSAGE:
540:                    outputMessageMap.setNewEffectivePolicy(key,
541:                            newEffectivePolicy);
542:                    break;
543:                case FAULT_MESSAGE:
544:                    faultMessageMap.setNewEffectivePolicy(key,
545:                            newEffectivePolicy);
546:                    break;
547:                default:
548:                    throw LOGGER
549:                            .logSevereException(new IllegalArgumentException(
550:                                    LocalizationMessages
551:                                            .WSP_0002_UNRECOGNIZED_SCOPE_TYPE(scopeType)));
552:                }
553:            }
554:
555:            /**
556:             * Returns all policy subjects contained by this map.
557:             *
558:             * @return All policy subjects contained by this map
559:             */
560:            public Collection<PolicySubject> getPolicySubjects() {
561:                final List<PolicySubject> subjects = new LinkedList<PolicySubject>();
562:                addSubjects(subjects, serviceMap);
563:                addSubjects(subjects, endpointMap);
564:                addSubjects(subjects, operationMap);
565:                addSubjects(subjects, inputMessageMap);
566:                addSubjects(subjects, outputMessageMap);
567:                addSubjects(subjects, faultMessageMap);
568:                return subjects;
569:            }
570:
571:            /*
572:             * TODO: reconsider this QUICK HACK
573:             */
574:            public boolean isInputMessageSubject(final PolicySubject subject) {
575:                for (PolicyScope scope : inputMessageMap.getStoredScopes()) {
576:                    if (scope.getPolicySubjects().contains(subject)) {
577:                        return true;
578:                    }
579:                }
580:                return false;
581:            }
582:
583:            /*
584:             * TODO: reconsider this QUICK HACK
585:             */
586:            public boolean isOutputMessageSubject(final PolicySubject subject) {
587:                for (PolicyScope scope : outputMessageMap.getStoredScopes()) {
588:                    if (scope.getPolicySubjects().contains(subject)) {
589:                        return true;
590:                    }
591:                }
592:                return false;
593:            }
594:
595:            /*
596:             * TODO: reconsider this QUICK HACK
597:             */
598:            public boolean isFaultMessageSubject(final PolicySubject subject) {
599:                for (PolicyScope scope : faultMessageMap.getStoredScopes()) {
600:                    if (scope.getPolicySubjects().contains(subject)) {
601:                        return true;
602:                    }
603:                }
604:                return false;
605:            }
606:
607:            /**
608:             * Returns true if this map contains no key - policy pairs
609:             *
610:             * A null object key or policy constitutes a non-empty map.
611:             *
612:             * @return true if this map contains no key - policy pairs
613:             */
614:            public boolean isEmpty() {
615:                return serviceMap.isEmpty() && endpointMap.isEmpty()
616:                        && operationMap.isEmpty() && inputMessageMap.isEmpty()
617:                        && outputMessageMap.isEmpty()
618:                        && faultMessageMap.isEmpty();
619:            }
620:
621:            /**
622:             * Add all subjects in the given map to the collection
623:             *
624:             * @param subjects A collection that should hold subjects. The new subjects are added to the collection. Must not be {@code null}.
625:             * @param scopeMap A scope map that holds policy scopes. The subjects are retrieved from the scope objects.
626:             */
627:            private void addSubjects(final Collection<PolicySubject> subjects,
628:                    final ScopeMap scopeMap) {
629:                for (PolicyScope scope : scopeMap.getStoredScopes()) {
630:                    final Collection<PolicySubject> scopedSubjects = scope
631:                            .getPolicySubjects();
632:                    subjects.addAll(scopedSubjects);
633:                }
634:            }
635:
636:            /**
637:             * Creates a service policy scope <emph>locator</emph> object, that serves as a access key into
638:             * a {@code PolicyMap} where actual service policy scope for given service can be retrieved.
639:             *
640:             * @param service qualified name of the service. Must not be {@code null}.
641:             * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}.
642:             */
643:            public static PolicyMapKey createWsdlServiceScopeKey(
644:                    final QName service) throws IllegalArgumentException {
645:                if (service == null) {
646:                    throw LOGGER
647:                            .logSevereException(new IllegalArgumentException(
648:                                    LocalizationMessages
649:                                            .WSP_0031_SERVICE_PARAM_MUST_NOT_BE_NULL()));
650:                }
651:                return new PolicyMapKey(service, null, null);
652:            }
653:
654:            /**
655:             * Creates an endpoint policy scope <emph>locator</emph> object, that serves as a access key into
656:             * a {@code PolicyMap} where actual endpoint policy scope for given endpoint can be retrieved.
657:             *
658:             * @param service qualified name of the service. Must not be {@code null}.
659:             * @param port qualified name of the endpoint. Must not be {@code null}.
660:             * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}.
661:             */
662:            public static PolicyMapKey createWsdlEndpointScopeKey(
663:                    final QName service, final QName port)
664:                    throws IllegalArgumentException {
665:                if (service == null || port == null) {
666:                    throw LOGGER
667:                            .logSevereException(new IllegalArgumentException(
668:                                    LocalizationMessages
669:                                            .WSP_0033_SERVICE_AND_PORT_PARAM_MUST_NOT_BE_NULL(
670:                                                    service, port)));
671:                }
672:                return new PolicyMapKey(service, port, null);
673:            }
674:
675:            /**
676:             * Creates an operation policy scope <emph>locator</emph> object, that serves as a access key into
677:             * a {@code PolicyMap} where actual operation policy scope for given bound operation can be retrieved.
678:             *
679:             * @param service qualified name of the service. Must not be {@code null}.
680:             * @param port qualified name of the endpoint. Must not be {@code null}.
681:             * @param operation qualified name of the operation. Must not be {@code null}.
682:             * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}.
683:             */
684:            public static PolicyMapKey createWsdlOperationScopeKey(
685:                    final QName service, final QName port, final QName operation)
686:                    throws IllegalArgumentException {
687:                return createOperationOrInputOutputMessageKey(service, port,
688:                        operation);
689:            }
690:
691:            /**
692:             * Creates an input/output message policy scope <emph>locator</emph> object identified by a bound operation, that serves as a
693:             * access key into {@code PolicyMap} where actual input/output message policy scope for given input message of a bound operation
694:             * can be retrieved.
695:             * <p/>
696:             * The method returns a key that is compliant with <emph>WSDL 1.1 Basic Profile Specification</emph>, according to which there
697:             * should be no two operations with the same name in a single port type definition.
698:             *
699:             * @param service qualified name of the service. Must not be {@code null}.
700:             * @param port qualified name of the endpoint. Must not be {@code null}.
701:             * @param operation qualified name of the operation. Must not be {@code null}.
702:             * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}.
703:             *
704:             */
705:            public static PolicyMapKey createWsdlMessageScopeKey(
706:                    final QName service, final QName port, final QName operation)
707:                    throws IllegalArgumentException {
708:                return createOperationOrInputOutputMessageKey(service, port,
709:                        operation);
710:            }
711:
712:            /**
713:             * Creates a fault message policy scope <emph>locator</emph> object identified by a bound operation, that serves as a
714:             * access key into {@code PolicyMap} where the actual fault message policy scope for one of the faults of a bound operation
715:             * can be retrieved.
716:             * <p/>
717:             * The method returns a key that is compliant with the <emph>WSDL 1.1 Basic Profile Specification</emph>, according to which there
718:             * should be no two operations with the same name in a single port type definition.
719:             *
720:             * @param service qualified name of the service. Must not be {@code null}.
721:             * @param port qualified name of the endpoint. Must not be {@code null}.
722:             * @param operation qualified name of the operation. Must not be {@code null}.
723:             * @param fault qualified name of the fault. Do not confuse this with the name of the actual message. This parameter
724:             * takes the wsdl:binding/wsdl:operation/wsdl:fault name and not the wsdl:message name. Must not be {@code null}.
725:             * @throws IllegalArgumentException in case service, port or operation parameter is {@code null}.
726:             *
727:             */
728:            public static PolicyMapKey createWsdlFaultMessageScopeKey(
729:                    final QName service, final QName port,
730:                    final QName operation, final QName fault)
731:                    throws IllegalArgumentException {
732:                if (service == null || port == null || operation == null
733:                        || fault == null) {
734:                    throw LOGGER
735:                            .logSevereException(new IllegalArgumentException(
736:                                    LocalizationMessages
737:                                            .WSP_0030_SERVICE_PORT_OPERATION_FAULT_MSG_PARAM_MUST_NOT_BE_NULL(
738:                                                    service, port, operation,
739:                                                    fault)));
740:                }
741:
742:                return new PolicyMapKey(service, port, operation, fault);
743:            }
744:
745:            private static PolicyMapKey createOperationOrInputOutputMessageKey(
746:                    final QName service, final QName port, final QName operation) {
747:                if (service == null || port == null || operation == null) {
748:                    throw LOGGER
749:                            .logSevereException(new IllegalArgumentException(
750:                                    LocalizationMessages
751:                                            .WSP_0029_SERVICE_PORT_OPERATION_PARAM_MUST_NOT_BE_NULL(
752:                                                    service, port, operation)));
753:                }
754:
755:                return new PolicyMapKey(service, port, operation);
756:            }
757:
758:            public String toString() {
759:                // TODO
760:                final StringBuffer result = new StringBuffer();
761:                if (null != this .serviceMap) {
762:                    result.append("\nServiceMap=").append(this .serviceMap);
763:                }
764:                if (null != this .endpointMap) {
765:                    result.append("\nEndpointMap=").append(this .endpointMap);
766:                }
767:                if (null != this .operationMap) {
768:                    result.append("\nOperationMap=").append(this .operationMap);
769:                }
770:                if (null != this .inputMessageMap) {
771:                    result.append("\nInputMessageMap=").append(
772:                            this .inputMessageMap);
773:                }
774:                if (null != this .outputMessageMap) {
775:                    result.append("\nOutputMessageMap=").append(
776:                            this .outputMessageMap);
777:                }
778:                if (null != this .faultMessageMap) {
779:                    result.append("\nFaultMessageMap=").append(
780:                            this .faultMessageMap);
781:                }
782:                return result.toString();
783:            }
784:
785:            public Iterator<Policy> iterator() {
786:                return new Iterator<Policy>() {
787:                    private final Iterator<Iterator<Policy>> mainIterator;
788:                    private Iterator<Policy> currentScopeIterator;
789:
790:                    { // instance initialization
791:                        final Collection<Iterator<Policy>> scopeIterators = new ArrayList<Iterator<Policy>>(
792:                                6);
793:                        scopeIterators.add(serviceMap.iterator());
794:                        scopeIterators.add(endpointMap.iterator());
795:                        scopeIterators.add(operationMap.iterator());
796:                        scopeIterators.add(inputMessageMap.iterator());
797:                        scopeIterators.add(outputMessageMap.iterator());
798:                        scopeIterators.add(faultMessageMap.iterator());
799:
800:                        mainIterator = scopeIterators.iterator();
801:                        currentScopeIterator = mainIterator.next();
802:                    }
803:
804:                    public boolean hasNext() {
805:                        while (!currentScopeIterator.hasNext()) {
806:                            if (mainIterator.hasNext()) {
807:                                currentScopeIterator = mainIterator.next();
808:                            } else {
809:                                return false;
810:                            }
811:                        }
812:
813:                        return true;
814:                    }
815:
816:                    public Policy next() {
817:                        if (hasNext()) {
818:                            return currentScopeIterator.next();
819:                        }
820:                        throw LOGGER
821:                                .logSevereException(new NoSuchElementException(
822:                                        LocalizationMessages
823:                                                .WSP_0054_NO_MORE_ELEMS_IN_POLICY_MAP()));
824:                    }
825:
826:                    public void remove() {
827:                        throw LOGGER
828:                                .logSevereException(new UnsupportedOperationException(
829:                                        LocalizationMessages
830:                                                .WSP_0034_REMOVE_OPERATION_NOT_SUPPORTED()));
831:                    }
832:                };
833:            }
834:
835:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.