1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.expando.model.impl;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.util.UnicodeProperties;
20  import com.liferay.portlet.expando.model.ExpandoColumn;
21  import com.liferay.portlet.expando.model.ExpandoColumnConstants;
22  import com.liferay.portlet.expando.model.ExpandoValue;
23  
24  import java.io.IOException;
25  import java.io.Serializable;
26  
27  /**
28   * <a href="ExpandoColumnImpl.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Raymond Augé
31   * @author Brian Wing Shun Chan
32   */
33  public class ExpandoColumnImpl
34      extends ExpandoColumnModelImpl implements ExpandoColumn {
35  
36      public ExpandoColumnImpl() {
37      }
38  
39      public Serializable getDefaultValue() {
40          try {
41              ExpandoValue value = new ExpandoValueImpl();
42  
43              value.setColumnId(getColumnId());
44              value.setData(getDefaultData());
45  
46              int type = getType();
47  
48              if (type == ExpandoColumnConstants.BOOLEAN) {
49                  return value.getBoolean();
50              }
51              else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
52                  return value.getBooleanArray();
53              }
54              else if (type == ExpandoColumnConstants.DATE) {
55                  return value.getDate();
56              }
57              else if (type == ExpandoColumnConstants.DATE_ARRAY) {
58                  return value.getDateArray();
59              }
60              else if (type == ExpandoColumnConstants.DOUBLE) {
61                  return value.getDouble();
62              }
63              else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
64                  return value.getDoubleArray();
65              }
66              else if (type == ExpandoColumnConstants.FLOAT) {
67                  return value.getFloat();
68              }
69              else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
70                  return value.getFloatArray();
71              }
72              else if (type == ExpandoColumnConstants.INTEGER) {
73                  return value.getInteger();
74              }
75              else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
76                  return value.getIntegerArray();
77              }
78              else if (type == ExpandoColumnConstants.LONG) {
79                  return value.getLong();
80              }
81              else if (type == ExpandoColumnConstants.LONG_ARRAY) {
82                  return value.getLongArray();
83              }
84              else if (type == ExpandoColumnConstants.SHORT) {
85                  return value.getShort();
86              }
87              else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
88                  return value.getShortArray();
89              }
90              else if (type == ExpandoColumnConstants.STRING_ARRAY) {
91                  return value.getStringArray();
92              }
93              else {
94                  return value.getString();
95              }
96          }
97          catch (Exception e) {
98              return null;
99          }
100     }
101 
102     public String getTypeSettings() {
103         if (_typeSettingsProperties == null) {
104             return super.getTypeSettings();
105         }
106         else {
107             return _typeSettingsProperties.toString();
108         }
109     }
110 
111     public UnicodeProperties getTypeSettingsProperties() {
112         if (_typeSettingsProperties == null) {
113             _typeSettingsProperties = new UnicodeProperties(true);
114 
115             try {
116                 _typeSettingsProperties.load(super.getTypeSettings());
117             }
118             catch (IOException ioe) {
119                 _log.error(ioe, ioe);
120             }
121         }
122 
123         return _typeSettingsProperties;
124     }
125 
126     public void setTypeSettings(String typeSettings) {
127         _typeSettingsProperties = null;
128 
129         super.setTypeSettings(typeSettings);
130     }
131 
132     public void setTypeSettingsProperties(
133         UnicodeProperties typeSettingsProperties) {
134 
135         _typeSettingsProperties = typeSettingsProperties;
136 
137         super.setTypeSettings(_typeSettingsProperties.toString());
138     }
139 
140     private static Log _log = LogFactoryUtil.getLog(ExpandoColumnImpl.class);
141 
142     private UnicodeProperties _typeSettingsProperties = null;
143 
144 }