KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > mail > MailServiceImpl


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Florent BENOIT & Ludovic BERT
22  * --------------------------------------------------------------------------
23  * $Id: MailServiceImpl.java,v 1.25 2005/04/28 08:43:26 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.mail;
28
29
30 import java.io.FileNotFoundException JavaDoc;
31 import java.util.Enumeration JavaDoc;
32 import java.util.Hashtable JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Properties JavaDoc;
35 import java.util.StringTokenizer JavaDoc;
36 import java.util.Vector JavaDoc;
37
38 import javax.management.JMException JavaDoc;
39 import javax.management.MBeanServer JavaDoc;
40 import javax.management.ObjectName JavaDoc;
41 import javax.management.modelmbean.ModelMBean JavaDoc;
42 import javax.naming.Context JavaDoc;
43 import javax.naming.InitialContext JavaDoc;
44 import javax.naming.NamingException JavaDoc;
45
46 import org.apache.commons.modeler.ManagedBean;
47 import org.apache.commons.modeler.Registry;
48 import org.objectweb.jonas.common.JModule;
49 import org.objectweb.jonas.common.JProp;
50 import org.objectweb.jonas.common.Log;
51 import org.objectweb.jonas.common.PropDump;
52 import org.objectweb.jonas.jmx.J2eeObjectName;
53 import org.objectweb.jonas.jmx.JmxService;
54 import org.objectweb.jonas.jmx.JonasObjectName;
55 import org.objectweb.jonas.mail.factory.JavaMail;
56 import org.objectweb.jonas.mail.factory.JavaMailMimePartDS;
57 import org.objectweb.jonas.mail.factory.JavaMailMimePartDSResource;
58 import org.objectweb.jonas.mail.factory.JavaMailSession;
59 import org.objectweb.jonas.mail.factory.JavaMailSessionResource;
60 import org.objectweb.jonas.management.JonasMBeanTools;
61 import org.objectweb.jonas.service.AbsServiceImpl;
62 import org.objectweb.jonas.service.ServiceException;
63 import org.objectweb.jonas.service.ServiceManager;
64 import org.objectweb.util.monolog.api.BasicLevel;
65 import org.objectweb.util.monolog.api.Logger;
66 /**
67  * This class provides an implementation of the javaMail service.
68  * @author Florent Benoit
69  * @author Ludovic Bert
70  * Contributor(s):
71  * Adriana Danes :
72  * - Make possible to change configuration of a JOnAS mail factory object.
73  * - Make possible to change the JNDI name of a JOnAS mail factory object.
74  */

