Source Code Cross Referenced for DeviceLoader.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » pos » device » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » ofbiz » org.ofbiz.pos.device 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         *******************************************************************************/package org.ofbiz.pos.device;
019:
020:        import java.util.Map;
021:
022:        import jpos.JposException;
023:
024:        import org.ofbiz.base.container.ContainerConfig;
025:        import org.ofbiz.base.util.Debug;
026:        import org.ofbiz.base.util.GeneralException;
027:        import org.ofbiz.base.util.UtilValidate;
028:        import org.ofbiz.pos.device.impl.CashDrawer;
029:        import org.ofbiz.pos.device.impl.CheckScanner;
030:        import org.ofbiz.pos.device.impl.Journal;
031:        import org.ofbiz.pos.device.impl.Keyboard;
032:        import org.ofbiz.pos.device.impl.LineDisplay;
033:        import org.ofbiz.pos.device.impl.Msr;
034:        import org.ofbiz.pos.device.impl.PinPad;
035:        import org.ofbiz.pos.device.impl.Receipt;
036:        import org.ofbiz.pos.device.impl.Scanner;
037:
038:        public class DeviceLoader {
039:
040:            public static final String module = DeviceLoader.class.getName();
041:
042:            public static CashDrawer[] drawer = null;
043:            public static CheckScanner check = null;
044:            public static Journal journal = null;
045:            public static Keyboard keyboard = null;
046:            public static LineDisplay ldisplay = null;
047:            public static Msr msr = null;
048:            public static PinPad pinpad = null;
049:            public static Receipt receipt = null;
050:            public static Scanner scanner = null;
051:
052:            public static void load(Map devices) throws GeneralException {
053:                // load the keyboard
054:                if (devices.get("Keyboard") != null) {
055:                    String keyboardDevice = ((ContainerConfig.Container.Property) devices
056:                            .get("Keyboard")).value;
057:                    if (UtilValidate.isNotEmpty(keyboardDevice)
058:                            && !"[NOT IMPLEMENTED]".equals(keyboardDevice)) {
059:                        keyboard = new Keyboard(keyboardDevice, -1);
060:                        try {
061:                            keyboard.open();
062:                        } catch (jpos.JposException jpe) {
063:                            Debug.logError(jpe, "JPOS Exception", module);
064:                            throw new GeneralException(jpe.getOrigException());
065:                        }
066:                    }
067:                }
068:
069:                // load the scanner
070:                if (devices.get("Scanner") != null) {
071:                    String scannerDevice = ((ContainerConfig.Container.Property) devices
072:                            .get("Scanner")).value;
073:                    if (UtilValidate.isNotEmpty(scannerDevice)
074:                            && !"[NOT IMPLEMENTED]".equals(scannerDevice)) {
075:                        scanner = new Scanner(scannerDevice, -1);
076:                        try {
077:                            scanner.open();
078:                        } catch (jpos.JposException jpe) {
079:                            Debug.logError(jpe, "JPOS Exception", module);
080:                            throw new GeneralException(jpe.getOrigException());
081:                        }
082:                    }
083:                }
084:
085:                // load the check reader
086:                if (devices.get("CheckScanner") != null) {
087:                    String checkScannerDevice = ((ContainerConfig.Container.Property) devices
088:                            .get("CheckScanner")).value;
089:                    if (UtilValidate.isNotEmpty(checkScannerDevice)
090:                            && !"[NOT IMPLEMENTED]".equals(checkScannerDevice)) {
091:                        check = new CheckScanner(checkScannerDevice, -1);
092:                        try {
093:                            check.open();
094:                        } catch (jpos.JposException jpe) {
095:                            Debug.logError(jpe, "JPOS Exception", module);
096:                            throw new GeneralException(jpe.getOrigException());
097:                        }
098:                    }
099:                }
100:
101:                // load the msr
102:                if (devices.get("Msr") != null) {
103:                    String msrDevice = ((ContainerConfig.Container.Property) devices
104:                            .get("Msr")).value;
105:                    if (UtilValidate.isNotEmpty(msrDevice)
106:                            && !"[NOT IMPLEMENTED]".equals(msrDevice)) {
107:                        msr = new Msr(msrDevice, -1);
108:                        try {
109:                            msr.open();
110:                        } catch (jpos.JposException jpe) {
111:                            Debug.logError(jpe, "JPOS Exception", module);
112:                            throw new GeneralException(jpe.getOrigException());
113:                        }
114:                    }
115:                }
116:
117:                // load the receipt printer
118:                if (devices.get("Receipt") != null) {
119:                    String receiptDevice = ((ContainerConfig.Container.Property) devices
120:                            .get("Receipt")).value;
121:                    if (UtilValidate.isNotEmpty(receiptDevice)
122:                            && !"[NOT IMPLEMENTED]".equals(receiptDevice)) {
123:                        receipt = new Receipt(receiptDevice, -1);
124:                        try {
125:                            receipt.open();
126:                        } catch (jpos.JposException jpe) {
127:                            Debug.logError(jpe, "JPOS Exception", module);
128:                            throw new GeneralException(jpe.getOrigException());
129:                        }
130:                    }
131:                }
132:
133:                // load the journal printer
134:                if (devices.get("Journal") != null) {
135:                    String journalDevice = ((ContainerConfig.Container.Property) devices
136:                            .get("Journal")).value;
137:                    if (UtilValidate.isNotEmpty(journalDevice)
138:                            && !"[NOT IMPLEMENTED]".equals(journalDevice)) {
139:                        journal = new Journal(journalDevice, -1);
140:                        try {
141:                            journal.open();
142:                        } catch (jpos.JposException jpe) {
143:                            Debug.logError(jpe, "JPOS Exception", module);
144:                            throw new GeneralException(jpe.getOrigException());
145:                        }
146:                    }
147:                }
148:
149:                // load the line display
150:                if (devices.get("LineDisplay") != null) {
151:                    String lineDisplayDevice = ((ContainerConfig.Container.Property) devices
152:                            .get("LineDisplay")).value;
153:                    if (UtilValidate.isNotEmpty(lineDisplayDevice)
154:                            && !"[NOT IMPLEMENTED]".equals(lineDisplayDevice)) {
155:                        ldisplay = new LineDisplay(lineDisplayDevice, -1);
156:                        try {
157:                            ldisplay.open();
158:                        } catch (jpos.JposException jpe) {
159:                            Debug.logError(jpe, "JPOS Exception", module);
160:                            throw new GeneralException(jpe.getOrigException());
161:                        }
162:                    }
163:                }
164:
165:                // load the cash drawer(s) -- Currently only supports one drawer per terminal
166:                for (int i = 1; i < 10; i++) { // more than 10 cash drawers on a terminal??
167:                    String idName = "CashDrawer." + i;
168:                    if (devices.get(idName) != null) {
169:                        String cashDrawerDevice = ((ContainerConfig.Container.Property) devices
170:                                .get(idName)).value;
171:                        if (UtilValidate.isNotEmpty(cashDrawerDevice)
172:                                && !"[NOT IMPLEMENTED]"
173:                                        .equals(cashDrawerDevice)) {
174:                            if (drawer == null) {
175:                                drawer = new CashDrawer[10];
176:                            }
177:
178:                            // create the instance
179:                            drawer[i - 1] = new CashDrawer(cashDrawerDevice, -1);
180:                            try {
181:                                drawer[i - 1].open();
182:                            } catch (jpos.JposException jpe) {
183:                                Debug.logError(jpe, "JPOS Exception", module);
184:                                throw new GeneralException(jpe
185:                                        .getOrigException());
186:                            }
187:                        }
188:                    }
189:                }
190:            }
191:
192:            public static void enable(boolean enable) {
193:                if (keyboard != null) {
194:                    keyboard.enable(enable);
195:                }
196:                if (scanner != null) {
197:                    scanner.enable(enable);
198:                }
199:                if (msr != null) {
200:                    msr.enable(enable);
201:                }
202:                if (check != null) {
203:                    check.enable(enable);
204:                }
205:                if (ldisplay != null) {
206:                    ldisplay.enable(enable);
207:                }
208:                if (pinpad != null) {
209:                    pinpad.enable(enable);
210:                }
211:                if (receipt != null) {
212:                    receipt.enable(enable);
213:                }
214:
215:                // cash drawers and journal printer are
216:                // never able to be disabled so we can
217:                // notify when the drawer is open and
218:                // print any information needed to the
219:                // journal
220:            }
221:
222:            public static void stop() throws GeneralException {
223:                try {
224:                    if (keyboard != null) {
225:                        keyboard.close();
226:                    }
227:                    if (scanner != null) {
228:                        scanner.close();
229:                    }
230:                    if (msr != null) {
231:                        msr.close();
232:                    }
233:                    if (check != null) {
234:                        check.close();
235:                    }
236:                    if (ldisplay != null) {
237:                        ldisplay.close();
238:                    }
239:                    if (pinpad != null) {
240:                        pinpad.close();
241:                    }
242:
243:                    if (drawer != null) {
244:                        for (int i = 0; i < drawer.length; i++) {
245:                            if (drawer[i] != null) {
246:                                drawer[i].close();
247:                            }
248:                        }
249:                    }
250:
251:                    if (receipt != null) {
252:                        receipt.close();
253:                    }
254:                    if (journal != null) {
255:                        journal.close();
256:                    }
257:                } catch (JposException jpe) {
258:                    Debug.logError(jpe, "JPOS Exception", module);
259:                    throw new GeneralException(jpe.getOrigException());
260:                }
261:            }
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.