001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.dynamicdatamapping.storage;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
020    import com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalServiceUtil;
021    
022    import java.io.Serializable;
023    
024    import java.util.Locale;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class Field implements Serializable {
030    
031            public Field() {
032            }
033    
034            public Field(long ddmStructureId, String name, Serializable value) {
035                    _ddmStructureId = ddmStructureId;
036                    _name = name;
037                    _value = value;
038            }
039    
040            public Field(String name, Serializable value) {
041                    this(0, name, value);
042            }
043    
044            public String getDataType() throws PortalException, SystemException {
045                    DDMStructure ddmStructure = getDDMStructure();
046    
047                    return ddmStructure.getFieldDataType(_name);
048            }
049    
050            public DDMStructure getDDMStructure() throws SystemException {
051                    return DDMStructureLocalServiceUtil.fetchStructure(_ddmStructureId);
052            }
053    
054            public long getDDMStructureId() {
055                    return _ddmStructureId;
056            }
057    
058            public String getName() {
059                    return _name;
060            }
061    
062            public String getRenderedValue(Locale locale)
063                    throws PortalException, SystemException {
064    
065                    DDMStructure ddmStructure = getDDMStructure();
066    
067                    String dataType = null;
068    
069                    if (ddmStructure != null) {
070                            dataType = getDataType();
071                    }
072    
073                    FieldRenderer fieldrenderer = FieldRendererFactory.getFieldRenderer(
074                            dataType);
075    
076                    return fieldrenderer.render(this, locale);
077            }
078    
079            public String getType() throws PortalException, SystemException {
080                    DDMStructure ddmStructure = getDDMStructure();
081    
082                    return ddmStructure.getFieldType(_name);
083            }
084    
085            public Serializable getValue() {
086                    return _value;
087            }
088    
089            public void setDDMStructureId(long ddmStructureId) {
090                    _ddmStructureId = ddmStructureId;
091            }
092    
093            public void setName(String name) {
094                    _name = name;
095            }
096    
097            public void setValue(Serializable value) {
098                    _value = value;
099            }
100    
101            private long _ddmStructureId;
102            private String _name;
103            private Serializable _value;
104    
105    }