75 public class MailServiceImpl extends AbsServiceImpl
76     implements MailService, MailServiceImplMBean {
77
78     /**
79      * The list of the registered mail session factories.
80      */

81     private Vector JavaDoc mailSessionList = null;
82
83     /**
84      * The list of the registered mime part data source factories.
85      */

86     private Vector JavaDoc mailMimePartDSList = null;
87
88     /**
89      * Reference to a MBean server.
90      */

91     private MBeanServer JavaDoc mbeanServer = null;
92
93     /**
94      * Initial Context for Naming
95      */

96     private Context JavaDoc ictx = null;
97
98     // the name of the JOnAS server that is administerd by the MBeanServer
99
// the current management domain's name
100
protected String JavaDoc serverName = null;
101     protected String JavaDoc domainName = null;
102
103     /**
104      * Logger for this service.
105      */

106     private static Logger logger = null;
107
108     /**
109      * List of the factories names to load when starting the MailService
110      */

111     private Vector JavaDoc factoryNames = new Vector JavaDoc();
112
113     /**
114      * List of the javax.mail.Session factories currently loaded
115      */

116     private Hashtable JavaDoc jMailSessionFactories = new Hashtable JavaDoc();
117
118     /**
119      * List of the javax.mail.internet.MimePartDataSource factories currently loaded
120      */

121     private Hashtable JavaDoc jMailMimePartDSFactories = new Hashtable JavaDoc();
122
123     /**
124      * List of the binded factories (jndi name -> factory name)
125      * This is needed by EJB components in order to find out the factory name
126      * based upon their jndi name
127      */

128     private Hashtable JavaDoc bindedFactories = new Hashtable JavaDoc();
129
130     /**
131      * Session Factory
132      */

133     private static final int JAVAX_MAIL_SESSION_FACTORY = 1;
134
135     /**
136      * MimepartDatasource Factory
137      */

138     private static final int JAVAX_MAIL_INTERNET_MIMEPARTDATASOURCE = 2;
139
140     /**
141      * JOnAS-specific properties (name)
142      */

143     public static final String JavaDoc PROPERTY_NAME = "mail.factory.name";
144
145     /**
146      * JOnAS-specific properties (type)
147      */

148     public static final String JavaDoc PROPERTY_TYPE = "mail.factory.type";
149
150     public static final String JavaDoc SESSION_PROPERTY_TYPE = "javax.mail.Session";
151     public static final String JavaDoc MIMEPART_PROPERTY_TYPE = "javax.mail.internet.MimePartDataSource";
152
153     /**
154      * Mail service configuration parameters (factories)
155      */

156     public static final String JavaDoc FACTORIES = "jonas.service.mail.factories";
157
158     /**
159      * Mail service configuration parameters (class)
160      */

161     public static final String JavaDoc CLASS = "jonas.service.mail.class";
162
163     /**
164      * Init the Mail service.
165      * @param ctx the configuration of the Ear service.
166      * @throws ServiceException if the initialization failed.
167      */

168     protected void doInit(Context JavaDoc ctx) throws ServiceException {
169
170         // get logger for this service
171
logger = Log.getLogger(Log.JONAS_MAIL_PREFIX);
172         // the logger for reconfig management
173
super.initLogger(Log.getLogger(Log.JONAS_MANAGEMENT_PREFIX));
174
175         //Get the inital Context
176
try {
177             ictx = new InitialContext JavaDoc();
178         } catch (NamingException JavaDoc e) {
179             logger.log(BasicLevel.ERROR, "Cannot create initial context during the mail service initializing");
180             throw new ServiceException("Cannot create initial context during the mail service initializing", e);
181         }
182
183         // Get the current server and domain names
184
try {
185             serverName = (String JavaDoc) ctx.lookup(JProp.JONAS_NAME);
186             domainName = (String JavaDoc) ctx.lookup(JProp.DOMAIN_NAME);
187         } catch (NamingException JavaDoc ne) {
188             logger.log(BasicLevel.DEBUG, "Cannot initialize the Mail service " + ne);
189             throw new ServiceException("Cannot initialize the Mail service", ne);
190         }
191
192         // Get the JMX Server via JMX Service
193
try {
194             mbeanServer =
195                 ((JmxService) ServiceManager.getInstance().getJmxService()).getJmxServer();
196         } catch (Exception JavaDoc e) {
197             // the JMX service may not be started
198
mbeanServer = null;
199         }
200
201         // Get the list of the factory names
202
String JavaDoc factories = null;
203         try {
204             factories = (String JavaDoc) ctx.lookup(FACTORIES);
205         } catch (NamingException JavaDoc e) {
206             ; // No problem if there is no value for 'factories'
207
}
208         if (factories != null) {
209             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(factories, ",");
210             while (st.hasMoreTokens()) {
211                 factoryNames.add(st.nextToken().trim());
212             }
213         }
214         if (logger.isLoggable(BasicLevel.DEBUG)) {
215             logger.log(BasicLevel.DEBUG, "Mail service initialized");
216         }
217
218     }
219
220     /**
221      * Start the Mail Service.
222      * @throws ServiceException if the initialization failed.
223      */

224     protected void doStart() throws ServiceException {
225
226         // creates each factory
227
String JavaDoc factoryName = null;
228         for (int i = 0; i < factoryNames.size(); i++) {
229             factoryName = (String JavaDoc) factoryNames.elementAt(i);
230             try {
231                 JProp prop = JProp.getInstance(factoryName);
232                 if (logger.isLoggable(BasicLevel.DEBUG)) {
233                     logger.log(BasicLevel.DEBUG, "Creating mail factory " + factoryName);
234                 }
235                 createMailFactory(factoryName, prop.getConfigFileEnv());
236             } catch (Exception JavaDoc e) {
237                 if (logger.isLoggable(BasicLevel.ERROR)) {
238                     logger.log(BasicLevel.ERROR, "JOnAS: Cannot create mail factory " + factoryName + " : " + e);
239                     logger.log(BasicLevel.ERROR, "Please check the " + factoryName + ".properties file");
240                 }
241             }
242         }
243
244         try {
245             // Register MailService MBean : MailServiceImplMBean
246
if (mbeanServer != null) {
247                 mbeanServer.registerMBean(this, JonasObjectName.mailService());
248             }
249         } catch (JMException JavaDoc e) {
250             throw new ServiceException("Cannot start the MailService: " , e);
251         }
252
253     }
254
255     /**
256      * Stop the Mail service.
257      * @throws ServiceException if the stop failed.
258      */

259     protected void doStop() throws ServiceException {
260
261         try {
262             unbindMailFactories();
263         } catch (MailServiceException e) {
264             logger.log(BasicLevel.ERROR, "Cannot unbind mail factories " + e);
265             throw new ServiceException("Cannot unbind mail factories ", e);
266         }
267
268         if (mbeanServer != null) {
269             try {
270                 mbeanServer.unregisterMBean(JonasObjectName.mailService());
271                 // unregister all mail factories
272
} catch (Exception JavaDoc e) {
273                 logger.log(BasicLevel.ERROR, "Cannot stop the Mail Service (JMX): " + e.getMessage());
274                 throw new ServiceException("Cannot stop the mail service (JMX).", e);
275             }
276         }
277         if (logger.isLoggable(BasicLevel.DEBUG)) {
278             logger.log(BasicLevel.DEBUG, "mail service stopped");
279         }
280     }
281
282     /**
283      * This method is used when a Mail Factory configuration is modified via jonasAdmin.
284      * In this case, the updated JavaMail object (JavaMailSession or JavaMailMimePartDS object)
285      * must be rebound in JNDI
286      * @param factory the factory
287      * @throws MailServiceException if the recreation of
288      * the factory failed.
289      */

290     public void recreateJavaMailFactory(JavaMail factory) throws MailServiceException {
291         String JavaDoc jndiName = factory.getName();
292         // Rebind the factory object in the naming context
293
try {
294             ictx.rebind(jndiName, factory);
295         } catch (NamingException JavaDoc e) {
296             logger.log(BasicLevel.ERROR, "Cannot bind mail factory '" + jndiName + "' :" + e.getMessage());
297             throw new MailServiceException("Cannot bind mail factory " + jndiName + ".", e);
298         }
299     }
300
301     /**
302      * This method is used when a particular Mail Factory configuration operation is done via jonasAdmin :
303      * when the JNDI name of this resource is modified.
304      * In this case, the initial JavaMail object (JavaMailSession or JavaMailMimePartDS object) must be unbound
305      * and the updated JavaMail object must be reloaded.
306      * Also, the Mail Service private data structures must be updated.
307      * @param oldName old name of the factory
308      * @param factory the new factory
309      * @throws MailServiceException if the rename of the
310      * the factory failed.
311      */

312     public void renameJavaMailFactory(String JavaDoc oldName, JavaMail factory) throws MailServiceException {
313
314         if (logger.isLoggable(BasicLevel.DEBUG)) {
315             logger.log(BasicLevel.DEBUG, "In renameMailFactory, old name = " + oldName);
316         }
317         try {
318             ictx.unbind(oldName);
319             if (logger.isLoggable(BasicLevel.DEBUG)) {
320                 logger.log(BasicLevel.DEBUG, oldName + " unbound");
321             }
322         } catch (Exception JavaDoc e) {
323             if (logger.isLoggable(BasicLevel.DEBUG)) {
324                 logger.log(BasicLevel.DEBUG, "Warning: cannot unbind mail factory object named " + oldName);
325             }
326         }
327         String JavaDoc jndiName = factory.getName();
328         // Rebind the factory object in the naming context
329
try {
330             ictx.rebind(jndiName, factory);
331             if (logger.isLoggable(BasicLevel.DEBUG)) {
332                 logger.log(BasicLevel.DEBUG, "factory rebound under the name " + jndiName);
333             }
334         } catch (NamingException JavaDoc e) {
335             logger.log(BasicLevel.ERROR, "Cannot bind mail factory '" + jndiName + "' :" + e.getMessage());
336             throw new MailServiceException("Cannot bind mail factory " + jndiName + ".", e);
337         }
338         bindedFactories.put(jndiName, factory.getFactoryName());
339         bindedFactories.remove(oldName);
340     }
341
342     /**
343      * Create a mail factory with the specified properties and register it
344      * into the registry.
345      * @param factoryName name of the factory to create
346      * @param props the properties used to configure the mail factory.
347      * @throws MailServiceException if the creation or the registration of
348      * the factory failed.
349      */

350     public void createMailFactory(String JavaDoc factoryName, Properties JavaDoc props)
351         throws MailServiceException {
352
353         if (logger.isLoggable(BasicLevel.DEBUG)) {
354             PropDump.print("These are the properties from which the MailService picks to construct Mail Factories", props, logger, BasicLevel.DEBUG);
355         }
356
357         Object JavaDoc factory = null;
358
359         //Factory type/jndi name must be non null
360
String JavaDoc factoryType = props.getProperty(PROPERTY_TYPE);
361         String JavaDoc jndiName = props.getProperty(PROPERTY_NAME);
362
363         if (jndiName == null) {
364             logger.log(BasicLevel.ERROR, "The property 'mail.factory.name' is a required property.");
365             throw new MailServiceException("The property 'mail.factory.name' is a required property for this factory.");
366         }
367
368         if (factoryType == null) {
369             logger.log(BasicLevel.ERROR, "The property 'mail.factory.type' is a required property.");
370             throw new MailServiceException("The property 'mail.factory.type' is a required property for this factory.");
371         }
372
373         // Verify that jndi name not already used
374
if (bindedFactories.containsKey(jndiName)) {
375             logger.log(BasicLevel.ERROR, "There is already a factory bound with the name " + jndiName);
376             throw new MailServiceException("There is already a factory bound with the name '" + jndiName + "', please correct the provided configuration properties");
377         }
378
379         //Define the type of our factory
380
int typeOfFactory;
381         if (factoryType.equalsIgnoreCase("javax.mail.Session")) {
382             typeOfFactory = JAVAX_MAIL_SESSION_FACTORY;
383         } else if (factoryType.equalsIgnoreCase("javax.mail.internet.MimePartDataSource")) {
384             typeOfFactory = JAVAX_MAIL_INTERNET_MIMEPARTDATASOURCE;
385         } else {
386             typeOfFactory = 0;
387         }
388
389         // Create the factory object and register it in the internal data structure
390
switch (typeOfFactory) {
391
392         case JAVAX_MAIL_SESSION_FACTORY :
393             JavaMailSession sessionFactory = new JavaMailSession(factoryName, jndiName, props);
394             jMailSessionFactories.put(factoryName, sessionFactory);
395             factory = sessionFactory;
396             break;
397
398         case JAVAX_MAIL_INTERNET_MIMEPARTDATASOURCE :
399             JavaMailMimePartDS mimeFactory = new JavaMailMimePartDS(factoryName, jndiName, props);
400             jMailMimePartDSFactories.put(factoryName, mimeFactory);
401             factory = mimeFactory;
402             break;
403
404         default :
405             throw new MailServiceException("Can not create a factory of the type '" + factoryType + "'. This type is incorrect.");
406         }
407
408         // Bind the factory object in the naming context
409
try {
410             ictx.rebind(jndiName, factory);
411             bindedFactories.put(jndiName, factoryName);
412         } catch (NamingException JavaDoc e) {
413             logger.log(BasicLevel.ERROR, "Cannot bind mail factory '" + jndiName + "' :" + e.getMessage());
414             throw new MailServiceException("Cannot bind mail factory " + jndiName + ".", e);
415         }
416
417         logger.log(BasicLevel.INFO, "Mapping Mail Factory " + factoryType + " on " + jndiName);
418
419         // Register the factory object as an MBean with the jmx server
420
// Get the MBean register (and load mbeans-descriptors)
421
Registry oRegistry = JonasMBeanTools.getRegistry();
422
423         // Register the factory object as an MBean with the jmx server
424
try {
425             if (mbeanServer != null) {
426                 ObjectName JavaDoc on = null;
427                 switch (typeOfFactory) {
428                 case JAVAX_MAIL_SESSION_FACTORY :
429                     // J2EEManagement
430

431                     on = J2eeObjectName.JavaMailResource(domainName, factoryName, serverName, SESSION_PROPERTY_TYPE);
432                     JavaMailSessionResource javaMailSessionResource = new JavaMailSessionResource(on.toString(), false, false, false, (JavaMailSession) factory);
433                     // JSR77
434
ManagedBean oManaged = oRegistry.findManagedBean("JavaMailSessionResource");
435                     ModelMBean JavaDoc oMBean = oManaged.createMBean(javaMailSessionResource);
436                     mbeanServer.registerMBean(oMBean, on);
437                     //mbeanServer.registerMBean(s_mbean, on);
438
if (logger.isLoggable(BasicLevel.DEBUG)) {
439                         logger.log(BasicLevel.DEBUG, "Register session mail factory with name " + factoryName);
440                     }
441                     break;
442                 case JAVAX_MAIL_INTERNET_MIMEPARTDATASOURCE :
443                     // J2EEManagement
444
on = J2eeObjectName.JavaMailResource(domainName, factoryName, serverName, MIMEPART_PROPERTY_TYPE);
445                     JavaMailMimePartDSResource javaMailMimePartDSResource = new JavaMailMimePartDSResource(on.toString(), false, false, false, (JavaMailMimePartDS) factory);
446                     // JSR77
447
oManaged = oRegistry.findManagedBean("JavaMailMimePartDSResource");
448                     oMBean = oManaged.createMBean(javaMailMimePartDSResource);
449                     mbeanServer.registerMBean(oMBean, on);
450                     if (logger.isLoggable(BasicLevel.DEBUG)) {
451                         logger.log(BasicLevel.DEBUG, "Register mime mail factory with name " + factoryName);
452                     }
453                 }
454             }
455         } catch (JMException JavaDoc me) {
456             throw new MailServiceException("Cannot register mail factory '" + factoryName + "' in JMX server", me);
457         } catch (Exception JavaDoc e) {
458             logger.log(BasicLevel.WARN, "Could not register JavaMailResource MBean");
459         }
460
461
462     }
463
464     /**
465      * Create a mail factory with the specified properties and register it
466      * into the registry.
467      * @param name the mail factory name
468      * @param props the properties used to configure the mail factory.
469      * @param loadFromFile true if the mail factory is loaded from a .properties file
470      * @throws MailServiceException if the creation or the registration of
471      * the factory failed.
472      * @throws MailServiceException
473      */

474     public void createMailFactoryMBean(String JavaDoc name, Properties JavaDoc props, Boolean JavaDoc loadFromFile)
475         throws MailServiceException {
476
477         boolean fromFile = loadFromFile.booleanValue();
478         if (!fromFile) {
479             try {
480                 if (logger.isLoggable(BasicLevel.DEBUG)) {
481                     logger.log(BasicLevel.DEBUG, "Call getInstance on JProp in order to create the properties file");
482                 }
483                 JProp.getInstance(name, props);
484             } catch (Exception JavaDoc e) {
485                 logger.log(BasicLevel.ERROR, "Cannot create mail factory " + name + " as cannot create properties file : " + e.toString());
486                 throw new ServiceException("MailService: Cannot create mail factory " + name + ",\n" + e.toString());
487             }
488         }
489         //call the internal proc
490
try {
491             createMailFactory(name, props);
492         } catch (Exception JavaDoc e) {
493             logger.log(BasicLevel.ERROR, "Cannot create mail factory: " + name);
494             throw new ServiceException("MailService: Cannot create mail factory: " + name + ",\n" + e.toString());
495         }
496     }
497
498     /**
499      * Unregister all the binding factories on the server and in JMX Server.
500      * @throws MailServiceException if the unregistration of the factories
501      * failed.
502      */

503     public void unbindMailFactories() throws MailServiceException {
504         //Unbind all factories
505
for (Enumeration JavaDoc e = jMailSessionFactories.keys(); e.hasMoreElements();) {
506             unbindMailFactoryMBean((String JavaDoc) e.nextElement());
507         }
508         for (Enumeration JavaDoc e = jMailMimePartDSFactories.keys(); e.hasMoreElements();) {
509             unbindMailFactoryMBean((String JavaDoc) e.nextElement());
510         }
511     }
512
513     /**
514      * Unregister the factory with the given name.
515      * @param factoryName the name of the factory to unbind.
516      * @throws MailServiceException if the unregistration of the factory
517      * failed.
518      */

519     public void unbindMailFactoryMBean(String JavaDoc factoryName)
520         throws MailServiceException {
521
522         // determine the type of the factory and the jndi name
523
String JavaDoc name = null;
524         int typeOfFactory;
525         JavaMailSession jmailSession = (JavaMailSession) jMailSessionFactories.get(factoryName);
526         JavaMailMimePartDS jMailMimePartDS = (JavaMailMimePartDS) jMailMimePartDSFactories.get(factoryName);
527         if (jmailSession != null) {
528             name = jmailSession.getName();
529             typeOfFactory = JAVAX_MAIL_SESSION_FACTORY;
530         } else if (jMailMimePartDS != null) {
531             name = jMailMimePartDS.getName();
532             typeOfFactory = JAVAX_MAIL_INTERNET_MIMEPARTDATASOURCE;
533         } else {
534             throw new MailServiceException("Can not unload the mail factory '" + factoryName + "' (this is not a known factory name");
535         }
536
537         // unbind the factory
538
try {
539             ictx.unbind(name);
540             bindedFactories.remove(name);
541         } catch (NamingException JavaDoc e) {
542             throw new MailServiceException("Can not unbind the factory '" + name + "'.", e);
543         }
544
545         // De-register the factory object from the jmx server and remove the factory from the internal data structure
546
try {
547             if (mbeanServer != null) {
548                 ObjectName JavaDoc on = null;
549                 switch (typeOfFactory) {
550                 case JAVAX_MAIL_SESSION_FACTORY :
551                     // J2EEManagement
552
on = J2eeObjectName.JavaMailResource(domainName, factoryName, serverName, SESSION_PROPERTY_TYPE);
553                     mbeanServer.unregisterMBean(on);
554                     if (logger.isLoggable(BasicLevel.DEBUG)) {
555                         logger.log(BasicLevel.DEBUG, "Unregister session mail factory with name " + factoryName);
556                     }
557                     jMailSessionFactories.remove(factoryName);
558                     break;
559                 case JAVAX_MAIL_INTERNET_MIMEPARTDATASOURCE :
560                     // J2EEManagement
561
on = J2eeObjectName.JavaMailResource(domainName, factoryName, serverName, MIMEPART_PROPERTY_TYPE);
562                     mbeanServer.unregisterMBean(on);
563                     if (logger.isLoggable(BasicLevel.DEBUG)) {
564                         logger.log(BasicLevel.DEBUG, "Unregister mime mail factory with name " + factoryName);
565                     }
566                     jMailMimePartDSFactories.remove(factoryName);
567                 }
568             }
569         } catch (JMException JavaDoc me) {
570             throw new MailServiceException("Cannot unregister mail factory '" + factoryName + "' from the JMX server", me);
571         }
572
573
574     }
575
576     /**
577      * Gets the factory name given the jndi name. Null is returned if the given name is not binded.
578      * @param jndiName the jndi name
579      * @return the factory name given the jndi name. Null is returned if the given name is not binded.
580      */

581     public String JavaDoc getFactoryName(String JavaDoc jndiName) {
582         return (String JavaDoc) bindedFactories.get(jndiName);
583     }
584
585     /**
586      * Gets the total number of mail factories available in JOnAS
587      * @return Integer Total number of mail factories available in JOnAS
588      */

589     public Integer JavaDoc getCurrentNumberOfMailFactories() {
590         return new Integer JavaDoc(jMailSessionFactories.size() + jMailMimePartDSFactories.size());
591     }
592
593     /**
594      * Gets the number of Session mail factories available in JOnAS
595      * @return Integer Number of Session mail factories available in JOnAS
596      */

597     public Integer JavaDoc getCurrentNumberOfSessionMailFactories() {
598         return new Integer JavaDoc(jMailSessionFactories.size());
599     }
600
601     /**
602      * Gets the integer Number of internet
603      * @return Integer Number of internet.MimePartDataSource mail factories available in JOnAS
604      */

605     public Integer JavaDoc getCurrentNumberOfMimeMailFactories() {
606         return new Integer JavaDoc(jMailMimePartDSFactories.size());
607     }
608
609     /**
610      * Gets the mail factory configuration properties from a local file
611      * @param configFile configuration to use
612      * @return mail factory configuration properties from a local file
613      * @throws Exception if it fails
614      */

615     public Properties JavaDoc getMailFactoryPropertiesFile(String JavaDoc configFile) throws Exception JavaDoc {
616         try {
617             return JProp.getInstance(configFile).getConfigFileEnv();
618         } catch (Exception JavaDoc e) {
619             if (e instanceof FileNotFoundException JavaDoc) {
620                 logger.log(BasicLevel.ERROR, "Please check if " + configFile + ".properties is available in JONAS_ROOT/config, HOME, or .");
621             } else {
622                 logger.log(BasicLevel.ERROR, "Error occured when reading file " + configFile);
623             }
624             throw e;
625         }
626     }
627
628     /**
629      * MBean method:
630      * @return the list of properties files describing mail factories found in JONAS_BASE/conf
631      */

632     public List JavaDoc getMailFactoryPropertiesFiles() throws Exception JavaDoc {
633         return JModule.getMailFactoryPropsInDir();
634     }
635     /**
636      * MBean method:
637      * @return the list of properties files describing mail factories found in JONAS_BASE/conf
638      */

639     public List JavaDoc getMimePartMailFactoryPropertiesFiles() throws Exception JavaDoc {
640         return JModule.getMailFactoryPropsInDir(MIMEPART_PROPERTY_TYPE);
641     }
642     /**
643      * MBean method:
644      * @return the list of properties files describing mail factories found in JONAS_BASE/conf
645      */

646     public List JavaDoc getSessionMailFactoryPropertiesFiles() throws Exception JavaDoc {
647         return JModule.getMailFactoryPropsInDir(SESSION_PROPERTY_TYPE);
648     }
649 }
650
Popular Tags