예제 #1
0
  /**
   * Process a single row (this is repeated for all rows on input). On the first row, we do the
   * following:
   *
   * <ul>
   *   <li>Setup a class loader that contains the Transformer jar file
   *   <li>Use this class loader to create a new instance of the transformer
   *   <li>The transformer will be reused for all subsequent rows
   *   <li>Open the zos file
   *   <li>Process the first row (classloader will find custom code if needed)
   *   <li>Restore the context class loader to avoid interference with PDI
   * </ul>
   *
   * Here we also keep track of how many bytes from the file record were actually consumed by the
   * transformers. This allows the leftover to be processed on the next call to this method.
   *
   * @param smi Step meta
   * @param sdi Step data
   * @throws KettleException if something goes wrong
   */
  public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (ZosFileInputMeta) smi;
    data = (ZosFileInputData) sdi;

    if (first) {
      first = false;

      data.outputRowMeta = new RowMeta();
      meta.getFields(data.outputRowMeta, getStepname(), null, null, this);

      ClassLoader tccl = Thread.currentThread().getContextClassLoader();
      try {
        Cob2Pdi.setTransformerClassLoader(
            getClass(), Cob2Pdi.getJarFileName(data.compositeJaxbClassName));
        data.cobolBinding =
            Cob2Pdi.newCobolBinding(Cob2Pdi.getJaxbClassName(data.compositeJaxbClassName));
        data.fis = ZosFileInputStreamFactory.create(meta, new File(data.filename));
        data.hostRecord = Cob2Pdi.newHostRecord(data.cobolBinding);
        data.hostCharset = meta.getHostCharset();
        data.status = new HostTransformStatus();
        logBasic(BaseMessages.getString(PKG, "ZosFileInput.FileOpened.Message", data.filename));

        return processRow();

      } catch (FileNotFoundException e) {
        throw new KettleException(e);
      } finally {
        Thread.currentThread().setContextClassLoader(tccl);
      }

    } else {
      return processRow();
    }
  }
예제 #2
0
  /**
   * Process each record from the input file.
   *
   * @return true if we are not done yet
   * @throws KettleException if processing fails
   */
  protected boolean processRow() throws KettleException {
    try {
      // Tell the reader how many bytes we processed last time
      int count = data.fis.read(data.hostRecord, data.status.getHostBytesProcessed());

      if (count > 0) {
        Object[] outputRowData =
            Cob2Pdi.toOutputRowData(
                data.outputRowMeta,
                data.cobolBinding,
                data.hostRecord,
                data.hostCharset,
                data.status);
        putRow(data.outputRowMeta, outputRowData);
        if (checkFeedback(getLinesRead())) {
          logBasic(
              BaseMessages.getString(
                  PKG, "ZosFileInput.LinesRead.Message", getLinesRead(), data.filename));
        }
        return true;

      } else {
        setOutputDone();
        return false;
      }
    } catch (IOException e) {
      throw new KettleException(e);
    }
  }