Source Code Cross Referenced for BasicServerInfo.java in  » EJB-Server-geronimo » system » org » apache » geronimo » system » serverinfo » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server geronimo » system » org.apache.geronimo.system.serverinfo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.system.serverinfo;
017:
018:        import java.io.File;
019:        import java.net.URI;
020:
021:        import org.apache.geronimo.gbean.GBeanInfo;
022:        import org.apache.geronimo.gbean.GBeanInfoBuilder;
023:
024:        /**
025:         * Contains information about the server and functions for resolving
026:         * pathnames.
027:         *
028:         * @version $Rev: 601152 $ $Date: 2007-12-04 15:49:03 -0800 (Tue, 04 Dec 2007) $
029:         */
030:        public class BasicServerInfo implements  ServerInfo {
031:            public static final String SERVER_NAME_SYS_PROP = "org.apache.geronimo.server.name";
032:            public static final String SERVER_DIR_SYS_PROP = "org.apache.geronimo.server.dir";
033:            public static final String HOME_DIR_SYS_PROP = "org.apache.geronimo.home.dir";
034:
035:            private final String baseDirectory;
036:            private final File base;
037:            private final File baseServer;
038:            private final URI baseURI;
039:            private final URI baseServerURI;
040:
041:            public BasicServerInfo() {
042:                baseDirectory = null;
043:                base = null;
044:                baseServer = null;
045:                baseURI = null;
046:                baseServerURI = null;
047:            }
048:
049:            public BasicServerInfo(String defaultBaseDirectory)
050:                    throws Exception {
051:                this (defaultBaseDirectory, true);
052:            }
053:
054:            public BasicServerInfo(String defaultBaseDirectory,
055:                    boolean useSystemProperties) throws Exception {
056:                // Before we try the persistent value, we always check the
057:                // system properties first.  This lets an admin override this
058:                // on the command line.
059:                this .baseDirectory = useSystemProperties ? System.getProperty(
060:                        HOME_DIR_SYS_PROP, defaultBaseDirectory)
061:                        : defaultBaseDirectory;
062:
063:                // force load of server constants
064:                ServerConstants.getVersion();
065:
066:                if (baseDirectory == null || baseDirectory.length() == 0) {
067:                    base = DirectoryUtils.getGeronimoInstallDirectory();
068:                    if (base == null) {
069:                        throw new IllegalArgumentException(
070:                                "Could not determine geronimo installation directory");
071:                    }
072:                } else {
073:                    base = new File(baseDirectory);
074:                }
075:
076:                if (!base.isDirectory()) {
077:                    throw new IllegalArgumentException(
078:                            "Base directory is not a directory: "
079:                                    + baseDirectory);
080:                }
081:
082:                baseURI = base.toURI();
083:                baseServer = deriveBaseServer(useSystemProperties);
084:                baseServerURI = baseServer.toURI();
085:                if (useSystemProperties) {
086:                    System.setProperty(HOME_DIR_SYS_PROP, base
087:                            .getAbsolutePath());
088:                    System.setProperty(SERVER_DIR_SYS_PROP, baseServer
089:                            .getAbsolutePath());
090:                }
091:                String tmpDir = resolveServerPath(System
092:                        .getProperty("java.io.tmpdir"));
093:                System.setProperty("java.io.tmpdir", tmpDir);
094:            }
095:
096:            /**
097:             * Resolves an abstract pathname to an absolute one.
098:             *
099:             * @param filename a pathname that can either be
100:             * fully-qualified (i.e. starts with a "/") or
101:             * relative (i.e. starts with any character but "/").  If it's
102:             * fully-qualified it will be resolved to an absolute pathname
103:             * using system-dependent rules (@link java.io.File). If it's relative
104:             * it will be resolved relative to the base directory.
105:             * @return an absolute pathname
106:             * @see java.io.File#File(String pathname)
107:             * @see java.io.File#getAbsolutePath()
108:             */
109:            public String resolvePath(final String filename) {
110:                return resolve(filename).getAbsolutePath();
111:            }
112:
113:            public String resolveServerPath(String filename) {
114:                return resolveServer(filename).getAbsolutePath();
115:            }
116:
117:            /**
118:             * Resolves an abstract pathname to a File.
119:             *
120:             * @param filename a <code>String</code> containing a pathname,
121:             * which will be resolved by {@link #resolvePath(String
122:             * filename)}.
123:             * @return a <code>File</code> value
124:             */
125:            public File resolve(final String filename) {
126:                return resolveWithBase(base, filename);
127:            }
128:
129:            public File resolveServer(String filename) {
130:                return resolveWithBase(baseServer, filename);
131:            }
132:
133:            public URI resolve(final URI uri) {
134:                return baseURI.resolve(uri);
135:            }
136:
137:            public URI resolveServer(URI uri) {
138:                return baseServerURI.resolve(uri);
139:            }
140:
141:            public String getBaseDirectory() {
142:                return baseDirectory;
143:            }
144:
145:            public String getCurrentBaseDirectory() {
146:                return base.getAbsolutePath();
147:            }
148:
149:            public String getVersion() {
150:                return ServerConstants.getVersion();
151:            }
152:
153:            public String getBuildDate() {
154:                return ServerConstants.getBuildDate();
155:            }
156:
157:            public String getBuildTime() {
158:                return ServerConstants.getBuildTime();
159:            }
160:
161:            public String getCopyright() {
162:                return ServerConstants.getCopyright();
163:            }
164:
165:            private File resolveWithBase(File baseDir, String filename) {
166:                File file = new File(filename);
167:                if (file.isAbsolute()) {
168:                    return file;
169:                }
170:                return new File(baseDir, filename);
171:            }
172:
173:            private File deriveBaseServer(boolean useSystemProperties) {
174:                File baseServerDir;
175:
176:                // first check if the base server directory has been provided via
177:                // system property override.
178:                String baseServerDirPath = System
179:                        .getProperty(SERVER_DIR_SYS_PROP);
180:                if (!useSystemProperties || null == baseServerDirPath) {
181:                    // then check if a server name has been provided
182:                    String serverName = System
183:                            .getProperty(SERVER_NAME_SYS_PROP);
184:                    if (!useSystemProperties || null == serverName) {
185:                        // default base server directory.
186:                        baseServerDir = base;
187:                    } else {
188:                        baseServerDir = new File(base, serverName);
189:                    }
190:                } else {
191:                    baseServerDir = new File(baseServerDirPath);
192:                    if (!baseServerDir.isAbsolute()) {
193:                        baseServerDir = new File(base, baseServerDirPath);
194:                    }
195:                }
196:
197:                if (!baseServerDir.isDirectory()) {
198:                    throw new IllegalArgumentException(
199:                            "Server directory is not a directory: "
200:                                    + baseServerDir);
201:                }
202:
203:                return baseServerDir;
204:            }
205:
206:            public static final GBeanInfo GBEAN_INFO;
207:
208:            static {
209:                GBeanInfoBuilder infoFactory = GBeanInfoBuilder
210:                        .createStatic(BasicServerInfo.class);
211:
212:                infoFactory.addAttribute("baseDirectory", String.class, true);
213:
214:                infoFactory.addInterface(ServerInfo.class);
215:
216:                infoFactory.setConstructor(new String[] { "baseDirectory" });
217:
218:                GBEAN_INFO = infoFactory.getBeanInfo();
219:            }
220:
221:            public static GBeanInfo getGBeanInfo() {
222:                return GBEAN_INFO;
223:            }
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.