KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > portlet > PortletModeConverter


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.portlet;
10
11 import javax.portlet.PortletMode;
12
13 import org.jboss.portal.common.value.Converter;
14 import org.jboss.portal.common.value.FormatConversionException;
15 import org.jboss.portal.common.value.NullConversionException;
16
17 /**
18  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
19  * @version $Revision: 1.2 $
20  */

21 public class PortletModeConverter implements Converter
22 {
23
24    public static final Converter INSTANCE = new PortletModeConverter();
25
26    public boolean accept(Class JavaDoc clazz)
27    {
28       return PortletMode.class.equals(clazz);
29    }
30
31    public Object JavaDoc toObject(String JavaDoc value) throws NullConversionException, FormatConversionException
32    {
33       if (value == null)
34       {
35          throw new NullConversionException();
36       }
37       return PortletUtils.decodePortletMode(value);
38    }
39
40    public String JavaDoc toString(Object JavaDoc value) throws NullConversionException, FormatConversionException
41    {
42       if (value == null)
43       {
44          throw new NullConversionException();
45       }
46       if (value instanceof PortletMode)
47       {
48          return ((PortletMode)value).toString();
49       }
50       else
51       {
52          throw new FormatConversionException();
53       }
54    }
55 }
56
Popular Tags