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.PolicyMapKey;
32 import com.sun.xml.internal.ws.policy.PolicySubject;
33 import com.sun.xml.internal.ws.policy.sourcemodel.PolicySourceModel;
35 import java.util.Collection;
36 import java.util.Map;
37 import javax.xml.namespace.QName;
39 /**
40 *
41 * @author Jakub Podlesak (jakub.podlesak at sun.com)
42 */
43 final class BuilderHandlerMessageScope extends BuilderHandler{
44 private final QName service;
45 private final QName port;
46 private final QName operation;
47 private final QName message;
48 private final Scope scope;
50 enum Scope{
51 InputMessageScope,
52 OutputMessageScope,
53 FaultMessageScope,
54 };
57 /** Creates a new instance of WSDLServiceScopeBuilderHandler */
58 BuilderHandlerMessageScope(
59 Collection<String> policyURIs
60 , Map<String,PolicySourceModel> policyStore
61 , Object policySubject
62 , Scope scope
63 , QName service, QName port, QName operation, QName message) {
65 super(policyURIs, policyStore, policySubject);
66 this.service = service;
67 this.port = port;
68 this.operation = operation;
69 this.scope = scope;
70 this.message = message;
71 }
73 /**
74 * Multiple bound operations may refer to the same fault messages. This would result
75 * in multiple builder handlers referring to the same policies. This method allows
76 * to sort out these duplicate handlers.
77 */
78 @Override
79 public boolean equals(final Object obj) {
80 if (this == obj) {
81 return true;
82 }
84 if (!(obj instanceof BuilderHandlerMessageScope)) {
85 return false;
86 }
88 final BuilderHandlerMessageScope that = (BuilderHandlerMessageScope) obj;
89 boolean result = true;
91 result = result && ((this.policySubject == null) ? ((that.policySubject == null) ? true : false) :this.policySubject.equals(that.policySubject));
92 result = result && ((this.scope == null) ? ((that.scope == null) ? true : false) :this.scope.equals(that.scope));
93 result = result && ((this.message == null) ? ((that.message == null) ? true : false) :this.message.equals(that.message));
94 if (this.scope != Scope.FaultMessageScope) {
95 result = result && ((this.service == null) ? ((that.service == null) ? true : false) :this.service.equals(that.service));
96 result = result && ((this.port == null) ? ((that.port == null) ? true : false) :this.port.equals(that.port));
97 result = result && ((this.operation == null) ? ((that.operation == null) ? true : false) :this.operation.equals(that.operation));
98 }
100 return result;
101 }
103 @Override
104 public int hashCode() {
105 int hashCode = 19;
106 hashCode = 31 * hashCode + (policySubject == null ? 0 : policySubject.hashCode());
107 hashCode = 31 * hashCode + (message == null ? 0 : message.hashCode());
108 hashCode = 31 * hashCode + (scope == null ? 0 : scope.hashCode());
109 if (scope != Scope.FaultMessageScope) {
110 hashCode = 31 * hashCode + (service == null ? 0 : service.hashCode());
111 hashCode = 31 * hashCode + (port == null ? 0 : port.hashCode());
112 hashCode = 31 * hashCode + (operation == null ? 0 : operation.hashCode());
113 }
114 return hashCode;
115 }
117 protected void doPopulate(final PolicyMapExtender policyMapExtender) throws PolicyException{
118 PolicyMapKey mapKey;
120 if (Scope.FaultMessageScope == scope) {
121 mapKey = PolicyMap.createWsdlFaultMessageScopeKey(service, port, operation, message);
122 } else { // in|out msg scope
123 mapKey = PolicyMap.createWsdlMessageScopeKey(service, port, operation);
124 }
126 if (Scope.InputMessageScope == scope) {
127 for (PolicySubject subject:getPolicySubjects()) {
128 policyMapExtender.putInputMessageSubject(mapKey, subject);
129 }
130 } else if (Scope.OutputMessageScope == scope) {
131 for (PolicySubject subject:getPolicySubjects()) {
132 policyMapExtender.putOutputMessageSubject(mapKey, subject);
133 }
134 } else if (Scope.FaultMessageScope == scope) {
135 for (PolicySubject subject : getPolicySubjects()) {
136 policyMapExtender.putFaultMessageSubject(mapKey, subject);
137 }
138 }
139 }
140 }