KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > perseus > cache > FractalHelper


1 /**
2  * Copyright (C) 2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.perseus.cache;
19
20 import org.objectweb.fractal.adl.Parser;
21 import org.objectweb.fractal.adl.Launcher;
22 import org.objectweb.fractal.util.Fractal;
23 import org.objectweb.fractal.api.Component;
24
25 /**
26  *
27  * @author S.Chassande-Barrioz
28  */

29 public class FractalHelper {
30
31     private final static String JavaDoc FRACTAL_PROVIDER = "fractal.provider";
32     private final static String JavaDoc DEFAULT_FRACTAL_PROVIDER
33             = "org.objectweb.fractal.julia.Julia";
34
35     private final static String JavaDoc JULIA_LOADER = "julia.loader";
36     private final static String JavaDoc DEFAULT_JULIA_LOADER
37             = "org.objectweb.fractal.julia.loader.DynamicLoader";
38
39     private final static String JavaDoc JULIA_CONFIG = "julia.config";
40     private final static String JavaDoc DEFAULT_JULIA_CONFIG = "julia.cfg";
41
42     private static Parser parser;
43
44     /**
45      * Retrieve the unique julia parser instance. If the parser does not already
46      * exist, it is created.
47      * @throws java.lang.Exception if an error occur during the creationg of the parser.
48      */

49     private static Parser getParser() throws Exception JavaDoc {
50         if (parser == null) {
51             synchronized(FractalHelper.class) {
52                 if (parser == null) {
53                     System.setProperty(FRACTAL_PROVIDER, DEFAULT_FRACTAL_PROVIDER);
54                     System.setProperty(JULIA_LOADER, DEFAULT_JULIA_LOADER);
55                     System.setProperty(JULIA_CONFIG, DEFAULT_JULIA_CONFIG);
56                     parser = Launcher.getBootstrapParser();
57                 }
58             }
59         }
60         return parser;
61     }
62
63
64     /**
65      * Instanciate a component since the template name
66      * @param templateName is the name of the template to load and to
67      * instanciate
68      * @return the component instance
69      * @throws java.lang.Exception if an error occurs during the template loading or in
70      * the component instanciation.
71      */

72     public static Component instanciate(String JavaDoc templateName) throws Exception JavaDoc {
73         return instanciate(getParser().loadTemplate(templateName, true));
74     }
75
76     /**
77      * Instanciate a component since the template component
78      */

79     public static Component instanciate(Component template) throws Exception JavaDoc {
80         return Fractal.getFactory(template).newFcInstance();
81     }
82
83 }
84
Popular Tags