Skip to main content
summaryrefslogtreecommitdiffstats
blob: bdd1413277ce71998e5d8c0f33033ff86c5e02ab (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
/*******************************************************************************
 * Copyright (c) 2007 Versant Corp.
 * 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:
 *     Markus Kuppe
 ******************************************************************************/
package org.eclipse.ecf.provider.jslp.identity;

import ch.ethz.iks.slp.ServiceType;
import ch.ethz.iks.slp.ServiceURL;
import org.eclipse.ecf.core.identity.*;
import org.eclipse.ecf.discovery.identity.*;
import org.eclipse.ecf.internal.provider.jslp.Messages;

public class JSLPNamespace extends Namespace {
	private static final String JSLP_SCHEME = "jslp"; //$NON-NLS-1$

	private static final long serialVersionUID = -3041453162456476102L;

	public static final String NAME = "ecf.namespace.slp"; //$NON-NLS-1$

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.core.identity.Namespace#createInstance(java.lang.Object[])
	 */
	public ID createInstance(Object[] parameters) {
		// error case
		if (parameters == null || parameters.length < 1 || parameters.length > 3) {
			throw new IDCreateException(Messages.JSLPNamespace_2);

			// error case
		} else if (parameters[0] == null || parameters[0].equals("")) { //$NON-NLS-1$
			throw new IDCreateException(Messages.JSLPNamespace_3);

			// create by jSLP ServiceURL
		} else if (parameters[0] instanceof ServiceURL) {
			ServiceURL anURL = (ServiceURL) parameters[0];
			IServiceTypeID stid = new JSLPServiceTypeID(this, anURL, (String[]) parameters[2]);
			String serviceName = (String) (parameters[1] != null ? parameters[1] : anURL.getHost());
			return new JSLPServiceID(this, stid, serviceName);

			// conversion call where conversion isn't necessary
		} else if (parameters[0] instanceof JSLPServiceID) {
			return (ID) parameters[0];

			// convert from IServiceID to IServiceTypeID, String
		} else if (parameters[0] instanceof IServiceID && parameters.length == 1) {
			IServiceID anId = (IServiceID) parameters[0];
			Object[] newParams = new Object[2];
			newParams[0] = anId.getServiceTypeID();
			newParams[1] = anId.getName();
			return createInstance(newParams);

			// create by ECF discovery generic IServiceTypeID (but not JSLPServiceID!!!)
		} else if (parameters[0] instanceof IServiceTypeID) {
			IServiceTypeID stid = (IServiceTypeID) parameters[0];
			parameters[0] = stid.getName();
			return createInstance(parameters);

			// create by jSLP ServiceType
		} else if (parameters[0] instanceof ServiceType) {
			IServiceTypeID stid = new JSLPServiceTypeID(this, (ServiceType) parameters[0]);
			return new JSLPServiceID(this, stid, (String) parameters[1]);

			// create by jSLP ServiceType String representation (from external)
		} else if (parameters[0] instanceof String && ((String) parameters[0]).startsWith("service:")) { //$NON-NLS-1$
			parameters[0] = new ServiceType((String) parameters[0]);
			return createInstance(parameters);

			// create by ECF discovery generic String representation
		} else if (parameters[0] instanceof String && ((String) parameters[0]).startsWith("_")) { //$NON-NLS-1$
			String type = (String) parameters[0];
			String name = (String) parameters[1];
			IServiceTypeID stid = new JSLPServiceTypeID(this, new ServiceTypeID(this, type));
			return new JSLPServiceID(this, stid, name);

			// create by "jslp:..."
		} else if (parameters[0] instanceof String && ((String) parameters[0]).startsWith(getScheme() + Namespace.SCHEME_SEPARATOR)) {
			String str = (String) parameters[0];
			int index = str.indexOf(Namespace.SCHEME_SEPARATOR);
			parameters[0] = str.substring(index + 1);
			return createInstance(parameters);

			// error case second parameter not a String
		} else if (parameters.length == 2 && parameters[1] != null && !(parameters[1] instanceof String)) {
			throw new IDCreateException(Messages.JSLPNamespace_4);

			// error case
		} else {
			throw new IDCreateException(Messages.JSLPNamespace_3);
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.core.identity.Namespace#getScheme()
	 */
	public String getScheme() {
		return JSLP_SCHEME;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.core.identity.Namespace#getSupportedParameterTypesForCreateInstance()
	 */
	public Class[][] getSupportedParameterTypes() {
		return new Class[][] { {String.class}, {String.class, String.class}, {ServiceURL.class, String[].class, String.class}, {IServiceTypeID.class}, {IServiceID.class}, {ServiceType.class, String.class}};
	}
}

Back to the top