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 FLOAT = "float";
041    
042            public static final String INTEGER = "integer";
043    
044            public static final String LABEL = "label";
045    
046            public static final String LONG = "long";
047    
048            public static final String NAME = "name";
049    
050            public static final String PREDIFINED_VALUE = "predefinedValue";
051    
052            public static final String REQUIRED = "required";
053    
054            public static final String SHORT = "short";
055    
056            public static final String SHOW = "showLabel";
057    
058            public static final String SORTABLE = "sortable";
059    
060            public static final String STRING = "string";
061    
062            public static final String TYPE = "type";
063    
064            public static final String VALUE  = "value";
065    
066            public static final Serializable getSerializable(
067                    String type, String value) {
068    
069                    if (type.equals(BOOLEAN)) {
070                            return GetterUtil.getBoolean(value);
071                    }
072                    else if (type.equals(DATE)) {
073                            return new Date(GetterUtil.getLong(value));
074                    }
075                    else if (type.equals(DOUBLE)) {
076                            return GetterUtil.getDouble(value);
077                    }
078                    else if (type.equals(FLOAT)) {
079                            return GetterUtil.getFloat(value);
080                    }
081                    else if (type.equals(INTEGER)) {
082                            return GetterUtil.getInteger(value);
083                    }
084                    else if (type.equals(LONG)) {
085                            return GetterUtil.getLong(value);
086                    }
087                    else if (type.equals(SHORT)) {
088                            return GetterUtil.getShort(value);
089                    }
090                    else {
091                            return value;
092                    }
093            }
094    
095    }