forked from m0ver/tinystruct-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.java
More file actions
80 lines (63 loc) · 2.27 KB
/
hello.java
File metadata and controls
80 lines (63 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package tinystruct.examples;
import org.tinystruct.AbstractApplication;
import org.tinystruct.Application;
import org.tinystruct.ApplicationException;
import org.tinystruct.system.ApplicationManager;
import org.tinystruct.system.ClassFileLoader;
import org.tinystruct.system.Configuration;
import org.tinystruct.system.Settings;
public class hello extends AbstractApplication {
@Override
public void init() {
// TODO Auto-generated method stub
this.setAction("say", "say");
this.setAction("smile", "smile");
this.setAction("render", "render");
}
@Override
public String version() {
System.out.println("tinystruct version 2.0.1");
return null;
}
public String say(String words){
return words;
}
public String smile() throws ApplicationException{
return ":)";
}
public hello render() {
return this;
}
/**
* @param args
* @throws ApplicationException
* @throws IllegalAccessException
* @throws InstantiationException
*/
public static void main(String[] args) throws ApplicationException, InstantiationException, IllegalAccessException {
// Praise to the Lord!
ApplicationManager.install(new hello());
// to print 'Hello World'
ApplicationManager.call("say/Hello World", null); // Hello World
// or...
Application app=ApplicationManager.get( hello.class.getName());
app.invoke("say", new Object[]{"<h1>Hello, World!</h1>"}); // <h1>Hello, World!</h1>
app.invoke("say", new Object[]{"<h2>Bye!</h2>"}); // <h2>Bye!</h2>
// or...
// http://localhost:8080/?q=say/Hello World
// to run nothing
ApplicationManager.call("smile", null); // Looks nothing
// What will be happened?
System.out.println(ApplicationManager.call("smile", null)); // Will render the default template
// Use ClassFileLoader to load Java class
ClassFileLoader loader = ClassFileLoader.getInstance();
Configuration<String> config = new Settings("/application.properties");
config.set("default.apps.path", "WEB-INF/classes");
config.set("default.apps.package", "tinystruct.examples");
Class<?> clz = loader.findClass("hello");
if(clz!=null && clz.getSuperclass().equals(AbstractApplication.class)) {
ApplicationManager.install((Application) clz.newInstance());
ApplicationManager.call("say/Merry Christmas!", null);
}
}
}