1 25 package org.ofbiz.pos.device; 26 27 import java.util.Map ; 28 29 import jpos.JposException; 30 31 import org.ofbiz.base.container.ContainerConfig; 32 import org.ofbiz.base.util.Debug; 33 import org.ofbiz.base.util.GeneralException; 34 import org.ofbiz.base.util.UtilValidate; 35 import org.ofbiz.pos.device.impl.CashDrawer; 36 import org.ofbiz.pos.device.impl.CheckScanner; 37 import org.ofbiz.pos.device.impl.Journal; 38 import org.ofbiz.pos.device.impl.Keyboard; 39 import org.ofbiz.pos.device.impl.LineDisplay; 40 import org.ofbiz.pos.device.impl.Msr; 41 import org.ofbiz.pos.device.impl.PinPad; 42 import org.ofbiz.pos.device.impl.Receipt; 43 import org.ofbiz.pos.device.impl.Scanner; 44 45 51 public class DeviceLoader { 52 53 public static final String module = DeviceLoader.class.getName(); 54 55 public static CashDrawer[] drawer = null; 56 public static CheckScanner check = null; 57 public static Journal journal = null; 58 public static Keyboard keyboard = null; 59 public static LineDisplay ldisplay = null; 60 public static Msr msr = null; 61 public static PinPad pinpad = null; 62 public static Receipt receipt = null; 63 public static Scanner scanner = null; 64 65 public static void load(Map devices) throws GeneralException { 66 if (devices.get("Keyboard") != null) { 68 String keyboardDevice = ((ContainerConfig.Container.Property) devices.get("Keyboard")).value; 69 if (UtilValidate.isNotEmpty(keyboardDevice) && !"[NOT IMPLEMENTED]".equals(keyboardDevice)) { 70 keyboard = new Keyboard(keyboardDevice, -1); 71 try { 72 keyboard.open(); 73 } catch (jpos.JposException jpe) { 74 Debug.logError(jpe, "JPOS Exception", module); 75 throw new GeneralException(jpe.getOrigException()); 76 } 77 } 78 } 79 80 if (devices.get("Scanner") != null) { 82 String scannerDevice = ((ContainerConfig.Container.Property) devices.get("Scanner")).value; 83 if (UtilValidate.isNotEmpty(scannerDevice) && !"[NOT IMPLEMENTED]".equals(scannerDevice)) { 84 scanner = new Scanner(scannerDevice, -1); 85 try { 86 scanner.open(); 87 } catch (jpos.JposException jpe) { 88 Debug.logError(jpe, "JPOS Exception", module); 89 throw new GeneralException(jpe.getOrigException()); 90 } 91 } 92 } 93 94 if (devices.get("CheckScanner") != null) { 96 String checkScannerDevice = ((ContainerConfig.Container.Property) devices.get("CheckScanner")).value; 97 if (UtilValidate.isNotEmpty(checkScannerDevice) && !"[NOT IMPLEMENTED]".equals(checkScannerDevice)) { 98 check = new CheckScanner(checkScannerDevice, -1); 99 try { 100 check.open(); 101 } catch (jpos.JposException jpe) { 102 Debug.logError(jpe, "JPOS Exception", module); 103 throw new GeneralException(jpe.getOrigException()); 104 } 105 } 106 } 107 108 if (devices.get("Msr") != null) { 110 String msrDevice = ((ContainerConfig.Container.Property) devices.get("Msr")).value; 111 if (UtilValidate.isNotEmpty(msrDevice) && !"[NOT IMPLEMENTED]".equals(msrDevice)) { 112 msr = new Msr(msrDevice, -1); 113 try { 114 msr.open(); 115 } catch (jpos.JposException jpe) { 116 Debug.logError(jpe, "JPOS Exception", module); 117 throw new GeneralException(jpe.getOrigException()); 118 } 119 } 120 } 121 122 if (devices.get("Receipt") != null) { 124 String receiptDevice = ((ContainerConfig.Container.Property) devices.get("Receipt")).value; 125 if (UtilValidate.isNotEmpty(receiptDevice) && !"[NOT IMPLEMENTED]".equals(receiptDevice)) { 126 receipt = new Receipt(receiptDevice, -1); 127 try { 128 receipt.open(); 129 } catch (jpos.JposException jpe) { 130 Debug.logError(jpe, "JPOS Exception", module); 131 throw new GeneralException(jpe.getOrigException()); 132 } 133 } 134 } 135 136 if (devices.get("Journal") != null) { 138 String journalDevice = ((ContainerConfig.Container.Property) devices.get("Journal")).value; 139 if (UtilValidate.isNotEmpty(journalDevice) && !"[NOT IMPLEMENTED]".equals(journalDevice)) { 140 journal = new Journal(journalDevice, -1); 141 try { 142 journal.open(); 143 } catch (jpos.JposException jpe) { 144 Debug.logError(jpe, "JPOS Exception", module); 145 throw new GeneralException(jpe.getOrigException()); 146 } 147 } 148 } 149 150 if (devices.get("LineDisplay") != null) { 152 String lineDisplayDevice = ((ContainerConfig.Container.Property) devices.get("LineDisplay")).value; 153 if (UtilValidate.isNotEmpty(lineDisplayDevice) && !"[NOT IMPLEMENTED]".equals(lineDisplayDevice)) { 154 ldisplay = new LineDisplay(lineDisplayDevice, -1); 155 try { 156 ldisplay.open(); 157 } catch (jpos.JposException jpe) { 158 Debug.logError(jpe, "JPOS Exception", module); 159 throw new GeneralException(jpe.getOrigException()); 160 } 161 } 162 } 163 164 for (int i = 1; i < 10; i++) { String idName = "CashDrawer." + i; 167 if (devices.get(idName) != null) { 168 String cashDrawerDevice = ((ContainerConfig.Container.Property) devices.get(idName)).value; 169 if (UtilValidate.isNotEmpty(cashDrawerDevice) && !"[NOT IMPLEMENTED]".equals(cashDrawerDevice)) { 170 if (drawer == null) { 171 drawer = new CashDrawer[10]; 172 } 173 174 drawer[i-1] = new CashDrawer(cashDrawerDevice, -1); 176 try { 177 drawer[i-1].open(); 178 } catch (jpos.JposException jpe) { 179 Debug.logError(jpe, "JPOS Exception", module); 180 throw new GeneralException(jpe.getOrigException()); 181 } 182 } 183 } 184 } 185 } 186 187 public static void enable(boolean enable) { 188 if (keyboard != null) { 189 keyboard.enable(enable); 190 } 191 if (scanner != null) { 192 scanner.enable(enable); 193 } 194 if (msr != null) { 195 msr.enable(enable); 196 } 197 if (check != null) { 198 check.enable(enable); 199 } 200 if (ldisplay != null) { 201 ldisplay.enable(enable); 202 } 203 if (pinpad != null) { 204 pinpad.enable(enable); 205 } 206 if (receipt != null) { 207 receipt.enable(enable); 208 } 209 210 } 216 217 public static void stop() throws GeneralException { 218 try { 219 if (keyboard != null) { 220 keyboard.close(); 221 } 222 if (scanner != null) { 223 scanner.close(); 224 } 225 if (msr != null) { 226 msr.close(); 227 } 228 if (check != null) { 229 check.close(); 230 } 231 if (ldisplay != null) { 232 ldisplay.close(); 233 } 234 if (pinpad != null) { 235 pinpad.close(); 236 } 237 238 if (drawer != null) { 239 for (int i = 0; i < drawer.length; i++) { 240 if (drawer[i] != null) { 241 drawer[i].close(); 242 } 243 } 244 } 245 246 if (receipt != null) { 247 receipt.close(); 248 } 249 if (journal != null) { 250 journal.close(); 251 } 252 } catch (JposException jpe) { 253 Debug.logError(jpe, "JPOS Exception", module); 254 throw new GeneralException(jpe.getOrigException()); 255 } 256 } 257 } 258 | Popular Tags |