KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > pos > device > GenericDevice


1 /*
2  * $Id: GenericDevice.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2004 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.pos.device;
26
27 import jpos.BaseControl;
28 import jpos.JposException;
29
30 import org.ofbiz.base.util.Debug;
31 import org.ofbiz.pos.event.MenuEvents;
32 import org.ofbiz.pos.screen.PosScreen;
33
34 /**
35  *
36  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
37  * @version $Rev: 5462 $
38  * @since 3.2
39  */

40 public abstract class GenericDevice implements JposDevice {
41
42     public static final String JavaDoc module = GenericDevice.class.getName();
43
44     protected BaseControl control = null;
45     protected String JavaDoc deviceName = null;
46     protected int timeout = -1;
47
48     public GenericDevice(String JavaDoc deviceName, int timeout) {
49         this.deviceName = deviceName;
50         this.timeout = timeout;
51     }
52
53     public void open() throws JposException {
54         if (deviceName != null && control != null) {
55             if (!"[NOT IMPLEMENTED]".equals(deviceName) && !"[DISABLED]".equals(deviceName)) {
56                 control.open(deviceName);
57                 control.claim(timeout);
58                 this.enable(true);
59                 this.initialize();
60             }
61         } else {
62             Debug.logWarning("No device named [" + deviceName + "] available", module);
63         }
64     }
65
66     public void close() throws JposException {
67         control.release();
68         control.close();
69         control = null;
70     }
71
72     public boolean isEnabled() {
73         try {
74             return control.getDeviceEnabled();
75         } catch (JposException e) {
76             Debug.logError(e, module);
77             return false;
78         }
79     }
80
81     public void enable(boolean enable) {
82         try {
83             control.setDeviceEnabled(enable);
84         } catch (JposException e) {
85             Debug.logError(e, module);
86         }
87     }
88
89     protected void callEnter() {
90         // first invoke the enter event
91
MenuEvents.triggerEnter(PosScreen.currentScreen, null);
92         MenuEvents.triggerClear(PosScreen.currentScreen);
93     }
94     
95     protected abstract void initialize() throws JposException;
96 }
97
Popular Tags