⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jcrespec03appletlife.html

📁 JAVA CARD 开发包规格说明,版本为2.2.2
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><HTML LANG="en"><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"><META NAME="GENERATOR" CONTENT="Adobe FrameMaker 7.0/HTML Export Filter"><LINK REL="STYLESHEET" HREF="unx_unstr_styles.css" CHARSET="ISO-8859-1" TYPE="text/css"><META name="DC.TITLE" content="Runtime Environment Specification for the Java Card Platform, Version 2.2.2"><TITLE>C H A P T E R    3 - Java Card Applet Lifetime </TITLE></HEAD><BODY BGCOLOR="#ffffff"><DIV><div class="navbar" align="center"><table dir="LTR" summary="Navigation bar, includes the book title and navigation buttons" width=100% cellpadding="0" cellspacing="0" border="0"><colgroup span="2" width="100%"><col id="1" span="1" width="50%"><col id="2" span="1" width="50%"><tr bgcolor="#cccccc"><td class="navbartitle" align=left rowspan="1" colspan="1" abbr="ChapTitle">&nbsp;&nbsp;Runtime Environment Specification for the Java Card Platform, Version 2.2.2</td><td valign="top" align="right" rowspan="1" colspan="1" abbr="NavButtons"><a href="index.html"><img src="shared/toc01.gif" title="Table Of Contents" alt="Table Of Contents" width="30" height="26" border="0"></a><a href="JCRESpec02vmlife.html"><img src="shared/prev01.gif" title="Previous Chapter" alt="Previous Chapter" width="30" height="26" border="0"></a><a href="JCRESpec04selection.html"><img src="shared/next01.gif" title="Next Chapter" alt="Next Chapter" width="30" height="26" border="0"></a><a href="ix.html"><img src="shared/index01.gif" title="Book Index" alt="Book Index" width="30" height="26" border="0"></a></td></tr></table><br><br></div></DIV><TABLE DIR="LTR" SUMMARY="Chapter Number" ABBR="ChapNum" WIDTH="100%" BORDER="0"><COLGROUP SPAN="1" WIDTH="100%"><COL ID="1" SPAN="1"><TR><TD ALIGN="right" CLASS="ChapNumber"><SPAN CLASS="ChapNumPrefix"><A NAME="pgfId-409021"></A>C H A P T E R    </SPAN>&nbsp;<SPAN CLASS="ChapNumNum">3</SPAN><A NAME="64379"></A></TD></TR></TABLE><TABLE DIR="LTR" SUMMARY="Chapter Title" ABBR="ChapTitle" WIDTH="100%" BORDER="0"><COLGROUP SPAN="1" WIDTH="100%"><COL ID="1" SPAN="1" WIDTH="100%"><TR><TD ALIGN="right" CLASS="ChapTitle"><HR SIZE=7 NOSHADE><A NAME="pgfId-409022"></A><A NAME="36198"></A><A NAME="marker-415291"></A>Java Card Applet Lifetime</TD></TR></TABLE><P CLASS="Paragraph"><A NAME="pgfId-406189"></A>For the purposes of this specification, applet refers to an applet written for the Java Card platform. An applet instance's lifetime begins when it is successfully registered with the Java Card RE via the <KBD CLASS="Filename-Command">Applet.register</KBD> method. Applets registered with the <KBD CLASS="Filename-Command">Applet.register</KBD> method exist until <A NAME="marker-415292"></A>deleted by the Applet Deletion Manager (<A HREF="JCRESpec11installer.html#32414" CLASS="XRef">Section 11.3, The Applet Deletion Manager</A>). The Java Card RE initiates interactions with the applet via the applet's public methods <KBD CLASS="Filename-Command">install</KBD>, <KBD CLASS="Filename-Command">select</KBD>, <KBD CLASS="Filename-Command">deselect</KBD>, and <KBD CLASS="Filename-Command">process</KBD>. An applet shall implement the static <KBD CLASS="Filename-Command">install(byte[], short, byte)</KBD> method. If the <KBD CLASS="Filename-Command">install(byte[], short, byte)</KBD> method is not implemented, the applet's objects cannot be created or initialized. A Java Card RE implementation shall call an applet's <KBD CLASS="Filename-Command">install</KBD>, <KBD CLASS="Filename-Command">select</KBD>, <KBD CLASS="Filename-Command">deselect</KBD>, and <KBD CLASS="Filename-Command">process</KBD> methods as described below.</P><P CLASS="Paragraph"><A NAME="pgfId-409941"></A>When the applet is installed on the smart card, the static <KBD CLASS="Filename-Command">install(byte[], short, byte)</KBD> method is called once by the Java Card RE for each applet instance created. The Java Card RE shall not call the applet's constructor directly.</P><H2 CLASS="Head1"><A NAME="pgfId-409942"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>3.1	<KBD CLASS="Filename-Command">install</KBD><A NAME="21819"></A><A NAME="marker-415293"></A> Method</H2><P CLASS="Paragraph"><A NAME="pgfId-419142"></A>When the <KBD CLASS="Filename-Command">install(byte[], short, byte)</KBD> method is called, the applet instance does not yet exist. The main task of the <KBD CLASS="Filename-Command">install</KBD> method within the applet is to create an instance of the <KBD CLASS="Filename-Command">Applet</KBD> subclass using its constructor, and to register the instance. All other objects that the applet needs during its lifetime can be created as is feasible. Any other preparations necessary for the applet to be selected and accessed by a CAD also can be done as is feasible. The <KBD CLASS="Filename-Command">install</KBD> method obtains initialization parameters from the contents of the incoming byte array parameter.</P><P CLASS="Paragraph"><A NAME="pgfId-419259"></A>Typically, an applet creates various objects, initializes them with predefined values, sets some internal state variables, and calls either the <KBD CLASS="Filename-Command">Applet.register()</KBD> method or the <KBD CLASS="Filename-Command">Applet.register(byte[], short, byte)</KBD> method to specify the AID (applet IDentifier as defined in ISO 7816-5) to be used to select it. This i<A NAME="marker-415294"></A>nstallation is considered successful when the call to the <KBD CLASS="Filename-Command">Applet.register</KBD> method completes without an exception. The installation is deemed unsuccessful if the <KBD CLASS="Filename-Command">install</KBD> method does not call the <KBD CLASS="Filename-Command">Applet.register</KBD> method, or if an exception is thrown from within the <KBD CLASS="Filename-Command">install</KBD> method prior to the <KBD CLASS="Filename-Command">Applet.register</KBD> method being called, or if the <KBD CLASS="Filename-Command">Applet.register</KBD> method throws an exception. If the installation is unsuccessful, the Java Card RE shall perform all cleanup when it regains control. That is, all conditional updates to persistent storage shall be returned to the state they had prior to calling the <KBD CLASS="Filename-Command">install</KBD> method. If the installation is successful, the Java Card RE can mark the applet as available for selection.</P><P CLASS="Paragraph"><A NAME="pgfId-409975"></A>Only one applet instance can be successfully registered each time the Java Card RE calls the <KBD CLASS="Filename-Command">Applet.install</KBD> method. </P><H2 CLASS="Head1"><A NAME="pgfId-409976"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>3.2	<KBD CLASS="Filename-Command">select</KBD><A NAME="marker-415295"></A> Method</H2><P CLASS="Paragraph"><A NAME="pgfId-406217"></A>Applets remain in a suspended state until they are explicitly selected. <A NAME="marker-415296"></A>Selection occurs when the Java Card RE receives a SELECT FILE APDU command in which the name data matches the AID of the applet. Applet selection can also occur on a MANAGE CHANNEL OPEN command. Selection causes an applet to become the currently selected applet. For more details, see <A HREF="JCRESpec04selection.html#92536" CLASS="XRef">Section 4.5, Applet Selection</A>.</P><P CLASS="Paragraph"><A NAME="pgfId-406219"></A>Prior to calling <KBD CLASS="Filename-Command">select</KBD>, the Java Card RE shall <A NAME="marker-415297"></A>deselect the previously selected applet. The Java Card RE indicates this to the applet by invoking the applet's <KBD CLASS="Filename-Command">deselect</KBD> method or, if concurrently selected on more than one logical channel, its <KBD CLASS="Filename-Command">MultiSelectable.deselect</KBD> method (for more details, see <A HREF="JCRESpec04selection.html#32535" CLASS="XRef">Section 4.2, Multiselectable Applets</A>).</P><P CLASS="Paragraph"><A NAME="pgfId-412401"></A>The Java Card RE informs the applet of selection by invoking its <KBD CLASS="Filename-Command">select</KBD> method or, if being concurrently selected on more than one logical channel, its <KBD CLASS="Filename-Command">MultiSelectable.select</KBD> method (for more details, see <A HREF="JCRESpec04selection.html#32535" CLASS="XRef">Section 4.2, Multiselectable Applets</A>).</P><P CLASS="Paragraph"><A NAME="pgfId-412406"></A>The applet may decline to be selected by returning <KBD CLASS="Filename-Command">false</KBD> from the call to the <KBD CLASS="Filename-Command">select</KBD> method or by throwing an exception. If the applet returns <KBD CLASS="Filename-Command">true</KBD>, the actual SELECT FILE APDU command is supplied to the applet in the subsequent call to its <KBD CLASS="Filename-Command">process</KBD> method, so that the applet can examine the APDU contents. The applet can process the SELECT FILE APDU command exactly like it processes any other APDU command. It can respond to the SELECT FILE APDU with data (see <A HREF="JCRESpec03appletlife.html#17454" CLASS="XRef">Section 3.3, process Method</A> for details), or it can flag errors by throwing an <KBD CLASS="Filename-Command">ISOException</KBD> with the appropriate returned status word. The status word and optional response data are returned to the CAD. </P><P CLASS="Paragraph"><A NAME="pgfId-406225"></A>The <KBD CLASS="Filename-Command">Applet.selectingApplet</KBD> method shall return <KBD CLASS="Filename-Command">true</KBD> when called during the <KBD CLASS="Filename-Command">select</KBD> method. The <KBD CLASS="Filename-Command">Applet.selectingApplet</KBD> method continues to return <KBD CLASS="Filename-Command">true</KBD> during the subsequent <KBD CLASS="Filename-Command">process</KBD> method, which is called to process the SELECT FILE APDU command.</P><P CLASS="Paragraph"><A NAME="pgfId-409999"></A>If the applet declines to be selected, the Java Card RE returns an APDU response status word of <KBD CLASS="Filename-Command">ISO7816.SW_APPLET_SELECT_FAILED</KBD> to the CAD. Upon selection failure, the Java Card RE state is set to indicate that no applet is selected. See <A HREF="JCRESpec04selection.html#92536" CLASS="XRef">Section 4.5, Applet Selection</A> for more details.</P><P CLASS="Paragraph"><A NAME="pgfId-406229"></A>After successful selection, all subsequent APDUs directed to the assigned logical channel are delivered to the currently selected applet via the <KBD CLASS="Filename-Command">process</KBD> method. </P><H2 CLASS="Head1"><A NAME="pgfId-406239"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>3.3	<A NAME="17454"></A><A NAME="marker-415298"></A><KBD CLASS="Filename-Command">process</KBD> Method</H2><P CLASS="Paragraph"><A NAME="pgfId-412418"></A>All APDUs are received by the Java Card RE and preprocessed. All commands, except for the MANAGE CHANNEL command result in an instance of the APDU class containing the command being passed to the <KBD CLASS="Filename-Command">process(APDU)</KBD> method of the currently selected applet. </P><BR><HR NOSHADE SIZE=1><TABLE CLASS="TipNote" DIR="LTR" WIDTH="100%" SUMMARY="TipNote"><COLGROUP SPAN="1" WIDTH="100%"><TR ALIGN="left" VALIGN="top"><TD ROWSPAN="1" COLSPAN="1" ABBR="TipNoteText"><P CLASS="TipNote"><B CLASS="TipNote">Note - </B><A NAME="pgfId-406243"></A>A SELECT FILE APDU command might cause a change in the currently selected applet prior to the call to the <KBD CLASS="Filename-Command">process</KBD> method. The actual change occurs before the call to the <KBD CLASS="Filename-Command">select</KBD> method.</P></TD></TR></TABLE><HR NOSHADE SIZE=1><BR><P CLASS="Paragraph"><A NAME="pgfId-406245"></A>On normal return, the Java Card RE automatically appends <KBD CLASS="Filename-Command">0x9000</KBD> as the completion response status word to any data already sent by the applet.</P><P CLASS="Paragraph"><A NAME="pgfId-406247"></A>At any time during process, the applet may throw an <KBD CLASS="Filename-Command">ISOException</KBD> with an appropriate status word, in which case the Java Card RE catches the exception and returns the status word to the CAD. </P><P CLASS="Paragraph"><A NAME="pgfId-406249"></A>If any other exception is thrown during process, the Java Card RE catches the exception and returns the status word <KBD CLASS="Filename-Command">ISO7816.SW_UNKNOWN</KBD> to the CAD. </P><H2 CLASS="Head1"><A NAME="pgfId-406259"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>3.4	<A NAME="67974"></A><A NAME="marker-415299"></A><KBD CLASS="Filename-Command">deselect</KBD> Method(s)</H2><P CLASS="Paragraph"><A NAME="pgfId-419758"></A>When the Java Card RE receives a SELECT FILE APDU command in which the name matches the AID of an applet, the Java Card RE calls the <KBD CLASS="Filename-Command">Applet.deselect</KBD> method of the currently selected applet or, if concurrently selected on more than one logical channel, its <KBD CLASS="Filename-Command">MultiSelectable.deselect</KBD> method. For more details see <A HREF="JCRESpec04selection.html#32535" CLASS="XRef">Section 4.2, Multiselectable Applets</A>. Applet deselection may also be requested by the MANAGE CHANNEL CLOSE command. For more details, see <A HREF="JCRESpec04selection.html#11324" CLASS="XRef">Section 4.6, Applet Deselection</A>.</P><P CLASS="Paragraph"><A NAME="pgfId-419765"></A>The <KBD CLASS="Filename-Command">deselect</KBD> method allows the applet to perform any cleanup operations that may be required to allow some other applet to execute.</P><P CLASS="Paragraph"><A NAME="pgfId-419666"></A>The <KBD CLASS="Filename-Command">Applet.selectingApple</KBD>t method shall return <KBD CLASS="Filename-Command">false</KBD> when called during the <KBD CLASS="Filename-Command">deselect</KBD> method. Exceptions thrown by the <KBD CLASS="Filename-Command">deselect</KBD> method are caught by the Java Card RE, but the applet is deselected.</P><H2 CLASS="Head1"><A NAME="pgfId-419684"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>3.5	<KBD CLASS="Filename-Command">uninstall</KBD> Method</H2>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -