Source code for /engineering/autohit-2003/src/autohit/server/command/CommandLoadProps.javaOriginal file CommandLoadProps.java
   1 /**
   2  * AUTOHIT 2003
   3  * Copyright Erich P Gatejen (c) 1989,1997,2003,2004
   4  * 
   5  * This program is free software; you can redistribute it and/or modify 
   6  * it under the terms of the GNU General Public License as published by 
   7  * the Free Software Foundation; either version 2 of the License, or (at
   8  * your option) any later version.
   9  * This program is distributed in the hope that it will be useful, but
  10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12  * more details.
  13  * 
  14  * You should have received a copy of the GNU General Public License along
  15  * with this program; if not, write to the Free Software Foundation, Inc.,
  16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17  *
  18  * Additional license information can be found in the documentation.
  19  * @author Erich P Gatejen
  20  */
  21 package autohit.server.command;
  22 
  23 import java.io.IOException;
  24 import java.io.InputStream;
  25 
  26 import org.apache.commons.collections.ExtendedProperties;
  27 
  28 import autohit.common.AutohitErrorCodes;
  29 import autohit.server.ServerException;
  30 import autohit.universe.UniverseException;
  31 
  32 /**
  33  * The LOADPROPS command.  It will load properties to a specified
  34  * disk locations.  The load may or may not be destructive.  
  35  * <p>
  36  * <code>
  37  * COMMAND LIST
  38  * this.assert(false,false,false,false,true,false)
  39  * 0-UNI 		- OPTIONAL
  40  * 1-RESPONSE 	- OPTIONAL
  41  * 2-TARGET		- OPTIONAL
  42  * 3-CLASS		- UNUSED
  43  * 4-COMMAND	- REQUIRED
  44  * 5-OBJECT		- UNUSED
  45  * </code>
  46  * 
  47  * @author Erich P. Gatejen
  48  * @version 1.0 <i>Version History</i><code>EPG - Initial - 4Dec03</code>
  49  */
  50 public class CommandLoadProps extends Command {
  51 
  52 	final static long serialVersionUID = 1;
  53 	
  54 	/**
  55 	 * My name */
  56 	public final static String MY_NAME = "props";
  57 	public final static String LIST_HEADER = "LOAD PROPERTIES" + RESPONSE_ELEMENT_SEPERATOR;
  58 
  59 	/**
  60 	 * Execute the command.
  61 	 * 
  62 	 * @throws ServerException
  63 	 * @return return the manreadable message for success.
  64 	 */
  65 	public String execute() throws ServerException {
  66 
  67 		String victory = "failed.";
  68 		boolean started = false;
  69 
  70 		// Trap all non-critical errors and just log them to the
  71 		// responseChannel
  72 		try {
  73 
  74 			// Get the properties and try to save them.
  75 			ExtendedProperties iprops = sc.getInvokerProperties();
  76 			InputStream is = uni.getStream(command);
  77 			iprops.load(is);
  78 			is.close();
  79 			
  80 			// Ok, it's working
  81 			victory = "saved.";
  82 
  83 		} catch (IOException ioe) {	
  84 			throw new ServerException(
  85 					"failed.  There was an IO error.  message=" + ioe.getMessage(),
  86 					AutohitErrorCodes.EVENT_COMMAND_FAILED, ioe);
  87 			
  88 		} catch (UniverseException ue) {	
  89 	
  90 			throw new ServerException(
  91 					"failed.  There was a Universe Exception.  message=" + ue.getMessage(),
  92 					AutohitErrorCodes.EVENT_COMMAND_FAILED, ue);
  93 			
  94 		} catch (Exception e) {
  95 
  96 			throw new ServerException(
  97 				"failed.  There was a general Exception.  message=" + e.getMessage(),
  98 				AutohitErrorCodes.EVENT_COMMAND_FAILED,e);
  99 		}
 100 
 101 		// return
 102 		return victory;
 103 	}
 104 
 105 	/**
 106 	 * Verify the Save Props command.
 107 	 * 
 108 	 * @throws ServerException
 109 	 * @return return the manreadable message for accepting the command.
 110 	 */
 111 	public String verify() throws ServerException {
 112 		this.assertparam(false, false, false, false, true, false);
 113 		return "parameters are good.";
 114 	}
 115 
 116 	/**
 117 	 * Get the textual name for the command.
 118 	 * 
 119 	 * @return return the manreadable name of this command.
 120 	 */
 121 	public String getName() {
 122 		return MY_NAME;
 123 	}
 124 }