Source Code Cross Referenced for CollectionManagerXStreamDAOImpl.java in  » Search-Engine » zilverline » org » zilverline » dao » xstream » 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 » Search Engine » zilverline » org.zilverline.dao.xstream 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2003-2005 Michael Franken, Zilverline.
003:         *
004:         * The contents of this file, or the files included with this file, are subject to
005:         * the current version of ZILVERLINE Collaborative Source License for the
006:         * Zilverline Search Engine (the "License"); You may not use this file except in
007:         * compliance with the License.
008:         *
009:         * You may obtain a copy of the License at
010:         *
011:         *     http://www.zilverline.org.
012:         *
013:         * See the License for the rights, obligations and
014:         * limitations governing use of the contents of the file.
015:         *
016:         * The Original and Upgraded Code is the Zilverline Search Engine. The developer of
017:         * the Original and Upgraded Code is Michael Franken. Michael Franken owns the
018:         * copyrights in the portions it created. All Rights Reserved.
019:         *
020:         */
021:
022:        package org.zilverline.dao.xstream;
023:
024:        import java.io.File;
025:        import java.io.FileReader;
026:        import java.io.FileWriter;
027:        import java.io.IOException;
028:
029:        import com.thoughtworks.xstream.converters.ConversionException;
030:
031:        import org.zilverline.core.ExtractorFactory;
032:        import org.zilverline.core.FileSystemCollection;
033:        import org.zilverline.core.Handler;
034:        import org.zilverline.dao.CollectionManagerDAO;
035:        import org.zilverline.dao.DAOException;
036:        import org.zilverline.service.CollectionManager;
037:        import org.zilverline.service.CollectionManagerImpl;
038:
039:        /**
040:         * Implementation of CollectionManagerDAO interface using XStream.
041:         * 
042:         * @author Michael Franken
043:         * @version $Revision: 1.11 $
044:         */
045:        public class CollectionManagerXStreamDAOImpl extends
046:                AbstractXStreamDAOImpl implements  CollectionManagerDAO {
047:
048:            /**
049:             * Create a DAO for persisting CollectionManager.
050:             */
051:            public CollectionManagerXStreamDAOImpl() {
052:                super ();
053:                xstream.alias("collectionManager", CollectionManagerImpl.class);
054:                xstream.alias("collection", FileSystemCollection.class);
055:                filename = "collectionManager.xml";
056:            }
057:
058:            /**
059:             * Save the CollectionManager to the datastore.
060:             * 
061:             * @param manager the CollectionManager
062:             * @throws DAOException if the manager can not be stored
063:             */
064:            public final void store(final CollectionManager manager)
065:                    throws DAOException {
066:                try {
067:                    writer = new FileWriter(new File(getBaseDir(), filename));
068:                    xstream.toXML(manager, writer);
069:                } catch (Exception e) {
070:                    throw new DAOException("Error saving collections", e);
071:                } finally {
072:                    if (writer != null) {
073:                        try {
074:                            writer.close();
075:                        } catch (IOException e1) {
076:                            throw new DAOException("Error closing file writer",
077:                                    e1);
078:                        }
079:                    }
080:                }
081:            }
082:
083:            /**
084:             * Retrieve the CollectionManager from store.
085:             * 
086:             * @return CollectionManager the Manager
087:             */
088:            public final CollectionManager load() {
089:                CollectionManager manager = null;
090:                try {
091:                    reader = new FileReader(new File(getBaseDir(), filename));
092:                    manager = (CollectionManager) xstream.fromXML(reader);
093:                    log.debug("Reading " + manager.getCollections().size()
094:                            + " collections from store: "
095:                            + new File(getBaseDir(), filename));
096:                } catch (ConversionException e) {
097:                    log
098:                            .warn(
099:                                    "Inconsistent CollectionManager data found. Possibly old version. Ignoring old data.",
100:                                    e);
101:                } catch (IOException e) {
102:                    log
103:                            .warn(
104:                                    "Can not read collections. Possibly first time zilverline runs.",
105:                                    e);
106:                } catch (Exception e) {
107:                    log.warn("Something went wrong, but the show must go on.",
108:                            e);
109:                } finally {
110:                    if (reader != null) {
111:                        try {
112:                            reader.close();
113:                        } catch (IOException e1) {
114:                            log.warn("Can not close file reader", e1);
115:                        }
116:                    }
117:                    manager = checkManagerIntegrity(manager);
118:                }
119:                return manager;
120:            }
121:
122:            private CollectionManager checkManagerIntegrity(
123:                    CollectionManager manager) {
124:                if (manager == null) {
125:                    log
126:                            .warn("Invalid collectionManager configuration found, resetting to defaults");
127:                    manager = new CollectionManagerImpl();
128:                }
129:                if (manager.getFactory() == null
130:                        || manager.getArchiveHandler() == null
131:                        || manager.getFactory().getMappings() == null
132:                        || manager.getFactory().getMimeMappings() == null
133:                        || manager.getArchiveHandler().getMappings() == null) {
134:                    log
135:                            .warn("Invalid collectionManager configuration found, resetting to defaults");
136:                    manager.setFactory(new ExtractorFactory());
137:                    manager.setArchiveHandler(new Handler());
138:                }
139:                return manager;
140:            }
141:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.