Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/globalretailtech/pos/services/DeviceService.java


1   /*
2    * Copyright (C) 2001 Global Retail Technology, LLC
3    * <http://www.globalretailtech.com>
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18   */
19  
20  package com.globalretailtech.pos.services;
21  
22  import java.awt.*;
23  import java.io.*;
24  import java.util.*;
25  import java.awt.event.*;
26  import javax.swing.*;
27  import jpos.*;
28  import jpos.services.*;
29  
30  import jpos.config.JposEntry;
31  import jpos.loader.JposServiceInstance;
32  
33  
34  import com.globalretailtech.util.Log;
35  
36  /**
37   * Super class for JFC JPOS services.
38   * Opens property file based on service name, from
39   * there it figures out the size and layout for the 
40   * service. Creates a device properties pane used
41   * to show the configued properties.
42   *
43   * @author  Quentin Olson
44   * @see 
45   */
46  public class DeviceService implements jpos.services.BaseService, jpos.JposConst
47  {
48  
49      // Event management
50  
51      static private  int EventCount;
52      static private  Vector event_list;
53  
54      // Jpos Properties
55  
56      private boolean AutoDisable;
57      private int     CapPowerReporting;
58      private String  CheckHealthText;
59      private boolean Claimed;
60      private int     DataCount;
61      private boolean DataEventEnabled;
62      private boolean DeviceEnabled;
63      private boolean FreezeEvents;
64      private int     OutputID;
65      private int     PowerNotify;
66      private int     PowerState;
67      private int     State;
68      private String  DeviceControlDescription;
69      private int     DeviceControlVersion;
70      private String  DeviceServiceDescription;
71      private int     DeviceServiceVersion;
72      private String  PhysicalDeviceDescription;
73      private String  PhysicalDeviceName;
74  
75      /** X position in grid */
76      public int x;
77      /** Y position in grid */
78      public int y;
79      /** Height position in grid */
80      public int h;
81      /** Width position in grid */
82      public int w;
83  
84      /** the device panel (properties) for this device */
85      private JFrame frame;
86      public JFrame frame ()
87      {
88          return frame;
89      }
90      public JPanel devPanel ()
91      {
92          return dev;
93      }
94      private JPanel dev;
95      /**
96       * Constructor creates the device panel based on name.
97       */
98      public DeviceService ()
99      {
100 
101         frame = new JFrame ("Cash Drawer");
102         event_list = new Vector ();
103 
104         dev = new JPanel ();
105 
106         frame.addWindowListener(new WindowAdapter()
107                                 {
108                                     public void windowClosing(WindowEvent e)
109                                     {
110                                         System.exit (0);
111                                     }
112                                 }
113                                );
114 
115 
116     }
117 
118     public void display ()
119     {
120         frame.validate ();
121         frame.setVisible (true);
122         frame.getContentPane ().add (dev);
123         frame.setSize (100, 100);
124     }
125     public void open(String logicalName, EventCallbacks cb) throws JposException
126     {
127 
128       Log.debug ("open in DeviceService " + logicalName + " " + cb);
129 
130         if (getState () == JPOS_S_ERROR)
131         {
132             throw (new jpos.JposException (JPOS_S_ERROR));
133         }
134         eventCallbacks = cb;
135 
136         checkHealthText = "Device OK";
137         claimed = false;
138         deviceEnabled = false;
139         deviceServiceDescription    = "JavaPOS LineDisplayService version 1.5";
140         deviceServiceVersion = 1006000;
141         freezeEvents = false;
142         physicalDeviceDescription   = "";
143         physicalDeviceName = "";
144         state = JposConst.JPOS_S_IDLE;
145     }
146 
147     public void close() throws JposException
148     {
149         checkHealthText = "";
150         claimed = false;
151         deviceEnabled = false;
152         deviceServiceDescription = "";
153         deviceServiceVersion = 1006000;
154         freezeEvents = false;
155         physicalDeviceDescription = "";
156         physicalDeviceName = "";
157         state = JposConst.JPOS_S_CLOSED;
158     }
159 
160     /** See JPOS */
161     public void fireEvent (jpos.events.DataEvent ev)
162     {
163         eventCallbacks.fireDataEvent (ev);
164     }
165 
166     /** See JPOS */
167     public void fireEvent (jpos.events.DirectIOEvent ev)
168     {
169         eventCallbacks.fireDirectIOEvent (ev);
170     }
171 
172     public void fireEvent (jpos.events.StatusUpdateEvent ev)
173     {
174         eventCallbacks.fireStatusUpdateEvent (ev);
175     }
176 
177     // Jpos Implementation
178 
179     /** See JPOS */
180     public String  getCheckHealthText () throws jpos.JposException
181     {
182         if (getState () == JPOS_S_ERROR)
183         {
184             throw (new jpos.JposException (JPOS_S_ERROR));
185         }
186         return CheckHealthText;
187     }
188     /** See JPOS */
189     public void    setCheckHealthText (String s) throws jpos.JposException
190     {
191         if (getState () == JPOS_S_ERROR)
192         {
193             throw (new jpos.JposException (JPOS_S_ERROR));
194         }
195         CheckHealthText = s;
196     }
197     /** See JPOS */
198     public boolean getClaimed () throws jpos.JposException
199     {
200         if (getState () == JPOS_S_ERROR)
201         {
202             throw (new jpos.JposException (JPOS_S_ERROR));
203         }
204         return Claimed;
205     }
206     /** See JPOS */
207     public void    setClaimed (boolean b) throws jpos.JposException
208     {
209         if (getState () == JPOS_S_ERROR)
210         {
211             throw (new jpos.JposException (JPOS_S_ERROR));
212         }
213         Claimed = b;
214     }
215     /** See JPOS */
216     public boolean getDeviceEnabled () throws jpos.JposException
217     {
218         if (getState () == JPOS_S_ERROR)
219         {
220             throw (new jpos.JposException (JPOS_S_ERROR));
221         }
222         return DeviceEnabled;
223     }
224     /** See JPOS */
225     public void    setDeviceEnabled (boolean b) throws jpos.JposException
226     {
227         if (getState () == JPOS_S_ERROR)
228         {
229             throw (new jpos.JposException (JPOS_S_ERROR));
230         }
231         DeviceEnabled = b;
232     }
233     /** See JPOS */
234     public String  getDeviceServiceDescription () throws jpos.JposException
235     {
236         if (getState () == JPOS_S_ERROR)
237         {
238             throw (new jpos.JposException (JPOS_S_ERROR));
239         }
240         return DeviceServiceDescription;
241     }
242     /** See JPOS */
243     public void    setDeviceServiceDescription (String s) throws jpos.JposException
244     {
245         if (getState () == JPOS_S_ERROR)
246         {
247             throw (new jpos.JposException (JPOS_S_ERROR));
248         }
249         DeviceServiceDescription = s;
250     }
251     /** See JPOS */
252     public int     getDeviceServiceVersion () throws jpos.JposException
253     {
254         if (getState () == JPOS_S_ERROR)
255         {
256             throw (new jpos.JposException (JPOS_S_ERROR));
257         }
258         return DeviceServiceVersion;
259     }
260     /** See JPOS */
261     public void    setDeviceServiceVersion (int v) throws jpos.JposException
262     {
263         if (getState () == JPOS_S_ERROR)
264         {
265             throw (new jpos.JposException (JPOS_S_ERROR));
266         }
267         DeviceServiceVersion = v;
268     }
269     /** See JPOS */
270     public boolean getFreezeEvents () throws jpos.JposException
271     {
272         if (getState () == JPOS_S_ERROR)
273         {
274             throw (new jpos.JposException (JPOS_S_ERROR));
275         }
276         if (getState () == JPOS_S_ERROR)
277         {
278             throw (new jpos.JposException (JPOS_S_ERROR));
279         }
280         return FreezeEvents;
281     }
282     /** See JPOS */
283     public void    setFreezeEvents (boolean freezeEvents) throws jpos.JposException
284     {
285         if (getState () == JPOS_S_ERROR)
286         {
287             throw (new jpos.JposException (JPOS_S_ERROR));
288         }
289         FreezeEvents = freezeEvents;
290     }
291     /** See JPOS */
292     public String  getPhysicalDeviceDescription () throws jpos.JposException
293     {
294         if (getState () == JPOS_S_ERROR)
295         {
296             throw (new jpos.JposException (JPOS_S_ERROR));
297         }
298         return PhysicalDeviceDescription;
299     }
300     /** See JPOS */
301     public void    setPhysicalDeviceDescription (String s) throws jpos.JposException
302     {
303         if (getState () == JPOS_S_ERROR)
304         {
305             throw (new jpos.JposException (JPOS_S_ERROR));
306         }
307         PhysicalDeviceDescription = s;
308     }
309     /** See JPOS */
310     public String  getPhysicalDeviceName () throws jpos.JposException
311     {
312         if (getState () == JPOS_S_ERROR)
313         {
314             throw (new jpos.JposException (JPOS_S_ERROR));
315         }
316         return PhysicalDeviceName;
317     }
318     /** See JPOS */
319     public void    setPhysicalDeviceName (String s) throws jpos.JposException
320     {
321         if (getState () == JPOS_S_ERROR)
322         {
323             throw (new jpos.JposException (JPOS_S_ERROR));
324         }
325         PhysicalDeviceName = s;
326     }
327     /** See JPOS */
328     public int getState () throws jpos.JposException
329     {
330         if (State == JPOS_S_ERROR)
331         {   // oops
332             throw (new jpos.JposException (JPOS_S_ERROR));
333         }
334         return State;
335     }
336     /** See JPOS */
337     public void    setState (int s) throws jpos.JposException
338     {
339         if (getState () == JPOS_S_ERROR)
340         {
341             throw (new jpos.JposException (JPOS_S_ERROR));
342         }
343         State = s;
344     }
345 
346     // Methods supported by all device services
347 
348     /** See JPOS */
349     public void    claim (int timeout) throws jpos.JposException
350     {
351         if (getState () == JPOS_S_ERROR)
352         {
353             throw (new jpos.JposException (JPOS_S_ERROR));
354         }
355     }
356 
357     /** See JPOS */
358     public void    checkHealth (int level) throws jpos.JposException
359     {
360         if (getState () == JPOS_S_ERROR)
361         {
362             throw (new jpos.JposException (JPOS_S_ERROR));
363         }
364     }
365     /** See JPOS */
366     public void    directIO (int command, int[] data, Object object) throws jpos.JposException
367     {
368         if (getState () == JPOS_S_ERROR)
369         {
370             throw (new jpos.JposException (JPOS_S_ERROR));
371         }
372     }
373 
374     /** See JPOS */
375     public void    release() throws jpos.JposException
376     {
377         if (getState () == JPOS_S_ERROR)
378         {
379             throw (new jpos.JposException (JPOS_S_ERROR));
380         }
381     }
382     void setJposEntry( JposEntry entry )
383     {
384 
385         //Of course after setting one can do further intialization here...
386     }
387     protected boolean autoDisable                = false;
388     protected int capPowerReporting              = JposConst.JPOS_PR_NONE;
389     protected String checkHealthText             = "JPOS_SUCCESS";
390     protected int dataCount                      = 0;
391     protected boolean dataEventEnabled           = false;
392     protected boolean deviceEnabled              = false;
393     protected int outputID                       = 0;
394     protected int powerNotify                    = JposConst.JPOS_PN_DISABLED;
395     protected int powerState                     = JposConst.JPOS_PS_UNKNOWN;
396     protected String deviceServiceDescription    = "";
397     protected int deviceServiceVersion           = 1006000;
398     protected boolean freezeEvents               = false;
399     protected String physicalDeviceDescription   = "";
400     protected String physicalDeviceName          = "";
401     protected int state                          = JposConst.JPOS_S_CLOSED;
402 
403     protected static boolean claimed             = false;
404 
405     protected EventCallbacks eventCallbacks      = null;
406     protected JposEntry jposEntry              = null;
407 }
408 
409 /**
410  * $Log: DeviceService.java,v $
411  * Revision 1.1.1.1  2001/08/13 22:18:19  qolson
412  * Initial Checkin 0.2-2
413  *
414  *
415  */