Source Code Cross Referenced for Velosurf.java in  » Database-ORM » Velosurf » velosurf » 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 » Database ORM » Velosurf » velosurf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2003 The Apache Software Foundation.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package velosurf;
018:
019:        import velosurf.context.DBReference;
020:        import velosurf.util.Logger;
021:        import velosurf.util.XIncludeResolver;
022:        import velosurf.sql.Database;
023:
024:        import java.io.File;
025:        import java.io.FileInputStream;
026:        import java.io.IOException;
027:        import java.io.InputStream;
028:        import java.sql.SQLException;
029:
030:        import org.apache.velocity.app.Velocity;
031:
032:        /** <p>This class is the Velosurf main entry class if you do not use the toolbox.xml mechanism.
033:         *  Unless you specify the config file to use, it will successively search for a configuration file :</p>
034:         *  <ul>
035:         *  <li><p>from the java property "config.velosurf" (like in 'java -Dconfig.velosurf=/.../velosurf.xml ...' )</p>
036:         *  <li><p>from the Velocity property "config.velosurf" (entry of the velocity.properties file)</p>
037:         *  <li><p>as './velosurf.xml', './conf/velosurf.xml', './WEB-INF/velosurf.xml', './cfg/velosurf.xml'
038:         * </ul>
039:         *
040:         * @author <a href="mailto:claude.brisson@gmail.com">Claude Brisson</a>
041:         *
042:         */
043:
044:        public class Velosurf extends DBReference {
045:            /** Initialization flag.
046:             */
047:            private boolean initialized = false;
048:
049:            /** Configuration file.
050:             */
051:            private String configFile = null;
052:
053:            /** Empty constructor.
054:             */
055:            public Velosurf() {
056:            }
057:
058:            /**
059:             * Constructor taking a File object as configuration.
060:             * @param configFile configuration file
061:             * @throws IOException
062:             * @throws SQLException
063:             */
064:            public Velosurf(File configFile) throws IOException, SQLException {
065:                this (new FileInputStream(configFile));
066:            }
067:
068:            /**
069:             * Constructor taking an InputStream object as configuration.
070:             * @param config
071:             * @throws IOException
072:             * @throws SQLException
073:             */
074:            public Velosurf(InputStream config) throws IOException,
075:                    SQLException {
076:                initLogging();
077:                init(config);
078:            }
079:
080:            /**
081:             * Explicitely set the configuration file.
082:             * @param config configuration pathname
083:             */
084:            public void setConfigFile(String config) {
085:                configFile = config;
086:            }
087:
088:            /**
089:             * Initializes the logger.
090:             */
091:            private void initLogging() {
092:                if (!Logger.isInitialized()) {
093:                    Logger.log2Stderr();
094:                }
095:            }
096:
097:            /**
098:             * Tries to find a configuration file using some default locations.
099:             * @return the pathname of the configuration file, if found - null otherwise
100:             */
101:            private static String findConfig() {
102:                String pathname = null;
103:                File file = null;
104:
105:                /* first, ask Java */
106:                pathname = System.getProperty("velosurf.config");
107:                if (pathname != null) {
108:                    file = new File(pathname);
109:                    if (file.exists())
110:                        return pathname;
111:                }
112:
113:                /* then Velocity */
114:                pathname = (String) Velocity.getProperty("velosurf.config");
115:                if (pathname != null) {
116:                    file = new File(pathname);
117:                    if (file.exists())
118:                        return pathname;
119:                }
120:
121:                /* then try some standard pathes */
122:                String[] guesses = { "./velosurf.xml", "./conf/velosurf.xml",
123:                        "./WEB-INF/velosurf.xml", "./cfg/velosurf.xml",
124:                        "./model.xml", "./conf/model.xml",
125:                        "./WEB-INF/model.xml", "./cfg/model.xml" };
126:                for (int i = 0; i < guesses.length; i++) {
127:                    file = new File(guesses[i]);
128:                    if (file.exists())
129:                        return guesses[i];
130:                }
131:
132:                return null;
133:            }
134:
135:            /**
136:             * Lazzy initialization.
137:             * @param config configuration file input stream
138:             * @throws SQLException
139:             * @throws IOException
140:             */
141:            private void init(InputStream config) throws SQLException,
142:                    IOException {
143:                Database db = Database.getInstance(config);
144:                super .init(db);
145:                initialized = true;
146:            }
147:
148:            /**
149:             * Lazzy initialization.
150:             * @throws SQLException
151:             * @throws IOException
152:             */
153:            private void init() throws SQLException, IOException {
154:                if (configFile == null) {
155:                    configFile = findConfig();
156:                }
157:                if (configFile == null) {
158:                    throw new IOException(
159:                            "No Velosurf config file found. Please specify one using setConfig(pathname).");
160:                }
161:                /* calculate the base directory, for XInclude */
162:                /* Velosurf won't like '/' in windows names neither '\' in linux ones... Does Java? */
163:                String base = null;
164:                configFile.replace('\\', '/');
165:                int i = configFile.lastIndexOf('/');
166:                if (i == -1) {
167:                    base = ".";
168:                } else {
169:                    base = configFile.substring(0, i);
170:                }
171:                Database db = Database.getInstance(new FileInputStream(
172:                        configFile), new XIncludeResolver(base));
173:                super .init(db);
174:                initialized = true;
175:            }
176:
177:            /**
178:             * Generic getter.
179:             * @param key
180:             * @return property
181:             */
182:            public Object get(Object key) {
183:                if (!initialized) {
184:                    try {
185:                        init();
186:                    } catch (Exception e) {
187:                        Logger.log(e);
188:                        return null;
189:                    }
190:                }
191:                return super .get(key);
192:            }
193:
194:            /**
195:             * Generic setter.
196:             * @param key
197:             * @param value
198:             * @return old value
199:             */
200:            public Object put(String key, Object value) {
201:                if (!initialized) {
202:                    try {
203:                        init();
204:                    } catch (Exception e) {
205:                        Logger.log(e);
206:                        return null;
207:                    }
208:                }
209:                return super .put(key, value);
210:            }
211:
212:            /**
213:             * Schema name getter.
214:             * @return the name of the current schema
215:             */
216:            public String getSchema() {
217:                if (!initialized) {
218:                    try {
219:                        init();
220:                    } catch (Exception e) {
221:                        Logger.log(e);
222:                        return null;
223:                    }
224:                }
225:                return super .getSchema();
226:            }
227:
228:            /** Obfuscate the given value.
229:             * @param value value to obfuscate
230:             * @return obfuscated value
231:             */
232:            public String obfuscate(Object value) {
233:                if (!initialized) {
234:                    try {
235:                        init();
236:                    } catch (Exception e) {
237:                        Logger.log(e);
238:                        return null;
239:                    }
240:                }
241:                return super .obfuscate(value);
242:            }
243:
244:            /** De-obfuscate the given value.
245:             * @param value value to de-obfuscate
246:             * @return obfuscated value
247:             */
248:            public String deobfuscate(Object value) {
249:                if (!initialized) {
250:                    try {
251:                        init();
252:                    } catch (Exception e) {
253:                        Logger.log(e);
254:                        return null;
255:                    }
256:                }
257:                return super.deobfuscate(value);
258:            }
259:
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.