Source code for /engineering/autohit-2003/src/autohit/server/command/CommandDump.javaOriginal file CommandDump.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.InputStream;
  24 
  25 import autohit.common.AutohitErrorCodes;
  26 import autohit.common.AutohitProperties;
  27 import autohit.server.ServerException;
  28 import autohit.universe.UniverseException;
  29 import autohit.vm.VMExecutableWrapper;
  30 
  31 /**
  32  * The DUMP command.  It expects a single string that points
  33  * to the universe object to dump.
  34  * <p>
  35  * <code>
  36  * COMMAND LIST
  37  * this.assert(false,false,false,false,true,false)
  38  * 0-UNI 		- OPTIONAL
  39  * 1-RESPONSE 	- OPTIONAL
  40  * 2-TARGET		- OPTIONAL
  41  * 3-CLASS		- UNUSED
  42  * 4-COMMAND	- REQUIRED	- Name of object in universe to dump
  43  * 5-OBJECT		- UNUSED
  44  * </code>
  45  * 
  46  * @author Erich P. Gatejen
  47  * @version 1.0
  48  * <i>Version History</i>
  49  * <code>EPG - Initial - 24Jul03<
  50  * 
  51  */
  52 public class CommandDump extends Command {
  53 
  54 	final static long serialVersionUID = 1;
  55 	
  56 	/**
  57 	 * My name
  58 	 */
  59 	public final static String MY_NAME = "dump";
  60 
  61 	/**
  62 	 * Execute the command.
  63 	 * @throws ServerException
  64 	 * @return return the manreadable message for success.
  65 	 */
  66 	public String execute() throws ServerException {
  67 
  68 		InputStream is;
  69 		VMExecutableWrapper ob;
  70 
  71 		try {
  72 
  73 			// find it
  74 			is =
  75 				uni.getStream(
  76 					AutohitProperties.literal_UNIVERSE_CACHE
  77 						+ AutohitProperties.literal_NAME_SEPERATOR
  78 						+ command);
  79 
  80 			// Load it
  81 			ob = new VMExecutableWrapper();
  82 			ob.load(is);
  83 
  84 			// dump it
  85 			String data = ob.toString();
  86 			sendTarget("DUMP (from cache) for " + command, AutohitErrorCodes.EVENT_COMMAND_PARTIAL_RESULTS, null);
  87 			sendTarget(data, AutohitErrorCodes.EVENT_COMMAND_FINAL_RESULTS, null);			
  88 
  89 		} catch (ServerException sse) {
  90 			throw sse;
  91 		} catch (UniverseException ue) {
  92 			switch (ue.numeric) {
  93 				case UniverseException.UE_OBJECT_DOESNT_EXIST :
  94 					throw new ServerException(
  95 						"Could not find source in the specified universe.  Source="
  96 							+ command,
  97 						ue.numeric);
  98 				case UniverseException.UE_OBJECT_LOCKED :
  99 				case UniverseException.UE_DONT_OWN_THE_LOCK :
 100 				case UniverseException.UE_CANNOT_STREAM :
 101 					throw new ServerException(
 102 						"Could not find source in the specified universe.   Universe won't let us stream to the object.",
 103 						ue.numeric);
 104 				default :
 105 					throw new ServerException(
 106 						"Failed to serious Universe exception.  message="
 107 							+ ue.getMessage(),
 108 						ue.numeric);
 109 			}
 110 		} catch (Exception eee) {
 111 			throw new ServerException(
 112 				"Failed to general exception.  message=" + eee.getMessage(),
 113 				AutohitErrorCodes.CODE_COMMAND_FAULT);
 114 		}
 115 
 116 		// return 
 117 		return "Dump completed with no errors";
 118 	}
 119 
 120 	/**
 121 	 * Verify the Compile command. 
 122 	 * @throws ServerException
 123 	 * @return return the manreadable message for accepting the command.
 124 	 */
 125 	public String verify() throws ServerException {
 126 		this.assertparam(false, false, false, false, true, false);
 127 		return "parameters are good.";
 128 	}
 129 
 130 	/**
 131 	 * Get the textual name for the command.
 132 	 * @return return the manreadable name of this command.
 133 	 */
 134 	public String getName() {
 135 		return MY_NAME;
 136 	}
 137 }