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 javax.xml.namespace.QName;
042:
043: /**
044: * This class provides implementation of PolicyMapKey interface to be used in connection with {@link PolicyMap}.
045: * Instances of the class are created by a call to one of {@link PolicyMap} <code>createWsdl<emph>XXX</emph>PolicyMapKey(...)</code>
046: * methods.
047: * <p/>
048: * The class wraps scope information and adds a package setter method to allow injection of actual equality comparator/tester. This injection
049: * is made within a <code>get...</code> call on {@link PolicyMap}, before the actual scope map search is performed.
050: *
051: *
052: * @author Marek Potociar (marek.potociar at sun.com)
053: */
054: final public class PolicyMapKey {
055: private static final PolicyLogger LOGGER = PolicyLogger
056: .getLogger(PolicyMapKey.class);
057:
058: QName service;
059: QName port;
060: QName operation;
061: QName faultMessage;
062: // QName inputMessage;
063: // QName outputMessage;
064:
065: private PolicyMapKeyHandler handler;
066:
067: PolicyMapKey(final QName service, final QName port,
068: final QName operation) {
069: this .service = service;
070: this .port = port;
071: this .operation = operation;
072:
073: // this.inputMessage = inputMessage;
074: // this.outputMessage = outputMessage;
075: }
076:
077: PolicyMapKey(final QName service, final QName port,
078: final QName operation, final QName faultMessage) {
079: this .service = service;
080: this .port = port;
081: this .operation = operation;
082:
083: // this.inputMessage = inputMessage;
084: // this.outputMessage = outputMessage;
085:
086: this .faultMessage = faultMessage;
087: }
088:
089: PolicyMapKey(final PolicyMapKey that) {
090: this .service = that.service;
091: this .port = that.port;
092: this .operation = that.operation;
093: this .faultMessage = that.faultMessage;
094:
095: // this.inputMessage = that.inputMessage;
096: // this.outputMessage = that.outputMessage;
097:
098: this .handler = that.handler;
099: }
100:
101: void setHandler(final PolicyMapKeyHandler handler) {
102: this .handler = handler;
103: }
104:
105: public boolean equals(final Object that) {
106: if (this == that) {
107: return true; // we are lucky here => no special handling is required
108: }
109:
110: if (that == null) {
111: return false;
112: }
113:
114: if (handler == null) {
115: throw LOGGER
116: .logSevereException(new IllegalStateException(
117: LocalizationMessages
118: .WSP_0046_POLICY_MAP_KEY_HANDLER_NOT_SET()));
119: }
120:
121: if (that instanceof PolicyMapKey) {
122: return handler.areEqual(this , (PolicyMapKey) that);
123: } else {
124: return false;
125: }
126: }
127:
128: public int hashCode() {
129: if (handler == null) {
130: throw LOGGER
131: .logSevereException(new IllegalStateException(
132: LocalizationMessages
133: .WSP_0046_POLICY_MAP_KEY_HANDLER_NOT_SET()));
134: }
135:
136: return handler.generateHashCode(this );
137: }
138:
139: public String toString() {
140: final StringBuffer result = new StringBuffer(
141: "WsdlPolicyMapKey(");
142: result.append(this .service).append(", ").append(port).append(
143: ", ").append(operation).append(", ").append(
144: faultMessage);
145: return result.append(")").toString();
146: }
147: }
|