01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.satsa.satapplet;
28:
29: import javacard.framework.*;
30: import sim.toolkit.*;
31:
32: /**
33: * An example SAT applet to demonstrate how an SAT applet can be written.
34: */
35: public class SATApplet extends SATBaseApplet {
36:
37: /** Instance to toolkit registry which is used to register for events */
38: private ToolkitRegistry reg;
39:
40: /**
41: * Constructor.
42: */
43: private SATApplet() {
44: // have to call register before getting the toolkit registry
45: // object
46: register();
47: // EVENT_UNFORMATTED_SMS_PP_ENV
48: // register to the SIM Toolkit Framework
49: reg = ToolkitRegistry.getEntry();
50: // register to the EVENT_UNFORMATTED_SMS_PP_ENV
51: reg.setEvent(EVENT_UNFORMATTED_SMS_PP_ENV);
52: }
53:
54: /**
55: * Applet's install method. Creates an instance of SATApplet.
56: * @param bArray parameters array
57: * @param bOffset offset in the parameters array
58: * @param bLength length of parameters
59: */
60: public static void install(byte[] bArray, short bOffset,
61: byte bLength) {
62: new SATApplet();
63: }
64:
65: /**
66: * Process method called by GSMApplet when an evelope is received.
67: * @param event Event which should be processed
68: */
69: public void processToolkit(byte event) {
70: EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler();
71: EnvelopeResponseHandler evpRspHdlr = EnvelopeResponseHandler
72: .getTheHandler();
73: switch (event) {
74: case EVENT_UNFORMATTED_SMS_PP_ENV:
75: byte result = envHdlr.findTLV(TAG_SMS_TPDU, (byte) 1);
76: short length = envHdlr.getLength();
77: byte[] rspBuffer = new byte[length];
78: short rspLength = envHdlr.findAndCopyValue(TAG_SMS_TPDU,
79: rspBuffer, (short) 0);
80: evpRspHdlr.appendArray(rspBuffer, (short) 0, rspLength);
81: evpRspHdlr.post(rspBuffer[(short) (length - 1)]);
82: break;
83: }
84: }
85: }
|