Source Code Cross Referenced for KeYResourceManager.java in  » Testing » KeY » de » uka » ilkd » key » 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 » KeY » de.uka.ilkd.key.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // This file is part of KeY - Integrated Deductive Software Design
002:        // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003:        //                         Universitaet Koblenz-Landau, Germany
004:        //                         Chalmers University of Technology, Sweden
005:        //
006:        // The KeY system is protected by the GNU General Public License. 
007:        // See LICENSE.TXT for details.
008:        //
009:        //
010:
011:        /**
012:         * KeYResourceManager controls the access to the properties
013:         * and resources used in the KeY system.
014:         * Use the static method getManager to get the unique instance.
015:         */package de.uka.ilkd.key.util;
016:
017:        import java.io.*;
018:        import java.net.URL;
019:
020:        import javax.swing.ImageIcon;
021:
022:        public class KeYResourceManager {
023:
024:            /** the unique instance */
025:            private static final KeYResourceManager instance = new KeYResourceManager();
026:
027:            private String version = null;
028:            private String sha1 = null;
029:
030:            private KeYResourceManager() {
031:            }
032:
033:            /**
034:             * Return an instance of the ResourceManager
035:             */
036:            public static KeYResourceManager getManager() {
037:                return instance;
038:            }
039:
040:            /**
041:             * reads a version string or returns "x.z.y" in case of failures
042:             */
043:            private String readVersionString(URL url) {
044:                String result = "";
045:                if (url != null) {
046:                    try {
047:                        final InputStream io = new BufferedInputStream(url
048:                                .openStream());
049:                        int c;
050:                        while ((c = io.read()) != -1) {
051:                            result += (char) c;
052:                        }
053:                    } catch (IOException ioe) {
054:                        // who cares it is just a version number
055:                        result = "x.z.y";
056:                    }
057:                } else {
058:                    result = "x.z.y";
059:                }
060:                return result.trim();
061:            }
062:
063:            /**
064:             * returns the SHA 1 git code from which this version has been 
065:             * derived
066:             * @return returns the SHA1 hash uniquely identifying the version
067:             */
068:            public String getSHA1() {
069:                if (sha1 != null) {
070:                    return sha1;
071:                }
072:                sha1 = readVersionString(getResourceFile(this , "sha1"));
073:
074:                return sha1;
075:            }
076:
077:            /**
078:             * returns a readable customizable versin number    
079:             * @return 
080:             */
081:            public String getVersion() {
082:                if (version != null) {
083:                    return version;
084:                }
085:                version = readVersionString(getResourceFile(this , "version"));
086:
087:                return version;
088:            }
089:
090:            /**
091:             * Creates an icon from an image contained in a resource.
092:             * The resource is fist search using the package name of the calling Object
093:             * and if it is not found there the packagename of its superclass is used
094:             * recusrivly.
095:             * @param o the Object reference to the calling object
096:             * @param filename String the name of the file to search (only relative
097:             * pathname to the path of the calling class)
098:             * @return the newly created image
099:             */
100:            public ImageIcon createImageIcon(Object o, String filename) {
101:                return createImageIcon(o.getClass(), filename);
102:            }
103:
104:            /**
105:             * Creates an icon from an image contained in a resource.
106:             * The resource is fist search using the package name of the given class
107:             * and if the resource is not found the packagename of its superclass is used
108:             * recursivly.
109:             * @param cl the Class the resource is looked for
110:             * @param filename String the name of the file to search  (only relative
111:             * pathname to the path of the calling class)
112:             * @return the newly created image
113:             */
114:            public ImageIcon createImageIcon(Class cl, String filename) {
115:                URL iconURL = cl.getResource(filename);
116:                Debug.out("Load Resource:" + filename + " of class " + cl);
117:                if (iconURL == null && cl.getSuperclass() != null) {
118:                    return createImageIcon(cl.getSuperclass(), filename);
119:                } else if (iconURL == null && cl.getSuperclass() == null) {
120:                    // error message Resource not found
121:                    System.out.println("No image resource " + filename
122:                            + " found");
123:                    return null;
124:                } else {
125:                    Debug.out("Done.");
126:                    return new ImageIcon(iconURL);
127:                }
128:            }
129:
130:            /**
131:             * Copies the specified resource to targetLocation if such a file
132:             * does not exist yet.
133:             * The created file is removed automatically after finishing JAVA.
134:             * @param o an Object the directory from where <code>resourcename</code>
135:             * is copied is determined by looking on the package where <code>o.getClass()</code>
136:             * is declared  
137:             * @param resourcename String the name of the file to search  (only relative
138:             * pathname to the path of the calling class)
139:             * @param targetLocation target for copying
140:             * @return true if resource was copied 
141:             */
142:            public boolean copyIfNotExists(Object o, String resourcename,
143:                    String targetLocation) {
144:                return copyIfNotExists(o.getClass(), resourcename,
145:                        targetLocation);
146:            }
147:
148:            public boolean copyIfNotExists(Class cl, String resourcename,
149:                    String targetLocation) {
150:                URL resourceURL = cl.getResource(resourcename);
151:
152:                Debug.out("Load Resource:" + resourcename + " of class " + cl);
153:
154:                if (resourceURL == null && cl.getSuperclass() != null) {
155:                    return copyIfNotExists(cl.getSuperclass(), resourcename,
156:                            targetLocation);
157:                } else if (resourceURL == null && cl.getSuperclass() == null) {
158:                    // error message Resource not found
159:                    System.out
160:                            .println("No resource " + resourcename + " found");
161:                    return false;
162:                }
163:
164:                // copying the resource to the target if targetfile 
165:                // does not exist yet
166:                boolean result = false;
167:                try {
168:                    File targetFile = new File(targetLocation);
169:                    if (!targetFile.exists()) {
170:                        result = true;
171:                        targetFile.createNewFile();
172:                        targetFile.deleteOnExit();
173:
174:                        InputStream sourceStream = resourceURL.openStream();
175:                        FileOutputStream targetStream = new FileOutputStream(
176:                                targetFile);
177:
178:                        int copyItem;
179:                        copyItem = sourceStream.read();
180:                        while (copyItem > -1) {
181:                            targetStream.write(copyItem);
182:                            copyItem = sourceStream.read();
183:                        }
184:                        sourceStream.close();
185:                        targetStream.close();
186:                    }
187:                } catch (Exception e) {
188:                    System.err.println("KeYError: " + e);
189:                    return false;
190:                }
191:                return result;
192:            }
193:
194:            /** loads a resource and returns its URL 
195:             * @param cl the Class used to determine the resource 
196:             * @param resourcename the String that contains the name of the resource
197:             * @return the URL of the resource
198:             */
199:            public URL getResourceFile(Class cl, String resourcename) {
200:                URL resourceURL = cl.getResource(resourcename);
201:                if (resourceURL == null && cl.getSuperclass() != null) {
202:                    return getResourceFile(cl.getSuperclass(), resourcename);
203:                } else if (resourceURL == null && cl.getSuperclass() == null) {
204:                    return null;
205:                }
206:                return resourceURL;
207:            }
208:
209:            /** loads a resource and returns its URL 
210:             * @param o the Object used to determine the resource 
211:             * @param resourcename the String that contains the name of the resource
212:             * @return the URL of the resource
213:             */
214:            public URL getResourceFile(Object o, String resourcename) {
215:                return getResourceFile(o.getClass(), resourcename);
216:            }
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.