KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/EmbeddedDomain.java,v 1.12 2004/07/28 09:38:20 ib Exp $
3  * $Revision: 1.12 $
4  * $Date: 2004/07/28 09:38:20 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.common;
25
26 import java.util.Enumeration JavaDoc;
27 import java.util.Hashtable JavaDoc;
28
29 import org.apache.slide.util.conf.Configuration;
30 import org.apache.slide.util.conf.ConfigurationException;
31 import org.apache.slide.util.logger.Logger;
32
33 /**
34  * Alternate domain designed to ease embedding.
35  *
36  * @version $Revision: 1.12 $
37  */

38 public class EmbeddedDomain {
39     
40     
41     // ------------------------------------------------------------ Constructor
42

43     
44     /**
45      * Default constructor.
46      */

47     public EmbeddedDomain() {
48         
49         // Compatibility with the static domain
50
if (!Domain.isInitialized())
51             Domain.setDomain(this);
52         
53     }
54     
55     
56     // ----------------------------------------------------- Instance Variables
57

58     
59     /**
60      * Namespaces hashtable.
61      */

62     private Hashtable JavaDoc namespaces = new Hashtable JavaDoc();
63     
64     
65     /**
66      * Default namespace.
67      */

68     private String JavaDoc defaultNamespace;
69     
70     
71     /**
72      * Namespace name.
73      */

74     private String JavaDoc name = "slide-domain";
75     
76     
77     // --------------------------------------------------------- Public Methods
78

79     
80     /**
81      * Sets the qualified name of the namespace.
82      *
83      * @param name Name of the namespace
84      */

85     public void setName(String JavaDoc name) {
86         this.name = name;
87     }
88     
89     
90     /**
91      * Gets the qulified name of the namespace.
92      *
93      * @return String Namespace name
94      */

95     public String JavaDoc getName() {
96         return name;
97     }
98     
99     
100     /**
101      * Return the default namespace of this domain.
102      *
103      * @return the name of the default namespace
104      */

105     public String JavaDoc getDefaultNamespace() {
106         return defaultNamespace;
107     }
108     
109     
110     /**
111      * Set the default namespace of this domain.
112      *
113      * @param defaultNamespace New default namespace name
114      */

115     public void setDefaultNamespace(String JavaDoc defaultNamespace) {
116         this.defaultNamespace = defaultNamespace;
117     }
118     
119     
120     /**
121      * Set the logger to be used by Slide.
122      *
123      * @param logger Logger the domain will use
124      * @deprecated Use the namespace loggers instead
125      */

126     public void setLogger(Logger logger) {
127         Domain.setLogger(logger);
128     }
129     
130     
131     /**
132      * Get the Domain logger.
133      *
134      * @return The domain logger
135      * @deprecated Use the namespace loggers instead
136      */

137     public Logger getLogger() {
138         return Domain.getLogger();
139     }
140     
141     
142     /**
143      * Access a Namespace.
144      *
145      * @param namespaceName Name of the namespace on which access is requested
146      * @return NamespaceAccessToken Access token to the namespace
147      */

148     public NamespaceAccessToken getNamespaceToken(String JavaDoc namespaceName) {
149         Namespace namespace = (Namespace) namespaces.get(namespaceName);
150         if (namespace == null)
151             return null;
152         else
153             return new NamespaceAccessTokenImpl(namespace);
154     }
155     
156     
157     /**
158      * Enumerate namespace names.
159      */

160     public Enumeration JavaDoc enumerateNamespaces() {
161         return (namespaces.keys());
162     }
163     
164     
165     /**
166      * Add a namespace to this domain.
167      *
168      * @param name Namespace name
169      * @param logger Namespace logger
170      * @param definition Input stream to the namepace definition
171      * @param configuration Input stream to the namespace configuration
172      * @param baseData Input stream to the anmespace base data
173      */

174     public Namespace addNamespace(String JavaDoc name, Logger logger,
175                                   Configuration definition,
176                                   Configuration configuration,
177                                   Configuration baseData) {
178         
179         // FIXME: Check parameters
180

181         Namespace namespace = new Namespace();
182         namespace.setName(name);
183         namespace.setLogger(logger);
184         
185         try {
186             namespace.loadParameters(configuration);
187             namespace.loadDefinition(definition);
188             namespace.loadBaseData(baseData);
189             namespace.loadConfiguration(configuration);
190         } catch (SlideException e) {
191             e.printStackTrace();
192             return null;
193         } catch (ConfigurationException e) {
194             e.printStackTrace();
195             return null;
196         }
197         
198         namespaces.put(name, namespace);
199         
200         return namespace;
201         
202     }
203     
204     
205     /**
206      * Clsose a namespace.
207      *
208      * @param name Name of the namespace
209      */

210     public Namespace removeNamespace(String JavaDoc name) {
211         
212         // FIXME: Check parameters
213

214         try {
215             Namespace namespace = (Namespace) namespaces.get(name);
216             namespace.disconnectServices();
217         } catch(Exception JavaDoc e) {
218         }
219         return (Namespace) namespaces.remove(name);
220         
221     }
222     
223     
224     /**
225      * Get a namespace.
226      *
227      * @param name Name of the namespace
228      * @return Namespace
229      */

230     public Namespace getNamespace(String JavaDoc name) {
231         return (Namespace) namespaces.get(name);
232     }
233     
234     /**
235      * Set the specified parameters
236      *
237      * @param parameters the parameters
238      *
239      */

240     public void setParameters( Hashtable JavaDoc parameters ) {
241         Domain.setParameters( parameters );
242     }
243     
244     /**
245      * Start domain (doesn't do anything yet).
246      */

247     public void start()
248         throws Exception JavaDoc {
249         
250     }
251     
252     
253     /**
254      * Stop domain.
255      */

256     public void stop()
257         throws Exception JavaDoc {
258         
259         Enumeration JavaDoc active = namespaces.elements();
260         while (active.hasMoreElements()) {
261             ((Namespace) active.nextElement()).disconnectServices();
262         }
263         
264     }
265     
266     
267     // --------------------------------------------------------- Object Methods
268

269     
270     /**
271      * Get a String representation of this domain.
272      */

273     public String JavaDoc toString() {
274         return getName();
275     }
276     
277     
278 }
279
Popular Tags