All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.keyple.calypso.command.po.AbstractPoResponseParser Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
/* **************************************************************************************
 * Copyright (c) 2019 Calypso Networks Association https://www.calypsonet-asso.org/
 *
 * See the NOTICE file(s) distributed with this work for additional information
 * regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the terms of the
 * Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 ************************************************************************************** */
package org.eclipse.keyple.calypso.command.po;

import org.eclipse.keyple.calypso.command.po.exception.*;
import org.eclipse.keyple.core.card.command.AbstractApduResponseParser;
import org.eclipse.keyple.core.card.command.CardCommand;
import org.eclipse.keyple.core.card.command.exception.KeypleCardCommandException;
import org.eclipse.keyple.core.card.message.ApduResponse;

public abstract class AbstractPoResponseParser extends AbstractApduResponseParser {

  /**
   * The generic abstract constructor to build a parser of the APDU response.
   *
   * @param response response to parse
   * @param builder the reference of the builder that created the parser
   */
  public AbstractPoResponseParser(
      ApduResponse response, AbstractPoCommandBuilder builder) {
    super(response, builder);
  }

  /** {@inheritDoc} */
  @Override
  public final AbstractPoCommandBuilder getBuilder() {
    return (AbstractPoCommandBuilder) super.getBuilder();
  }

  /** {@inheritDoc} */
  @Override
  protected final KeypleCardCommandException buildCommandException(
      Class exceptionClass,
      String message,
      CardCommand commandRef,
      Integer statusCode) {

    KeypleCardCommandException e;
    CalypsoPoCommand command = (CalypsoPoCommand) commandRef;
    if (exceptionClass == CalypsoPoAccessForbiddenException.class) {
      e = new CalypsoPoAccessForbiddenException(message, command, statusCode);
    } else if (exceptionClass == CalypsoPoDataAccessException.class) {
      e = new CalypsoPoDataAccessException(message, command, statusCode);
    } else if (exceptionClass == CalypsoPoDataOutOfBoundsException.class) {
      e = new CalypsoPoDataOutOfBoundsException(message, command, statusCode);
    } else if (exceptionClass == CalypsoPoIllegalArgumentException.class) {
      e = new CalypsoPoIllegalArgumentException(message, command);
    } else if (exceptionClass == CalypsoPoIllegalParameterException.class) {
      e = new CalypsoPoIllegalParameterException(message, command, statusCode);
    } else if (exceptionClass == CalypsoPoPinException.class) {
      e = new CalypsoPoPinException(message, command, statusCode);
    } else if (exceptionClass == CalypsoPoSecurityContextException.class) {
      e = new CalypsoPoSecurityContextException(message, command, statusCode);
    } else if (exceptionClass == CalypsoPoSecurityDataException.class) {
      e = new CalypsoPoSecurityDataException(message, command, statusCode);
    } else if (exceptionClass == CalypsoPoSessionBufferOverflowException.class) {
      e = new CalypsoPoSessionBufferOverflowException(message, command, statusCode);
    } else if (exceptionClass == CalypsoPoTerminatedException.class) {
      e = new CalypsoPoTerminatedException(message, command, statusCode);
    } else {
      e = new CalypsoPoUnknownStatusException(message, command, statusCode);
    }
    return e;
  }

  /** {@inheritDoc} */
  @Override
  public void checkStatus() {
    try {
      super.checkStatus();
    } catch (KeypleCardCommandException e) {
      throw (CalypsoPoCommandException) e;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy