001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.tools.servicebuilder;
022:
023: import com.liferay.portal.kernel.util.GetterUtil;
024: import com.liferay.portal.kernel.util.Validator;
025: import com.liferay.util.TextFormatter;
026:
027: import java.util.List;
028:
029: /**
030: * <a href="Entity.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class Entity {
036:
037: public static EntityColumn getColumn(String name, List columnList) {
038: int pos = columnList.indexOf(new EntityColumn(name));
039:
040: if (pos == -1) {
041: throw new RuntimeException("Column " + name + " not found");
042: }
043:
044: return (EntityColumn) columnList.get(pos);
045: }
046:
047: public Entity(String name) {
048: this (null, null, null, name, null, false, false, true, null,
049: null, null, null, null, null, null, null, null, null,
050: null, null, null);
051: }
052:
053: public Entity(String packagePath, String portletName,
054: String portletShortName, String name, String table,
055: boolean uuid, boolean localService, boolean remoteService,
056: String persistenceClass, String finderClass,
057: String dataSource, String sessionFactory, String txManager,
058: List pkList, List regularColList, List collectionList,
059: List columnList, EntityOrder order, List finderList,
060: List referenceList, List txRequiredList) {
061:
062: _packagePath = packagePath;
063: _portletName = portletName;
064: _portletShortName = portletShortName;
065: _name = name;
066: _table = table;
067: _uuid = uuid;
068: _localService = localService;
069: _remoteService = remoteService;
070: _persistenceClass = persistenceClass;
071: _finderClass = finderClass;
072: _dataSource = GetterUtil.getString(dataSource,
073: "liferayDataSource");
074: _sessionFactory = GetterUtil.getString(sessionFactory,
075: "liferaySessionFactory");
076: _txManager = GetterUtil.getString(txManager,
077: "liferayTransactionManager");
078: _pkList = pkList;
079: _regularColList = regularColList;
080: _collectionList = collectionList;
081: _columnList = columnList;
082: _order = order;
083: _finderList = finderList;
084: _referenceList = referenceList;
085: _txRequiredList = txRequiredList;
086: }
087:
088: public String getPackagePath() {
089: return _packagePath;
090: }
091:
092: public String getPortletName() {
093: return _portletName;
094: }
095:
096: public String getPortletShortName() {
097: return _portletShortName;
098: }
099:
100: public String getName() {
101: return _name;
102: }
103:
104: public String getNames() {
105: return TextFormatter.formatPlural(new String(_name));
106: }
107:
108: public String getVarName() {
109: return TextFormatter.format(_name, TextFormatter.I);
110: }
111:
112: public String getVarNames() {
113: return TextFormatter.formatPlural(new String(getVarName()));
114: }
115:
116: public String getTable() {
117: return _table;
118: }
119:
120: public boolean hasUuid() {
121: return _uuid;
122: }
123:
124: public boolean hasLocalService() {
125: return _localService;
126: }
127:
128: public boolean hasRemoteService() {
129: return _remoteService;
130: }
131:
132: public String getPersistenceClass() {
133: return _persistenceClass;
134: }
135:
136: public String getFinderClass() {
137: return _finderClass;
138: }
139:
140: public boolean hasFinderClass() {
141: if (Validator.isNull(_finderClass)) {
142: return false;
143: } else {
144: return true;
145: }
146: }
147:
148: public String getDataSource() {
149: return _dataSource;
150: }
151:
152: public String getSessionFactory() {
153: return _sessionFactory;
154: }
155:
156: public String getTXManager() {
157: return _txManager;
158: }
159:
160: public String getPKClassName() {
161: if (hasCompoundPK()) {
162: return _name + "PK";
163: } else {
164: EntityColumn col = (EntityColumn) _pkList.get(0);
165:
166: return col.getType();
167: }
168: }
169:
170: public String getPKVarName() {
171: if (hasCompoundPK()) {
172: return getVarName() + "PK";
173: } else {
174: EntityColumn col = (EntityColumn) _pkList.get(0);
175:
176: return col.getName();
177: }
178: }
179:
180: public boolean hasPrimitivePK() {
181: if (hasCompoundPK()) {
182: return false;
183: } else {
184: EntityColumn col = (EntityColumn) _pkList.get(0);
185:
186: if (col.isPrimitiveType()) {
187: return true;
188: } else {
189: return false;
190: }
191: }
192: }
193:
194: public boolean hasCompoundPK() {
195: if (_pkList.size() > 1) {
196: return true;
197: } else {
198: return false;
199: }
200: }
201:
202: public List getPKList() {
203: return _pkList;
204: }
205:
206: public List getRegularColList() {
207: return _regularColList;
208: }
209:
210: public List getCollectionList() {
211: return _collectionList;
212: }
213:
214: public List getColumnList() {
215: return _columnList;
216: }
217:
218: public boolean hasColumns() {
219: if ((_columnList == null) || (_columnList.size() == 0)) {
220: return false;
221: } else {
222: return true;
223: }
224: }
225:
226: public EntityOrder getOrder() {
227: return _order;
228: }
229:
230: public boolean isOrdered() {
231: if (_order != null) {
232: return true;
233: } else {
234: return false;
235: }
236: }
237:
238: public List getFinderList() {
239: return _finderList;
240: }
241:
242: public List getReferenceList() {
243: return _referenceList;
244: }
245:
246: public List getTxRequiredList() {
247: return _txRequiredList;
248: }
249:
250: public EntityColumn getColumn(String name) {
251: return getColumn(name, _columnList);
252: }
253:
254: public EntityColumn getColumnByMappingTable(String mappingTable) {
255: for (int i = 0; i < _columnList.size(); i++) {
256: EntityColumn col = (EntityColumn) _columnList.get(i);
257:
258: if (col.getMappingTable() != null
259: && col.getMappingTable().equals(mappingTable)) {
260:
261: return col;
262: }
263: }
264:
265: return null;
266: }
267:
268: public boolean equals(Object obj) {
269: Entity entity = (Entity) obj;
270:
271: String name = entity.getName();
272:
273: if (_name.equals(name)) {
274: return true;
275: } else {
276: return false;
277: }
278: }
279:
280: private String _packagePath;
281: private String _portletName;
282: private String _portletShortName;
283: private String _name;
284: private String _table;
285: private boolean _uuid;
286: private boolean _localService;
287: private boolean _remoteService;
288: private String _persistenceClass;
289: private String _finderClass;
290: private String _dataSource;
291: private String _sessionFactory;
292: private String _txManager;
293: private List _pkList;
294: private List _regularColList;
295: private List _collectionList;
296: private List _columnList;
297: private EntityOrder _order;
298: private List _finderList;
299: private List _referenceList;
300: private List _txRequiredList;
301:
302: }
|