1 15 package org.apache.hivemind.util; 16 17 import org.apache.hivemind.ApplicationRuntimeException; 18 import org.apache.hivemind.HiveMind; 19 import org.apache.hivemind.Location; 20 import org.apache.hivemind.internal.Module; 21 22 29 public class InstanceCreationUtils 30 { 31 44 public static Object createInstance(Module module, String initializer, Location location) 45 { 46 int commax = initializer.indexOf(','); 47 48 String className = (commax < 0) ? initializer : initializer.substring(0, commax); 49 50 Class objectClass = module.resolveType(className); 51 52 try 53 { 54 Object result = objectClass.newInstance(); 55 56 HiveMind.setLocation(result, location); 57 58 if (commax > 0) 59 PropertyUtils.configureProperties(result, initializer.substring(commax + 1)); 60 61 return result; 62 } 63 catch (Exception ex) 64 { 65 68 throw new ApplicationRuntimeException(UtilMessages.unableToInstantiateInstanceOfClass( 69 objectClass, 70 ex), location, ex); 71 } 72 73 } 74 } | Popular Tags |