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 ; 13 14 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 66 public Namespace addNamespace(String name) { 67 68 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 109 public void removeNamespace(String name) { 110 Domain.closeNamespace(null, name); 111 } 112 113 public Configuration getConfiguration(){ 114 return this.conf; 115 } 116 117 } 118 | Popular Tags |