1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.fosstrak.llrp.commander;
23
24 import org.eclipse.jface.dialogs.MessageDialog;
25 import org.eclipse.swt.widgets.Shell;
26 import org.fosstrak.llrp.adaptor.exception.LLRPRuntimeException;
27 import org.fosstrak.llrp.client.LLRPExceptionHandler;
28 import org.fosstrak.llrp.client.LLRPExceptionHandlerTypeMap;
29
30
31
32
33
34
35
36
37 public class ExceptionHandler implements LLRPExceptionHandler {
38
39
40 private final static String DIALOG_CAPTION = "LLRP Client Warning";
41
42 private Shell shell;
43
44 public ExceptionHandler(Shell aShell) {
45 shell = aShell;
46 }
47
48 public void postExceptionToGUI(LLRPExceptionHandlerTypeMap exceptionType, LLRPRuntimeException e, String adaptorName, String readerName) {
49
50
51 final LLRPExceptionHandlerTypeMap aExceptionType = exceptionType;
52 final String aAdapter = adaptorName;
53 final String aReader = readerName;
54 final LLRPRuntimeException ex = e;
55
56
57 shell.getDisplay().asyncExec(new Runnable () {
58
59 public void run() {
60 switch (aExceptionType) {
61 case EXCEPTION_ADAPTOR_MANAGEMENT_NOT_INITIALIZED: {
62 processMessage("AdaptorManagement is not initialized." + '\n' +
63 ex.getMessage());
64 break;
65 }
66 case EXCEPTION_ADAPTOR_MANAGEMENT_CONFIG_NOT_STORABLE: {
67 processMessage("Could not store the configuration." + '\n' +
68 ex.getMessage());
69 break;
70 }
71 case EXCEPTION_ADAPTOR_ALREADY_EXISTS: {
72 processMessage("Adaptor already exists: " + aAdapter);
73 break;
74 }
75 case EXCEPTION_READER_NOT_EXIST: {
76 processReaderNotExist(aAdapter, aReader);
77 break;
78 }
79 case EXCEPTION_ADAPTER_NOT_EXIST: {
80 processAdapterNotExist(aAdapter);
81 break;
82 }
83 case EXCEPTION_READER_LOST: {
84 processReaderLost(aAdapter, aReader);
85 break;
86 }
87 case EXCEPTION_ADAPTER_LOST: {
88 processAdapterLost(aAdapter);
89 break;
90 }
91 case EXCEPTION_MSG_SENDING_ERROR: {
92 processSendingError(aAdapter, aReader);
93 break;
94 }
95 case EXCEPTION_NO_READER_CONFIG_MSG: {
96 processNoReaderConfigError(aAdapter, aReader);
97 break;
98 }
99 case EXCEPTION_NO_ROSPEC_MSG: {
100 processNoROSpecError(aAdapter, aReader);
101 break;
102 }
103 case EXCEPTION_MSG_SYNTAX_ERROR: {
104 processMsgSyntaxError();
105 break;
106 }
107 default: {
108 processGeneralException(aAdapter, aReader, ex.getMessage());
109 }
110 }
111 ResourceCenter.getInstance().
112 getReaderExplorerView().refresh();
113 }
114
115 });
116
117 }
118
119 private void processReaderNotExist(String aAdapter, String aReader) {
120 String aText = "Reader " + aReader + " @ " + aAdapter + " is not found!";
121 MessageDialog.openWarning(shell, DIALOG_CAPTION, aText);
122 }
123
124 private void processAdapterNotExist(String aAdapter) {
125 String aText = "Adapter " + aAdapter + " is not found!";
126 MessageDialog.openWarning(shell, DIALOG_CAPTION, aText);
127 }
128
129 private void processReaderLost(String aAdapter, String aReader) {
130 String aText = "Reader " + aReader + " @ " + aAdapter + " is lost!";
131 MessageDialog.openWarning(shell, DIALOG_CAPTION, aText);
132 }
133
134 private void processAdapterLost(String aAdapter) {
135 String aText = "Adapter " + aAdapter + " is lost!";
136 MessageDialog.openWarning(shell, DIALOG_CAPTION, aText);
137 }
138
139 private void processSendingError(String aAdapter, String aReader) {
140 String aText = "Sending Message to " + aReader + " @ " + aAdapter + " failed!";
141 MessageDialog.openWarning(shell, DIALOG_CAPTION, aText);
142 }
143
144 private void processNoReaderConfigError(String aAdapter, String aReader) {
145 String aText = "No existing GET_READER_CONFIG_RESPONSE message \nfrom " + aReader + " @ " + aAdapter + ".\nPlease send GET_READER_CONFIG first.";
146 MessageDialog.openWarning(shell, DIALOG_CAPTION, aText);
147 }
148
149 private void processNoROSpecError(String aAdapter, String aReader) {
150 String aText = "No existing GET_ROSPECS_RESPONSE message \nfrom " + aReader + " @ " + aAdapter + ".\nPlease send GET_ROSPECS first.";
151 MessageDialog.openWarning(shell, DIALOG_CAPTION, aText);
152 }
153
154 private void processGeneralException(String aAdapter, String aReader, String aText) {
155 MessageDialog.openWarning(shell, DIALOG_CAPTION, aText);
156 }
157
158 private void processMsgSyntaxError() {
159 String aText = "XML Syntax Error!";
160 MessageDialog.openWarning(shell, DIALOG_CAPTION, aText);
161 }
162
163 private void processMessage(String message) {
164 MessageDialog.openWarning(shell, DIALOG_CAPTION, message);
165 }
166 }