1 package org.objectweb.kilim.helpers; 2 3 import org.objectweb.kilim.KilimException; 4 import org.objectweb.kilim.KilimConfiguration; 5 import org.objectweb.kilim.description.TemplateDescription; 6 import org.objectweb.kilim.model.Component; 7 import org.objectweb.kilim.model.mapping.JavaLoggerMapper; 8 import org.objectweb.kilim.model.mapping.JavaRuntimeMapper; 9 import org.objectweb.kilim.model.mapping.Mapper; 10 11 import org.objectweb.kilim.model.instanciation.DefaultInstanciationStrategy; 12 import org.objectweb.kilim.model.instanciation.InstanciationStrategy; 13 14 import org.objectweb.kilim.repository.ClassLoaderResourceLoader; 15 import org.objectweb.kilim.repository.ResourceNotFoundException; 16 import org.objectweb.kilim.repository.ResourceRepository; 17 import org.objectweb.kilim.repository.TemplateDescriptionParser; 18 19 23 24 public class KilimHelper { 25 26 private static TemplateDescriptionParser parser = new TemplateDescriptionParser(true); 27 private static ResourceRepository rep = new ResourceRepository(parser); 28 29 38 public static Component newComponent(String name , Class clazz) throws ResourceNotFoundException, KilimException { 39 rep.setResourceLoader(new ClassLoaderResourceLoader(clazz.getClassLoader())); 40 TemplateDescription ts0 = rep.getTemplateDescription(name); 41 Component result = org.objectweb.kilim.model.ComponentFactory.newComponent(ts0); 42 return result; 43 44 } 45 46 55 public static TemplateDescription getTemplate(String name , Class clazz) throws ResourceNotFoundException, KilimException { 56 parser = KilimConfiguration.getTemplateDescriptionParser(); 57 rep.setResourceLoader(new ClassLoaderResourceLoader(clazz.getClassLoader())); 58 TemplateDescription ts0 = rep.getTemplateDescription(name); 59 return ts0; 60 } 61 62 72 public static Component newComponent(String name , Class clazz, InstanciationStrategy aStrategy) throws ResourceNotFoundException, KilimException { 73 rep.setResourceLoader(new ClassLoaderResourceLoader(clazz.getClassLoader())); 74 TemplateDescription ts0 = rep.getTemplateDescription(name); 75 KilimConfiguration.setInstanciationStrategy(aStrategy); 76 Component result = org.objectweb.kilim.model.ComponentFactory.newComponent(ts0); 77 return result; 78 } 79 80 } 81 | Popular Tags |