KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > format > BooleanHandler


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.format;
14
15 import java.util.List JavaDoc;
16
17
18 /**
19  * @author av
20  */

21 public class BooleanHandler extends FormatHandlerSupport {
22   /**
23    * formats a Boolean instance to "true" or "false"
24    * @param o a Boolean instance, null will be rendered as "false"
25    */

26   public String JavaDoc format(Object JavaDoc o, String JavaDoc userPattern) {
27     if (o == null) {
28       return "false";
29     }
30
31     return ((Boolean JavaDoc) o).toString();
32   }
33
34   public Object JavaDoc parse(String JavaDoc s, String JavaDoc userPattern) {
35     return new Boolean JavaDoc(s);
36   }
37   
38   public boolean canHandle(Object JavaDoc value) {
39     return value instanceof Boolean JavaDoc;
40   }
41
42   public Object JavaDoc toNativeArray(List JavaDoc list) {
43     boolean[] array = new boolean[list.size()];
44     for (int i = 0; i < array.length; i++)
45       array[i] = ((Boolean JavaDoc)list.get(i)).booleanValue();
46     return array;
47   }
48   
49   public Object JavaDoc[] toObjectArray(Object JavaDoc value) {
50     if (value instanceof Boolean JavaDoc)
51       return new Boolean JavaDoc[]{(Boolean JavaDoc)value};
52     boolean[] src = (boolean[])value;
53     Boolean JavaDoc[] dst = new Boolean JavaDoc[src.length];
54     for (int i = 0; i < src.length; i++)
55       dst[i] = new Boolean JavaDoc(src[i]);
56     return dst;
57   }
58   
59 }
Popular Tags