KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > common > JahiaDomain


1 package org.apache.slide.common;
2
3 import org.apache.slide.util.logger.Logger;
4 import org.apache.slide.util.conf.Configuration;
5 import org.apache.slide.util.conf.ConfigurationException;
6 import org.apache.slide.extractor.ExtractorManager;
7 import org.apache.slide.event.EventDispatcher;
8 import org.apache.slide.authenticate.CredentialsToken;
9 import org.apache.slide.structure.ObjectNotFoundException;
10 import org.apache.slide.store.ExtendedStore;
11
12 import java.util.Enumeration JavaDoc;
13
14 /**
15  * Created by IntelliJ IDEA.
16  * User: toto
17  * Date: 30 aožt 2004
18  * Time: 17:23:47
19  * <p/>
20  * $Author: tdraier $
21  * $Date: 2005-10-20 15:21:28 +0200 (Thu, 20 Oct 2005) $
22  * $Id: JahiaDomain.java 11270 2005-10-20 13:21:28Z tdraier $
23  * $RCSfile$
24  * $Revision: 11270 $
25  * $Source$
26  * $State$
27  */

28 public class JahiaDomain {
29
30     private static JahiaDomain instance;
31
32     private Configuration defs;
33     private Configuration data;
34     private Configuration conf;
35     private Logger logger;
36
37     private JahiaDomain(Configuration defs, Configuration data, Configuration conf, Logger logger) {
38         this.defs = defs;
39         this.data = data;
40         this.conf = conf;
41         this.logger = logger;
42     }
43
44     public static void init(Configuration defs, Configuration data, Configuration conf, Logger logger) {
45         instance = new JahiaDomain(defs, data, conf, logger);
46     }
47
48     public static JahiaDomain getInstance() {
49         return instance;
50     }
51
52     public static void init(Configuration configuration) {
53         try {
54             Domain.init(configuration);
55         } catch (DomainInitializationFailedError e) {
56             Domain.setInitialized(true);
57
58         }
59     }
60
61     /**
62      * Add a namespace to this domain.
63      *
64      * @param name Namespace name
65      */

66     public Namespace addNamespace(String JavaDoc name) {
67
68         // FIXME: Check parameters
69

70         Namespace namespace = new Namespace();
71         namespace.setName(name);
72         namespace.setLogger(logger);
73
74         try {
75             namespace.loadParameters(conf);
76             namespace.loadDefinition(defs);
77
78             Uri rootUri = null;
79             SlideToken slideToken = new SlideTokenImpl(new CredentialsToken(""));
80             rootUri = namespace.getUri(slideToken, "/");
81             try {
82                 ((ExtendedStore)rootUri.getStore()).removeObjectFromCache("/");
83                 rootUri.getStore().retrieveObject(rootUri);
84             } catch (ObjectNotFoundException e) {
85                 namespace.loadBaseData(data);
86                 ((ExtendedStore)rootUri.getStore()).removeObjectFromCache("/");
87             }
88             namespace.loadConfiguration(conf);
89         } catch (SlideException e) {
90             e.printStackTrace();
91             return null;
92         } catch (ConfigurationException e) {
93             e.printStackTrace();
94             return null;
95         }
96
97         Domain.addNamespace(namespace);
98
99         return namespace;
100
101     }
102
103
104     /**
105      * Clsose a namespace.
106      *
107      * @param name Name of the namespace
108      */

109     public void removeNamespace(String JavaDoc name) {
110         Domain.closeNamespace(null, name);
111     }
112     
113     public Configuration getConfiguration(){
114         return this.conf;
115     }
116     
117 }
118
Popular Tags