Esempio n. 1
0
  /**
   * Reads a DIMSE-C message.
   *
   * @param pdu the context pdu DICOMClientServer
   * @param dco the incoming DICOM message
   * @param ddo a place to store the incoming DICOM data object or null if not required
   * @exception DICOM_Exception DOCUMENT ME!
   */
  public void readCResponseAlias(
      final DICOM_PDUService pdu, final DICOM_Object dco, final DICOM_Object ddo)
      throws DICOM_Exception {

    if (dco == null) {
      throw new DICOM_Exception("null dco");
    }

    final int command = dco.getInt16(DICOM_RTC.DD_CommandField);

    if (command != COMMAND) { // not correct command
      throw new DICOM_Exception(
          "DIMSE-C Request error: "
              + DICOM_Util.toHexString((short) command)
              + " looking for "
              + DICOM_Util.toHexString(COMMAND));
    }

    final int dstype = dco.getInt16(DICOM_RTC.DD_DataSetType);

    if (dstype != DICOM_Constants.DSTYPE_NODATAPRESENT) {

      // data is present
      if (Preferences.debugLevel(Preferences.DEBUG_COMMS)) {
        Preferences.debug("CRequest.readCResponseAlias DCO : Data is present" + "\n");
      }

      if (ddo == null) {
        throw new DICOM_Exception("null ddo");
      }

      if (pdu == null) {
        throw new DICOM_Exception("null pdu");
      }

      pdu.readInObject(ddo);
    } else {

      if (ddo != null) {
        ddo.clear();
      }
    }

    final int status = dco.getInt16(DICOM_RTC.DD_Status);

    if (Preferences.debugLevel(Preferences.DEBUG_COMMS)) {

      if (dco != null) {
        Preferences.debug("CRequest.readCResponseAlias DCO : " + dco.toString("DCO") + "\n");
      }

      if (ddo != null) {
        Preferences.debug("CRequest.readCResponseAlias DDO : " + ddo.toString("DDO") + "\n");
      }
    }

    if ((status >= DICOM_Constants.STATUS_ERRORFIRST)
        && (status <= DICOM_Constants.STATUS_ERRORLAST)) {
      String str1, errorComment;

      str1 =
          "Status error for command  = "
              + DICOM_Constants.convertCommandToString(COMMAND)
              + // +DICOM_Util.toHexString(
              // (short)
              // COMMAND ) +
              " status = ["
              + DICOM_Util.toHexString((short) status)
              + "] ";
      errorComment = dco.getStr(DICOM_RTC.DD_ErrorComment); // + dco.getOffending Element;

      // Preferences.debug("CRequest.readCResponseAlias DCO : " + dco.toString("DCO") + "\n");
      // Preferences.debug("CRequest.readCResponseAlias DDO : " + ddo.toString("DDO") + "\n");
      // System.out.println("DD_ErrorComment = " + errorComment);

      if (errorComment != null) {
        str1 = str1 + errorComment + "\n";
      }

      throw new DICOM_Exception(str1);
    }
  }
Esempio n. 2
0
  /**
   * Reads a DIMSE-C message.
   *
   * @param pdu the context pdu
   * @param dco the incoming DICOM message
   * @param ddo store the incoming DICOM data object in this object
   * @exception DICOM_Exception DOCUMENT ME!
   */
  public void read(final DICOM_PDUService pdu, final DICOM_Object dco, final DICOM_Object ddo)
      throws DICOM_Exception {

    if (Preferences.debugLevel(Preferences.DEBUG_COMMS)) {
      Preferences.debug(DICOM_Util.timeStamper() + " CRequest.read: \n");
    }

    if (dco == null) {

      if (Preferences.debugLevel(Preferences.DEBUG_COMMS)) {
        Preferences.debug(DICOM_Util.timeStamper() + " CRequest.read: DCO is null \n");
      }

      throw new DICOM_Exception("DCO is null");
    }

    final int command = dco.getInt16(DICOM_RTC.DD_CommandField);

    if (command != COMMAND) {
      throw new DICOM_Exception(
          " DIMSE-C Request error : "
              + DICOM_Util.toHexString((short) command)
              + " looking for "
              + DICOM_Util.toHexString(COMMAND));
    }

    final int dataSetType = dco.getInt16(DICOM_RTC.DD_DataSetType);

    if (dataSetType != DICOM_Constants.DSTYPE_NODATAPRESENT) {

      if (ddo == null) {
        throw new DICOM_Exception("DICOM data object is null");
      }

      if (pdu == null) {
        throw new DICOM_Exception("PDU is null");
      }

      pdu.readInObject(ddo);
    } else {

      if (ddo != null) {
        ddo.clear();
      } // Information is not present
    }

    final int status = dco.getInt16(DICOM_RTC.DD_Status);

    if ((status >= DICOM_Constants.STATUS_ERRORFIRST)
        && (status <= DICOM_Constants.STATUS_ERRORLAST)) {
      String str1, str2;

      str1 =
          "Status in error "
              + DICOM_Util.toHexString((short) COMMAND)
              + " ["
              + DICOM_Util.toHexString((short) status)
              + "] ";
      str2 = dco.getStr(DICOM_RTC.DD_ErrorComment);

      if (str2 != null) {
        str1 = str1 + str2;
      }

      throw new DICOM_Exception(str1);
    }
  }