Source Code Cross Referenced for JFigLocator.java in  » Development » jfig » org » igfay » jfig » 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 » Development » jfig » org.igfay.jfig 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.igfay.jfig;
002:
003:        import java.io.FileInputStream;
004:        import java.io.FileNotFoundException;
005:        import java.io.InputStream;
006:
007:        import org.apache.log4j.Logger;
008:        import org.igfay.util.PropertyUtility;
009:
010:        /**
011:         * @author conrad4
012:         * 
013:         * Locate the intial Configuration file. Users may write their own
014:         * implementation of JFigLocatorIF with their own scheme of finding the initial
015:         * configuration file.
016:         * 
017:         * Best method may be to subclass the JFig implementation. Then, initialize JFig
018:         * via: getInstance(JFigLocatorIF), passing your implementation.
019:         */
020:        public class JFigLocator implements  JFigLocatorIF {
021:            private static Logger log = Logger.getLogger(JFigLocator.class);
022:
023:            protected String configFileName;
024:
025:            protected String configLocation;
026:
027:            protected String configDirectory = "";
028:
029:            public JFigLocator(String fileName) {
030:                this .configFileName = fileName;
031:            }
032:
033:            /**
034:             * Return the config location; file or classpath If user specified
035:             * LOCATION_PROPERTY on the command line, use that. Otherwise, default to
036:             * CLASSPATH.
037:             * 
038:             * @return String
039:             */
040:            public String getConfigLocation() throws JFigException {
041:                if (configLocation == null) {
042:                    setConfigLocation(PropertyUtility.getProperty(
043:                            JFigConstants.LOCATION_PROPERTY,
044:                            JFigConstants.CLASSPATH));
045:                    log.debug(configLocation);
046:                }
047:
048:                return configLocation;
049:            }
050:
051:            /**
052:             * Return a default config fileName. The filename will be the project name
053:             * and the machine name. This is used when no config. filename is passed as
054:             * an argument.
055:             */
056:            public String getDefaultConfigFileName() {
057:                return PropertyUtility.getHostName().toLowerCase() + "."
058:                        + JFigConstants.XML_FILENAME_SUFFIX;
059:            }
060:
061:            /**
062:             * Return the config fileName. This will be the last file processed.
063:             */
064:            public String getConfigFileName() {
065:                if (configFileName == null) {
066:                    this .configFileName = PropertyUtility.getProperty(
067:                            JFigConstants.FILENAME_PROPERTY,
068:                            getDefaultConfigFileName());
069:                    parseInitialFileName();
070:                }
071:                return getConfigDirectory() + this .configFileName;
072:            }
073:
074:            /**
075:             * Parse the directory name if one is specified.
076:             * This is only done on the initial file name.
077:             * That way, the initial directory name is saved for use on subsequent files.
078:             */
079:            protected void parseInitialFileName() {
080:                int lastIndex = Math.max(configFileName.lastIndexOf("/"),
081:                        configFileName.lastIndexOf("\\"));
082:                if (lastIndex > 0) {
083:                    setConfigDirectory(configFileName.substring(0,
084:                            lastIndex + 1));
085:                    this .configFileName = configFileName
086:                            .substring(lastIndex + 1);
087:                }
088:            }
089:
090:            /*
091:             * (non-Javadoc)
092:             * 
093:             * @see org.igfay.jfig.JFigLocatorIF#setConfigFileName(java.lang.String)
094:             */
095:            public void setConfigFileName(String value) {
096:                this .configFileName = value;
097:            }
098:
099:            /**
100:             * 
101:             * @see org.igfay.jfig.JFigLocatorIF#setConfigLocation(java.lang.String)
102:             */
103:            public void setConfigLocation(String value) throws JFigException {
104:                if ((!JFigConstants.FILE.equalsIgnoreCase(value))
105:                        && (!JFigConstants.CLASSPATH.equalsIgnoreCase(value))) {
106:                    throw new JFigException("{" + value + "}"
107:                            + " Invalid entry for "
108:                            + JFigConstants.LOCATION_PROPERTY
109:                            + ". Valid entries are " + JFigConstants.CLASSPATH
110:                            + " or " + JFigConstants.FILE);
111:                }
112:                this .configLocation = value;
113:
114:            }
115:
116:            /**
117:             * 
118:             * @see org.igfay.jfig.JFigLocatorIF#setDefaultConfigFileName(java.lang.String)
119:             */
120:            public void setDefaultConfigFileName(String value) {
121:                this .configFileName = value;
122:
123:            }
124:
125:            /**
126:             * Return the config file as an InputStream
127:             */
128:            public InputStream getInputStream() throws JFigException {
129:                InputStream inputStream = null;
130:
131:                if (isClasspath()) {
132:                    inputStream = getInputStreamForClasspath();
133:                } else {
134:                    inputStream = getInputStreamForFile(inputStream);
135:                }
136:
137:                return inputStream;
138:            }
139:
140:            /**
141:             * Return if we expect to find config file in the classpath
142:             * @return
143:             * @throws JFigException
144:             */
145:            private boolean isClasspath() throws JFigException {
146:                return JFigConstants.CLASSPATH
147:                        .equalsIgnoreCase(getConfigLocation());
148:            }
149:
150:            /**
151:             * Find the input stream in the file system.
152:             * 
153:             * @param inputStream
154:             * @return
155:             * @throws JFigException
156:             */
157:            protected InputStream getInputStreamForFile(InputStream inputStream)
158:                    throws JFigException {
159:                try {
160:                    inputStream = new FileInputStream(getConfigFileName());
161:                } catch (FileNotFoundException e) {
162:                    String msg = "FileNotFoundException for "
163:                            + getConfigFileName();
164:                    log.debug(msg);
165:                    throw new JFigException(msg);
166:                }
167:                return inputStream;
168:            }
169:
170:            /**
171:             * Find the input stream in the classpath
172:             * @return
173:             * @throws JFigException
174:             */
175:            protected InputStream getInputStreamForClasspath()
176:                    throws JFigException {
177:                InputStream inputStream;
178:                inputStream = JFig.class.getResourceAsStream("/"
179:                        + getConfigFileName());
180:                if (inputStream == null) {
181:                    String msg = "Resource not found in classpath: "
182:                            + getConfigFileName();
183:                    log.debug(msg);
184:                    throw new JFigException(msg);
185:                }
186:                return inputStream;
187:            }
188:
189:            /** 
190:             * Return the config directory. This directory is parsed from the initial 
191:             * config.name that is set. It is not changed by subsequent config file names.
192:             * That enables subsequent file names to set their paths relative to the initial.
193:             * 
194:             */
195:            public String getConfigDirectory() {
196:                return configDirectory;
197:            }
198:
199:            /**
200:             * Set the configDirectory. Parsed from the initial config.file name
201:             * 
202:             */
203:            public void setConfigDirectory(String value) {
204:                this.configDirectory = value;
205:
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.