Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7466c048f05d0a52446be0f7c93b29b46d59194b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*******************************************************************************
 * Copyright (c) 2004 Composent, Inc. and others. All rights reserved. This
 * program and the accompanying materials are made available under the terms of
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: Composent, Inc. - initial API and implementation
 ******************************************************************************/
package org.eclipse.ecf.discovery.identity;

import java.net.URI;
import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.core.identity.BaseID;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.discovery.IServiceInfo;

/**
 * Service identity type. ServiceIDs are IDs that uniquely identify a remote
 * service. Subclasses may be created as appropriate.
 */
public class ServiceID extends BaseID implements IServiceID {

	private static final long serialVersionUID = 4362768703249025783L;

	/**
	 * @since 3.0
	 */
	protected IServiceInfo serviceInfo;

	protected IServiceTypeID type;

	/**
	 * @since 3.0
	 */
	protected URI location;

	/**
	 * @param namespace
	 *            namespace should not be <code>null</code>
	 * @param type
	 *            service type ID should not be <code>null</code>
	 * @param anURI
	 *            uri for service location should not be <code>null</code>
	 * @since 3.0
	 */
	protected ServiceID(Namespace namespace, IServiceTypeID type, URI anURI) {
		super(namespace);
		Assert.isNotNull(type);
		Assert.isNotNull(anURI);
		this.type = type;
		this.location = anURI;
	}

	protected String getFullyQualifiedName() {
		return type.getName() + "@" + location; //$NON-NLS-1$
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.core.identity.BaseID#namespaceCompareTo(org.eclipse.ecf
	 * .core.identity.BaseID)
	 */
	protected int namespaceCompareTo(BaseID o) {
		if (o instanceof ServiceID) {
			final ServiceID other = (ServiceID) o;
			final String typename = other.getFullyQualifiedName();
			return getFullyQualifiedName().compareTo(typename);
		}
		return 1;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.core.identity.BaseID#namespaceEquals(org.eclipse.ecf.
	 * core.identity.BaseID)
	 */
	protected boolean namespaceEquals(BaseID o) {
		if (o == null)
			return false;
		if (o instanceof ServiceID) {
			final ServiceID other = (ServiceID) o;
			if (other.getName().equals(getName())) {
				return true;
			}
		}
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.core.identity.BaseID#namespaceGetName()
	 */
	protected String namespaceGetName() {
		return getFullyQualifiedName();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.core.identity.BaseID#namespaceHashCode()
	 */
	protected int namespaceHashCode() {
		return getFullyQualifiedName().hashCode();
	}

	/**
	 * Get service type for this ID.
	 * 
	 * @return String service type. Will not be <code>null</code>.
	 */
	public String getServiceType() {
		return type.getName();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.discovery.identity.IServiceID#getServiceTypeID()
	 */
	public IServiceTypeID getServiceTypeID() {
		return type;
	}

	/**
	 * Get service name for this ID.
	 * 
	 * @return String service name. May be <code>null</code>.
	 */
	public String getServiceName() {
		return serviceInfo.getServiceName();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		final StringBuffer buf = new StringBuffer("ServiceID["); //$NON-NLS-1$
		buf.append("type=").append(type).append(";location=").append(getLocation()).append( //$NON-NLS-1$ //$NON-NLS-2$
				";full=" + getFullyQualifiedName()).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
		return buf.toString();
	}

	/**
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.discovery.identity.IServiceID#getLocation()
	 * @since 3.0
	 */
	public URI getLocation() {
		return location;
	}

	/**
	 * @return the serviceInfo
	 * @since 3.0
	 */
	public IServiceInfo getServiceInfo() {
		return serviceInfo;
	}

	/**
	 * @param serviceInfo
	 *            the serviceInfo to set
	 * @since 3.0
	 */
	public void setServiceInfo(IServiceInfo serviceInfo) {
		this.serviceInfo = serviceInfo;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 * 
	 * @since 3.0
	 */
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((location == null) ? 0 : location.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 * 
	 * @since 3.0
	 */
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		ServiceID other = (ServiceID) obj;
		if (location == null) {
			if (other.location != null)
				return false;
		} else if (!location.equals(other.location))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}
}

Back to the top