예제 #1
0
 protected static <T extends JapidTemplateBaseWithoutPlay> RenderResult invokeNamedArgsRender(
     Class<T> c, NamedArgRuntime[] args) {
   try {
     return RenderInvokerUtils.invokeNamedArgsRender(c, args);
   } catch (Throwable e) {
     handleException(e);
     return null;
   }
 }
예제 #2
0
 /**
  * @param <T>
  * @param c
  * @param args
  * @return
  * @throws NoSuchMethodException
  * @throws InstantiationException
  * @throws IllegalAccessException
  * @throws InvocationTargetException
  */
 private static <T extends JapidTemplateBaseWithoutPlay> RenderResult invokeRender(
     Class<T> c, Object... args) {
   try {
     return RenderInvokerUtils.invokeRender(c, args);
   } catch (Throwable e) {
     handleException(e);
     return null;
   }
 }
예제 #3
0
 /**
  * @author Bing Ran ([email protected])
  * @param rc
  * @param args
  * @return
  */
 private static String invokeRender(RendererClass rc, Object[] args) {
   try {
     Method apply = rc.getApplyMethod();
     String rr = (String) RenderInvokerUtils.renderWithApply(apply, args);
     return rr;
   } catch (Exception e) {
     if (e instanceof RuntimeException) throw (RuntimeException) e;
     else throw new RuntimeException("Could not invoke the template object: " + e);
   }
 }
예제 #4
0
 /**
  * @param <T>
  * @param c the Japid renderer class, to be used with reflection.
  * @param args
  * @return
  * @throws NoSuchMethodException
  * @throws InstantiationException
  * @throws IllegalAccessException
  * @throws InvocationTargetException
  */
 private static <T extends JapidTemplateBaseWithoutPlay> String invokeRender(
     Class<T> c, Object... args) {
   int modifiers = c.getModifiers();
   if (Modifier.isAbstract(modifiers)) {
     throw new RuntimeException(
         "Cannot init the template class since it's an abstract class: " + c.getName());
   }
   try {
     Constructor<T> ctor = c.getConstructor(StringBuilder.class);
     StringBuilder sb = new StringBuilder(8000);
     T t = ctor.newInstance(sb);
     String rr = (String) RenderInvokerUtils.render(t, args);
     return rr;
   } catch (NoSuchMethodException e) {
     throw new RuntimeException("Could not match the arguments with the template args.");
   } catch (InstantiationException e) {
     // e.printStackTrace();
     throw new RuntimeException("Could not instantiate the template object. Abstract?");
   } catch (Exception e) {
     if (e instanceof RuntimeException) throw (RuntimeException) e;
     else throw new RuntimeException("Could not invoke the template object: " + e);
     // throw new RuntimeException(e);
   }
 }
예제 #5
0
 public static RenderResult getRenderResultWith(String template, NamedArgRuntime[] args) {
   String templateClassName = getTemapletClassName(template);
   Class<? extends JapidTemplateBaseWithoutPlay> tClass = getRenderClass(templateClassName);
   return RenderInvokerUtils.invokeNamedArgsRender(tClass, args);
 }