blob: 7de4e035a4555537ae7f65d912d352fd5a0d000e (
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
|
/*
* Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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:
* Eike Stepper - initial API and implementation
*/
package org.eclipse.net4j;
import org.eclipse.net4j.protocol.IProtocol;
import org.eclipse.net4j.protocol.IProtocolProvider;
import org.eclipse.net4j.util.factory.IFactory;
import org.eclipse.net4j.util.registry.HashMapRegistry;
import org.eclipse.net4j.util.registry.IRegistry;
/**
* Factory-based {@link IProtocolProvider protocol provider}.
*
* @author Eike Stepper
* @since 2.0
*/
public class FactoriesProtocolProvider implements IProtocolProvider
{
private IRegistry<String, IFactory> registry;
public FactoriesProtocolProvider()
{
}
public FactoriesProtocolProvider(IRegistry<String, IFactory> registry)
{
setRegistry(registry);
}
public FactoriesProtocolProvider(IFactory factory)
{
addFactory(factory);
}
public IRegistry<String, IFactory> getRegistry()
{
if (registry == null)
{
registry = new HashMapRegistry<String, IFactory>();
}
return registry;
}
public void setRegistry(IRegistry<String, IFactory> registry)
{
this.registry = registry;
}
public void addFactory(IFactory factory)
{
getRegistry().put(factory.getKey().getType(), factory);
}
public IProtocol<?> getProtocol(String type)
{
IFactory factory = registry.get(type);
if (factory != null)
{
return (IProtocol<?>)factory.create(null);
}
return null;
}
}
|