1 10 11 package org.mule.impl.model; 12 13 import org.mule.providers.service.ConnectorFactory; 14 import org.mule.umo.model.UMOModel; 15 import org.mule.util.BeanUtils; 16 import org.mule.util.ClassUtils; 17 import org.mule.util.SpiUtils; 18 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.util.Properties ; 22 23 27 public class ModelFactory 28 { 29 30 public static final String MODEL_SERVICE_PATH = "org/mule/models"; 31 32 public static UMOModel createModel(String type) throws ModelServiceNotFoundException 33 { 34 String location = SpiUtils.SERVICE_ROOT + MODEL_SERVICE_PATH; 35 InputStream is = SpiUtils.findServiceDescriptor(MODEL_SERVICE_PATH, type, ConnectorFactory.class); 36 try 37 { 38 if (is != null) 39 { 40 Properties props = new Properties (); 41 props.load(is); 42 String clazz = props.getProperty("model"); 43 try 44 { 45 UMOModel model = (UMOModel)ClassUtils.instanciateClass(clazz, ClassUtils.NO_ARGS, 46 ModelFactory.class); 47 BeanUtils.populateWithoutFail(model, props, false); 48 return model; 49 } 50 catch (Exception e) 51 { 52 throw new ModelServiceNotFoundException(location + "/" + type, e); 53 } 54 } 55 else 56 { 57 throw new ModelServiceNotFoundException(location + "/" + type); 58 } 59 } 60 catch (IOException e) 61 { 62 throw new ModelServiceNotFoundException(location + "/" + type, e); 63 } 64 } 65 } 66 | Popular Tags |