1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.desy.acop.transport;
24
25 import java.util.Vector;
26 import de.desy.acop.transport.simulator.AcopTransportSimulator;
27 import de.desy.acop.transport.tine.AcopTransportTine;
28
29
30
31
32
33 public class AcopTransportFactory
34 {
35 private static AcopTransportFactory instance;
36 protected String defaultProtocol;
37 protected Vector atps = new Vector();
38 protected String[] acopProtocolList;
39 public synchronized static AcopTransportFactory getInstance()
40 {
41 if (instance == null) instance = new AcopTransportFactory();
42 return instance;
43 }
44 int addProtocol(AcopTransportPlug atp)
45 {
46 for (int i = 0; i < atps.size(); i++)
47 {
48 if ((AcopTransportPlug) atps.elementAt(i) == atp) return 0;
49 }
50 atps.addElement(atp);
51 System.out.println("add protocol " + atp.getPlugName());
52 if (defaultProtocol == null) setDefaultProtocol(atp.getPlugName());
53 return 0;
54 }
55 AcopTransportFactory()
56 {
57
58 addProtocol(new AcopTransportTine());
59 addProtocol(new AcopTransportSimulator());
60 }
61 int setDefaultProtocol(String protocolName)
62 {
63 for (int i = 0; i < atps.size(); i++)
64 {
65 if (((AcopTransportPlug) atps.elementAt(i)).getPlugName() == protocolName)
66 {
67 defaultProtocol = new String(protocolName);
68 System.out.println("Use protocol " + protocolName + " as default");
69 return 0;
70 }
71 }
72 return -1;
73 }
74 public String getDefaultProtocol()
75 {
76 return defaultProtocol;
77 }
78 public String[] getProtocolList()
79 {
80 AcopTransportPlug atp;
81 if (acopProtocolList == null)
82 {
83 acopProtocolList = new String[atps.size()];
84 for (int i = 0; i < atps.size(); i++)
85 {
86 atp = (AcopTransportPlug) atps.elementAt(i);
87 acopProtocolList[i] = atp.getPlugName();
88 }
89 }
90 return acopProtocolList;
91 }
92 public AcopTransportPlug getProtocol(String protocolName)
93 {
94 AcopTransportPlug atp;
95 String protocol = protocolName;
96 if (protocol == null || protocol.length() == 0) protocol = getDefaultProtocol();
97 for (int i = 0; i < atps.size(); i++)
98 {
99 atp = (AcopTransportPlug) atps.elementAt(i);
100 if (atp.getPlugName().compareTo(protocol) == 0) return atp;
101 }
102 return null;
103 }
104 protected void halt()
105 {
106 AcopTransportPlug atp;
107 AcopTransportRequest atr = new AcopTransportRequest();
108 for (int i = 0; i < atps.size(); i++)
109 {
110 atp = (AcopTransportPlug) atps.elementAt(i);
111 atr.accessMethod = AcopTransportAccessMethods.SHUTDOWN;
112 atp.handleRequest(atr);
113 }
114 }
115 }