示例#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();
    }
  }