use of es.gob.jmulticard.apdu.connection.ApduConnectionOpenedInExclusiveModeException in project jmulticard by ctt-gob-es.
the class SmartcardIoConnection method open.
/**
* {@inheritDoc}
*/
@Override
public void open() throws ApduConnectionException {
// Desactivamos las respuestas automaticas para evitar los problemas con el canal seguro
// $NON-NLS-1$ //$NON-NLS-2$
System.setProperty("sun.security.smartcardio.t0GetResponse", "false");
// $NON-NLS-1$ //$NON-NLS-2$
System.setProperty("sun.security.smartcardio.t1GetResponse", "false");
if (isExclusiveUse() && isOpen()) {
throw new ApduConnectionOpenedInExclusiveModeException();
}
final List<CardTerminal> terminales;
try {
terminales = TerminalFactory.getDefault().terminals().list();
} catch (final Exception e) {
throw new NoReadersFoundException(// $NON-NLS-1$
"No se han podido listar los lectores del sistema: " + e, // $NON-NLS-1$
e);
}
try {
if (terminales.size() < 1) {
throw new NoReadersFoundException();
}
if (this.terminalNumber == -1) {
final long[] cadsWithCard = getTerminals(true);
if (cadsWithCard.length > 0) {
this.terminalNumber = (int) cadsWithCard[0];
} else {
throw new ApduConnectionException(// $NON-NLS-1$
"En el sistema no hay ningun terminal con tarjeta insertada");
}
}
if (terminales.size() <= this.terminalNumber) {
throw new ApduConnectionException(// $NON-NLS-1$
"No se detecto el lector de tarjetas numero " + Integer.toString(this.terminalNumber));
}
this.card = terminales.get(this.terminalNumber).connect(this.protocol.toString());
} catch (final javax.smartcardio.CardNotPresentException e) {
throw new CardNotPresentException(e);
} catch (final CardException e) {
throw new ApduConnectionException(// $NON-NLS-1$ //$NON-NLS-2$
"No se ha podido abrir la conexion con el lector de tarjetas numero " + Integer.toString(this.terminalNumber) + ": " + e, // $NON-NLS-1$ //$NON-NLS-2$
e);
}
if (this.exclusive) {
try {
this.card.beginExclusive();
} catch (final CardException e) {
throw new ApduConnectionException(// $NON-NLS-1$ //$NON-NLS-2$
"No se ha podido abrir la conexion exclusiva con el lector de tarjetas numero " + Integer.toString(this.terminalNumber) + ": " + e, // $NON-NLS-1$ //$NON-NLS-2$
e);
}
}
this.canal = this.card.getBasicChannel();
}
Aggregations