Source Code Cross Referenced for TempRepository.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas_lib » genbase » utils » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.jonas_lib.genbase.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS : Java(TM) OpenSource Application Server
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
017:         * USA
018:         *
019:         * Initial Developer : Guillaume Sauthier
020:         * --------------------------------------------------------------------------
021:         * $Id: TempRepository.java 6657 2005-04-27 12:28:21Z benoitf $
022:         * --------------------------------------------------------------------------
023:         */package org.objectweb.jonas_lib.genbase.utils;
024:
025:        import java.io.File;
026:        import java.io.IOException;
027:        import java.util.Iterator;
028:        import java.util.List;
029:        import java.util.Vector;
030:
031:        /**
032:         * A <code>TempRepository</code> object is tye main container for temporary
033:         * directories. When an object of WsGen or ClientStubGen wants to use a temporary directory, it
034:         * ask TempRepository instance to create a new one. It is usefull when multiples
035:         * tempo directories are created. Deletion is much more simpler. The
036:         * TempRepository is a Singleton.
037:         *
038:         * @author Guillaume Sauthier
039:         */
040:        public class TempRepository {
041:
042:            /** the TempRepository instance */
043:            private static TempRepository instance = null;
044:
045:            /** list of temporary directories */
046:            private List directories;
047:
048:            /**
049:             * Create a new empty TempRepository.
050:             */
051:            private TempRepository() {
052:                directories = new Vector();
053:            }
054:
055:            /**
056:             * Return the only instance of TempRepository.
057:             *
058:             * @return the only instance of TempRepository.
059:             */
060:            public static TempRepository getInstance() {
061:                if (instance == null) {
062:                    instance = new TempRepository();
063:                }
064:
065:                return instance;
066:            }
067:
068:            /**
069:             * Add a temporary File in the repository (file or directory).
070:             *
071:             * @param file the temporary file or directory to add.
072:             */
073:            public void addDir(File file) {
074:                directories.add(file);
075:            }
076:
077:            /**
078:             * Delete all the files contained in the repository. Returns true when
079:             * deletion is successfull, false otherwise.
080:             *
081:             * @return true when deletion is successfull, false otherwise.
082:             */
083:            public boolean deleteAll() {
084:                boolean result = true;
085:
086:                for (Iterator i = directories.iterator(); i.hasNext();) {
087:                    File dir = (File) i.next();
088:                    i.remove();
089:
090:                    // delete only if file exists
091:                    if (dir.exists()) {
092:                        result &= delete(dir);
093:                    }
094:                }
095:
096:                return result;
097:            }
098:
099:            /**
100:             * Delete a file or directory recursively
101:             *
102:             * @param f file or directory to be deleted
103:             *
104:             * @return true if deletion ok, false otherweise.
105:             */
106:            private boolean delete(File f) {
107:                if (f.isFile()) {
108:                    return f.delete();
109:                } else {
110:                    File[] childs = f.listFiles();
111:                    if (childs == null) {
112:                        // no childs
113:                        return f.delete();
114:                    } else {
115:                        // childs
116:                        boolean result = true;
117:                        for (int i = 0; i < childs.length; i++) {
118:                            result &= delete(childs[i]);
119:                        }
120:                        return result && f.delete();
121:                    }
122:                }
123:            }
124:
125:            /**
126:             * Return an empty temporary directory and automatically add it into the
127:             * repository.
128:             *
129:             * @return an empty temporary directory.
130:             *
131:             * @throws IOException when creation fails.
132:             */
133:            public File createDir() throws IOException {
134:                // create file
135:                File tmp = File.createTempFile("wsgen", null);
136:
137:                if (!tmp.delete()) {
138:                    throw new IOException("Cannot delete temporary file");
139:                }
140:
141:                // create directory
142:                if (!tmp.mkdir()) {
143:                    throw new IOException("Cannot create temporary directory");
144:                }
145:
146:                // add in repo
147:                addDir(tmp);
148:
149:                return tmp;
150:            }
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.