Skip to main content
summaryrefslogtreecommitdiffstats
blob: ff6eb8566262f7253a7666c2281596acc9092cce (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
/*******************************************************************************
 * 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 (mkuppe <at> versant <dot> com) - initial API and implementation
 ******************************************************************************/

package org.eclipse.ecf.provider.discovery;

import java.util.*;
import org.eclipse.ecf.core.*;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.core.provider.IContainerInstantiator;
import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
import org.eclipse.ecf.discovery.IDiscoveryLocator;

public class CompositeDiscoveryContainerInstantiator implements IContainerInstantiator {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.core.provider.IContainerInstantiator#createInstance(org.eclipse.ecf.core.ContainerTypeDescription,
	 *      java.lang.Object[])
	 */
	public IContainer createInstance(final ContainerTypeDescription description, final Object[] parameters) throws ContainerCreateException {

		try {
			final IContainerFactory factory = ContainerFactory.getDefault();
			final Set containers = new HashSet();
			final List list = factory.getDescriptions();
			for (final Iterator itr = list.iterator(); itr.hasNext();) {
				final ContainerTypeDescription ctd = (ContainerTypeDescription) itr.next();
				final String name = ctd.getName();
				// do not call ourself
				if (name.startsWith(CompositeDiscoveryContainer.NAME)) {
					continue;
				}
				if (name.startsWith("ecf.discovery.") && (name.endsWith(".locator") || name.endsWith(".advertiser"))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
					final IContainer container = factory.createContainer(ctd.getName());
					containers.add(container);
				}
			}
			return new CompositeDiscoveryContainer(containers);
		} catch (final IDCreateException e) {
			final ContainerCreateException excep = new ContainerCreateException(e.getMessage());
			excep.setStackTrace(e.getStackTrace());
			throw excep;
		} catch (final ContainerCreateException e) {
			final ContainerCreateException excep = new ContainerCreateException(e.getMessage());
			excep.setStackTrace(e.getStackTrace());
			throw excep;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.core.provider.IContainerInstantiator#getSupportedAdapterTypes(org.eclipse.ecf.core.ContainerTypeDescription)
	 */
	public String[] getSupportedAdapterTypes(final ContainerTypeDescription description) {
		return new String[] {IDiscoveryAdvertiser.class.getName(), IDiscoveryLocator.class.getName()};
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.core.provider.IContainerInstantiator#getSupportedParameterTypes(org.eclipse.ecf.core.ContainerTypeDescription)
	 */
	public Class[][] getSupportedParameterTypes(final ContainerTypeDescription description) {
		return new Class[0][0];
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.core.provider.IContainerInstantiator#getSupportedIntents(org.eclipse.ecf.core.ContainerTypeDescription)
	 */
	public String[] getSupportedIntents(ContainerTypeDescription description) {
		return null;
	}

}

Back to the top