001    /**
002     * Copyright (c) 2000-2010 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.portal.tools.servicebuilder;
016    
017    import com.liferay.portal.kernel.util.Validator;
018    import com.liferay.util.TextFormatter;
019    
020    /**
021     * @author Brian Wing Shun Chan
022     * @author Charles May
023     */
024    public class EntityColumn implements Cloneable {
025    
026            public EntityColumn(String name) {
027                    this(
028                            name, null, null, false, false, null, null, null, true, true, null,
029                            null, null, null, true, false);
030            }
031    
032            public EntityColumn(
033                    String name, String dbName, String type, boolean primary,
034                    boolean filterPrimary, String ejbName, String mappingKey,
035                    String mappingTable, boolean caseSensitive, boolean orderByAscending,
036                    String comparator, String arrayableOperator, String idType,
037                    String idParam, boolean convertNull, boolean localized) {
038    
039                    _name = name;
040                    _dbName = dbName;
041                    _type = type;
042                    _primary = primary;
043                    _filterPrimary = filterPrimary;
044                    _methodName = TextFormatter.format(name, TextFormatter.G);
045                    _ejbName = ejbName;
046                    _mappingKey = mappingKey;
047                    _mappingTable = mappingTable;
048                    _caseSensitive = caseSensitive;
049                    _orderByAscending = orderByAscending;
050                    _comparator = comparator;
051                    _arrayableOperator = arrayableOperator;
052                    _idType = idType;
053                    _idParam = idParam;
054                    _convertNull = convertNull;
055                    _localized = localized;
056            }
057    
058            public EntityColumn(
059                    String name, String dbName, String type, boolean primary,
060                    boolean filterPrimary, String ejbName, String mappingKey,
061                    String mappingTable, String idType, String idParam, boolean convertNull,
062                    boolean localized) {
063    
064                    this(
065                            name, dbName, type, primary, filterPrimary, ejbName, mappingKey,
066                            mappingTable, true, true, null, null, idType, idParam, convertNull,
067                            localized);
068            }
069    
070            public Object clone() {
071                    return new EntityColumn(
072                            getName(), getDBName(), getType(), isPrimary(), isFilterPrimary(),
073                            getEJBName(), getMappingKey(), getMappingTable(), isCaseSensitive(),
074                            isOrderByAscending(), getComparator(), getArrayableOperator(),
075                            getIdType(), getIdParam(), isConvertNull(), isLocalized());
076            }
077    
078            public boolean equals(Object obj) {
079                    EntityColumn col = (EntityColumn)obj;
080    
081                    String name = col.getName();
082    
083                    if (_name.equals(name)) {
084                            return true;
085                    }
086                    else {
087                            return false;
088                    }
089            }
090    
091            public String getArrayableOperator() {
092                    return _arrayableOperator;
093            }
094    
095            public String getComparator() {
096                    return _comparator;
097            }
098    
099            public String getDBName() {
100                    return _dbName;
101            }
102    
103            public String getEJBName() {
104                    return _ejbName;
105            }
106    
107            public String getIdParam() {
108                    return _idParam;
109            }
110    
111            public String getIdType() {
112                    return _idType;
113            }
114    
115            public String getMappingKey() {
116                    return _mappingKey;
117            }
118    
119            public String getMappingTable() {
120                    return _mappingTable;
121            }
122    
123            public String getMethodName() {
124                    return _methodName;
125            }
126    
127            public String getMethodNames() {
128                    return TextFormatter.formatPlural(new String(_methodName));
129            }
130    
131            public String getMethodUserUuidName() {
132                    return _methodName.substring(0, _methodName.length() - 2) + "Uuid";
133            }
134    
135            public String getName() {
136                    return _name;
137            }
138    
139            public String getNames() {
140                    return TextFormatter.formatPlural(new String(_name));
141            }
142    
143            public String getType() {
144                    return _type;
145            }
146    
147            public String getUserUuidName() {
148                    return _name.substring(0, _name.length() - 2) + "Uuid";
149            }
150    
151            public boolean hasArrayableOperator() {
152                    if (Validator.isNotNull(_arrayableOperator)) {
153                            return true;
154                    }
155                    else {
156                            return false;
157                    }
158            }
159    
160            public int hashCode() {
161                    return _name.hashCode();
162            }
163    
164            public boolean isArrayableAndOperator() {
165                    if (_arrayableOperator.equals("AND")) {
166                            return true;
167                    }
168                    else {
169                            return false;
170                    }
171            }
172    
173            public boolean isCaseSensitive() {
174                    return _caseSensitive;
175            }
176    
177            public boolean isCollection() {
178                    if (_type.equals("Collection")) {
179                            return true;
180                    }
181                    else {
182                            return false;
183                    }
184            }
185    
186            public boolean isConvertNull() {
187                    return _convertNull;
188            }
189    
190            public boolean isFetchFinderPath() {
191                    return _fetchFinderPath;
192            }
193    
194            public boolean isFilterPrimary() {
195                    return _filterPrimary;
196            }
197    
198            public boolean isLocalized() {
199                    return _localized;
200            }
201    
202            public boolean isMappingManyToMany() {
203                    return Validator.isNotNull(_mappingTable);
204            }
205    
206            public boolean isMappingOneToMany() {
207                    return Validator.isNotNull(_mappingKey);
208            }
209    
210            public boolean isOrderByAscending() {
211                    return _orderByAscending;
212            }
213    
214            public boolean isPrimary() {
215                    return _primary;
216            }
217    
218            public boolean isPrimitiveType() {
219                    if (Character.isLowerCase(_type.charAt(0))) {
220                            return true;
221                    }
222                    else if (_type.equals("Boolean")) {
223                            return true;
224                    }
225                    else if (_type.equals("Double")) {
226                            return true;
227                    }
228                    else if (_type.equals("Float")) {
229                            return true;
230                    }
231                    else if (_type.equals("Integer")) {
232                            return true;
233                    }
234                    else if (_type.equals("Long")) {
235                            return true;
236                    }
237                    else if (_type.equals("Short")) {
238                            return true;
239                    }
240                    else {
241                            return false;
242                    }
243            }
244    
245            public boolean isUserUuid() {
246                    if (_type.equals("long") && _methodName.endsWith("UserId")) {
247                            return true;
248                    }
249                    else {
250                            return false;
251                    }
252            }
253    
254            public void setArrayableOperator(String arrayableOperator) {
255                    _arrayableOperator = arrayableOperator.toUpperCase();
256            }
257    
258            public void setCaseSensitive(boolean caseSensitive) {
259                    _caseSensitive = caseSensitive;
260            }
261    
262            public void setComparator(String comparator) {
263                    _comparator = comparator;
264            }
265    
266            public void setConvertNull(boolean convertNull) {
267                    _convertNull = convertNull;
268            }
269    
270            public void setDBName(String dbName) {
271                    _dbName = dbName;
272            }
273    
274            public void setFetchFinderPath(boolean fetchFinderPath) {
275                    _fetchFinderPath = fetchFinderPath;
276            }
277    
278            public void setIdParam(String idParam) {
279                    _idParam = idParam;
280            }
281    
282            public void setIdType(String idType) {
283                    _idType = idType;
284            }
285    
286            public void setLocalized(boolean localized) {
287                    _localized = localized;
288            }
289    
290            public void setOrderByAscending(boolean orderByAscending) {
291                    _orderByAscending = orderByAscending;
292            }
293    
294            private String _arrayableOperator;
295            private boolean _caseSensitive;
296            private String _comparator;
297            private boolean _convertNull;
298            private String _dbName;
299            private String _ejbName;
300            private boolean _fetchFinderPath;
301            private boolean _filterPrimary;
302            private String _idParam;
303            private String _idType;
304            private boolean _localized;
305            private String _mappingKey;
306            private String _mappingTable;
307            private String _methodName;
308            private String _name;
309            private boolean _orderByAscending;
310            private boolean _primary;
311            private String _type;
312    
313    }