001: /*
002: *
003: * Copyright (c) 2004 SourceTap - www.sourcetap.com
004: *
005: * The contents of this file are subject to the SourceTap Public License
006: * ("License"); You may not use this file except in compliance with the
007: * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010: * the specific language governing rights and limitations under the License.
011: *
012: * The above copyright notice and this permission notice shall be included
013: * in all copies or substantial portions of the Software.
014: *
015: */
016:
017: package com.sourcetap.sfa.ui;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import org.ofbiz.base.util.UtilTimer;
025: import org.ofbiz.entity.GenericDelegator;
026: import org.ofbiz.entity.GenericEntityException;
027: import org.ofbiz.entity.GenericValue;
028: import org.ofbiz.entity.model.ModelEntity;
029:
030: /**
031: * DOCUMENT ME!
032: *
033: */
034: public class UIEntity {
035: public static final String module = UIEntity.class.getName();
036: private static final boolean TIMER = false;
037: protected String entityId = "";
038: protected String entityName = "";
039: protected String tableName = "";
040: protected String description = "";
041: protected String extTableName = "";
042: protected ModelEntity modelEntity = null;
043: protected List primaryKeyFieldNames = null;
044: protected GenericValue genericValue = null;
045: protected ArrayList uiAttributeList = new ArrayList();
046:
047: public UIEntity(GenericValue uiEntityGV,
048: GenericDelegator delegator, UICache uiCache)
049: throws GenericEntityException {
050: UtilTimer timer = new UtilTimer();
051:
052: if (TIMER) {
053: timer.timerString(5, "[UIEntity.UIEntity] Start");
054: }
055:
056: setGenericValue(uiEntityGV);
057:
058: // setDelegator(delegator);
059: setEntityId(uiEntityGV.getString("entityId"));
060: setEntityName(uiEntityGV.getString("entityName"));
061: setTableName(uiEntityGV.getString("tableName"));
062: setDescription(uiEntityGV.getString("description"));
063: setExtTableName(uiEntityGV.getString("extTableName"));
064:
065: if (TIMER) {
066: timer
067: .timerString(5,
068: "[UIEntity.UIEntity] Finished setting UI entity attributes");
069: }
070:
071: setModelEntity(delegator.getModelEntity(getEntityName()));
072: setPrimaryKeyFieldNames(getModelEntity().getPkFieldNames());
073:
074: if (TIMER) {
075: timer
076: .timerString(5,
077: "[UIEntity.UIEntity] Finished setting model entity");
078: }
079:
080: // Get info about the UI Attributes.
081: HashMap findMap = new HashMap();
082: findMap.put("entityId", getEntityId());
083:
084: List uiAttributeL = delegator.findByAnd("UiAttribute", findMap,
085: null);
086:
087: if (TIMER) {
088: timer
089: .timerString(5,
090: "[UIEntity.UIEntity] Finished finding UI attributes");
091: }
092:
093: Iterator uiAttributeI = uiAttributeL.iterator();
094:
095: while (uiAttributeI.hasNext()) {
096: // Get the UIAttribute object for this attribute.
097: GenericValue uiAttributeGV = (GenericValue) uiAttributeI
098: .next();
099: String attributeId = uiAttributeGV.getString("attributeId");
100:
101: if (TIMER) {
102: timer
103: .timerString(5,
104: "[UIEntity.UIEntity] Looking for UIAttribute in cache.");
105: }
106:
107: UIAttribute uiAttribute = uiCache
108: .getUiAttribute(attributeId);
109:
110: if (uiAttribute == null) {
111: if (TIMER) {
112: timer
113: .timerString(5,
114: "[UIEntity.UIEntity] UIAttribute not found in cache. Creating a new one.");
115: }
116:
117: uiAttribute = new UIAttribute(uiAttributeGV, delegator,
118: this );
119: uiCache.putUiAttribute(attributeId, uiAttribute);
120: } else {
121: if (TIMER) {
122: timer
123: .timerString(5,
124: "[UIEntity.UIEntity] Found UIAttribute in cache.");
125: }
126: }
127:
128: getUiAttributeList().add(uiAttribute);
129: }
130:
131: if (TIMER) {
132: timer.timerString(5, "[UIEntity.UIEntity] End");
133: }
134:
135: }
136:
137: /**
138: * DOCUMENT ME!
139: *
140: * @param entityId_
141: */
142: public void setEntityId(String entityId_) {
143: entityId = (entityId_ == null) ? "" : entityId_;
144: }
145:
146: /**
147: * DOCUMENT ME!
148: *
149: * @return
150: */
151: public String getEntityId() {
152: return entityId;
153: }
154:
155: /**
156: * DOCUMENT ME!
157: *
158: * @param entityName_
159: */
160: public void setEntityName(String entityName_) {
161: entityName = (entityName_ == null) ? "" : entityName_;
162: }
163:
164: /**
165: * DOCUMENT ME!
166: *
167: * @return
168: */
169: public String getEntityName() {
170: return entityName;
171: }
172:
173: /**
174: * DOCUMENT ME!
175: *
176: * @param tableName_
177: */
178: public void setTableName(String tableName_) {
179: tableName = (tableName_ == null) ? "" : tableName_;
180: }
181:
182: /**
183: * DOCUMENT ME!
184: *
185: * @return
186: */
187: public String getTableName() {
188: return tableName;
189: }
190:
191: /**
192: * DOCUMENT ME!
193: *
194: * @param description_
195: */
196: public void setDescription(String description_) {
197: description = (description_ == null) ? "" : description_;
198: }
199:
200: /**
201: * DOCUMENT ME!
202: *
203: * @return
204: */
205: public String getDescription() {
206: return description;
207: }
208:
209: /**
210: * DOCUMENT ME!
211: *
212: * @param extTableName_
213: */
214: public void setExtTableName(String extTableName_) {
215: extTableName = (extTableName_ == null) ? "" : extTableName_;
216: }
217:
218: /**
219: * DOCUMENT ME!
220: *
221: * @return
222: */
223: public String getExtTableName() {
224: return extTableName;
225: }
226:
227: /**
228: * DOCUMENT ME!
229: *
230: * @param modelEntity_
231: */
232: public void setModelEntity(ModelEntity modelEntity_) {
233: modelEntity = modelEntity_;
234: }
235:
236: /**
237: * DOCUMENT ME!
238: *
239: * @return
240: */
241: public ModelEntity getModelEntity() {
242: return modelEntity;
243: }
244:
245: /**
246: * DOCUMENT ME!
247: *
248: * @param primaryKeyFieldNames_
249: */
250: public void setPrimaryKeyFieldNames(List primaryKeyFieldNames_) {
251: primaryKeyFieldNames = primaryKeyFieldNames_;
252: }
253:
254: /**
255: * DOCUMENT ME!
256: *
257: * @return
258: */
259: public List getPrimaryKeyFieldNames() {
260: return primaryKeyFieldNames;
261: }
262:
263: // public GenericDelegator getDelegator() {
264: // return delegator;
265: // }
266: // public void setDelegator(GenericDelegator delegator_) {
267: // delegator = delegator_;
268: // }
269: public void setGenericValue(GenericValue genericValue_) {
270: genericValue = genericValue_;
271: }
272:
273: /**
274: * DOCUMENT ME!
275: *
276: * @return
277: */
278: public GenericValue getGenericValue() {
279: return genericValue;
280: }
281:
282: // public void setUiAttributeList(List uiAttributeList_) {
283: // uiAttributeList = uiAttributeList_;
284: // }
285: public ArrayList getUiAttributeList() {
286: return uiAttributeList;
287: }
288:
289: /**
290: * DOCUMENT ME!
291: *
292: * @param attributeNumber
293: *
294: * @return
295: */
296: public UIAttribute getUiAttribute(int attributeNumber) {
297: return (UIAttribute) uiAttributeList.get(attributeNumber);
298: }
299: }
|