KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > webservice > jaf > JAFConfigService


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

6 package org.jboss.webservice.jaf;
7
8 import javax.activation.CommandMap JavaDoc;
9 import javax.activation.MailcapCommandMap JavaDoc;
10
11 import org.jboss.logging.Logger;
12
13 /**
14  * A pojo service which can be used to populate the JAF MailcapCommandMap with
15  * mailcap content-type to DataContentHandler class. The default mailcaps are
16  * text/xml, application/xml mapping to org.jboss.webservice.jaf.XMLDataContentHandler
17  *
18  * @author Scott.Stark@jboss.org
19  * @version $Revision: 1.4 $
20  * @see javax.activation.DataContentHandler
21  * @see javax.activation.MailcapCommandMap
22  * @see org.jboss.webservice.jaf.XMLDataContentHandler
23  */

24 public class JAFConfigService
25 {
26    private static Logger log = Logger.getLogger(JAFConfigService.class);
27    /**
28     * The default mapping is for xml -> XMLDataContentHandler
29     */

30    private String JavaDoc[] mailcaps = {
31       "text/xml;;x-java-content-handler=org.jboss.webservice.jaf.XMLDataContentHandler",
32       "application/xml;;x-java-content-handler=org.jboss.webservice.jaf.XMLDataContentHandler"
33    };
34
35    public String JavaDoc[] getMailcaps()
36    {
37       return mailcaps;
38    }
39
40    public void setMailcaps(String JavaDoc[] mailcaps)
41    {
42       this.mailcaps = mailcaps;
43    }
44
45    /**
46     * Register the mailcaps with the default MailcapCommandMap
47     *
48     * @throws Exception
49     * @see MailcapCommandMap
50     */

51    public void start() throws Exception JavaDoc
52    {
53       CommandMap JavaDoc commandMap = CommandMap.getDefaultCommandMap();
54       if (commandMap instanceof MailcapCommandMap JavaDoc)
55       {
56          MailcapCommandMap JavaDoc mailMap = (MailcapCommandMap JavaDoc)commandMap;
57          for (int n = 0; n < mailcaps.length; n++)
58          {
59             String JavaDoc mailcap = mailcaps[n];
60             mailMap.addMailcap(mailcap);
61             log.debug("Added mailcap: " + mailcap);
62          }
63       }
64       else
65       {
66          throw new Exception JavaDoc("Cannot handle non-MailcapCommandMap, map="
67                  + commandMap);
68       }
69    }
70
71    /**
72     * Do nothing since MailcapCommandMap does not support removal of mailcaps
73     *
74     * @throws Exception
75     */

76    public void stop() throws Exception JavaDoc
77    {
78    }
79
80 }
81
Popular Tags