KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > helpers > KilimHelper


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 /**
20  * A helper class providing simplified ways of creating new Template instances.
21  * @author delpiano
22  */

23
24 public class KilimHelper {
25     
26     private static TemplateDescriptionParser parser = new TemplateDescriptionParser(true);
27     private static ResourceRepository rep = new ResourceRepository(parser);
28     
29     /**
30      * Creates a new instance of the Template named <code>name</code>, the definition of which will
31      * be loaded with the ClassLoader which loaded the class <code>clazz</code>.
32      * @param name the name of the Template that will be instantiated.
33      * @param clazz the class used to determine the ClassLoader used to load the Template definition.
34      * @return the component instance of the Template <code>name</code>
35      * @throws ResourceNotFoundException :
36      * @throws KilimException :
37      */

38     public static Component newComponent(String JavaDoc name , Class JavaDoc 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     /**
47      * Returns the Template named <code>name</code>, the definition of which will
48      * be loaded with the ClassLoader which loaded the class <code>clazz</code>.
49      * @param name the name of the Template that will be instantiated.
50      * @param clazz the class used to determine the ClassLoader used to load the Template definition.
51      * @return the Template <code>name</code>
52      * @throws ResourceNotFoundException :
53      * @throws KilimException :
54      */

55     public static TemplateDescription getTemplate(String JavaDoc name , Class JavaDoc 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     /**
63      * Creates a new instance of the Template named <code>name</code>, the definition of which will
64      * be loaded with the ClassLoader which loaded the class <code>clazz</code>.
65      * @param name the name of the Template that will be instantiated.
66      * @param aStrategy is the instanciation strategy to be used.
67      * @param clazz the class used to determine the ClassLoader used to load the Template definition.
68      * @return the component instance of the Template <code>name</code>
69      * @throws ResourceNotFoundException :
70      * @throws KilimException :
71      */

72     public static Component newComponent(String JavaDoc name , Class JavaDoc 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