1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.expando.model.impl;
24  
25  import com.liferay.portal.kernel.log.Log;
26  import com.liferay.portal.kernel.log.LogFactoryUtil;
27  import com.liferay.portal.kernel.util.UnicodeProperties;
28  import com.liferay.portlet.expando.model.ExpandoColumn;
29  import com.liferay.portlet.expando.model.ExpandoColumnConstants;
30  import com.liferay.portlet.expando.model.ExpandoValue;
31  
32  import java.io.IOException;
33  import java.io.Serializable;
34  
35  /**
36   * <a href="ExpandoColumnImpl.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Raymond Augé
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class ExpandoColumnImpl
43      extends ExpandoColumnModelImpl implements ExpandoColumn {
44  
45      public ExpandoColumnImpl() {
46      }
47  
48      public Serializable getDefaultValue() {
49          try {
50              ExpandoValue value = new ExpandoValueImpl();
51  
52              value.setColumnId(getColumnId());
53              value.setData(getDefaultData());
54  
55              int type = getType();
56  
57              if (type == ExpandoColumnConstants.BOOLEAN) {
58                  return value.getBoolean();
59              }
60              else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
61                  return value.getBooleanArray();
62              }
63              else if (type == ExpandoColumnConstants.DATE) {
64                  return value.getDate();
65              }
66              else if (type == ExpandoColumnConstants.DATE_ARRAY) {
67                  return value.getDateArray();
68              }
69              else if (type == ExpandoColumnConstants.DOUBLE) {
70                  return value.getDouble();
71              }
72              else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
73                  return value.getDoubleArray();
74              }
75              else if (type == ExpandoColumnConstants.FLOAT) {
76                  return value.getFloat();
77              }
78              else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
79                  return value.getFloatArray();
80              }
81              else if (type == ExpandoColumnConstants.INTEGER) {
82                  return value.getInteger();
83              }
84              else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
85                  return value.getIntegerArray();
86              }
87              else if (type == ExpandoColumnConstants.LONG) {
88                  return value.getLong();
89              }
90              else if (type == ExpandoColumnConstants.LONG_ARRAY) {
91                  return value.getLongArray();
92              }
93              else if (type == ExpandoColumnConstants.SHORT) {
94                  return value.getShort();
95              }
96              else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
97                  return value.getShortArray();
98              }
99              else if (type == ExpandoColumnConstants.STRING_ARRAY) {
100                 return value.getStringArray();
101             }
102             else {
103                 return value.getString();
104             }
105         }
106         catch (Exception e) {
107             return null;
108         }
109     }
110 
111     public String getTypeSettings() {
112         if (_typeSettingsProperties == null) {
113             return super.getTypeSettings();
114         }
115         else {
116             return _typeSettingsProperties.toString();
117         }
118     }
119 
120     public UnicodeProperties getTypeSettingsProperties() {
121         if (_typeSettingsProperties == null) {
122             _typeSettingsProperties = new UnicodeProperties(true);
123 
124             try {
125                 _typeSettingsProperties.load(super.getTypeSettings());
126             }
127             catch (IOException ioe) {
128                 _log.error(ioe, ioe);
129             }
130         }
131 
132         return _typeSettingsProperties;
133     }
134 
135     public void setTypeSettings(String typeSettings) {
136         _typeSettingsProperties = null;
137 
138         super.setTypeSettings(typeSettings);
139     }
140 
141     public void setTypeSettingsProperties(
142         UnicodeProperties typeSettingsProperties) {
143 
144         _typeSettingsProperties = typeSettingsProperties;
145 
146         super.setTypeSettings(_typeSettingsProperties.toString());
147     }
148 
149     private static Log _log = LogFactoryUtil.getLog(ExpandoColumnImpl.class);
150 
151     private UnicodeProperties _typeSettingsProperties = null;
152 
153 }