1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
19
20 import javax.jcr.Value;
21 import javax.jcr.ValueFactory;
22
23 import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
24 import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
25
26 /***
27 * Boolean Type Converter
28 *
29 * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
30 * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
31 */
32 public class BooleanTypeConverterImpl implements AtomicTypeConverter
33 {
34 /***
35 *
36 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
37 */
38 public Value getValue(ValueFactory valueFactory, Object propValue)
39 {
40 if (propValue == null)
41 {
42 return null;
43 }
44 boolean value = ((Boolean) propValue).booleanValue();
45 return valueFactory.createValue(value);
46 }
47
48
49 /***
50 *
51 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
52 */
53 public Object getObject(Value value)
54 {
55 try
56 {
57 return new Boolean(value.getBoolean());
58 }
59 catch (Exception e)
60 {
61 throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString() , e);
62 }
63 }
64
65 /***
66 *
67 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
68 */
69 public String getStringValue(Object object)
70 {
71 return ((Boolean) object).booleanValue() ? "true()" : "false()";
72 }
73
74 }