001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Sam
028: */
029:
030: package com.caucho.server.resin;
031:
032: import com.caucho.config.ConfigELContext;
033: import com.caucho.config.ConfigException;
034: import com.caucho.naming.Jndi;
035: import com.caucho.server.util.CauchoSystem;
036: import com.caucho.util.Alarm;
037: import com.caucho.vfs.Path;
038:
039: import java.net.InetAddress;
040: import java.util.logging.Level;
041: import java.util.logging.Logger;
042:
043: abstract public class ResinELContext {
044: private final JavaVar _javaVar = new JavaVar();
045: private final ResinVar _resinVar = new ResinVar();
046: private final ServerVar _serverVar = new ServerVar();
047:
048: public ResinELContext() {
049: }
050:
051: public JavaVar getJavaVar() {
052: return _javaVar;
053: }
054:
055: public ResinVar getResinVar() {
056: return _resinVar;
057: }
058:
059: public ServerVar getServerVar() {
060: return _serverVar;
061: }
062:
063: public String toString() {
064: return getClass().getSimpleName() + "[]";
065: }
066:
067: abstract public Path getResinHome();
068:
069: abstract public Path getRootDirectory();
070:
071: abstract public Path getResinConf();
072:
073: abstract public String getServerId();
074:
075: abstract public boolean isResinProfessional();
076:
077: /**
078: * Java variables
079: */
080: public class JavaVar {
081: /**
082: * Returns true for JDK 5
083: */
084: public boolean isJava5() {
085: return CauchoSystem.isJdk15();
086: }
087:
088: /**
089: * Returns the JDK version
090: */
091: public String getVersion() {
092: return System.getProperty("java.version");
093: }
094: }
095:
096: public class ResinVar {
097: /**
098: * Returns the -server id
099: */
100: public String getServerId() {
101: return ResinELContext.this .getServerId();
102: }
103:
104: /**
105: * @deprecated use {@link #getServerId()}
106: */
107: public String getId() {
108: return getServerId();
109: }
110:
111: /**
112: * Returns the local address
113: *
114: * @return IP address
115: */
116: public String getAddress() {
117: try {
118: if (Alarm.isTest())
119: return "127.0.0.1";
120: else
121: return InetAddress.getLocalHost().getHostAddress();
122: } catch (Exception e) {
123: Logger.getLogger(ResinELContext.class.getName()).log(
124: Level.FINE, e.toString(), e);
125:
126: return "localhost";
127: }
128: }
129:
130: /**
131: * Returns the resin config.
132: */
133: public Path getConf() {
134: return ResinELContext.this .getResinConf();
135: }
136:
137: /**
138: * Returns the resin home.
139: */
140: public Path getHome() {
141: return ResinELContext.this .getResinHome();
142: }
143:
144: /**
145: * Returns the root directory.
146: *
147: * @return the root directory
148: */
149: public Path getRoot() {
150: return ResinELContext.this .getRootDirectory();
151: }
152:
153: /**
154: * @deprecated use {@link #getRoot()}
155: */
156: public Path getRootDir() {
157: return getRoot();
158: }
159:
160: /**
161: * @deprecated use {@link #getRoot()}
162: */
163: public Path getRootDirectory() {
164: return getRoot();
165: }
166:
167: /**
168: * Returns the version
169: *
170: * @return version
171: */
172: public String getVersion() {
173: if (Alarm.isTest())
174: return "3.1.test";
175: else
176: return com.caucho.Version.VERSION;
177: }
178:
179: /**
180: * Returns the local hostname
181: *
182: * @return version
183: */
184: public String getHostName() {
185: try {
186: if (Alarm.isTest())
187: return "localhost";
188: else
189: return InetAddress.getLocalHost().getHostName();
190: } catch (Exception e) {
191: Logger.getLogger(ResinELContext.class.getName()).log(
192: Level.FINE, e.toString(), e);
193:
194: return "localhost";
195: }
196: }
197:
198: /**
199: * Returns true for Resin professional.
200: */
201: public boolean isProfessional() {
202: return ResinELContext.this .isResinProfessional();
203: }
204: }
205:
206: public class ServerVar {
207: public String getId() {
208: return ResinELContext.this .getServerId();
209: }
210:
211: /**
212: * Returns the root directory.
213: *
214: * @return the root directory
215: */
216: public Path getRoot() {
217: return ResinELContext.this .getRootDirectory();
218: }
219:
220: /**
221: * @deprecated use {@link #getRoot()}
222: */
223: public Path getRootDir() {
224: return getRoot();
225: }
226:
227: /**
228: * @deprecated use {@link #getRoot()}
229: */
230: public Path getRootDirectory() {
231: return getRoot();
232: }
233: }
234: }
|