File Source: DcopPlugin.java

         /* 
    P/P   *  Method: com.dmdirc.addons.dcop.DcopPlugin__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
     3   *
     4   * Permission is hereby granted, free of charge, to any person obtaining a copy
     5   * of this software and associated documentation files (the "Software"), to deal
     6   * in the Software without restriction, including without limitation the rights
     7   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8   * copies of the Software, and to permit persons to whom the Software is
     9   * furnished to do so, subject to the following conditions:
    10   *
    11   * The above copyright notice and this permission notice shall be included in
    12   * all copies or substantial portions of the Software.
    13   *
    14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    20   * SOFTWARE.
    21   */
    22  
    23  package com.dmdirc.addons.dcop;
    24  
    25  import com.dmdirc.plugins.Plugin;
    26  import com.dmdirc.commandparser.CommandManager;
    27  
    28  import java.io.BufferedReader;
    29  import java.io.IOException;
    30  import java.io.InputStreamReader;
    31  import java.util.ArrayList;
    32  import java.util.List;
    33  
    34  /**
    35   * Allows the user to execute dcop commands (and read the results).
    36   * 
    37   * @author chris
    38   */
    39  public final class DcopPlugin extends Plugin {
    40      /** The DcopCommand we created */
    41      private DcopCommand command = null;
    42      
    43      /** Creates a new instance of DcopPlugin. */
    44      public DcopPlugin() {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.dcop.DcopPlugin()
                  * 
                  *  Postconditions:
                  *    this.command == null
                  */
    45          super();
    46      }
    47      
    48      /**
    49       * Retrieves the result from executing the specified command.
    50       *
    51       * @param command The command to be executed
    52       * @return The output of the specified command
    53       */
    54      public static List<String> getDcopResult(final String command) {
                 /* 
    P/P           *  Method: List getDcopResult(String)
                  * 
                  *  Presumptions:
                  *    java.lang.Runtime:exec(...)@62 != null
                  *    java.lang.Runtime:getRuntime(...)@62 != null
                  * 
                  *  Postconditions:
                  *    return_value == &amp;new ArrayList(getDcopResult#1)
                  *    new ArrayList(getDcopResult#1) num objects == 1
                  * 
                  *  Test Vectors:
                  *    java.io.BufferedReader:readLine(...)@69: Addr_Set{null}, Inverse{null}
                  */
    55          final ArrayList<String> result = new ArrayList<String>();
    56  
    57          InputStreamReader reader;
    58          BufferedReader input;
    59          Process process;
    60          
    61          try {
    62              process = Runtime.getRuntime().exec(command);
    63              
    64              reader = new InputStreamReader(process.getInputStream());
    65              input = new BufferedReader(reader);
    66              
    67              String line = "";
    68              
    69              while ((line = input.readLine()) != null) {
    70                  result.add(line);
    71              }
    72              
    73              reader.close();
    74              input.close();
    75              process.destroy();
    76          } catch (IOException ex) {
    77              // Do nothing
    78          }
    79          
    80          return result;
    81      }
    82      
    83      /** {@inheritDoc} */
    84      @Override
    85      public void onLoad() {
                 /* 
    P/P           *  Method: void onLoad()
                  * 
                  *  Postconditions:
                  *    this.command == &amp;new DcopCommand(onLoad#1)
                  *    new DcopCommand(onLoad#1) num objects == 1
                  */
    86          command = new DcopCommand();
    87      }
    88      
    89      /** {@inheritDoc} */
    90      @Override
    91      public void onUnload() {
                 /* 
    P/P           *  Method: void onUnload()
                  * 
                  *  Preconditions:
                  *    init'ed(this.command)
                  */
    92          CommandManager.unregisterCommand(command);
    93      }
    94  
    95  }








SofCheck Inspector Build Version : 2.17854
DcopPlugin.java 2009-Jun-25 01:54:24
DcopPlugin.class 2009-Sep-02 17:04:15