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 @ 46419

History | View | Annotate | Download (1.4 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
    protected Object doCreateData(Object data, Tags tags) {
24
        try {
25
            return Objects.toString(data, null);
26
        } catch (Exception ex) {
27
            LOGGER.debug("Can't create text", ex);
28
        }
29
        return null;
30

    
31
    }
32

    
33
    @Override
34
    protected Object doCoerce(DataType dataType, Object data, Tags tags) throws CoercionException {
35
        String s = Objects.toString(data, null);
36
        if( s == null ) {
37
            return null;
38
        }    
39
        try {
40
            data = dataType.coerce(s);
41
            return data;
42
        } catch(Exception ex) {
43
            LOGGER.debug("Can't coerce text", ex);
44
        }
45
        return null;
46
    }
47
    
48
    public static void selfRegister() {
49
        DataManager dataManager = DALLocator.getDataManager();
50
        
51
        dataManager.registerDataProfile(new DataProfileText());
52
    }
53
    
54
}