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: package com.sun.xml.ws.handler;
037:
038: import com.sun.xml.ws.api.BindingID;
039: import com.sun.xml.ws.client.WSServiceDelegate;
040:
041: import javax.xml.namespace.QName;
042: import javax.xml.ws.handler.PortInfo;
043:
044: /**
045: * <p>Implementation of the PortInfo interface. This is just a simple
046: * class used to hold the info necessary to uniquely identify a port,
047: * including the port name, service name, and binding ID. This class
048: * is only used on the client side.
049: *
050: * <p>An instance is created by
051: * {@link WSServiceDelegate} when used to
052: * place a handler chain into the HandlerResolver map. Another is
053: * created later by
054: * {@link com.sun.xml.ws.client.WSServiceDelegate} to retrieve the
055: * necessary handler chain to set on a binding instance.
056: *
057: * @see WSServiceDelegate
058: * @see com.sun.xml.ws.client.HandlerResolverImpl
059: *
060: * @author WS Development Team
061: */
062: public class PortInfoImpl implements PortInfo {
063:
064: private BindingID bindingId;
065: private QName portName;
066: private QName serviceName;
067:
068: /**
069: * The class is constructed with the information needed to identify
070: * a port. This information cannot be changed later.
071: *
072: * @param bindingId The binding ID string.
073: * @param portName The QName of the port.
074: * @param serviceName The QName of the service.
075: */
076: public PortInfoImpl(BindingID bindingId, QName portName,
077: QName serviceName) {
078: if (bindingId == null) {
079: throw new RuntimeException("bindingId cannot be null");
080: }
081: if (portName == null) {
082: throw new RuntimeException("portName cannot be null");
083: }
084: if (serviceName == null) {
085: throw new RuntimeException("serviceName cannot be null");
086: }
087: this .bindingId = bindingId;
088: this .portName = portName;
089: this .serviceName = serviceName;
090: }
091:
092: public String getBindingID() {
093: return bindingId.toString();
094: }
095:
096: public QName getPortName() {
097: return portName;
098: }
099:
100: public QName getServiceName() {
101: return serviceName;
102: }
103:
104: /**
105: * Object.equals is overridden here so that PortInfo objects
106: * can be compared when using them as keys in the map in
107: * HandlerResolverImpl. This method relies on the equals()
108: * methods of java.lang.String and javax.xml.namespace.QName.
109: *
110: * @param obj The PortInfo object to test for equality.
111: * @return True if they match, and false if they do not or
112: * if the object passed in is not a PortInfo.
113: */
114: public boolean equals(Object obj) {
115: if (obj instanceof PortInfo) {
116: PortInfo info = (PortInfo) obj;
117: if (bindingId.toString().equals(info.getBindingID())
118: && portName.equals(info.getPortName())
119: && serviceName.equals(info.getServiceName())) {
120: return true;
121: }
122: }
123: return false;
124: }
125:
126: /**
127: * Needed so PortInfoImpl can be used as a key in a map. This
128: * method just delegates to the hashCode method of java.lang.String.
129: */
130: public int hashCode() {
131: return bindingId.hashCode();
132: }
133:
134: }
|