Quellcode durchsuchen

added exception name in error output; added new instance executor

develop
Robin Thoni vor 8 Jahren
Ursprung
Commit
128d345500

+ 4
- 1
server/src/main/java/com/uqac/rthoni/java_rmi/server/ServerApplication.java Datei anzeigen

@@ -186,8 +186,11 @@ public class ServerApplication {
186 186
         else {
187 187
             try {
188 188
                 data = executor.run(command, this);
189
+                if (data == null) {
190
+                    data = "OK";
191
+                }
189 192
             } catch (Exception e) {
190
-                data = String.format("Error when handling command: %s", e.getMessage());
193
+                data = String.format("Error when handling command: %s %s", e.getClass().getName(), e.getMessage());
191 194
                 System.err.println(data);
192 195
             }
193 196
         }

+ 24
- 0
server/src/main/java/com/uqac/rthoni/java_rmi/server/executors/NewInstanceExecutor.java Datei anzeigen

@@ -0,0 +1,24 @@
1
+package com.uqac.rthoni.java_rmi.server.executors;
2
+
3
+import com.uqac.rthoni.java_rmi.common.Command;
4
+import com.uqac.rthoni.java_rmi.server.ServerApplication;
5
+
6
+/**
7
+ * Created by robin on 9/16/16.
8
+ */
9
+public class NewInstanceExecutor extends AbstractCommandExecutor {
10
+    @Override
11
+    public String getCommandName() {
12
+        return "creation";
13
+    }
14
+
15
+    @Override
16
+    public String run(Command command, ServerApplication server) throws Exception {
17
+        String className = command.getArgument(0);
18
+        String id = command.getArgument(1);
19
+        Class c = Class.forName(className);
20
+        Object obj = c.newInstance();
21
+        server.addObject(id, obj);
22
+        return null;
23
+    }
24
+}

Laden…
Abbrechen
Speichern