View Javadoc

    1   package org.codehaus.xfire.attachments;
    2
    3   import java.util.HashMap;
    4   import java.util.Map;
    5
    6   import javax.activation.DataContentHandler;
    7
    8
    9   /***
    10   * @author <a href="mailto:dan@envoisolutiosn.com">Dan Diephouse</a>
    11   */
    12  public class AbstractDataContentHandlerFactory
    13      implements javax.activation.DataContentHandlerFactory
    14  {
    15      private Map types = new HashMap();
    16      private Map classToHandlers = new HashMap();
    17      private Map classToType = new HashMap();
    18
    19      public DataContentHandler createDataContentHandler(String contentType)
    20      {
    21          return (DataContentHandler) types.get(contentType);
    22      }
    23
    24      public DataContentHandler getDataContentHandler(Class clazz)
    25      {
    26          return (DataContentHandler) classToHandlers.get(clazz);
    27      }
    28
    29      public String getContentType(Class clazz)
    30      {
    31          return (String) classToHandlers.get(clazz);
    32      }
    33
    34      /***
    35       * Register a DataContentHandler for a particular MIME type.
    36       * @param contentType The Content Type.
    37       * @param handler The DataContentHandler.
    38       */
    39      public void register(String contentType, Class clazz, DataContentHandler handler)
    40      {
    41          types.put(contentType, handler);
    42          classToHandlers.put(clazz, handler);
    43          classToType.put(clazz, contentType);
    44      }
    45  }