1 10 11 package org.mmbase.bridge.implementation; 12 import org.mmbase.bridge.*; 13 import org.mmbase.security.*; 14 import org.mmbase.module.core.*; 15 import java.util.*; 16 import org.mmbase.util.logging.*; 17 18 25 public class BasicCloudContext implements CloudContext { 26 private static final Logger log = Logging.getLoggerInstance(BasicCloudContext.class); 27 28 31 static MMBase mmb = null; 32 33 36 static TemporaryNodeManager tmpObjectManager = null; 37 38 41 static TransactionManager transactionManager = null; 42 43 private static final Set localClouds = new HashSet(); 45 46 private static Map localModules = new HashMap(); 48 49 53 protected BasicCloudContext() { 54 } 55 56 60 protected boolean check() { 61 if(mmb == null) { 62 synchronized(this) { 63 if (mmb == null) { Iterator i = org.mmbase.module.Module.getModules(); 66 if (i == null) { 68 if (java.lang.System.getProperty("mmbase.config") == null) { 71 throw new NotFoundException("MMBase has not been started, and cannot be started by this Class. (" + getClass().getName() + " : no property mmbase.config found)"); 75 } 76 try { 78 org.mmbase.module.core.MMBaseContext.init(); 80 org.mmbase.module.core.MMBase.getMMBase(); 82 i = org.mmbase.module.Module.getModules(); 84 } 85 catch(java.lang.Exception ex) { 86 log.error("Error while trying to start MMBase from the bridge:" + Logging.stackTrace(ex)); 87 } 88 if(i == null) { 90 return false; 91 } 92 } 93 MMBase m = org.mmbase.module.core.MMBase.getMMBase(); 95 tmpObjectManager = new TemporaryNodeManager(m); 97 transactionManager = new TransactionManager(m, tmpObjectManager); 98 while(i.hasNext()) { 100 Module mod = ModuleHandler.getModule((org.mmbase.module.Module)i.next(),this); 101 localModules.put(mod.getName(), mod); 102 } 103 localClouds.add("mmbase"); 105 mmb = m; 106 } 107 } 108 } 109 return true; 110 } 111 112 public ModuleList getModules() { 113 if (!check()) throw new BridgeException("MMBase has not been started, and cannot be started by this Class. (" + getClass().getName() + ")"); 114 ModuleList ml = new BasicModuleList(localModules.values()); 115 return ml; 116 } 117 118 public Module getModule(String moduleName) throws NotFoundException { 119 if (!check()) throw new BridgeException("MMBase has not been started, and cannot be started by this Class. (" + getClass().getName() + ")"); 120 Module mod = (Module)localModules.get(moduleName); 121 if (mod == null) { 122 throw new NotFoundException("Module '" + moduleName + "' does not exist."); 123 } 124 return mod; 125 } 126 127 public boolean hasModule(String moduleName) { 128 if (!check()) throw new BridgeException("MMBase has not been started, and cannot be started by this Class. (" + getClass().getName() + ")"); 129 return localModules.get(moduleName) != null; 130 } 131 132 133 protected void checkExists(String cloudName) throws NotFoundException { 134 if (!check()) throw new BridgeException("MMBase has not been started, and cannot be started by this Class. (" + getClass().getName() + ")"); 135 if ( !localClouds.contains(cloudName) ) { 136 throw new NotFoundException("Cloud '" + cloudName + "' does not exist."); 137 } 138 if (mmb == null || ! mmb.getState()) { 139 throw new NotFoundException("MMBase is not yet initialized"); 140 } 141 } 142 public Cloud getCloud(String cloudName) { 143 checkExists(cloudName); 144 return getCloud(cloudName, "anonymous", null); 145 } 146 147 public Cloud getCloud(String cloudName, String authenticationType, Map loginInfo) throws NotFoundException { 148 checkExists(cloudName); 149 return new BasicCloud(cloudName, authenticationType, loginInfo, this); 150 } 151 152 public Cloud getCloud(String cloudName, UserContext user) throws NotFoundException { 153 checkExists(cloudName); 154 return new BasicCloud(cloudName, user, this); 155 } 156 157 public StringList getCloudNames() { 158 if (!check()) throw new BridgeException("MMBase has not been started, and cannot be started by this Class. (" + getClass().getName() + ")"); 159 return new BasicStringList(localClouds); 160 } 161 162 166 public String getDefaultCharacterEncoding() { 167 if (!check()) throw new BridgeException("MMBase has not been started, and cannot be started by this Class. (" + getClass().getName() + ")"); 168 return mmb.getEncoding(); 169 } 170 171 public java.util.Locale getDefaultLocale() { 172 if (!check()) throw new BridgeException("MMBase has not been started, and cannot be started by this Class. (" + getClass().getName() + ")"); 173 return mmb.getLocale(); 174 } 175 176 public java.util.TimeZone getDefaultTimeZone() { 177 if (!check()) throw new BridgeException("MMBase has not been started, and cannot be started by this Class. (" + getClass().getName() + ")"); 178 return mmb.getTimeZone(); 179 } 180 181 public FieldList createFieldList() { 182 return new BasicFieldList(); 183 } 184 185 public NodeList createNodeList() { 186 return new BasicNodeList(); 187 } 188 189 public RelationList createRelationList() { 190 return new BasicRelationList(); 191 } 192 193 public NodeManagerList createNodeManagerList() { 194 return new BasicNodeManagerList(); 195 } 196 197 public RelationManagerList createRelationManagerList() { 198 return new BasicRelationManagerList(); 199 } 200 201 public ModuleList createModuleList() { 202 return new BasicModuleList(); 203 } 204 205 public StringList createStringList() { 206 return new BasicStringList(); 207 } 208 209 public AuthenticationData getAuthentication() throws NotFoundException { 210 if (!check()) throw new BridgeException("MMBase has not been started, and cannot be started by this Class. (" + getClass().getName() + ")"); 211 MMBaseCop cop = mmb.getMMBaseCop(); 213 if (cop == null) { 214 throw new NotFoundException("MMBase not yet initialized"); 215 } else { 216 return cop.getAuthentication(); 217 } 218 } 219 220 public boolean isUp() { 221 return mmb != null && mmb.getState() && check(); 222 } 223 224 public void assertUp() { 225 CloudContext ctx = LocalContext.getCloudContext(); 227 while (!MMBaseContext.isInitialized() || ! isUp()) { 228 try { 229 check(); 230 Thread.currentThread().sleep(10000); 231 log.debug("Sleeping another 10 secs"); 232 } catch (Exception e) { 233 } 235 } 236 } 237 238 } 239 | Popular Tags |