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.jaxws;
038:
039: import com.sun.xml.ws.policy.PolicyException;
040: import com.sun.xml.ws.policy.PolicyMap;
041: import com.sun.xml.ws.policy.PolicyMapExtender;
042: import com.sun.xml.ws.policy.PolicyMapKey;
043: import com.sun.xml.ws.policy.PolicySubject;
044: import com.sun.xml.ws.policy.sourcemodel.PolicySourceModel;
045: import java.util.Collection;
046: import java.util.Map;
047: import javax.xml.namespace.QName;
048:
049: /**
050: *
051: * @author Jakub Podlesak (jakub.podlesak at sun.com)
052: */
053: final class BuilderHandlerMessageScope extends BuilderHandler {
054: private final QName service;
055: private final QName port;
056: private final QName operation;
057: private final QName message;
058: private final Scope scope;
059:
060: enum Scope {
061: InputMessageScope, OutputMessageScope, FaultMessageScope,
062: };
063:
064: /** Creates a new instance of WSDLServiceScopeBuilderHandler */
065: BuilderHandlerMessageScope(Collection<String> policyURIs,
066: Map<String, PolicySourceModel> policyStore,
067: Object policySubject, Scope scope, QName service,
068: QName port, QName operation, QName message) {
069:
070: super (policyURIs, policyStore, policySubject);
071: this .service = service;
072: this .port = port;
073: this .operation = operation;
074: this .scope = scope;
075: this .message = message;
076: }
077:
078: /**
079: * Multiple bound operations may refer to the same fault messages. This would result
080: * in multiple builder handlers referring to the same policies. This method allows
081: * to sort out these duplicate handlers.
082: */
083: public boolean equals(final Object obj) {
084: if (this == obj) {
085: return true;
086: }
087:
088: if (!(obj instanceof BuilderHandlerMessageScope)) {
089: return false;
090: }
091:
092: final BuilderHandlerMessageScope that = (BuilderHandlerMessageScope) obj;
093: boolean result = true;
094:
095: result = result
096: && ((this .policySubject == null) ? ((that.policySubject == null) ? true
097: : false)
098: : this .policySubject.equals(that.policySubject));
099: result = result
100: && ((this .scope == null) ? ((that.scope == null) ? true
101: : false) : this .scope.equals(that.scope));
102: result = result
103: && ((this .message == null) ? ((that.message == null) ? true
104: : false)
105: : this .message.equals(that.message));
106: if (this .scope != Scope.FaultMessageScope) {
107: result = result
108: && ((this .service == null) ? ((that.service == null) ? true
109: : false)
110: : this .service.equals(that.service));
111: result = result
112: && ((this .port == null) ? ((that.port == null) ? true
113: : false)
114: : this .port.equals(that.port));
115: result = result
116: && ((this .operation == null) ? ((that.operation == null) ? true
117: : false)
118: : this .operation.equals(that.operation));
119: }
120:
121: return result;
122: }
123:
124: public int hashCode() {
125: int hashCode = 19;
126: hashCode = 31
127: * hashCode
128: + (policySubject == null ? 0 : policySubject.hashCode());
129: hashCode = 31 * hashCode
130: + (message == null ? 0 : message.hashCode());
131: hashCode = 31 * hashCode
132: + (scope == null ? 0 : scope.hashCode());
133: if (scope != Scope.FaultMessageScope) {
134: hashCode = 31 * hashCode
135: + (service == null ? 0 : service.hashCode());
136: hashCode = 31 * hashCode
137: + (port == null ? 0 : port.hashCode());
138: hashCode = 31 * hashCode
139: + (operation == null ? 0 : operation.hashCode());
140: }
141: return hashCode;
142: }
143:
144: protected void doPopulate(final PolicyMapExtender policyMapExtender)
145: throws PolicyException {
146: PolicyMapKey mapKey;
147:
148: if (Scope.FaultMessageScope == scope) {
149: mapKey = PolicyMap.createWsdlFaultMessageScopeKey(service,
150: port, operation, message);
151: } else { // in|out msg scope
152: mapKey = PolicyMap.createWsdlMessageScopeKey(service, port,
153: operation);
154: }
155:
156: if (Scope.InputMessageScope == scope) {
157: for (PolicySubject subject : getPolicySubjects()) {
158: policyMapExtender.putInputMessageSubject(mapKey,
159: subject);
160: }
161: } else if (Scope.OutputMessageScope == scope) {
162: for (PolicySubject subject : getPolicySubjects()) {
163: policyMapExtender.putOutputMessageSubject(mapKey,
164: subject);
165: }
166: } else if (Scope.FaultMessageScope == scope) {
167: for (PolicySubject subject : getPolicySubjects()) {
168: policyMapExtender.putFaultMessageSubject(mapKey,
169: subject);
170: }
171: }
172: }
173: }
|