Package net.sf.xbus.technical.misc

Source Code of net.sf.xbus.technical.misc.ProgramSender

package net.sf.xbus.technical.misc;

import net.sf.xbus.base.core.Constants;
import net.sf.xbus.base.core.XException;
import net.sf.xbus.base.core.config.Configuration;
import net.sf.xbus.base.core.timeoutcall.TimedCallable;
import net.sf.xbus.base.xbussystem.XBUSSystem;
import net.sf.xbus.technical.Sender;
import net.sf.xbus.technical.TextSender;

/**
* <code>ProgramSender</code> calls an external program. Program name and
* parameters are read out of the configuration.
*/
public class ProgramSender implements Sender, TextSender
{
  protected XBUSSystem mDestination = null;

  /**
   * Stores the destination.
   *
   * @param destination name of the interface definition
   * @throws XException never
   */
  public ProgramSender(XBUSSystem destination)
  {
    mDestination = destination;
  }

  /**
   * Calls an external program. Program name and parameters are read out of
   * the configuration.
   *
   * @param function ignored
   * @param callData ignored
   */
  public String execute(String function, String callData) throws XException
  {
    String retString = null;

    Configuration config = Configuration.getInstance();
    int timeout = config.getValueAsIntOptional(Constants.CHAPTER_SYSTEM,
        mDestination.getName(), "Timeout") * 1000;
    if (timeout == 0)
    {
      timeout = Integer.MAX_VALUE;
    }

    ProgramCaller caller = new ProgramCaller(mDestination, callData);
    TimedCallable tc = new TimedCallable(caller, timeout);
    try
    {
      retString = (String) tc.call();
    }
    catch (Exception e)
    {
      throw new XException(Constants.LOCATION_EXTERN,
          Constants.LAYER_TECHNICAL,
          Constants.PACKAGE_TECHNICAL_JAVA, "0", e);
    }
    return retString;
  }

  /*
   * (non-Javadoc)
   *
   * @see net.sf.xbus.technical.Sender#getType()
   */
  public String getType()
  {
    return Constants.TYPE_TEXT;
  }
}
TOP

Related Classes of net.sf.xbus.technical.misc.ProgramSender

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.