88import org .tinystruct .system .Configuration ;
99import org .tinystruct .system .Settings ;
1010
11+ import java .lang .reflect .InvocationTargetException ;
12+
1113public class hello extends AbstractApplication {
1214
1315 @ Override
@@ -20,15 +22,14 @@ public void init() {
2022
2123 @ Override
2224 public String version () {
23- System .out .println ("tinystruct version 2.0.1" );
24- return null ;
25+ return "tinystruct version 2.0.1" ;
2526 }
2627
2728 public String say (String words ){
2829 return words ;
2930 }
3031
31- public String smile () throws ApplicationException {
32+ public String smile () {
3233 return ":)" ;
3334 }
3435
@@ -42,15 +43,15 @@ public hello render() {
4243 * @throws IllegalAccessException
4344 * @throws InstantiationException
4445 */
45- public static void main (String [] args ) throws ApplicationException , InstantiationException , IllegalAccessException {
46+ public static void main (String [] args ) throws ApplicationException , InstantiationException , IllegalAccessException , NoSuchMethodException , InvocationTargetException {
4647 // Praise to the Lord!
4748 ApplicationManager .install (new hello ());
4849
4950 // to print 'Hello World'
5051 ApplicationManager .call ("say/Hello World" , null ); // Hello World
51-
52+
5253 // or...
53- Application app =ApplicationManager .get ( hello .class .getName ());
54+ Application app =ApplicationManager .get ( hello .class .getName ());
5455 app .invoke ("say" , new Object []{"<h1>Hello, World!</h1>" }); // <h1>Hello, World!</h1>
5556 app .invoke ("say" , new Object []{"<h2>Bye!</h2>" }); // <h2>Bye!</h2>
5657
@@ -59,10 +60,12 @@ public static void main(String[] args) throws ApplicationException, Instantiatio
5960
6061 // to run nothing
6162 ApplicationManager .call ("smile" , null ); // Looks nothing
62-
63+
6364 // What will be happened?
6465 System .out .println (ApplicationManager .call ("smile" , null )); // Will render the default template
65-
66+ ApplicationManager .call ("render" , null ); // Will render the default template
67+
68+
6669 // Use ClassFileLoader to load Java class
6770 ClassFileLoader loader = ClassFileLoader .getInstance ();
6871
@@ -72,7 +75,7 @@ public static void main(String[] args) throws ApplicationException, Instantiatio
7275
7376 Class <?> clz = loader .findClass ("hello" );
7477 if (clz !=null && clz .getSuperclass ().equals (AbstractApplication .class )) {
75- ApplicationManager .install ((Application ) clz .newInstance ());
78+ ApplicationManager .install ((Application ) ( clz .getDeclaredConstructor (). newInstance () ));
7679 ApplicationManager .call ("say/Merry Christmas!" , null );
7780 }
7881 }
0 commit comments