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