Thu, 31 Aug 2017 15:18:52 +0800
merge
1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.xml.internal.ws.policy.jaxws;
28 import com.sun.xml.internal.ws.policy.PolicyException;
29 import com.sun.xml.internal.ws.policy.PolicyMap;
30 import com.sun.xml.internal.ws.policy.PolicyMapExtender;
31 import com.sun.xml.internal.ws.policy.PolicyMapMutator;
33 import java.util.Arrays;
34 import java.util.HashSet;
35 import java.util.LinkedList;
36 import java.util.List;
38 /**
39 * Used for populating changes into PolicyMap. Once a PolicyMap is created
40 * PolicyMapBuilder notifies all the registered WSPolicyBuilderHandler to populate
41 * changes to the PolicyMap.
42 *
43 *
44 * @author Jakub Podlesak (jakub.podlesak at sun.com)
45 */
46 class PolicyMapBuilder {
47 /**
48 * policyBuilders should contain list of registered PolicyBuilders
49 */
50 private List<BuilderHandler> policyBuilders = new LinkedList<BuilderHandler>();
52 /**
53 * Creates a new instance of PolicyMapBuilder
54 */
55 PolicyMapBuilder() {
56 // nothing to initialize
57 }
59 /**
60 * Registers another builder, which has to be notified after a new
61 * PolicyMap is created in order to populate it's changes.
62 *
63 */
64 void registerHandler(final BuilderHandler builder){
65 if (null != builder) {
66 policyBuilders.add(builder);
67 }
68 }
70 /**
71 * Iterates all the registered PolicyBuilders and lets them populate
72 * their changes into PolicyMap. Registers mutators given as a parameter
73 * with the newly created map.
74 */
75 PolicyMap getPolicyMap(final PolicyMapMutator... externalMutators) throws PolicyException{
76 return getNewPolicyMap(externalMutators);
77 }
80 /**
81 * Iterates all the registered PolicyBuilders and lets them populate
82 * their changes into PolicyMap. Registers mutators from collection given as a parameter
83 * with the newly created map.
84 */
85 private PolicyMap getNewPolicyMap(final PolicyMapMutator... externalMutators) throws PolicyException{
86 final HashSet<PolicyMapMutator> mutators = new HashSet<PolicyMapMutator>();
87 final PolicyMapExtender myExtender = PolicyMapExtender.createPolicyMapExtender();
88 mutators.add(myExtender);
89 if (null != externalMutators) {
90 mutators.addAll(Arrays.asList(externalMutators));
91 }
92 final PolicyMap policyMap = PolicyMap.createPolicyMap(mutators);
93 for(BuilderHandler builder : policyBuilders){
94 builder.populate(myExtender);
95 }
96 return policyMap;
97 }
99 void unregisterAll() {
100 this.policyBuilders = null;
101 }
102 }