KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > impl > preferences > ValueManager


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.core.impl.preferences;
10
11 import org.jboss.portal.common.value.BooleanValues;
12 import org.jboss.portal.common.value.IntegerValues;
13 import org.jboss.portal.common.value.StringValues;
14 import org.jboss.portal.common.value.Value;
15
16 /**
17  * A manager handling type conversion.
18  *
19  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
20  * @version $Revision: 1.1 $
21  */

22 public class ValueManager
23 {
24
25    public static final int TYPE_NULL = 0;
26    public static final int TYPE_STRING = 1;
27    public static final int TYPE_INTEGER = 2;
28    public static final int TYPE_BOOLEAN = 3;
29    private static final String JavaDoc[] EMPTY_STRING_ARRAY = new String JavaDoc[0];
30
31    public static Value createValue(TypedStringArray tsa)
32    {
33       switch(tsa.getType())
34       {
35          case TYPE_NULL:
36             return new StringValues();
37          case TYPE_INTEGER:
38             return new IntegerValues(tsa.getStrings());
39          case TYPE_BOOLEAN:
40             return new BooleanValues(tsa.getStrings());
41          default:
42             return new StringValues(tsa.getStrings());
43       }
44    }
45
46    public static TypedStringArray createTypedStringArray(Value value)
47    {
48       if (value.isNull())
49       {
50          return new TypedStringArray(TYPE_NULL, EMPTY_STRING_ARRAY);
51       }
52       else if (value instanceof IntegerValues)
53       {
54          return new TypedStringArray(TYPE_INTEGER, value.asStringArray());
55       }
56       else if (value instanceof BooleanValues)
57       {
58          return new TypedStringArray(TYPE_BOOLEAN, value.asStringArray());
59       }
60       else
61       {
62          return new TypedStringArray(TYPE_STRING, value.asStringArray());
63       }
64    }
65 }
66
Popular Tags