001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package sim.toolkit;
028:
029: import javacard.framework.*;
030: import sim.toolkit.*;
031:
032: /**
033: * This is a base class for all SAT applets. It provides shareable
034: * interface, local APDU buffer creation, local instance of the Toolkit
035: * Exception. The 'process' method should be never invoked and
036: * its overriding not needed.
037: *
038: * <p />Derived SAT applet can look like:
039: * <pre>
040: * public class SATApplet extends SATBaseApplet {
041: * private SATApplet() {
042: * ToolkitRegistry reg;
043: * register();
044: * reg = ToolkitRegistry.getEntry();
045: * reg.setEvent(EVENT_XXXXX);
046: * }
047: *
048: * public static void install(byte[] bArray, short bOffset, byte bLength) {
049: * new SATApplet();
050: * }
051: *
052: * public void processToolkit(byte event) {
053: * switch (event) {
054: * case EVENT_XXXXX:
055: * break;
056: * }
057: * }
058: * }
059: * </pre>
060: */
061: public abstract class SATBaseApplet extends Applet implements
062: ToolkitInterface, ToolkitConstants {
063:
064: /** APDU buffer */
065: private byte[] apduBuffer = null;
066: /** Shared instance of TookitException */
067: private ToolkitException toolkitExceptionInstance = null;
068:
069: /**
070: * Constructor
071: */
072: protected SATBaseApplet() {
073: }
074:
075: /**
076: * Returns shareable interface object to SAT Applet.
077: *
078: * @param clientAID - aid of SIM Framework
079: * @param parameter
080: * @return The current applet instance
081: */
082: public Shareable getShareableInterfaceObject(AID clientAID,
083: byte parameter) {
084: return this ;
085: }
086:
087: /**
088: * Returns the APDUBuffer. If it does not exist then allocates it.
089: * @return apdu buffer
090: * @throws ToolkitException if SATAccessor is unavailable
091: */
092: public byte[] getAPDUBuffer() throws ToolkitException {
093: if (apduBuffer == null) {
094: apduBuffer = new byte[ViewHandler.SATAccessor
095: .getAPDUBufferMax()];
096: }
097: return apduBuffer;
098: }
099:
100: /**
101: * Returns the ToolkitException instance.
102: * If it does not exist yet then creates it.
103: * @return ToolkitException instance
104: */
105: public ToolkitException getToolkitExceptionInstance() {
106: if (toolkitExceptionInstance == null) {
107: toolkitExceptionInstance = new ToolkitException((short) 0);
108: }
109: return toolkitExceptionInstance;
110: }
111:
112: /**
113: * Process method that is called by JCRE if this applet is selected.
114: * @param apdu An APDU to process
115: */
116: public void process(APDU apdu) {
117: }
118:
119: /**
120: * Process method called by GSMApplet when an evelope is received.
121: * @param event An event to be handled
122: */
123: public abstract void processToolkit(byte event);
124: }
|