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