1 package hero.user; 2 3 import hero.util.HeroHookException; 4 5 import java.util.ArrayList ; 6 import java.util.Collection ; 7 import java.util.Properties ; 8 import java.io.File ; 9 import java.io.FileInputStream ; 10 import java.lang.reflect.InvocationTargetException ; 11 12 28 29 public class UserBaseService { 30 private ArrayList userbases; 31 static private UserBaseService ubs=null; 32 33 private UserBaseService() { 34 userbases=new ArrayList (); 35 ArrayList result = new ArrayList (); 36 try { 37 Properties usersProps = new Properties (); 38 ReadEnv re = new ReadEnv(); 39 String bonitaHome=re.getVariable("BONITA_HOME"); 40 usersProps.load(new FileInputStream (bonitaHome+File.separator+".ant.properties")); 41 result.add(constructor((String )usersProps.getProperty("user.base"))); 42 userbases=result; 43 if (result.isEmpty()) 44 { 45 result.add(new DefaultUserBase()); 46 userbases=result; 47 } 48 }catch(Exception userEx){ 49 result.add(new DefaultUserBase()); 50 userbases=result; 51 userEx.printStackTrace();} 52 } 53 54 public Object constructor(String name) throws HeroHookException { 55 try { 56 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 57 Class clName=cl.loadClass(name); 58 Class [] o={}; 59 java.lang.reflect.Constructor cons = clName.getConstructor(o); 60 return(cons.newInstance(o)); 61 } catch (Exception ite) {ite.getCause().printStackTrace(); 62 throw new HeroHookException("Dynamic invocation failed :"+ite.getCause().getMessage()); 63 } 64 } 65 66 public static UserBaseService getInstance() { 67 if (ubs!=null) { 68 return ubs; 69 } else { 70 ubs=new UserBaseService(); 71 return ubs; 72 } 73 } 74 75 public Collection getUserBases() { 76 return userbases; 77 } 78 } 79 | Popular Tags |