001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)RegistrationInfo.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.binding.proxy;
030:
031: import com.sun.jbi.binding.proxy.connection.Event;
032: import com.sun.jbi.binding.proxy.connection.EventInfo;
033:
034: import javax.jbi.servicedesc.ServiceEndpoint;
035:
036: import javax.xml.namespace.QName;
037:
038: /**
039: * Represents a service or endpoint registration in the distributed registry.
040: * @author Sun Microsystems, Inc
041: */
042: public class RegistrationInfo extends EventInfo implements
043: java.io.Serializable {
044: private QName mServiceName;
045: private String mEndpointName;
046: private String mInstanceId;
047: private transient ServiceEndpoint mEndpointReference;
048: private transient String mAction;
049: private transient ClassLoader mClassLoader;
050:
051: public static final String EVENTNAME = "Registration";
052: public static final String ACTION_ADD = "Add";
053: public static final String ACTION_REMOVE = "Remove";
054:
055: /**
056: * Constructor.
057: */
058: public RegistrationInfo(ServiceEndpoint reference,
059: String instanceId, ClassLoader classLoader, String action) {
060: mServiceName = reference.getServiceName();
061: mEndpointName = reference.getEndpointName();
062: mInstanceId = instanceId;
063: mClassLoader = classLoader;
064: mAction = action;
065: }
066:
067: public String getEventName() {
068: return (EVENTNAME);
069: }
070:
071: /**
072: * Accessor for ServiceName.
073: * @return QName containing the ServiceName.
074: */
075: public QName getServiceName() {
076: return (mServiceName);
077: }
078:
079: /**
080: * Accessor for EndpointName.
081: * @return String containing the EndpointName.
082: */
083: public String getEndpointName() {
084: return (mEndpointName);
085: }
086:
087: /**
088: * Accessor for InstanceId.
089: * @return String containing the InstanceId.
090: */
091: public String getInstanceId() {
092: return (mInstanceId);
093: }
094:
095: /**
096: * Accessor for Action.
097: * @return String containing the Action.
098: */
099: public String getAction() {
100: return (mAction);
101: }
102:
103: /**
104: * Accesor for ClassLoader.
105: * @return ClassLoader for this registration.
106: */
107: public ClassLoader getClassLoader() {
108: return (mClassLoader);
109: }
110:
111: public RegistrationInfo(Event event)
112: throws com.sun.jbi.binding.proxy.connection.EventException {
113: super (event);
114:
115: String namespace;
116: String local;
117:
118: mAction = event.getString();
119: mInstanceId = event.getString();
120: namespace = event.getString();
121: local = event.getString();
122: mServiceName = new QName(namespace, local);
123: mEndpointName = event.getString();
124: }
125:
126: public void encodeEvent(Event event)
127: throws com.sun.jbi.binding.proxy.connection.EventException {
128: event.putString(mAction);
129: event.putString(mInstanceId);
130: event.putString(mServiceName.getNamespaceURI());
131: event.putString(mServiceName.getLocalPart());
132: event.putString(mEndpointName);
133: }
134:
135: public int hashCode() {
136: int hash = 0;
137: String value;
138:
139: if (mServiceName != null) {
140: if ((value = mServiceName.getNamespaceURI()) != null) {
141: hash ^= hash + value.hashCode();
142: }
143: if ((value = mServiceName.getLocalPart()) != null) {
144: hash ^= hash + value.hashCode();
145: }
146: }
147: if (mEndpointName != null) {
148: hash ^= hash + mEndpointName.hashCode();
149: }
150: return (hash);
151: }
152:
153: public boolean equals(Object equalTo) {
154: RegistrationInfo ri;
155:
156: if (equalTo instanceof RegistrationInfo) {
157: ri = (RegistrationInfo) equalTo;
158: if (mServiceName == null) {
159: if (ri.getServiceName() != null) {
160: return (false);
161: }
162: } else {
163: if (!mServiceName.getNamespaceURI().equals(
164: ri.getServiceName().getNamespaceURI())
165: || !mServiceName.getLocalPart().equals(
166: ri.getServiceName().getLocalPart())) {
167: return (false);
168: }
169: }
170: if (mEndpointName == null) {
171: if (ri.getEndpointName() != null) {
172: return (false);
173: }
174: } else {
175: if (!mEndpointName.equals(ri.getEndpointName())) {
176: return (false);
177: }
178: }
179:
180: return (true);
181: }
182: return (false);
183: }
184:
185: public String toString() {
186: StringBuffer sb = new StringBuffer();
187:
188: sb.append(" InstanceId (");
189: sb.append(mInstanceId);
190: sb.append(")\n Service (");
191: sb.append(mServiceName.toString());
192: sb.append(")\n Endpoint (");
193: sb.append(mEndpointName);
194: sb.append(")\n");
195: return (sb.toString());
196: }
197: }
|