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.RepositoryException;
21 import javax.jcr.Value;
22 import javax.jcr.ValueFactory;
23
24 import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
25 import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
26
27 /***
28 * Double Type Converter
29 *
30 * @author <a href="mailto:christophe.lombart@gmail.com">Christophe Lombart</a>
31 * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
32 */
33 public class DoubleTypeConverterImpl implements AtomicTypeConverter
34 {
35 /***
36 *
37 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getValue(java.lang.Object)
38 */
39 public Value getValue(ValueFactory valueFactory, Object propValue)
40 {
41 if (propValue == null)
42 {
43 return null;
44 }
45
46 double value = ((Double) propValue).doubleValue();
47 return valueFactory.createValue(value);
48 }
49
50 /***
51 *
52 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getObject(javax.jcr.Value)
53 */
54 public Object getObject(Value value)
55 {
56 try
57 {
58 double beanPropValue = value.getDouble();
59 return new Double(beanPropValue);
60 }
61 catch (RepositoryException e)
62 {
63 throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString(), e);
64 }
65 }
66
67 /***
68 *
69 * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter#getStringValue(java.lang.Object)
70 */
71 public String getStringValue(Object object)
72 {
73 return object.toString();
74 }
75 }