KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > attachments > AttachmentSupport


1 /**
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.axis.attachments;
8
9 // $Id: AttachmentSupport.java,v 1.1.2.1 2005/03/02 14:28:44 tdiesler Exp $
10

11 import org.jboss.axis.AxisEngine;
12 import org.jboss.axis.MessageContext;
13 import org.jboss.axis.utils.ClassUtils;
14 import org.jboss.axis.utils.Messages;
15 import org.jboss.logging.Logger;
16
17 /**
18  * Provide access to the attechment support implementation.
19  * <p/>
20  * The default implementation is {@link AttachmentsImpl}
21  * You can overwrite the implementation through the engine option {@link AxisEngine.PROP_ATTACHMENT_IMPLEMENTATION}
22  *
23  * @author Thomas Diesler (thomas.diesler@jboss.org)
24  * @since 31-May-2004
25  */

26 public final class AttachmentSupport
27 {
28
29    /**
30     * Provides logging
31     */

32    private static Logger log = Logger.getLogger(AttachmentSupport.class.getName());
33
34    /**
35     * Default Attachments Implementation class.
36     */

37    public static final String JavaDoc DEFAULT_ATTACHMNET_IMPL = AxisEngine.DEFAULT_ATTACHMENT_IMPL;
38
39    /**
40     * Current Attachment implementation.
41     */

42    private static String JavaDoc attachImplClassName = DEFAULT_ATTACHMNET_IMPL;
43
44    private static boolean checkForAttachmentSupport = true;
45    private static boolean attachmentSupportEnabled = false;
46    private static Class JavaDoc attachImplClass;
47
48    /**
49     * Check if we have attachments enabled.
50     * <p/>
51     * The check is only done once.
52     */

53    public static synchronized boolean isAttachmentSupportEnabled()
54    {
55       return isAttachmentSupportEnabled(null);
56    }
57
58    /**
59     * Check if we have attachments enabled.
60     * <p/>
61     * The check is only done once.
62     */

63    public static synchronized boolean isAttachmentSupportEnabled(MessageContext msgCtx)
64    {
65
66       if (checkForAttachmentSupport)
67       {
68          checkForAttachmentSupport = false;
69
70          try
71          {
72             if (msgCtx != null)
73             {
74                AxisEngine engine = msgCtx.getAxisEngine();
75                if (engine != null)
76                {
77                   attachImplClassName = (String JavaDoc)engine.getOption(AxisEngine.PROP_ATTACHMENT_IMPLEMENTATION);
78                }
79             }
80
81             if (attachImplClassName == null)
82             {
83                attachImplClassName = AxisEngine.DEFAULT_ATTACHMENT_IMPL;
84             }
85
86             /**
87              * Attempt to resolve class name, verify that these are present...
88              */

89             ClassUtils.forName("javax.activation.DataHandler");
90             ClassUtils.forName("javax.mail.internet.MimeMultipart");
91
92             attachImplClass = ClassUtils.forName(attachImplClassName);
93             attachmentSupportEnabled = true;
94          }
95          catch (ClassNotFoundException JavaDoc ex)
96          {
97             // no support for it, leave mAttachments null.
98
}
99          catch (NoClassDefFoundError JavaDoc ex)
100          {
101             // no support for it, leave mAttachments null.
102
}
103          log.debug(Messages.getMessage("attachEnabled") + " " + attachmentSupportEnabled);
104       }
105
106       return attachmentSupportEnabled;
107    }
108
109    /**
110     * Get the attachment implementation class
111     */

112    public static Class JavaDoc getImplementationClass()
113    {
114       return attachImplClass;
115    }
116 }
117
Popular Tags