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 import java.io.OutputStream;
25
26 import autohit.common.AutohitErrorCodes;
27 import autohit.common.AutohitProperties;
28 import autohit.creator.compiler.XmlCompiler;
29 import autohit.server.ServerException;
30 import autohit.universe.UniverseException;
31 import autohit.vm.VMExecutableWrapper;
32
33 /**
34 * The COMPILE command. It expects a single string that points
35 * to the universe object to compile
36 * <p>
37 * <code>
38 * COMMAND LIST
39 * this.assert(false,false,false,false,true,false)
40 * 0-UNI - OPTIONAL
41 * 1-RESPONSE - OPTIONAL
42 * 2-TARGET - UNUSED
43 * 3-CLASS - UNUSED
44 * 4-COMMAND - REQUIRED - Name of object in universe to compile;
45 * 5-OBJECT - UNUSED
46 * </code>
47 *
48 * @author Erich P. Gatejen
49 * @version 1.0
50 * <i>Version History</i>
51 * <code>EPG - Initial - 24Jul03
52 * EPG - rewrite for new scheme - 31Jul03</code>
53 *
54 */
55 public class CommandCompile extends Command {
56
57 final static long serialVersionUID = 1;
58
59 /**
60 * My name
61 */
62 public final static String MY_NAME = "compile";
63
64 /**
65 * Execute the command.
66 * @throws ServerException
67 * @return return the manreadable message for success.
68 */
69 public String execute() throws ServerException {
70
71 InputStream is;
72 OutputStream os;
73 XmlCompiler cp;
74 VMExecutableWrapper ob;
75 String dest;
76
77 try {
78
79 // find it
80 is = uni.getStream(command);
81
82 // compile it
83 cp = sc.getCompiler();
84 ob = (VMExecutableWrapper) cp.compile(is);
85
86 // Did compile succeed?
87 if (ob == null) {
88 // NO
89 throw new ServerException(
90 "Compile of " + command + " failed.",
91 AutohitErrorCodes.CODE_COMPILE_ABORT);
92
93 } else {
94 // are we replacing an object in the cache? if so, kill it
95 // and dump it out of any loader cache
96 dest =
97 AutohitProperties.literal_UNIVERSE_CACHE
98 + AutohitProperties.literal_NAME_SEPERATOR
99 + command;
100 if (uni.exists(dest)) {
101 uni.remove(dest);
102 sc.getLoader().flush(command);
103 }
104 // save it to the cache
105 os = uni.putStream(dest);
106 ob.save(os);
107 }
108
109 } catch (ServerException sse) {
110 throw sse;
111 } catch (UniverseException ue) {
112 switch (ue.numeric) {
113 case UniverseException.UE_OBJECT_DOESNT_EXIST :
114 throw new ServerException(
115 "Could not find source in the specified universe. Source="
116 + command,
117 ue.numeric);
118 case UniverseException.UE_OBJECT_LOCKED :
119 case UniverseException.UE_DONT_OWN_THE_LOCK :
120 case UniverseException.UE_CANNOT_STREAM :
121 throw new ServerException(
122 "Could not find source in the specified universe. Universe won't let us stream to the object.",
123 ue.numeric);
124 default :
125 throw new ServerException(
126 "Failed to serious Universe exception. message="
127 + ue.getMessage(),
128 ue.numeric);
129 }
130 } catch (Exception eee) {
131 throw new ServerException(
132 "Failed to general exception. message=" + eee.getMessage(),
133 AutohitErrorCodes.CODE_COMMAND_FAULT);
134 }
135
136 // return
137 return "Compile of " + command + " completed with no errors";
138 }
139
140 /**
141 * Verify the Compile command.
142 * @throws ServerException
143 * @return return the manreadable message for accepting the command.
144 */
145 public String verify() throws ServerException {
146 this.assertparam(false,false,false,false,true,false);
147 return "parameters are good.";
148 }
149
150 /**
151 * Get the textual name for the command.
152 * @return return the manreadable name of this command.
153 */
154 public String getName(){
155 return MY_NAME;
156 }
157 }
|