Source Code Cross Referenced for BackupInstance.java in  » Content-Management-System » daisy » org » outerj » daisy » backupTool » 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 » Content Management System » daisy » org.outerj.daisy.backupTool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004 Outerthought bvba and Schaubroeck nv
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:        package org.outerj.daisy.backupTool;
017:
018:        import java.io.File;
019:        import java.text.DateFormat;
020:        import java.text.DecimalFormat;
021:        import java.text.SimpleDateFormat;
022:        import java.util.ArrayList;
023:        import java.util.Date;
024:        import java.util.List;
025:        import java.util.Locale;
026:
027:        import javax.xml.parsers.DocumentBuilder;
028:        import javax.xml.parsers.DocumentBuilderFactory;
029:
030:        import org.w3c.dom.Document;
031:        import org.w3c.dom.Element;
032:
033:        public class BackupInstance {
034:            private final DateFormat dateFormat = new SimpleDateFormat(
035:                    "EEE MMM dd hh:mm:ss z yyyy", Locale.US);
036:            private String name;
037:            private List<BackupEntry> entries;
038:            private File directory;
039:            private Date createDate;
040:            private String serverVersion;
041:            private File instanceFile;
042:            private Document instanceDocument;
043:            private boolean changed;
044:
045:            public BackupInstance(File backupBaseDir) throws Exception {
046:                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
047:                String dirName = dateFormat.format(new Date());
048:
049:                long seq = 0;
050:                DecimalFormat df = new DecimalFormat("000");
051:                do {
052:                    String dirNameSeq = dirName + "_" + df.format(seq);
053:                    directory = new File(backupBaseDir, dirNameSeq);
054:                    seq++;
055:                } while (!directory.mkdir() && seq < 1000);
056:                if (seq > 999)
057:                    throw new Exception(
058:                            "Could not create directory with prefix " + dirName);
059:
060:                entries = new ArrayList<BackupEntry>();
061:                name = directory.getName();
062:                createDate = new Date();
063:                serverVersion = BackupManager.getLocker().getServerVersion();
064:            }
065:
066:            public BackupInstance(File backupBaseDir, String backupName)
067:                    throws Exception {
068:                this .name = backupName;
069:                directory = new File(backupBaseDir, this .name);
070:                entries = new ArrayList<BackupEntry>();
071:                if (!directory.exists())
072:                    throw new Exception("Backup " + name
073:                            + " does not exist at " + directory.getPath());
074:
075:                instanceDocument = BackupHelper.parseFile(getInstanceFile());
076:
077:                createDate = dateFormat.parse(BackupHelper.getStringFromDom(
078:                        instanceDocument, "/backupInstance/@createDate"));
079:                serverVersion = BackupHelper.getStringFromDom(instanceDocument,
080:                        "/backupInstance/@serverVersion");
081:            }
082:
083:            public void addEntry(BackupEntry entry) {
084:                entries.add(entry);
085:            }
086:
087:            public BackupEntry getEntry(int index) {
088:                return entries.get(index);
089:            }
090:
091:            public int entryCount() {
092:                return entries.size();
093:            }
094:
095:            public void backup() {
096:
097:            }
098:
099:            public void restore() {
100:
101:            }
102:
103:            public File getDirectory() {
104:                return directory;
105:            }
106:
107:            public void setDirectory(File directory) {
108:                changed = true;
109:                this .directory = directory;
110:            }
111:
112:            public Date getCreateDate() {
113:                return createDate;
114:            }
115:
116:            public String getName() {
117:                return name;
118:            }
119:
120:            public void setName(String name) {
121:                changed = true;
122:                this .name = name;
123:            }
124:
125:            public String getServerVersion() {
126:                return serverVersion;
127:            }
128:
129:            public Document getInstanceDocument() throws Exception {
130:                if (changed || instanceDocument == null)
131:                    instanceDocument = backupToDocument();
132:                return instanceDocument;
133:            }
134:
135:            public File getInstanceFile() {
136:                if (instanceFile == null
137:                        || instanceFile.getParentFile().equals(getDirectory()))
138:                    instanceFile = new File(getDirectory(), "instance.xml");
139:                return instanceFile;
140:            }
141:
142:            public void invalidate() {
143:                changed = true;
144:            }
145:
146:            private Document backupToDocument() throws Exception {
147:                DocumentBuilderFactory dbf = DocumentBuilderFactory
148:                        .newInstance();
149:                DocumentBuilder db = dbf.newDocumentBuilder();
150:                Document document = db.newDocument();
151:
152:                Element backupElement = document
153:                        .createElement("backupInstance");
154:                document.appendChild(backupElement);
155:                backupElement.setAttribute("name", this .getName());
156:                backupElement.setAttribute("createDate", dateFormat.format(this 
157:                        .getCreateDate()));
158:                backupElement.setAttribute("serverVersion", serverVersion);
159:
160:                for (int i = 0; i < this .entryCount(); i++) {
161:                    AbstractBackupEntry buEntry = (AbstractBackupEntry) this 
162:                            .getEntry(i);
163:                    if (buEntry.backupFile.exists()) {
164:                        Element entry = document.createElement("entry");
165:                        backupElement.appendChild(entry);
166:                        entry
167:                                .setAttribute("checksum", buEntry
168:                                        .generateDigest());
169:                        entry.setAttribute("filename", buEntry.backupFile
170:                                .getName());
171:                    }
172:                }
173:
174:                return document;
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.