package com.vci.omd.utils; import java.util.ArrayList; import com.vci.corba.omd.data.AttributeValue; import com.vci.corba.omd.data.BusinessObject; import com.vci.corba.omd.data.LinkObject; /** * 获取业务对象或链接对象的属性值信息 * @author VCI_STGK_Lincq * */ public class ObjectTool { /** * 获取业务对象的属性信息 * @param bo * @param attrName * @return */ public static String getBOAttributeValue(BusinessObject bo, String attrName) { for (int i = 0; i < bo.hisAttrValList.length; i++) { if (bo.hisAttrValList[i].attrName.equalsIgnoreCase(attrName)) { return bo.hisAttrValList[i].attrVal; } } return ""; } /** * 获取链接对象的属性信息 * @param lo * @param attrName * @return */ public static String getLOAttributeValue(LinkObject lo, String attrName) { for (int i = 0; i < lo.hisAttrValList.length; i++) { if (lo.hisAttrValList[i].attrName.equalsIgnoreCase(attrName)) { return lo.hisAttrValList[i].attrVal; } } return ""; } /** * 获取业务对象中新设置的属性信息 * @param bo * @param attrName * @return */ public static String getNewBOAttributeValue(BusinessObject bo, String attrName) { for (int i = 0; i < bo.newAttrValList.length; i++) { if (bo.newAttrValList[i].attrName.equalsIgnoreCase(attrName)) { return bo.newAttrValList[i].attrVal; } } return ""; } /** * 获取链接对象的新设置属性信息 * @param lo * @param attrName * @return */ public static String getNewLOAttributeValue(LinkObject lo, String attrName) { for (int i = 0; i < lo.newAttrValList.length; i++) { if (lo.newAttrValList[i].attrName.equalsIgnoreCase(attrName)) { return lo.newAttrValList[i].attrVal; } } return ""; } public static void setBOAttributeValue(BusinessObject businessObject, String attributeName, String attributeValue) { AttributeValue[] attrValues = businessObject.newAttrValList; ArrayList attrValList = new ArrayList(); if (attrValues != null && attrValues.length > 0) { for (AttributeValue attrVal: attrValues) { attrValList.add(attrVal); } } AttributeValue attrVal = null; boolean isExist = false; for (int i = 0; i < attrValList.size(); i++) { attrVal = attrValList.get(i); if (attrVal.attrName.equalsIgnoreCase(attributeName)) { attrVal.attrVal = attributeValue; isExist = true; break; } } if (!isExist) { attrVal = new AttributeValue(); attrVal.attrName = attributeName; attrVal.attrVal = attributeValue; attrValList.add(attrVal); } businessObject.newAttrValList = attrValList.toArray(new AttributeValue[attrValList.size()]); } public static void setLOAttributeValue(LinkObject linkObject, String attributeName, String attributeValue) { AttributeValue[] attrValues = linkObject.newAttrValList; ArrayList attrValList = new ArrayList(); if (attrValues != null && attrValues.length > 0) { for (AttributeValue attrVal: attrValues) { attrValList.add(attrVal); } } AttributeValue attrVal = null; boolean isExist = false; for (int i = 0; i < attrValList.size(); i++) { attrVal = attrValList.get(i); if (attrVal.attrName.equalsIgnoreCase(attributeName)) { attrVal.attrVal = attributeValue; isExist = true; break; } } if (!isExist) { attrVal = new AttributeValue(); attrVal.attrName = attributeName; attrVal.attrVal = attributeValue; attrValList.add(attrVal); } linkObject.newAttrValList = attrValList.toArray(new AttributeValue[attrValList.size()]); } public static void setLOFromBO(LinkObject lo, BusinessObject fromBo) { lo.fromOid = fromBo.oid; lo.fromRevOid = fromBo.revisionid; lo.fromNameOid = fromBo.nameoid; lo.fromBTName = fromBo.btName; } public static void setLOToBO(LinkObject lo, BusinessObject toBo) { lo.toOid = toBo.oid; lo.toRevOid = toBo.revisionid; lo.toNameOid = toBo.nameoid; lo.toBTName = toBo.btName; } /** * 设置业务对象的历史属性值 * @param bo * @param attrName * @param attrVal */ public static void setHisBOAttributeValue(BusinessObject bo, String attrName, String attrVal) { if (attrVal == null) { attrVal = ""; } for (int i = 0; i < bo.hisAttrValList.length; i++) { if (bo.hisAttrValList[i].attrName.equalsIgnoreCase(attrName)) { bo.hisAttrValList[i].attrVal = attrVal; return; } } } /** * 设置链接对象的历史属性值 * @param lo * @param attrName * @param attrVal */ public static void setLOHisAttributeValue(LinkObject lo, String attrName, String attrVal) { if (attrVal == null) { attrVal = ""; } for (int i = 0; i < lo.hisAttrValList.length; i++) { if (lo.hisAttrValList[i].attrName.equalsIgnoreCase(attrName)) { lo.hisAttrValList[i].attrVal = attrVal; } } } }