001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.dynamicdatamapping.storage;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    
019    import java.io.Serializable;
020    
021    import java.util.Date;
022    
023    /**
024     * @author Marcellus Tavares
025     */
026    public class FieldConstants {
027    
028            public static final String BOOLEAN = "boolean";
029    
030            public static final String DATA_TYPE = "dataType";
031    
032            public static final String DATE = "date";
033    
034            public static final String DOCUMENT_LIBRARY = "document-library";
035    
036            public static final String DOUBLE = "double";
037    
038            public static final String EDITABLE = "editable";
039    
040            public static final String FILE_UPLOAD = "file-upload";
041    
042            public static final String FLOAT = "float";
043    
044            public static final String INTEGER = "integer";
045    
046            public static final String LABEL = "label";
047    
048            public static final String LONG = "long";
049    
050            public static final String NAME = "name";
051    
052            public static final String NUMBER = "number";
053    
054            public static final String PREDIFINED_VALUE = "predefinedValue";
055    
056            public static final String REQUIRED = "required";
057    
058            public static final String SHORT = "short";
059    
060            public static final String SHOW = "showLabel";
061    
062            public static final String SORTABLE = "sortable";
063    
064            public static final String STRING = "string";
065    
066            public static final String TYPE = "type";
067    
068            public static final String VALUE = "value";
069    
070            public static final Serializable getSerializable(
071                    String type, String value) {
072    
073                    if (type.equals(BOOLEAN)) {
074                            return GetterUtil.getBoolean(value);
075                    }
076                    else if (type.equals(DATE)) {
077                            return new Date(GetterUtil.getLong(value));
078                    }
079                    else if (type.equals(DOUBLE)) {
080                            return GetterUtil.getDouble(value);
081                    }
082                    else if (type.equals(FLOAT)) {
083                            return GetterUtil.getFloat(value);
084                    }
085                    else if (type.equals(INTEGER)) {
086                            return GetterUtil.getInteger(value);
087                    }
088                    else if (type.equals(LONG)) {
089                            return GetterUtil.getLong(value);
090                    }
091                    else if (type.equals(NUMBER)) {
092                            return GetterUtil.getNumber(value);
093                    }
094                    else if (type.equals(SHORT)) {
095                            return GetterUtil.getShort(value);
096                    }
097                    else {
098                            return value;
099                    }
100            }
101    
102    }