svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / impl / dataprofile / DataProfileText.java @ 44448
History | View | Annotate | Download (1.29 KB)
1 | 44253 | jjdelcerro | package org.gvsig.fmap.dal.impl.dataprofile; |
---|---|---|---|
2 | |||
3 | import java.util.Objects; |
||
4 | import org.gvsig.fmap.dal.DALLocator; |
||
5 | import org.gvsig.fmap.dal.DataManager; |
||
6 | import org.gvsig.fmap.dal.feature.AbstractDataProfile; |
||
7 | 44448 | jjdelcerro | import org.gvsig.tools.dataTypes.CoercionException; |
8 | import org.gvsig.tools.dataTypes.DataType; |
||
9 | 44253 | jjdelcerro | import org.gvsig.tools.dynobject.Tags; |
10 | |||
11 | /**
|
||
12 | *
|
||
13 | * @author jjdelcerro
|
||
14 | */
|
||
15 | @SuppressWarnings("UseSpecificCatch") |
||
16 | 44262 | jjdelcerro | public class DataProfileText extends AbstractDataProfile { |
17 | 44253 | jjdelcerro | |
18 | 44262 | jjdelcerro | public DataProfileText() {
|
19 | 44253 | jjdelcerro | super("Text", "Text", String.class); |
20 | } |
||
21 | |||
22 | @Override
|
||
23 | public Object createData(Object data, Tags tags) { |
||
24 | return Objects.toString(data, null); |
||
25 | } |
||
26 | 44448 | jjdelcerro | |
27 | @Override
|
||
28 | public Object coerce(DataType dataType, Object data, Tags tags) throws CoercionException { |
||
29 | String s = Objects.toString(data, null); |
||
30 | if( s == null ) { |
||
31 | return null; |
||
32 | } |
||
33 | try {
|
||
34 | data = dataType.coerce(s); |
||
35 | return data;
|
||
36 | } catch(Exception ex) { |
||
37 | throw new CoercionException("Can't convert String to "+dataType.getName(), ex); |
||
38 | } |
||
39 | } |
||
40 | 44253 | jjdelcerro | |
41 | public static void selfRegister() { |
||
42 | DataManager dataManager = DALLocator.getDataManager(); |
||
43 | |||
44 | 44262 | jjdelcerro | dataManager.registerDataProfile(new DataProfileText());
|
45 | 44253 | jjdelcerro | } |
46 | |||
47 | } |