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.displayers.selector;
24
25 import java.util.Map;
26
27 import com.cosylab.gui.displayers.CommonDisplayer;
28
29 import de.desy.acop.displayers.tools.AcopDisplayer;
30 import de.desy.acop.transport.ConnectionFailed;
31 import de.desy.acop.transport.ConnectionParameters;
32 import de.desy.acop.transport.adapters.AdapterFactoryService;
33 import de.desy.tine.definitions.TArrayType;
34
35
36
37
38
39
40
41
42
43 public class SelectorUtilities {
44
45 private static ConnectionParameters latestParameters;
46 private static Map<String, Object> latestCharacteristics;
47
48
49
50
51
52
53
54 public static boolean isChannel(ConnectionParameters param) {
55 try {
56 if (param == null) return false;
57 if (!(param.equals(latestParameters))) {
58 latestCharacteristics = AdapterFactoryService.getInstance().getAdapterFactory().getCharacteristics(param);
59 }
60 latestParameters = param;
61 return ((TArrayType)latestCharacteristics.get("arrayType")).isChannel();
62
63 } catch (ConnectionFailed e) {
64 e.printStackTrace();
65 }
66 return false;
67 }
68
69
70
71
72
73
74
75
76 public static boolean isConnectionParametersValid(ConnectionParameters param) {
77 if (param == null) return false;
78 if (param.getAccessProtocol() == null || param.getAccessMode() == null
79 || param.getDeviceContext() == null || param.getDeviceGroup() == null
80 || param.getDeviceName() == null || param.getDeviceProperty() == null ||
81 param.getAccessProtocol().trim().equals("") || param.getDeviceContext().trim().equals("")
82 || param.getDeviceGroup().trim().equals("")
83 || param.getDeviceName().trim().equals("") || param.getDeviceProperty().trim().equals("")) return false;
84 return true;
85 }
86
87
88
89
90
91
92
93
94
95
96 public static String getInfo(ConnectionParameters param) {
97 try {
98 if (param == null) return "";
99 if (!(param.equals(latestParameters))) {
100 latestCharacteristics = AdapterFactoryService.getInstance().getAdapterFactory().getCharacteristics(param);
101 }
102 latestParameters = param;
103 return (String)latestCharacteristics.get(CommonDisplayer.C_DESCRIPTION);
104
105 } catch (ConnectionFailed e) {
106 e.printStackTrace();
107 }
108 return "N/A";
109 }
110
111
112
113
114
115
116
117 public static int getSequenceLength(ConnectionParameters param) {
118 try {
119 if (param == null) return 1;
120 if (!(param.equals(latestParameters))) {
121 latestCharacteristics = AdapterFactoryService.getInstance().getAdapterFactory().getCharacteristics(param);
122 }
123 latestParameters = param;
124 return ((Integer)latestCharacteristics.get(AcopDisplayer.C_SEQUENCE_LENGTH)).intValue();
125
126 } catch (ConnectionFailed e) {
127 System.out.println(e.getMessage());
128 }
129
130 return 0;
131 }
132
133
134
135
136
137
138
139
140
141 public static String getExtendedDataString(ConnectionParameters param){
142 StringBuilder builder = new StringBuilder();
143 Object extendedData = param.getDynamicParameters();
144 if (extendedData != null) {
145 if (extendedData.getClass() == double[].class) {
146 double[] array = (double[]) extendedData;
147 builder.append("new double[]{");
148 for (int i = 0; i < array.length; i++) {
149 if (i != 0) builder.append(',');
150 builder.append(array[i]);
151 }
152 builder.append('}');
153 } else if (extendedData.getClass() == float[].class) {
154 float[] array = (float[]) extendedData;
155 builder.append("new float[]{");
156 for (int i = 0; i < array.length; i++) {
157 if (i != 0) builder.append(',');
158 builder.append(array[i]);
159 }
160 builder.append('}');
161 } else if (extendedData.getClass() == int[].class) {
162 int[] array = (int[]) extendedData;
163 builder.append("new int[]{");
164 for (int i = 0; i < array.length; i++) {
165 if (i != 0) builder.append(',');
166 builder.append(array[i]);
167 }
168 builder.append('}');
169 } else if (extendedData.getClass() == short[].class) {
170 short[] array = (short[]) extendedData;
171 builder.append("new short[]{");
172 for (int i = 0; i < array.length; i++) {
173 if (i != 0) builder.append(',');
174 builder.append(array[i]);
175 }
176 builder.append('}');
177 } else if (extendedData.getClass() == byte[].class) {
178 byte[] array = (byte[]) extendedData;
179 builder.append("new byte[]{");
180 for (int i = 0; i < array.length; i++) {
181 if (i != 0) builder.append(',');
182 builder.append(array[i]);
183 }
184 builder.append('}');
185 } else if (extendedData.getClass() == long[].class) {
186 long[] array = (long[]) extendedData;
187 builder.append("new long[]{");
188 for (int i = 0; i < array.length; i++) {
189 if (i != 0) builder.append(',');
190 builder.append(array[i]);
191 }
192 builder.append('}');
193 } else if (extendedData.getClass() == char[].class) {
194 char[] array = (char[]) extendedData;
195 builder.append("new char[]{");
196 for (int i = 0; i < array.length; i++) {
197 if (i != 0) builder.append(',');
198 builder.append(array[i]);
199 }
200 builder.append('}');
201 } else if (extendedData.getClass() == String.class) {
202 builder.append("\"" + (String) extendedData + "\"");
203 }
204 } else
205 builder.append("null");
206 return builder.toString();
207 }
208 }