OpenCard Framework 1.2 Programmer's Guide - OpenSCDP
OpenCard Framework 1.2 Programmer's Guide - OpenSCDP
OpenCard Framework 1.2 Programmer's Guide - OpenSCDP
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Obtaining a card service<br />
Handling exceptions<br />
Card services are the means by which smart card functions are made available to<br />
the application. Thus, the next step is to obtain the proper instance of a given card<br />
service.<br />
The actions you have to take depend on the nature of the application. We<br />
distinguish between two types of applications: (1) the ones that are prepared to<br />
work with only one particular card-resident application, and (2) the ones that can<br />
interact with a variety of different (at least two) card-resident applications.<br />
In the first situation, you have probably specified the CardService class that you<br />
already required at the time you issued the waitForCard call. The code fragment to<br />
obtain e.g. FileAccessCardService looks like this:<br />
FileAccessCardService facs = null;<br />
try {<br />
facs = (FileAccessCardService)<br />
card.getCardService(FileAccessCardService, true);<br />
} catch <strong>OpenCard</strong> Exceptions {<br />
// handle error...<br />
}<br />
You’re now ready to start working with the requested card service. We’ll show you<br />
how to work with some of the available card services in subsequent sections.<br />
In the situation where your application can interact with several different<br />
card-resident applications, you will have to find out what card-resident<br />
applications are present. For that purpose, you must obtain<br />
AppletAccessCardService, which has a list method that lets you obtain the list of<br />
applications on the card. In this case, the code looks something like this:<br />
AppletAccessCardService aacs = null;<br />
try {<br />
aacs = (AppletAccessCardService)<br />
card.getCardService(AppletAccessCardService, true);<br />
} catch <strong>OpenCard</strong> Exceptions {<br />
// handle error...<br />
}<br />
You’re now ready to write the code to select a particular application in the card.<br />
We’ll show you how to do that in the next section.<br />
It is important that provisions be made in every code for dealing with exceptional<br />
circumstances, and OPENCARD FRAMEWORK features a number of corresponding<br />
methods for responding appropriately to unusual situations.<br />
At the root of OCF’s exception hierarchy are two classes:<br />
opencard.core.<strong>OpenCard</strong>Exception and opencard.core.<strong>OpenCard</strong>RuntimeException.<br />
The first is a subclass of JAVA’s IOException and is therefore checked, while the<br />
second is a subclass of RuntimeException and is thus unchecked. The distinction is<br />
that the latter need not be caught or declared to be thrown (i.e. the compiler does<br />
not force you to handle these exceptions - hence the term ’unchecked exception’).<br />
The rationale behind this concept is that exceptions of this kind disrupt the normal<br />
program flow so severely that continuing would not make much sense. Further,<br />
from a pragmatic point of view, it would often be impractical to check for these<br />
conditions (an example of this is OutOfMemoryError, which can be thrown<br />
Chapter 4. Programming with OCF 21