JavaHandler.java
Go to the documentation of this file.
00001 
00009 package com.rosalfred.core.ia.rivescript.lang.java;
00010 
00011 import com.rosalfred.core.ia.rivescript.BotReply;
00012 import com.rosalfred.core.ia.rivescript.ObjectHandler;
00013 import com.rosalfred.core.ia.rivescript.RiveScript;
00014 
00020 public abstract class JavaHandler implements ObjectHandler<BotReply> {
00021 
00022     protected RiveScript rs;
00023 
00024     protected JavaHandler(RiveScript rs) {
00025         this.rs = rs;
00026     }
00027 
00028     @Override
00029     public BotReply onCall(String name, String user, String[] args) {
00030         BotReply result = new BotReply(name);
00031         // Creating an instance of our compiled class and
00032         // running its toString() method
00033         try {
00034             ClassLoader loader = this.getClassLoader();
00035             Class<?> runtimeClass = loader.loadClass(name);
00036             RunRiver instance = (RunRiver) runtimeClass.newInstance();
00037             result = instance.invoke(this.rs, user, args);
00038         } catch (InstantiationException e) {
00039             e.printStackTrace();
00040         } catch (IllegalAccessException e) {
00041             e.printStackTrace();
00042         } catch (ClassNotFoundException e) {
00043             e.printStackTrace();
00044         } catch (ClassFormatError e) {
00045             e.printStackTrace();
00046         } catch (Exception e) {
00047             e.printStackTrace();
00048         }
00049 
00050         return result;
00051     }
00052 
00053     protected ClassLoader getClassLoader() {
00054         return this.getClass().getClassLoader();
00055     }
00056 }


alfred_bot
Author(s): Mickael Gaillard , Erwan Le Huitouze
autogenerated on Tue Jun 14 2016 01:34:50