package connection;

import java.util.List;

import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
import javax.smartcardio.Card;
import javax.smartcardio.CardChannel;
import javax.smartcardio.TerminalFactory;

public class Connection {

	private static CardTerminal terminal;
	private static Card card;
	private static boolean isConnected = false;

	public static List<CardTerminal> getTerminals() {
		try {
			TerminalFactory terminalFactory = TerminalFactory.getDefault();
			return terminalFactory.terminals().list();
		} catch (CardException e) {
			e.printStackTrace();
			System.exit(-1);
		}
		return null;
	}

	public static boolean connect() {

		try {
			card = terminal.connect("*");
			isConnected = true;
			return true;
		} catch (CardException e) {
			System.err.println("Bitte erst Karte einlegen");
		} catch (NullPointerException e) {
			System.err.println("Kein Lesegerät ausgewählt");
		}
		return false;
	}

	public static boolean disconnect() {

		try {
			card.disconnect(true);
			isConnected = false;
			return true;
		} catch (CardException e) {
			e.printStackTrace();
		} catch (NullPointerException e) {
			System.err.println("Keine offene Verbindung zu einer Karte");
		}

		return false;
	}

	public static void setTerminal(CardTerminal terminal) {
		Connection.terminal = terminal;
	}

	public static CardChannel getCardChannel() {
		
		try {
			return card.getBasicChannel();
		} catch (NullPointerException e) {
			System.err.println("Nicht zur Karte verbunden");
		}
		
		return null;
	}

	public static boolean isConnected() {
		return isConnected;
	}
	
	public static ResponseAPDU send(CommandAPDU select) {

		ResponseAPDU answer = null;

		try {
			answer = getCardChannel().transmit(select);
		} catch (CardException e) {
			e.printStackTrace();
		}

		return answer;
	}

}

@@ -344,16 +344,92 @@
 ction %7B%0D
+%0A%09%0D%0A%09private static final byte%5B%5D EMPTY = %7B (byte) 0x00, 0x00, 0x00, 0x00 %7D;%0D
 %0A%0D%0A%09priv
@@ -1922,22 +1922,43 @@
 swer = n
-ull
+ew ResponseAPDU(EMPTY)
 ;%0D%0A
+%09%09
 %0D%0A%09%09try 
@@ -2031,32 +2031,32 @@
 Exception e) %7B%0D%0A
-
 %09%09%09e.printStackT
@@ -2063,24 +2063,204 @@
 race();%0D%0A%09%09%7D
+ catch (IllegalStateException e) %7B%0D%0A%09%09%09System.err.println(%22Nicht zur Karte verbunden%22);%0D%0A%09%09%7D catch (NullPointerException e) %7B%0D%0A%09%09%09System.err.println(%22Keine Antwort erhalten%22);%0D%0A%09%09%7D
 %0D%0A%0D%0A%09%09return

Add exceptions to class Connection