Source Code Cross Referenced for CastorHelper.java in  » Web-Mail » Jwma » dtw » webmail » plugin » std » 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 » Web Mail » Jwma » dtw.webmail.plugin.std 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***
002:         * jwma Java WebMail
003:         * Copyright (c) 2000-2003 jwma team
004:         *
005:         * jwma is free software; you can distribute and use this source
006:         * under the terms of the BSD-style license received along with
007:         * the distribution.
008:         ***/package dtw.webmail.plugin.std;
009:
010:        import dtw.webmail.JwmaKernel;
011:        import dtw.webmail.model.JwmaException;
012:        import dtw.webmail.util.CastorDatabasePool;
013:        import org.apache.log4j.Logger;
014:        import org.exolab.castor.jdo.Database;
015:        import org.exolab.castor.jdo.JDO;
016:        import org.exolab.castor.mapping.Mapping;
017:        import org.exolab.castor.xml.Marshaller;
018:        import org.exolab.castor.xml.Unmarshaller;
019:
020:        import java.io.Reader;
021:        import java.io.Writer;
022:        import java.net.URL;
023:
024:        /**
025:         * An utility/helper class with common functionality
026:         * for the standard Castor based plugin implementations.
027:         *
028:         * @author Dieter Wimberger
029:         * @version 0.9.7 07/02/2003
030:         */
031:        public class CastorHelper {
032:
033:            //Singleton reference
034:            private static CastorHelper c_Self;
035:            //logging
036:            private static Logger log = Logger.getLogger(CastorHelper.class);
037:
038:            //instance attributes
039:            private Mapping m_Mapping; //Mapping instance
040:            private JDO m_JDO; //JDO Engine instance
041:            private CastorDatabasePool m_DBPool;
042:            private boolean m_JDOprepared = false;
043:
044:            private CastorHelper() {
045:                //set reference to single instance
046:                c_Self = this ;
047:                //load mapping
048:                loadMapping();
049:            }//CastorHelper
050:
051:            /**
052:             * Marshals an object to the given writer.
053:             *
054:             * @param object the instance to be marshalled.
055:             * @param writer the <tt>Writer</tt>.
056:             *
057:             * @throws JwmaException on failure.
058:             */
059:            public void marshal(Object object, Writer writer)
060:                    throws JwmaException {
061:                try {
062:                    Marshaller m_Marshaller = new Marshaller(writer);
063:                    m_Marshaller.setMapping(m_Mapping);
064:                    m_Marshaller.marshal(object);
065:                    writer.flush();
066:                } catch (Exception ex) {
067:                    throw new JwmaException("").setException(ex);
068:                }
069:            }//marshal
070:
071:            /**
072:             * Unmarshalls an object from the given reader.
073:             *
074:             * @param reader the <tt>Reader</tt>.
075:             */
076:            public Object unmarshal(Reader reader) throws JwmaException {
077:                try {
078:                    Unmarshaller m_Unmarshaller = new Unmarshaller(m_Mapping);
079:                    return m_Unmarshaller.unmarshal(reader);
080:                } catch (Exception ex) {
081:                    throw new JwmaException("").setException(ex);
082:                }
083:            }//unmarshal
084:
085:            /**
086:             * Prepares Castor JDO, with configuration
087:             * (i.e. database.xml) given as URL.
088:             *
089:             * @param configurl the URL to the configuration file.
090:             */
091:            public void prepareJDO(String configurl) throws JwmaException {
092:                if (m_JDOprepared) {
093:                    return;
094:                }
095:                try {
096:                    //create new jdo object
097:                    m_JDO = new JDO();
098:                    //DEBUG:
099:                    //m_JDO.setLogWriter(new org.exolab.castor.util.Logger(
100:                    //    new PrintWriter(new FileWriter("/Users/wimpi/castorlog.txt"))
101:                    //));
102:                    //load configuration
103:                    m_JDO.loadConfiguration(configurl);
104:
105:                    //pooling connections
106:                    m_JDO.setDatabasePooling(true);
107:                    //the name of the database
108:                    m_JDO.setDatabaseName("jwma");
109:                    //set jwma's class loader, just in case
110:                    //castor was loaded with some strange class loader
111:                    m_JDO.setClassLoader(JwmaKernel.getReference().getClass()
112:                            .getClassLoader());
113:
114:                    //prepare pool
115:                    m_DBPool = CastorDatabasePool.createCastorDatabasePool(5,
116:                            new JwmaDatabase());
117:                    m_JDOprepared = true;
118:                } catch (Exception ex) {
119:                    String msg = JwmaKernel.getReference().getLogMessage(
120:                            "jwma.plugin.castorhelper.jdofail");
121:                    log.error(msg, ex);
122:                    throw new JwmaException(msg).setException(ex);
123:                }
124:            }//prepareJDO
125:
126:            /**
127:             * Returns a Castor JDO database.
128:             *
129:             * @return a Castor JDO <tt>Database</tt> instance.
130:             */
131:            public Database getJDODatabase() throws JwmaException {
132:                try {
133:                    return m_JDO.getDatabase();
134:                } catch (Exception ex) {
135:                    throw new JwmaException("").setException(ex);
136:                }
137:            }//getJDODatabase
138:
139:            /**
140:             * Returns the pool of Castor JDO Database
141:             * instances.
142:             *
143:             * @return the pool as <tt>CastorDatabasePool</tt>.
144:             */
145:            public CastorDatabasePool getDatabasePool() {
146:                return m_DBPool;
147:            }//getDatabasePool
148:
149:            /**
150:             * Returns a reference to the singleton instance
151:             * of the <tt>CastorHelper</tt>.
152:             *
153:             * @return the <tt>CastorHelper</tt> singleton.
154:             */
155:            public static CastorHelper getReference() {
156:                if (c_Self != null) {
157:                    return c_Self;
158:                } else {
159:                    return new CastorHelper();
160:                }
161:            }//getReference
162:
163:            /**
164:             * Loads the castor mapping file.
165:             *
166:             * @param file the url of the mapping file.
167:             */
168:            private void loadMapping() {
169:
170:                log.info("Loading Castor mappings.");
171:
172:                ClassLoader cl = this .getClass().getClassLoader();
173:                URL mapping = cl
174:                        .getResource("dtw/webmail/resources/castor_mappings.xml");
175:                m_Mapping = new Mapping(cl);
176:
177:                try {
178:                    m_Mapping.loadMapping(mapping);
179:                } catch (Exception ex) {
180:                    log.fatal("loadMappings()", ex);
181:                }
182:            }//loadMapping
183:
184:        }//class CastorHelper
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.