Source Code Cross Referenced for PropertiesLoader.java in  » Testing » PolePosition-0.20 » com » versant » core » util » 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 » Testing » PolePosition 0.20 » com.versant.core.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1998 - 2005 Versant Corporation
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         * Versant Corporation - initial API and implementation
010:         */
011:        package com.versant.core.util;
012:
013:        import com.versant.core.common.BindingSupportImpl;
014:        import com.versant.core.common.Utils;
015:        import com.versant.core.common.config.ConfigParser;
016:
017:        import java.util.Properties;
018:        import java.io.*;
019:        import java.net.MalformedURLException;
020:
021:        /**
022:         * Utility methods to load Properties instances as resources from a ClassLoader
023:         * based on a name prefix and type String.
024:         */
025:        public class PropertiesLoader {
026:
027:            public static final String RES_NAME_PROP = "this.resource.name";
028:
029:            /**
030:             * Look for a resorce named prefix-type.properties and load it. If
031:             * the resource contains a property named alias.for then replace type
032:             * with that String and attempt to load that resource instead.
033:             * If sucessful the name of the resource loaded is inserted into the
034:             * Properties instance using the key {@link #RES_NAME_PROP}.
035:             *
036:             * @exception FileNotFoundException if no resource could be loaded
037:             * @exception IOException on read errors
038:             */
039:            public static Properties loadPropertiesForURL(ClassLoader loader,
040:                    String prefix, String url) throws IOException {
041:                int i = url.indexOf(':');
042:                if (i <= 0) {
043:                    throw new MalformedURLException(url);
044:                }
045:                String type = url.substring(0, i);
046:                return loadProperties(loader, prefix, type);
047:            }
048:
049:            public static Properties loadPropertiesForDB(ClassLoader loader,
050:                    String prefix, String db) throws IOException {
051:                if (Utils.isStringEmpty(db)) {
052:                    throw BindingSupportImpl.getInstance().runtime(
053:                            "Unable to guess " + "database type. use the "
054:                                    + ConfigParser.STORE_DB
055:                                    + " property to set the database type");
056:                }
057:
058:                if (Utils.isVersantDatabaseType(db)) {
059:                    return loadProperties(loader, prefix, "versant");
060:                } else {
061:                    return loadProperties(loader, prefix, "jdbc");
062:                }
063:            }
064:
065:            /**
066:             * Look for a resorce named prefix-type.properties and load it. If
067:             * the resource contains a property named alias.for then replace type
068:             * with that String and attempt to load that resource instead.
069:             * If sucessful the name of the resource loaded is inserted into the
070:             * Properties instance using the key {@link #RES_NAME_PROP}.
071:             *
072:             * @exception FileNotFoundException if no resource could be loaded
073:             * @exception IOException on read errors
074:             */
075:            public static Properties loadProperties(ClassLoader loader,
076:                    String prefix, String type) throws IOException {
077:                for (;;) {
078:                    String resourceName = prefix + "-" + type + ".properties";
079:                    Properties p = loadProperties(loader, resourceName);
080:                    if (p == null) {
081:                        throw new FileNotFoundException("Resource not found: "
082:                                + resourceName);
083:                    }
084:                    type = p.getProperty("alias.for");
085:                    if (type == null) {
086:                        p.put(RES_NAME_PROP, resourceName);
087:                        return p;
088:                    }
089:                }
090:            }
091:
092:            /**
093:             * Load Properties from resource name. If the first attempt fails then
094:             * '/' is prepended to the resource name and another try is made.
095:             * Returns null if not found.
096:             *
097:             */
098:            public static Properties loadProperties(ClassLoader loader,
099:                    String resourceName) throws IOException {
100:                InputStream in = loader.getResourceAsStream(resourceName);
101:                if (in == null) {
102:                    in = loader.getResourceAsStream("/" + resourceName);
103:                }
104:                if (in == null) {
105:                    return null;
106:                }
107:                try {
108:                    Properties p = new Properties();
109:                    p.load(in);
110:                    return p;
111:                } finally {
112:                    try {
113:                        in.close();
114:                    } catch (IOException e) {
115:                        // ignore
116:                    }
117:                }
118:            }
119:
120:            /**
121:             * Load Properties from a file. Returns null if not found.
122:             */
123:            public static Properties loadProperties(String fileName)
124:                    throws IOException {
125:                InputStream in;
126:                try {
127:                    in = new FileInputStream(fileName);
128:                } catch (FileNotFoundException e) {
129:                    return null;
130:                }
131:                try {
132:                    Properties p = new Properties();
133:                    p.load(in);
134:                    return p;
135:                } finally {
136:                    try {
137:                        in.close();
138:                    } catch (IOException e) {
139:                        // ignore
140:                    }
141:                }
142:            }
143:
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.