Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

How to write a CardTerminal class for simple and complex readers in an OpenCard environment

Learn the ropes of writing the software part for your card terminal device using the OpenCard Framework

So, you've been reading previous Java Developer columns on smart cards and the OpenCard Framework (OCF). You have the OpenCard Framework software and your card terminal device. Now, what exactly do you need to do to make the two work together? In this edition of Java Developer, we'll explain, step-by-step, exactly how to get your software and hardware to cooperate. We hope this article will convince you that this is a fairly easy process!

The OpenCard Framework offers general functionality for dealing with card terminals. (Although they're often called card readers, the OCF uses the more general, all-encompassing term card terminal for these devices.) Unfortunately, no concrete card terminal class was provided in the core and opt packages (although there are a few example implementations in the OCF Reference Implementation). Including a concrete card terminal class simply isn't possible due to the sheer variety of existing devices. This means some work remains to be done by the "terminal integrator" -- yes, that's you!

The missing terminal-dependent functionality is comprised of the following facilities:

  • Creation of the card terminal object
  • Initialization/shutdown of the card terminal object
  • Provision of information about the card terminal type


Smart card-related functionality:

  • Detection of insertion or removal of a smart card
  • Powering/unpowering of the card
  • Return of information about the smart card (ATR)
  • Communication with a smart card
  • Resetting of a card


In the following section, we'll show you what to implement in order to realize this functionality.

Writing an OCF card terminal step by step

Step 1. Obtain the required information & make the basic decisions
To ensure an efficient development process, it is recommended that you collect the following information and make a few decisions right from the beginning:

A. Create a new factory class or reuse an existing one

Objects of subclasses of CardTerminal are brought into being by means of a factory object. If you already have such a factory class, reuse it and change it such that it can handle the new CardTerminal class too. If you don't have a factory class yet, well, write one from scratch! (We'll explain how to do this later on in the article.)

B. Determine the name of the terminal family

The card terminal device should come with a name. So take this name and make a name string from it that complies with the Java syntax.

C. Determine the number of slots

The number of slots will default to one in most cases, but as the smart card market expands we'll see devices with more than one slot.

D. Enable communication over javax.comm or native methods

Your Java terminal class must somehow communicate with the physical device. This can be accomplished in one of several ways. If the terminal comes with prebuilt libraries, you can use those by means of Java's native method interface (JNI). The advantage to this is that a lot of the required functionality is already implemented. The downside is, of course, that this approach renders your card terminal implementation platform-dependent. The second possibility is to use Java's mechanism of accessing the serial port of your machine using the package javax.comm. This package isn't included in the current JDK release but it is part of Java's extension classes in the just-released major upgrade to JDK 1.2 (now known as the Java 2 platform). A beta release can be obtained separately from the Java Developer Connection on Sun's java.sun.com site. Currently javax.comm supports only serial and parallel devices.

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |  Next >
Resources
  • Litronic source code for an OCF card terminal ftp://www.itplus.dk/
  • TLP224 source code for an OCF card terminal http://www.javaworld.com/jw-01-1999/javadev/tlp224.jar
  • SmartMouse Source code for a non-OCF terminal http://www.javaworld.com/jw-01-1999/javadev/sm.jar
  • The official OpenCard Framework site http://www.opencard.org
  • An introduction to the Java Native Method Interface in the Java Tutorial http://www.javasoft.com/docs/books/tutorial/native1.1/index.html
  • A previous Java Developer column, "Smart cards and the OpenCard Framework" http://www.javaworld.com/jw-01-1998/jw-01-javadev.html
  • The beta version of Java's communication API on Java Developer Connection (registration required) http://developer.java.sun.com/developer/earlyAccess/javacomm/index.html
  • Previous Java Developer columns can be found at http://www.javaworld.com/topicalindex/jw-ti-javadev.html