/*
*
* Copyright (c) 2004 SourceTap - www.sourcetap.com
*
* The contents of this file are subject to the SourceTap Public License
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*/
package com.sourcetap.sfa.ui;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.ofbiz.base.util.UtilTimer;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.model.ModelEntity;
/**
* DOCUMENT ME!
*
*/
public class UIEntity {
public static final String module = UIEntity.class.getName();
private static final boolean TIMER = false;
protected String entityId = "";
protected String entityName = "";
protected String tableName = "";
protected String description = "";
protected String extTableName = "";
protected ModelEntity modelEntity = null;
protected List primaryKeyFieldNames = null;
protected GenericValue genericValue = null;
protected ArrayList uiAttributeList = new ArrayList();
public UIEntity(GenericValue uiEntityGV, GenericDelegator delegator,
UICache uiCache) throws GenericEntityException {
UtilTimer timer = new UtilTimer();
if (TIMER) {
timer.timerString(5, "[UIEntity.UIEntity] Start");
}
setGenericValue(uiEntityGV);
// setDelegator(delegator);
setEntityId(uiEntityGV.getString("entityId"));
setEntityName(uiEntityGV.getString("entityName"));
setTableName(uiEntityGV.getString("tableName"));
setDescription(uiEntityGV.getString("description"));
setExtTableName(uiEntityGV.getString("extTableName"));
if (TIMER) {
timer.timerString(5,
"[UIEntity.UIEntity] Finished setting UI entity attributes");
}
setModelEntity(delegator.getModelEntity(getEntityName()));
setPrimaryKeyFieldNames(getModelEntity().getPkFieldNames());
if (TIMER) {
timer.timerString(5,
"[UIEntity.UIEntity] Finished setting model entity");
}
// Get info about the UI Attributes.
HashMap findMap = new HashMap();
findMap.put("entityId", getEntityId());
List uiAttributeL = delegator.findByAnd("UiAttribute", findMap, null);
if (TIMER) {
timer.timerString(5,
"[UIEntity.UIEntity] Finished finding UI attributes");
}
Iterator uiAttributeI = uiAttributeL.iterator();
while (uiAttributeI.hasNext()) {
// Get the UIAttribute object for this attribute.
GenericValue uiAttributeGV = (GenericValue) uiAttributeI.next();
String attributeId = uiAttributeGV.getString("attributeId");
if (TIMER) {
timer.timerString(5,
"[UIEntity.UIEntity] Looking for UIAttribute in cache.");
}
UIAttribute uiAttribute = uiCache.getUiAttribute(attributeId);
if (uiAttribute == null) {
if (TIMER) {
timer.timerString(5,
"[UIEntity.UIEntity] UIAttribute not found in cache. Creating a new one.");
}
uiAttribute = new UIAttribute(uiAttributeGV, delegator, this);
uiCache.putUiAttribute(attributeId, uiAttribute);
} else {
if (TIMER) {
timer.timerString(5,
"[UIEntity.UIEntity] Found UIAttribute in cache.");
}
}
getUiAttributeList().add(uiAttribute);
}
if (TIMER) {
timer.timerString(5, "[UIEntity.UIEntity] End");
}
}
/**
* DOCUMENT ME!
*
* @param entityId_
*/
public void setEntityId(String entityId_) {
entityId = (entityId_ == null) ? "" : entityId_;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getEntityId() {
return entityId;
}
/**
* DOCUMENT ME!
*
* @param entityName_
*/
public void setEntityName(String entityName_) {
entityName = (entityName_ == null) ? "" : entityName_;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getEntityName() {
return entityName;
}
/**
* DOCUMENT ME!
*
* @param tableName_
*/
public void setTableName(String tableName_) {
tableName = (tableName_ == null) ? "" : tableName_;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getTableName() {
return tableName;
}
/**
* DOCUMENT ME!
*
* @param description_
*/
public void setDescription(String description_) {
description = (description_ == null) ? "" : description_;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getDescription() {
return description;
}
/**
* DOCUMENT ME!
*
* @param extTableName_
*/
public void setExtTableName(String extTableName_) {
extTableName = (extTableName_ == null) ? "" : extTableName_;
}
/**
* DOCUMENT ME!
*
* @return
*/
public String getExtTableName() {
return extTableName;
}
/**
* DOCUMENT ME!
*
* @param modelEntity_
*/
public void setModelEntity(ModelEntity modelEntity_) {
modelEntity = modelEntity_;
}
/**
* DOCUMENT ME!
*
* @return
*/
public ModelEntity getModelEntity() {
return modelEntity;
}
/**
* DOCUMENT ME!
*
* @param primaryKeyFieldNames_
*/
public void setPrimaryKeyFieldNames(List primaryKeyFieldNames_) {
primaryKeyFieldNames = primaryKeyFieldNames_;
}
/**
* DOCUMENT ME!
*
* @return
*/
public List getPrimaryKeyFieldNames() {
return primaryKeyFieldNames;
}
// public GenericDelegator getDelegator() {
// return delegator;
// }
// public void setDelegator(GenericDelegator delegator_) {
// delegator = delegator_;
// }
public void setGenericValue(GenericValue genericValue_) {
genericValue = genericValue_;
}
/**
* DOCUMENT ME!
*
* @return
*/
public GenericValue getGenericValue() {
return genericValue;
}
// public void setUiAttributeList(List uiAttributeList_) {
// uiAttributeList = uiAttributeList_;
// }
public ArrayList getUiAttributeList() {
return uiAttributeList;
}
/**
* DOCUMENT ME!
*
* @param attributeNumber
*
* @return
*/
public UIAttribute getUiAttribute(int attributeNumber) {
return (UIAttribute) uiAttributeList.get(attributeNumber);
}
}