Changeset 3128


Ignore:
Timestamp:
Feb 9, 2007, 4:39:41 PM (16 years ago)
Author:
Johan Enell
Message:

Added javadoc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/core/net/sf/basedb/plugins/Base1PluginExecuter.java

    r3108 r3128  
    7474import java.io.BufferedInputStream;
    7575import java.io.BufferedOutputStream;
    76 import java.io.BufferedReader;
    7776import java.io.ByteArrayOutputStream;
    7877import java.io.FileInputStream;
     
    8180import java.io.IOException;
    8281import java.io.InputStream;
    83 import java.io.InputStreamReader;
    84 import java.io.PrintWriter;
     82import java.io.OutputStream;
    8583import java.sql.SQLException;
    8684import java.util.ArrayList;
     
    9795import java.util.regex.Pattern;
    9896
     97/**
     98 * This plug-in executes a plug-in from the Base1 system. It takes a base1 configuration
     99 * file to create its configuration.
     100 *
     101 * @author Johan Enell
     102 * @version 2.2
     103 * @base.modified $Date$
     104 */
    99105public class Base1PluginExecuter extends AbstractAnalysisPlugin implements InteractivePlugin
    100106{
     107
    101108  /**
    102109   * Plugin description
     
    111118    "http://base.thep.lu.se");
    112119 
     120  /**
     121   * The plug-ing permissions.
     122   */
    113123  private static final Set<Permissions> permissions = new HashSet<Permissions>();
    114124 
    115   /**
    116    * Parameter definition that asks for the file that should be imported. This
    117    * is a required parameter for the job configuration.
     125  /* Configuration parameters */
     126
     127  /**
     128   * Parameter definition that asks for the configuration file that should be imported.
    118129   */
    119130  private static final PluginParameter<File> fileParameter = new PluginParameter<File>(
     
    123134    new FileParameterType(null, false, 1));
    124135
     136  /**
     137   * The path to where the plug-in executer can find the executables. In Base1 this was
     138   * default to /usr/local/base/plugins.
     139   */
    125140  private static PluginParameter<String> execPathParameter = new PluginParameter<String>(
    126141    "execPath",
     
    128143    "The path to the executables",
    129144    new StringParameterType(255, null, true));
    130  
    131   /* File configuration parameters */
     145
     146  /**
     147   * This parameter describes if the data should be exported in serial format or
     148   * in matrix.
     149   */
    132150  private PluginParameter<Boolean> serialFormatParameter;
     151 
     152  /**
     153   * The version number of the plug-in.
     154   */
    133155  private PluginParameter<String> versionNumberParameter;
     156 
     157  /**
     158   * The name of the executable.
     159   */
    134160  private PluginParameter<String> execNameParameter;
     161 
     162  /**
     163   * If the data should be exported averaged per gene.
     164   */
    135165  private PluginParameter<Boolean> geneAveragesParameter;
     166 
     167  /**
     168   * The minimum number of channels.
     169   */
    136170  private PluginParameter<Integer> minChannelsParameter;
     171 
     172  /**
     173   * The maximu number of channels, 0 means unlimited.
     174   */
    137175  private PluginParameter<Integer> maxChannelsParameter;
     176 
     177  /**
     178   * If the plug-in should leave the stdin.txt after execution.
     179   */
    138180  private PluginParameter<Boolean> leaveStdinParameter;
     181 
     182  /**
     183   * If the plug-in should leave the stdout.txt after execution.
     184   */
    139185  private PluginParameter<Boolean> leaveStdoutParameter;
     186 
     187  /**
     188   * The reporter fields that should be exported as a tab separeated string
     189   * of column headers.
     190   */
    140191  private PluginParameter<String> usedColumnsParameter;
     192 
     193  /**
     194   * The spot fields that should be exported as a tab separated string of
     195   * column headres.
     196   */
    141197  private PluginParameter<String> usedFieldsParameter;
    142198 
    143199  /* Job parameters */
     200  /**
     201   * The directory where the plug-in will store it's output.
     202   */
    144203  private PluginParameter<String> pluginDirectoryParameter;
    145204
     205  /**
     206   * This command is used if the user decides to configure the plugin by hand.
     207   */
    146208  private static final String COMMAND_MANUAL_CONFIG = "COMMAND_MANUAL_CONFIG";
    147209
     210  /**
     211   * Holds info about a job configuration request.
     212   */
    148213  private RequestInformation configureJob;
     214 
     215  /**
     216   * Holds information about a plugin configuration request.
     217   */
    149218  private RequestInformation configurePlugin;
     219 
     220  /**
     221   * Holds information about a manual plugin configuration request.
     222   */
    150223  private RequestInformation configureManual;
    151224
     
    162235  /* From InteractivePlugin iterface */
    163236
     237  /**
     238   * Checks if the BioAssaySet has the number of channels specified by the
     239   * configuration and that it has the extra values.
     240   *
     241   * @param context The context from where the plugin is invoked.
     242   * @param item The item that should be checked if it is in context.
     243   * @return null if the the item is in context, otherwise an error messge.
     244   * @see net.sf.basedb.core.plugin.AbstractAnalysisPlugin#isInContext(net.sf.basedb.core.plugin.GuiContext, java.lang.Object)
     245   */
    164246  @Override
    165247  public String isInContext(GuiContext context, Object item)
     
    334416 
    335417 
     418  /**
     419   * Copies the content from a File to a directory on the filesystem.
     420   *
     421   * @param f The file to be copied.
     422   * @param d The directory where the file will be written.
     423   * @throws IOException If there is any error with target.
     424   */
    336425  private void copy(File f, java.io.File d)
    337426    throws IOException
     
    342431      InputStream in = f.getDownloadStream(0);
    343432      FileOutputStream out = new FileOutputStream(target);
    344       byte[] buf = new byte[1024];
    345       int i = 0;
    346       while((i = in.read(buf)) != -1)
    347       {
    348         out.write(buf, 0, i);
    349       }
    350       in.close();
    351       out.close();
    352     }
    353   }
    354  
    355  
     433     
     434      StreamHandler sh = new StreamHandler(in, out);
     435      sh.run();
     436    }
     437  }
     438 
     439 
     440  /**
     441   * Creates the plugin directory specified by {@link Base1PluginExecuter#pluginDirectoryParameter}.
     442   */
    356443  private void createPluginDirectory()
    357444  {
     
    379466 
    380467
    381   /**
    382   */
    383468  @Override
    384469  public Collection<Permissions> getPermissions()
     
    491576 
    492577
     578  /**
     579   * Export the bioassay set to a file called 'stdin.txt' in the plugin directory.
     580   *
     581   * @param dc The DbControl used to connect to the database.
     582   * @return The file where the data is exported to.
     583   */
    493584  private File exportData(DbControl dc)
    494585  {
     
    540631 
    541632 
     633  /**
     634   * Get the experimental factors connected to a experiment.
     635   *
     636   * @param dc The DbControl used to connect to the database.
     637   * @param e The experiment.
     638   * @return A list of {@link AnnotationType AnnotationTypes}
     639   */
    542640  private List<AnnotationType> getAnnotationTypes(DbControl dc, Experiment e)
    543641  {
     
    549647 
    550648 
    551  
     649  /**
     650   * Get the headers from a configuration file.
     651   *
     652   * @param f The file.
     653   * @return A map of name->value pairs.
     654   * @throws IOException If there i any problem reading from file.
     655   */
    552656  private Map<String, String> getBaseFileHeaders(File f)
    553657    throws IOException
     
    572676 
    573677 
     678  /**
     679   * Creates a boolean from a string.
     680   *
     681   * @param s The string.
     682   * @return false if s.equals("0") else true.
     683   */
    574684  private Boolean getBoolean(String s)
    575685  {
     
    577687  }
    578688 
     689  /**
     690   * Creates the information needed for manual configuration and initiates the
     691   * parameters. The parameters added are: versionNumber, usedColumns, usedFields, execName,
     692   * geneAverages, SerialFormat, leaveStdin, leaveStdout, minChannel and maxCannel.
     693   *
     694   * @return The RequestInformation.
     695   */
    579696  private RequestInformation getManualConfigureParameters()
    580697  {
     
    667784
    668785 
     786  /**
     787   * Creates the information needed for job configuration and initiates the
     788   * parameters. The parameters added are: bioAssaySet and the parameters
     789   * found in the configuration file.
     790   *
     791   * @return The RequestInformation.
     792   * @throws IOException If there is any error reading from the configuration file.
     793   */
    669794  private RequestInformation getConfigureJobParameters()
    670795    throws IOException
     
    687812 
    688813 
     814  /**
     815   * Creates the information needed for plugin configuration and initiates the
     816   * parameters. The parameters added are: file and execPath.
     817   *
     818   * @return The RequestInformation.
     819   */
    689820  private RequestInformation getConfigurePluginParameters()
    690821  {
     
    705836
    706837 
     838  /**
     839   * Get the exec directory as a java.io.File. The exec directory is a sudirectory in
     840   * "java.io.tmpdir".
     841   *
     842   * @return the directory.
     843   */
    707844  private java.io.File getExecDirectory()
    708845  {
     
    717854
    718855 
     856  /**
     857   * Creates a {@link FlatFileParser} for a plugin configuration file.
     858   *
     859   * @param stream The stream that the parser should read from.
     860   * @return The initialized parser
     861   */
    719862  private FlatFileParser getInitializedFlatFileParser(InputStream stream)
    720     throws BaseException
    721863  {
    722864    FlatFileParser ffp = new FlatFileParser();
     
    731873 
    732874 
     875  /**
     876   * Reads the configuration file an creates the parameters found there.
     877   *
     878   * @return A list of {@ling PluginParameter PluginsParameters}
     879   * @throws IOException Thrown if there is any problem reading the configuration file.
     880   */
    733881  private List<PluginParameter<?>> getJobParameters()
    734882    throws IOException
     
    8861034 
    8871035
     1036  /**
     1037   * Creates the {@link Path} to the plugin directory.
     1038   *
     1039   * @return The path
     1040   */
    8881041  private Path getPluginDirectoryPath()
    8891042  {
     
    8931046 
    8941047 
     1048  /**
     1049   * Imports the data from the file stdout.txt in the execution directory.
     1050   *
     1051   * @return The id of the transformation the data is connected to.
     1052   * @throws IOException if there is any error reading from stdou.txt
     1053   */
    8951054  private int importData()
    8961055    throws IOException
     
    12211380    }
    12221381  }
    1223    
    1224  
     1382 
     1383 
     1384  /**
     1385   * This thread read everything from one input streat ant writes everything to an output stream.
     1386   *
     1387   * @author Johan Enell
     1388   */
    12251389  private class StreamHandler extends Thread
    12261390  {
    1227     private BufferedInputStream is;
    1228 
    1229     private BufferedOutputStream os;
    1230 
    1231     StreamHandler(BufferedInputStream is, BufferedOutputStream redirect)
     1391    /**
     1392     * The input stream to read from;
     1393     */
     1394    private InputStream is;
     1395
     1396    /**
     1397     * The output stream to write to.
     1398     */
     1399    private OutputStream os;
     1400
     1401    /**
     1402     * Creates a steam handler connected to the specifiv streams.
     1403     *
     1404     * @param is The stream to read from.
     1405     * @param redirect The stream to write to.
     1406     */
     1407    StreamHandler(InputStream is, OutputStream redirect)
    12321408    {
    12331409      this.is = is;
     
    12381414    public void run()
    12391415    {
    1240       PrintWriter out = new PrintWriter(os);
    1241       BufferedReader in = new BufferedReader(new InputStreamReader(is));
    1242       String line = null;
    12431416      try
    12441417      {
    1245         while ((line = in.readLine()) != null)
    1246         {
    1247           out.println(line);
    1248         }
    1249         out.close();
    1250         in.close();
     1418        byte[] buf = new byte[1024];
     1419        int i = 0;
     1420        while((i = is.read(buf)) != -1)
     1421        {
     1422          os.write(buf, 0, i);
     1423        }
     1424        is.close();
     1425        os.close();
    12511426      }
    12521427      catch (IOException e)
Note: See TracChangeset for help on using the changeset viewer.