1 23 24 package org.apache.slide.common; 25 26 import java.util.Enumeration ; 27 import java.util.Hashtable ; 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 38 public class EmbeddedDomain { 39 40 41 43 44 47 public EmbeddedDomain() { 48 49 if (!Domain.isInitialized()) 51 Domain.setDomain(this); 52 53 } 54 55 56 58 59 62 private Hashtable namespaces = new Hashtable (); 63 64 65 68 private String defaultNamespace; 69 70 71 74 private String name = "slide-domain"; 75 76 77 79 80 85 public void setName(String name) { 86 this.name = name; 87 } 88 89 90 95 public String getName() { 96 return name; 97 } 98 99 100 105 public String getDefaultNamespace() { 106 return defaultNamespace; 107 } 108 109 110 115 public void setDefaultNamespace(String defaultNamespace) { 116 this.defaultNamespace = defaultNamespace; 117 } 118 119 120 126 public void setLogger(Logger logger) { 127 Domain.setLogger(logger); 128 } 129 130 131 137 public Logger getLogger() { 138 return Domain.getLogger(); 139 } 140 141 142 148 public NamespaceAccessToken getNamespaceToken(String 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 160 public Enumeration enumerateNamespaces() { 161 return (namespaces.keys()); 162 } 163 164 165 174 public Namespace addNamespace(String name, Logger logger, 175 Configuration definition, 176 Configuration configuration, 177 Configuration baseData) { 178 179 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 210 public Namespace removeNamespace(String name) { 211 212 214 try { 215 Namespace namespace = (Namespace) namespaces.get(name); 216 namespace.disconnectServices(); 217 } catch(Exception e) { 218 } 219 return (Namespace) namespaces.remove(name); 220 221 } 222 223 224 230 public Namespace getNamespace(String name) { 231 return (Namespace) namespaces.get(name); 232 } 233 234 240 public void setParameters( Hashtable parameters ) { 241 Domain.setParameters( parameters ); 242 } 243 244 247 public void start() 248 throws Exception { 249 250 } 251 252 253 256 public void stop() 257 throws Exception { 258 259 Enumeration active = namespaces.elements(); 260 while (active.hasMoreElements()) { 261 ((Namespace) active.nextElement()).disconnectServices(); 262 } 263 264 } 265 266 267 269 270 273 public String toString() { 274 return getName(); 275 } 276 277 278 } 279 | Popular Tags |