1 29 30 package com.caucho.server.resin; 31 32 import com.caucho.config.ConfigELContext; 33 import com.caucho.config.ConfigException; 34 import com.caucho.naming.Jndi; 35 import com.caucho.server.util.CauchoSystem; 36 import com.caucho.util.Alarm; 37 import com.caucho.vfs.Path; 38 39 import java.net.InetAddress ; 40 import java.util.logging.Level ; 41 import java.util.logging.Logger ; 42 43 abstract public class ResinELContext 44 extends ConfigELContext 45 { 46 private final JavaVar _javaVar = new JavaVar(); 47 private final ResinVar _resinVar = new ResinVar(); 48 private final ServerVar _serverVar = new ServerVar(); 49 50 public ResinELContext() 51 { 52 setValue("java", new JavaVar()); 53 setValue("resin", new ResinVar()); 54 setValue("server", new ServerVar()); 55 56 setValue("fmt", new com.caucho.config.functions.FmtFunctions()); 57 58 try { 59 setValue("jndi", Jndi.class.getMethod("lookup", new Class [] { String .class })); 60 setValue("jndi:lookup", Jndi.class.getMethod("lookup", new Class [] { String .class })); 61 } catch (Exception e) { 62 throw new ConfigException(e); 63 } 64 } 65 66 public JavaVar getJavaVar() 67 { 68 return _javaVar; 69 } 70 71 public ResinVar getResinVar() 72 { 73 return _resinVar; 74 } 75 76 public ServerVar getServerVar() 77 { 78 return _serverVar; 79 } 80 81 public Object getValue(String var) 82 { 83 85 if ("resinHome".equals(var) || "resin-home".equals(var)) 86 return getResinHome(); 87 88 if ("serverRoot".equals(var) || "server-root".equals(var)) 89 return getRootDirectory(); 90 91 return super.getValue(var); 92 } 93 94 public String toString() 95 { 96 return getClass().getSimpleName() + "[]"; 97 } 98 99 abstract public Path getResinHome(); 100 101 abstract public Path getRootDirectory(); 102 103 abstract public Path getResinConf(); 104 105 abstract public String getServerId(); 106 107 abstract public boolean isResinProfessional(); 108 109 112 public class JavaVar { 113 116 public boolean isJava5() 117 { 118 return CauchoSystem.isJdk15(); 119 } 120 123 public String getVersion() 124 { 125 return System.getProperty("java.version"); 126 } 127 } 128 129 public class ResinVar { 130 133 public String getServerId() 134 { 135 return ResinELContext.this.getServerId(); 136 } 137 138 141 public String getId() 142 { 143 return getServerId(); 144 } 145 146 147 152 public String getAddress() 153 { 154 try { 155 if (Alarm.isTest()) 156 return "127.0.0.1"; 157 else 158 return InetAddress.getLocalHost().getHostAddress(); 159 } catch (Exception e) { 160 Logger.getLogger(ResinELContext.class.getName()).log(Level.FINE, e.toString(), e); 161 162 return "localhost"; 163 } 164 } 165 166 169 public Path getConf() 170 { 171 return ResinELContext.this.getResinConf(); 172 } 173 174 177 public Path getHome() 178 { 179 return ResinELContext.this.getResinHome(); 180 } 181 182 187 public Path getRoot() 188 { 189 return ResinELContext.this.getRootDirectory(); 190 } 191 192 195 public Path getRootDir() 196 { 197 return getRoot(); 198 } 199 200 203 public Path getRootDirectory() 204 { 205 return getRoot(); 206 } 207 208 213 public String getVersion() 214 { 215 if (Alarm.isTest()) 216 return "3.1.test"; 217 else 218 return com.caucho.Version.VERSION; 219 } 220 221 226 public String getHostName() 227 { 228 try { 229 if (Alarm.isTest()) 230 return "localhost"; 231 else 232 return InetAddress.getLocalHost().getHostName(); 233 } catch (Exception e) { 234 Logger.getLogger(ResinELContext.class.getName()).log(Level.FINE, e.toString(), e); 235 236 return "localhost"; 237 } 238 } 239 240 243 public boolean isProfessional() 244 { 245 return ResinELContext.this.isResinProfessional(); 246 } 247 } 248 249 public class ServerVar { 250 public String getId() 251 { 252 return ResinELContext.this.getServerId(); 253 } 254 255 260 public Path getRoot() 261 { 262 return ResinELContext.this.getRootDirectory(); 263 } 264 265 268 public Path getRootDir() 269 { 270 return getRoot(); 271 } 272 273 276 public Path getRootDirectory() 277 { 278 return getRoot(); 279 } 280 } 281 } 282 | Popular Tags |