Пример #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
  /**
   * Step is initialized. Sanity checks the parameters.
   *
   * @param smi Step meta
   * @param sdi Step data
   * @return false if anything goes wrong
   */
  public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
    meta = (ZosFileInputMeta) smi;
    data = (ZosFileInputData) sdi;

    data.filename = environmentSubstitute(meta.getFilename());
    if (Const.isEmpty(data.filename)) {
      logError(BaseMessages.getString(PKG, "ZosFileInput.MissingFilename.Message"));
      return false;
    }
    logBasic(BaseMessages.getString(PKG, "ZosFileInput.ReadingFromFile.Message", data.filename));

    data.compositeJaxbClassName = environmentSubstitute(meta.getCompositeJaxbClassName());
    if (Const.isEmpty(data.compositeJaxbClassName)) {
      logError(BaseMessages.getString(PKG, "ZosFileInput.MissingJaxbClassName.Message"));
      return false;
    }

    logBasic(
        BaseMessages.getString(
            PKG, "ZosFileInput.UsingJAXBClass.Message", data.compositeJaxbClassName));

    return super.init(smi, sdi);
  }