KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > common > value > AbstractValue


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.common.value;
10
11
12 import java.util.Arrays JavaDoc;
13 import java.util.List JavaDoc;
14
15 /**
16  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
17  * @version $Revision: 1.2 $
18  */

19 public abstract class AbstractValue implements Value
20 {
21
22    public boolean isNull()
23    {
24       return asObject() == null;
25    }
26
27    public int asInt() throws NullConversionException, FormatConversionException
28    {
29       throw new FormatConversionException();
30    }
31
32    public boolean asBoolean() throws NullConversionException, FormatConversionException
33    {
34       throw new FormatConversionException();
35    }
36
37    public boolean isMultiValued()
38    {
39       return false;
40    }
41
42    public String JavaDoc[] asStringArray()
43    {
44       return new String JavaDoc[]{asString()};
45    }
46
47    public int[] asIntArray() throws NullConversionException, FormatConversionException
48    {
49       return new int[]{asInt()};
50    }
51
52    public boolean[] asBooleanArray() throws NullConversionException, FormatConversionException
53    {
54       return new boolean[]{asBoolean()};
55    }
56
57    public int hashCode()
58    {
59       Object JavaDoc o = asObject();
60       return o == null ? 0 : o.hashCode();
61    }
62
63    public boolean equals(Object JavaDoc obj)
64    {
65       if (obj == this)
66       {
67          return true;
68       }
69       if (obj != null && getClass().isAssignableFrom(obj.getClass()))
70       {
71          AbstractValue other = (AbstractValue)obj;
72          Object JavaDoc o1 = asObject();
73          Object JavaDoc o2 = other.asObject();
74          if (o1 == o2)
75          {
76             return true;
77          }
78          return o1 != null && o1.equals(o2);
79       }
80       return false;
81    }
82
83    public List JavaDoc asObjectList()
84    {
85       return Arrays.asList(asObjectArray());
86    }
87
88    public String JavaDoc toString()
89    {
90       return asString();
91    }
92 }
93
Popular Tags