PCSC4Java  0.2
Library PCSC for Java language.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
D:/Affaire/Perso/SmartCardToolBox/pcsc4java-framework-0.2/src/fr/redbilled/pcscforjava/CardTerminals.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
00003  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00004  *
00005  * This code is free software; you can redistribute it and/or modify it
00006  * under the terms of the GNU General Public License version 2 only, as
00007  * published by the Free Software Foundation.  Oracle designates this
00008  * particular file as subject to the "Classpath" exception as provided
00009  * by Oracle in the LICENSE file that accompanied this code.
00010  *
00011  * This code is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00014  * version 2 for more details (a copy is included in the LICENSE file that
00015  * accompanied this code).
00016  *
00017  * You should have received a copy of the GNU General Public License version
00018  * 2 along with this work; if not, write to the Free Software Foundation,
00019  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
00020  *
00021  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
00022  * or visit www.oracle.com if you need additional information or have any
00023  * questions.
00024  */
00025 
00026 package fr.redbilled.pcscforjava;
00027 
00028 import java.util.*;
00029 
00051 public abstract class CardTerminals{
00052 
00060     protected CardTerminals() {
00061         // empty
00062     }
00063         
00071     public List<CardTerminal> list() throws CardException {
00072          return list(State.ALL);
00073     }
00074 
00102     public abstract List<CardTerminal> list(State state) throws CardException;
00103 
00113     public CardTerminal getTerminal(String name) {
00114         if (name == null) {
00115             throw new NullPointerException();
00116         }
00117         try {
00118             for (CardTerminal terminal : list()) {
00119                 if (terminal.getName().equals(name)) {
00120                     return terminal;
00121                 }
00122             }
00123             return null;
00124         } catch (CardException e) {
00125             return null;
00126         }
00127     }
00128 
00140     public void waitForChange() throws CardException {
00141         waitForChange(0);
00142     }
00143 
00184     public abstract boolean waitForChange(long timeout) throws CardException;
00185         
00196     public abstract boolean isValidContext();
00197 
00204     public abstract void closeContext() throws CardException;
00205 
00214     public abstract void updateCardTerminalsListByEvent() throws CardException;
00215     
00216     public abstract boolean isPlugAndPlaySupported() throws CardException;
00217 
00224     public static enum State {
00228         ALL,
00232         CARD_PRESENT,
00236         CARD_ABSENT,
00242         CARD_INSERTION,
00248         CARD_REMOVAL,
00249     }
00250 
00255     @Override
00256     protected void finalize() throws Throwable {
00257         try {
00258             closeContext();
00259         } finally {
00260             super.finalize();
00261         }
00262     }
00263 }