Source Code Cross Referenced for CastorSQLContactManagement.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.JwmaContact;
012:        import dtw.webmail.model.JwmaContacts;
013:        import dtw.webmail.model.JwmaContactsImpl;
014:        import dtw.webmail.model.JwmaException;
015:        import dtw.webmail.plugin.ContactManagementPlugin;
016:        import dtw.webmail.util.CastorDatabase;
017:        import dtw.webmail.util.CastorDatabasePool;
018:        import dtw.webmail.util.JwmaSettings;
019:        import dtw.webmail.util.config.JwmaConfiguration;
020:        import org.apache.log4j.Logger;
021:
022:        import java.io.InputStream;
023:        import java.io.OutputStream;
024:
025:        /**
026:         * A <tt>ContactManagementPlugin</tt> implementation
027:         * based on Castor JDO.
028:         * <p>
029:         * Stores the contacts in a database.
030:         *
031:         * @author Dieter Wimberger
032:         * @version 0.9.7 07/02/2003
033:         */
034:        public class CastorSQLContactManagement implements 
035:                ContactManagementPlugin {
036:
037:            //class attributes
038:            private static Logger log = Logger
039:                    .getLogger(CastorSQLContactManagement.class);
040:
041:            //instance attributes
042:            private CastorPreferences m_PreferencesTemplate;
043:            private CastorDatabasePool m_DBPool;
044:
045:            public CastorSQLContactManagement() {
046:            }//constructor
047:
048:            public JwmaContactsImpl loadContacts(String cuid)
049:                    throws JwmaException {
050:
051:                CastorDatabase db = null;
052:                CastorContacts cts = null;
053:
054:                try {
055:                    db = m_DBPool.leaseDatabase();
056:                    //Begin transaction
057:                    db.begin();
058:
059:                    //load contacts
060:                    cts = (CastorContacts) db.load(CastorContacts.class, cuid);
061:
062:                    //end transaction
063:                    db.commit();
064:
065:                } catch (Exception ex) {
066:                    throw new JwmaException("").setException(ex);
067:                } finally {
068:                    //release the database
069:                    m_DBPool.releaseDatabase(db);
070:                }
071:                return cts;
072:            }//loadContacts
073:
074:            public void saveContacts(JwmaContactsImpl contacts)
075:                    throws JwmaException {
076:
077:                CastorDatabase db = null;
078:                CastorContacts ctdb = (CastorContacts) contacts;
079:
080:                try {
081:                    db = m_DBPool.leaseDatabase();
082:                    // Begin a transaction
083:                    log.debug("Persisting contact database...");
084:                    db.begin();
085:
086:                    //check if the preferences are not persistent yet.
087:                    //simplest is if the timestamp is not zero.
088:                    if (ctdb.jdoGetTimeStamp() != 0) {
089:                        log.debug("udpate...");
090:                        ctdb.updateContacts(db.getDatabase());
091:                    } else {
092:                        log.debug("create...");
093:                        ctdb.persistContacts(db.getDatabase());
094:                    }
095:
096:                    // Commit the transaction
097:                    db.commit();
098:                } catch (Exception ex) {
099:                    log.error("saveContacts()", ex);
100:                    throw new JwmaException("").setException(ex);
101:                } finally {
102:                    m_DBPool.releaseDatabase(db);
103:                }
104:            }//savePreferences
105:
106:            public boolean isPersistent(String cuid) throws JwmaException {
107:
108:                //FIXME:This is definately not very efficient, but
109:                //if ok, and castor caches..hmm
110:                if (cuid == null || cuid.length() == 0) {
111:                    return false;
112:                }
113:                CastorDatabase db = null;
114:                boolean exists = false;
115:                try {
116:                    db = m_DBPool.leaseDatabase();
117:                    //Begin transaction
118:                    db.begin();
119:
120:                    //retrieve prefs instance
121:                    if (db.load(CastorContacts.class, cuid) != null) {
122:                        exists = true;
123:                    }
124:
125:                    //end transaction
126:                    db.commit();
127:
128:                } catch (Exception ex) {
129:                    String msg = JwmaKernel.getReference().getLogMessage(
130:                            "jwma.plugin.castor.objcheck");
131:                    log.error(msg, ex);
132:                    throw new JwmaException(msg).setException(ex);
133:                } finally {
134:                    //release the database
135:                    m_DBPool.releaseDatabase(db);
136:                }
137:                return exists;
138:            }//isPersistent
139:
140:            public JwmaContactsImpl createContacts() {
141:                return new CastorContacts();
142:            }//createContacts
143:
144:            public void activate() throws JwmaException {
145:                JwmaKernel kernel = JwmaKernel.getReference();
146:                try {
147:                    String etc = kernel.getDirectoryPath(JwmaKernel.ETC_DIR);
148:
149:                    //Setup castor helper
150:                    CastorHelper helper = CastorHelper.getReference();
151:
152:                    //prepare jdo
153:                    helper.prepareJDO(etc + "database.xml");
154:
155:                    //set the pool
156:                    m_DBPool = helper.getDatabasePool();
157:
158:                    log.info(JwmaKernel.getReference().getLogMessage(
159:                            "jwma.plugin.activation"));
160:                } catch (Exception ex) {
161:                    log.info(JwmaKernel.getReference().getLogMessage(
162:                            "jwma.plugin.failedactivation"));
163:                    throw new JwmaException("").setException(ex);
164:                }
165:            }//activate
166:
167:            public void deactivate() {
168:                //FIXME: shut down pool, close down connections?
169:            }//deactivate
170:
171:            public String exportContact(JwmaContact contact, String TYPE)
172:                    throws JwmaException {
173:                return "";
174:                /*
175:                if(TYPE.equals(TYPE_VCARD3)) {
176:                  ByteArrayOutputStream bout=new ByteArrayOutputStream();
177:
178:                  m_vCardMarshaller.marshallContact(bout,((JpimContact)contact).getContact());
179:                  return new String(bout.toByteArray());
180:                } else {
181:                  return "";
182:                }
183:                 */
184:            }//export
185:
186:            public JwmaContact importContact(InputStream in, String TYPE)
187:                    throws JwmaException {
188:                return null;
189:                /*
190:                if(TYPE.equals(TYPE_VCARD3) || TYPE.equals(TYPE_VCARD2)) {
191:                  try {
192:                    return new JpimContact(
193:                      new vCardUnmarshaller()
194:                             .unmarshallContact(in)
195:                    );
196:                  } catch (Exception ex) {
197:                    log.error("importContact():",ex);
198:                    return null;
199:                  }
200:                } else {
201:                  return null;
202:                }
203:                 */
204:            }//importContact
205:
206:            public JwmaContact[] importDatabase(InputStream in, String TYPE)
207:                    throws JwmaException {
208:                return null;
209:            }//importDatabase
210:
211:            public void exportDatabase(OutputStream out, JwmaContacts db,
212:                    String TYPE) throws JwmaException {
213:                return;
214:            }//exportDatabase
215:
216:            public String[] getSupportedTypes(int IMEX_TYPE) {
217:                switch (IMEX_TYPE) {
218:                case CONTACT_IMPORT:
219:                    return CONTACT_IMPORT_TYPES;
220:                case CONTACT_EXPORT:
221:                    return CONTACT_EXPORT_TYPES;
222:                case DATABASE_EXPORT:
223:                    return DATABASE_EXPORT_TYPES;
224:                case DATABASE_IMPORT:
225:                    return DATABASE_IMPORT_TYPES;
226:                default:
227:                    return NO_TYPES;
228:                }
229:            }//getSupportedTypes
230:
231:            public boolean isSupportedContactImportType(String type) {
232:                for (int i = 0; i < CONTACT_IMPORT_TYPES.length; i++) {
233:                    if (type.equalsIgnoreCase(CONTACT_IMPORT_TYPES[i])) {
234:                        return true;
235:                    }
236:                }
237:                return false;
238:            }//isSupportedContactImportType
239:
240:            public static final String TYPE_VCARD3 = "text/directory";
241:            public static final String TYPE_VCARD2 = "application/directory";
242:            private static final String[] NO_TYPES = new String[0];
243:
244:            private static final String[] CONTACT_IMPORT_TYPES = NO_TYPES;
245:            private static final String[] CONTACT_EXPORT_TYPES = NO_TYPES;
246:            private static final String[] DATABASE_EXPORT_TYPES = NO_TYPES;
247:            private static final String[] DATABASE_IMPORT_TYPES = NO_TYPES;
248:
249:        }//class CastorContactManagement
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.