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  public class ExpandoColumnImpl
42      extends ExpandoColumnModelImpl implements ExpandoColumn {
43  
44      public ExpandoColumnImpl() {
45      }
46  
47      public Serializable getDefaultValue() {
48          try {
49              ExpandoValue value = new ExpandoValueImpl();
50  
51              value.setColumnId(getColumnId());
52              value.setData(getDefaultData());
53  
54              int type = getType();
55  
56              if (type == ExpandoColumnConstants.BOOLEAN) {
57                  return value.getBoolean();
58              }
59              else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
60                  return value.getBooleanArray();
61              }
62              else if (type == ExpandoColumnConstants.DATE) {
63                  return value.getDate();
64              }
65              else if (type == ExpandoColumnConstants.DATE_ARRAY) {
66                  return value.getDateArray();
67              }
68              else if (type == ExpandoColumnConstants.DOUBLE) {
69                  return value.getDouble();
70              }
71              else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
72                  return value.getDoubleArray();
73              }
74              else if (type == ExpandoColumnConstants.FLOAT) {
75                  return value.getFloat();
76              }
77              else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
78                  return value.getFloatArray();
79              }
80              else if (type == ExpandoColumnConstants.INTEGER) {
81                  return value.getInteger();
82              }
83              else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
84                  return value.getIntegerArray();
85              }
86              else if (type == ExpandoColumnConstants.LONG) {
87                  return value.getLong();
88              }
89              else if (type == ExpandoColumnConstants.LONG_ARRAY) {
90                  return value.getLongArray();
91              }
92              else if (type == ExpandoColumnConstants.SHORT) {
93                  return value.getShort();
94              }
95              else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
96                  return value.getShortArray();
97              }
98              else if (type == ExpandoColumnConstants.STRING_ARRAY) {
99                  return value.getStringArray();
100             }
101             else {
102                 return value.getString();
103             }
104         }
105         catch (Exception e) {
106             return null;
107         }
108     }
109 
110     public String getTypeSettings() {
111         if (_typeSettingsProperties == null) {
112             return super.getTypeSettings();
113         }
114         else {
115             return _typeSettingsProperties.toString();
116         }
117     }
118 
119     public UnicodeProperties getTypeSettingsProperties() {
120         if (_typeSettingsProperties == null) {
121             _typeSettingsProperties = new UnicodeProperties(true);
122 
123             try {
124                 _typeSettingsProperties.load(super.getTypeSettings());
125             }
126             catch (IOException ioe) {
127                 _log.error(ioe, ioe);
128             }
129         }
130 
131         return _typeSettingsProperties;
132     }
133 
134     public void setTypeSettings(String typeSettings) {
135         _typeSettingsProperties = null;
136 
137         super.setTypeSettings(typeSettings);
138     }
139 
140     public void setTypeSettingsProperties(
141         UnicodeProperties typeSettingsProperties) {
142 
143         _typeSettingsProperties = typeSettingsProperties;
144 
145         super.setTypeSettings(_typeSettingsProperties.toString());
146     }
147 
148     private static Log _log = LogFactoryUtil.getLog(ExpandoColumnImpl.class);
149 
150     private UnicodeProperties _typeSettingsProperties = null;
151 
152 }