1 29 30 package com.caucho.server.host; 31 32 import com.caucho.config.Config; 33 import com.caucho.config.ConfigELContext; 34 import com.caucho.config.ConfigException; 35 import com.caucho.config.types.RawString; 36 import com.caucho.el.EL; 37 import com.caucho.el.MapVariableResolver; 38 import com.caucho.log.Log; 39 import com.caucho.server.deploy.DeployContainer; 40 import com.caucho.server.deploy.ExpandDeployGenerator; 41 import com.caucho.vfs.Path; 42 43 import javax.el.ELContext; 44 import javax.el.ELResolver; 45 import java.util.ArrayList ; 46 import java.util.logging.Level ; 47 import java.util.logging.Logger ; 48 49 52 public class HostExpandDeployGenerator extends ExpandDeployGenerator<HostController> { 53 private static final Logger log = Log.open(HostExpandDeployGenerator.class); 54 55 private final HostExpandDeployGeneratorAdmin _admin = new HostExpandDeployGeneratorAdmin(this); 56 57 private HostContainer _container; 58 59 private ArrayList <HostConfig> _hostDefaults = new ArrayList <HostConfig>(); 60 61 private String _hostName; 62 63 66 public HostExpandDeployGenerator(DeployContainer<HostController> container, 67 HostContainer hostContainer) 68 { 69 super(container, hostContainer.getRootDirectory()); 70 71 _container = hostContainer; 72 } 73 74 77 public HostContainer getContainer() 78 { 79 return _container; 80 } 81 82 85 public void setHostName(RawString name) 86 { 87 _hostName = name.getValue(); 88 } 89 90 93 public String getHostName() 94 { 95 return _hostName; 96 } 97 98 101 public void setLazyInit(boolean lazyInit) 102 throws ConfigException 103 { 104 log.config("lazy-init is deprecated. Use <startup>lazy</startup> instead."); 105 if (lazyInit) 106 setStartupMode("lazy"); 107 else 108 setStartupMode("automatic"); 109 } 110 111 114 public void addHostDefault(HostConfig config) 115 { 116 _hostDefaults.add(config); 117 } 118 119 @Override 120 protected void initImpl() 121 throws ConfigException 122 { 123 super.initImpl(); 124 } 125 126 @Override 127 protected void startImpl() 128 throws ConfigException 129 { 130 super.startImpl(); 131 132 _admin.register(); 133 } 134 135 138 protected Logger getLog() 139 { 140 return log; 141 } 142 143 146 public HostController createController(String name) 147 { 148 if (name.equals("")) 150 return null; 151 152 156 157 Path rootDirectory = getExpandDirectory().lookup("./" + name); 158 159 HostController controller 160 = new HostController(name, rootDirectory, _container); 161 162 163 Path jarPath = getArchiveDirectory().lookup("./" + name + ".jar"); 164 controller.setArchivePath(jarPath); 165 166 if (rootDirectory.isDirectory() && 167 ! isValidDirectory(rootDirectory, name)) 168 return null; 169 else if (! rootDirectory.isDirectory() && 170 ! jarPath.isFile()) 171 return null; 172 173 try { 174 String hostName = getHostName(); 175 176 if (hostName != null) { 177 ELContext parentEnv = Config.getEnvironment(); 178 ELResolver resolver 179 = new MapVariableResolver(controller.getVariableMap()); 180 181 ELContext env = new ConfigELContext(resolver); 182 183 controller.setHostName(EL.evalString(hostName, env)); 184 } 185 else 186 controller.setHostName(name); 187 188 controller.addDepend(jarPath); 189 } catch (Throwable e) { 190 controller.setConfigException(e); 191 192 log.log(Level.WARNING, e.toString(), e); 193 } 194 195 return controller; 196 } 197 198 199 202 protected HostController mergeController(HostController controller, 203 String key) 204 { 205 try { 206 controller.setStartupMode(getStartupMode()); 207 208 for (int i = 0; i < _hostDefaults.size(); i++) 209 controller.addConfigDefault(_hostDefaults.get(i)); 210 } catch (ConfigException e) { 211 controller.setConfigException(e); 212 213 log.warning(e.toString()); 214 log.log(Level.FINER, e.toString(), e); 215 } catch (Throwable e) { 216 controller.setConfigException(e); 217 218 log.log(Level.WARNING, e.toString(), e); 219 } 220 221 return controller; 222 } 223 224 @Override 225 protected void destroyImpl() 226 { 227 _admin.unregister(); 228 229 super.destroyImpl(); 230 } 231 232 public boolean equals(Object o) 233 { 234 if (o == null || ! getClass().equals(o.getClass())) 235 return false; 236 237 HostExpandDeployGenerator deploy = (HostExpandDeployGenerator) o; 238 239 Path expandPath = getExpandDirectory(); 240 Path deployExpandPath = deploy.getExpandDirectory(); 241 if (expandPath != deployExpandPath && 242 (expandPath == null || ! expandPath.equals(deployExpandPath))) 243 return false; 244 245 return true; 246 } 247 248 public String toString() 249 { 250 return "HostExpandDeployGenerator[" + getExpandDirectory() + "]"; 251 } 252 } 253 | Popular Tags |