Newer
Older
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
/**
* Protocol port factory (Singleton)
*
* @author ETSI / STF424
* @version $URL$
* $Id$
*
*/
package org.etsi.its.adapter.ports;
import java.lang.reflect.Constructor;
import java.util.Map;
import java.util.TreeMap;
/**
* Protocol port factory (Singleton)
*/
public class ProtocolPortFactory {
/**
* Unique instance of the factory
*/
private static ProtocolPortFactory instance = new ProtocolPortFactory();
/**
* List of the registered protocol port types
*/
protected Map<String, Class<? extends ProtocolPort>> ports = new TreeMap<String, Class<? extends ProtocolPort>>();
/**
* Private constructor (Singleton pattern)
*/
private ProtocolPortFactory() {
// Register the ports - Refer to TTCN-3 component LibIts_TestSystem.ItsSystem for ports name
ports.put("camPort", CamPort.class);
ports.put("denmPort", DenmPort.class);
ports.put("btpPort", BtpPort.class);
ports.put("geoNetworkingPort", GnPort.class);
ports.put("ipv6OverGeoNetworkingPort", Gn6Port.class);
ports.put("v2gPort", V2GPort.class);
}
/**
* Gets the unique factory instance
* @return ProtocolPortFactory instance
*/
public static ProtocolPortFactory getInstance(){
return instance;
}
/**
* Creates a port of the desired type
* @param portName Name of the port
* @param componentName Name of the component owning the port instance
* @param lowerStackDesc Description of the lower protocol stack of the port in the form "Layer/Layer/Layer/..."
* @param linkLayerAddress Link-layer address to be used by this port as source address (null if not applicable)
* @return Protocol port instance
*/
public ProtocolPort createPort(String portName, String componentName, String lowerStackDesc, String linkLayerAddress) {
ProtocolPort port = null;
Class<?>[] ctorParams = {portName.getClass(), componentName.getClass(), lowerStackDesc.getClass(), linkLayerAddress.getClass()};
try {
Class<? extends ProtocolPort> cls = ports.get(portName);
if (cls == null) {
throw new RuntimeException("No class registered under " + portName);
}
Constructor<? extends ProtocolPort> ctor = cls.getConstructor(ctorParams);
port = ctor.newInstance(portName, componentName, lowerStackDesc, linkLayerAddress);
} catch (Exception ex) {
ex.printStackTrace();
}
return port;
}
}