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.exception.SystemException;
018    import com.liferay.portal.theme.ThemeDisplay;
019    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
020    import com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalServiceUtil;
021    
022    import java.io.Serializable;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class Field {
028    
029            public Field() {
030            }
031    
032            public Field(long ddmStructureId, String name, Serializable value) {
033                    _ddmStructureId = ddmStructureId;
034                    _name = name;
035                    _value = value;
036            }
037    
038            public Field(String name, Serializable value) {
039                    this(0, name, value);
040            }
041    
042            public String getDataType() throws SystemException {
043                    DDMStructure ddmStructure = getDDMStructure();
044    
045                    return ddmStructure.getFieldDataType(_name);
046            }
047    
048            public DDMStructure getDDMStructure() throws SystemException {
049                    return DDMStructureLocalServiceUtil.fetchStructure(_ddmStructureId);
050            }
051    
052            public long getDDMStructureId() {
053                    return _ddmStructureId;
054            }
055    
056            public String getName() {
057                    return _name;
058            }
059    
060            public String getRenderedValue(ThemeDisplay themeDisplay)
061                    throws SystemException {
062    
063                    DDMStructure ddmStructure = getDDMStructure();
064    
065                    String dataType = null;
066    
067                    if (ddmStructure != null) {
068                            dataType = getDataType();
069                    }
070    
071                    FieldRenderer fieldrenderer = FieldRendererFactory.getFieldRenderer(
072                            dataType);
073    
074                    return fieldrenderer.render(themeDisplay, _value);
075            }
076    
077            public String getType() throws SystemException {
078                    DDMStructure ddmStructure = getDDMStructure();
079    
080                    return ddmStructure.getFieldType(_name);
081            }
082    
083            public Serializable getValue() {
084                    return _value;
085            }
086    
087            public void setDDMStructureId(long ddmStructureId) {
088                    _ddmStructureId = ddmStructureId;
089            }
090    
091            public void setName(String name) {
092                    _name = name;
093            }
094    
095            public void setValue(Serializable value) {
096                    _value = value;
097            }
098    
099            private long _ddmStructureId;
100            private String _name;
101            private Serializable _value;
102    
103    }