replaced all StringBuffers with StringBuilder to improve performance
[Bob.git] / src / com / interrupt / bob / util / Util.java
blobf991c9d3adfc258cd40dd87afebe3149fb50067e
2 package com.interrupt.bob.util;
4 import java.io.ByteArrayInputStream;
5 import java.io.InputStream;
6 import java.io.UnsupportedEncodingException;
7 import java.lang.reflect.InvocationTargetException;
8 import java.lang.reflect.Method;
10 import org.apache.log4j.Logger;
12 import com.interrupt.bob.base.Bob;
13 import com.interrupt.bob.base.IBob;
15 public class Util {
17 public static final String HOME = "bob.home";
18 public static final String BASE = "bob.base";
19 public static final String END = "bob.end";
20 public static final String GEN = "bob.gen";
22 public static final String DEF = "bob.def";
23 public static final String SYS = "bob.sys";
25 public static boolean isInterpretable( String value ) {
27 if( value == null ) {
28 return false;
32 boolean starter = value.trim().startsWith("${");
33 boolean ending = value.trim().endsWith("}");
34 if( starter && ending ) {
35 return true;
37 return false;
40 public static String getInterpretableName(String name) {
42 //String sansPrefix = name.substring(name.indexOf("${"));
43 String sansPrefix = name.substring(2);
44 String sansSuffix = sansPrefix.substring(0, sansPrefix.indexOf("}"));
45 return sansSuffix;
49 public static void evalReflectedAdd(IBob parent, String tagName, Class methodDefinitionParams[], IBob methParams[])
50 throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, Throwable {
53 //parent.add{child}(created);
54 Class pclass = parent.getClass();
55 String methName = "add" + StringUtil.upperFirstLetter(tagName);
56 Method setMeth = null;
58 try {
60 setMeth = pclass.getMethod( methName, methodDefinitionParams );
61 setMeth.invoke( parent, methParams );
63 catch(NoSuchMethodException e) {
64 e.printStackTrace();
65 throw e;
67 catch(IllegalAccessException e) {
68 e.printStackTrace();
69 throw e;
71 catch(InvocationTargetException e) {
72 e.printStackTrace();
73 throw e;
79 public static IBob loadBobFromXML(String xmlString) {
81 Logger logger = Logger.getLogger(com.interrupt.bob.util.Util.class);
82 logger.debug("com.interrupt.bob.util.Util.loadBobFromXML:: ["+ xmlString +"]");
84 //** load a Bob object
85 InputStream istream = null;
86 try {
87 istream = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
89 catch(UnsupportedEncodingException e) {
90 throw new RuntimeException(e);
93 IBob bob = Bob.loadS(istream, System.getProperty(Util.DEF));
94 logger.debug("com.interrupt.bob.util.Util.loadBobFromXML:: Loaded Bob from XML [" + bob.toXML(false) + "]");
96 return bob;