KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > KilimConfiguration


1 package org.objectweb.kilim;
2
3 import org.objectweb.kilim.model.instanciation.DefaultInstanciationStrategy;
4 import org.objectweb.kilim.model.instanciation.InstanciationStrategy;
5 import org.objectweb.kilim.model.mapping.DefaultMappingContext;
6 import org.objectweb.kilim.model.mapping.DefaultMappingStrategy;
7 import org.objectweb.kilim.model.mapping.MappingContext;
8 import org.objectweb.kilim.model.mapping.MappingStrategy;
9 import org.objectweb.kilim.model.services.Annotations;
10 import org.objectweb.kilim.model.services.ExternalValueReferences;
11 import org.objectweb.kilim.repository.ClassLoaderResourceLoader;
12 import org.objectweb.kilim.repository.Repository;
13 import org.objectweb.kilim.repository.ResourceLoader;
14 import org.objectweb.kilim.repository.ResourceRepository;
15 import org.objectweb.kilim.repository.TemplateDescriptionParser;
16
17 /**
18  * A class where all the factories and global tables used by the Kilim environment, are created.
19  * @author Horn
20  */

21 public class KilimConfiguration extends Annotations {
22     private static TemplateDescriptionParser parser;
23     private static Repository repository;
24     private static ResourceLoader loader;
25     private static InstanciationStrategy instanciationStgy;
26     private static ExternalValueReferences xReferences;
27     private static MappingStrategy mappingStgy;
28     private static MappingContext mappingContext;
29
30     static {
31         parser = new TemplateDescriptionParser(true);
32         repository = new ResourceRepository(parser);
33         loader = new ClassLoaderResourceLoader(repository.getClass().getClassLoader());
34         repository.setResourceLoader(loader);
35         try {
36             instanciationStgy = new DefaultInstanciationStrategy();
37         } catch (KilimException ex) {
38             System.out.println("Problem when instanciating the default instanciation strategy");
39             System.exit(1);
40         }
41         try {
42             mappingStgy = new DefaultMappingStrategy();
43             mappingContext = new DefaultMappingContext();
44         } catch (KilimException ex) {
45             System.out.println("Problem when instanciating the default mapping strategy");
46             System.exit(2);
47         }
48     }
49     
50     /**
51      * Method getTemplateDescriptionParser. This method returns the SAX parser used to parse the templates stored in .kilim files
52      * @return TemplateDescriptionParser
53      */

54     public static TemplateDescriptionParser getTemplateDescriptionParser() {
55         return parser;
56     }
57     
58     /**
59      * Method setTemplateDescriptionParser. This method sets the SAX parser used to parse the templates stored in .kilim files
60      * @param aParser :
61      */

62     public static void setTemplateDescriptionParser(TemplateDescriptionParser aParser) {
63         parser = aParser;
64     }
65
66     /**
67      * Method getInstanciationStrategy. An instanciation strategy defines the instanciation managers to be used for each component of the system.
68      * This method returns the instanciation strategy.
69      * @return InstanciationStrategy
70      */

71     public static InstanciationStrategy getInstanciationStrategy() {
72         return instanciationStgy;
73     }
74
75     /**
76      * Method getLoader. This method returns the resource loader used to get the .kilim files.
77      * @return ResourceLoader
78      */

79     public static ResourceLoader getLoader() {
80         return loader;
81     }
82
83     /**
84      * Method getMappingStrategy. A mapping strategy defines the mappers used to effectively perform the mechanism associated to each Runtime source and action.
85      * This method returns the mapping strategy.
86      * @return MappingStrategy
87      */

88     public static MappingStrategy getMappingStrategy() {
89         return mappingStgy;
90     }
91
92     /**
93      * Method getMappingContext. A mapping strategy is enforced through mappers that take a global and shared context as a parameter.
94      * This method returns the mapping context.
95      * @return MappingContext
96      */

97     public static MappingContext getMappingContext() {
98         return mappingContext;
99     }
100
101     /**
102      * Method getRepository. The parsers are seen in Kilim as specific implementation of a generic Repository interface
103      * (@see org.objectweb.kilim.repository.Repository). This method returns the repository.
104      * @return Repository
105      */

106     public static Repository getRepository() {
107         return repository;
108     }
109
110     /**
111      * Method setInstanciationStgy. This method sets the instanciation strategy (@see org.objectweb.kilim.model.instanciation.InstanciationStrategy)
112      * @param aStrategy : the strategy to be set.
113      */

114     public static void setInstanciationStrategy(InstanciationStrategy aStrategy) {
115         instanciationStgy = aStrategy;
116     }
117
118     /**
119      * Method setLoader. This method sets the resource loader used to get the .kilim files.
120      * @param aLoader : the loader.
121      */

122     public static void setLoader(ResourceLoader aLoader) {
123         loader = aLoader;
124     }
125
126     /**
127      * Method setMappingStrategy.
128      * @param aStrategy : the strategy.
129      */

130     public static void setMappingStrategy(MappingStrategy aStrategy) {
131         mappingStgy = aStrategy;
132     }
133     
134     /**
135      * Method setMappingContext.
136      * @param aContext : the mapping context.
137      */

138     public static void setMappingContext(MappingContext aContext) {
139         mappingContext = aContext;
140     }
141
142     /**
143      * Sets the repository.
144      * @param repository The repository
145      */

146     public static void setRepository(Repository repository) {
147         KilimConfiguration.repository = repository;
148     }
149     /**
150      * Returns the xReferences.
151      * @return ExternalValueReferences
152      */

153     public static ExternalValueReferences getExternalReferences() {
154         return xReferences;
155     }
156
157     /**
158      * Sets the xReferences.
159      * @param xRefs The xReferences to set
160      */

161     public static void setExternalReferences(ExternalValueReferences xRefs) {
162         xReferences = xRefs;
163     }
164 }
165
Popular Tags