Statistics
| Revision:

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
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
import org.gvsig.tools.dataTypes.CoercionException;
8
import org.gvsig.tools.dataTypes.DataType;
9
import org.gvsig.tools.dynobject.Tags;
10

    
11
/**
12
 *
13
 * @author jjdelcerro
14
 */
15
@SuppressWarnings("UseSpecificCatch")
16
public class DataProfileText extends AbstractDataProfile {
17
    
18
    public DataProfileText() {
19
        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

    
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
    
41
    public static void selfRegister() {
42
        DataManager dataManager = DALLocator.getDataManager();
43
        
44
        dataManager.registerDataProfile(new DataProfileText());
45
    }
46
    
47
}