package com.vci.server.bof.objects; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import com.vci.corba.omd.data.AttributeValue; import com.vci.corba.omd.data.LinkObject; import com.vci.omd.constants.LinkConstants; import com.vci.server.bof.utils.ServerObjectUtil; public class ServerLinkObject { private String oid; private String creator; private long createTime; private String lastModifier; private long lastModifyTime; private String f_Oid; private String f_RevisionOid; private String f_NameOid; private String f_BtwName; private String t_Oid; private String t_RevisionOid; private String t_NameOid; private String t_BtwName; private long ts; private LinkObject linkObject; public ServerLinkObject() { linkObject = new LinkObject(); } public String getOid() { return oid; } public String getCreator() { return creator; } public long getCreateTime() { return createTime; } public String getLastModifier() { return lastModifier; } public long getLastModifyTime() { return lastModifyTime; } public String getF_Oid() { return f_Oid; } public String getF_RevisionOid() { return f_RevisionOid; } public String getF_NameOid() { return f_NameOid; } public String getF_BtwName() { return f_BtwName; } public String getT_Oid() { return t_Oid; } public String getT_RevisionOid() { return t_RevisionOid; } public String getT_NameOid() { return t_NameOid; } public String getT_BtwName() { return t_BtwName; } public long getTs() { return ts; } public LinkObject getLinkObject() { dealLinkObjectNullValue(); return linkObject; } public void setOid(String oid) { this.oid = oid; this.linkObject.oid = oid; } public void setCreator(String creator) { this.creator = creator; this.linkObject.creator = creator; } public void setCreateTime(long createTime) { this.createTime = createTime; this.linkObject.createTime = createTime; } public void setLastModifier(String lastModifier) { this.lastModifier = lastModifier; this.linkObject.modifier = lastModifier; } public void setLastModifyTime(long lastModifyTime) { this.lastModifyTime = lastModifyTime; this.linkObject.modifyTime = lastModifyTime; } public void setF_Oid(String f_Oid) { this.f_Oid = f_Oid; this.linkObject.fromOid = f_Oid; } public void setF_RevisionOid(String f_RevisionOid) { this.f_RevisionOid = f_RevisionOid; this.linkObject.fromRevOid = f_RevisionOid; } public void setF_NameOid(String f_NameOid) { this.f_NameOid = f_NameOid; this.linkObject.fromNameOid = f_NameOid; } public void setF_BtwName(String f_BtwName) { this.f_BtwName = f_BtwName; this.linkObject.fromBTName = f_BtwName; } public void setT_Oid(String t_Oid) { this.t_Oid = t_Oid; this.linkObject.toOid = t_Oid; } public void setT_RevisionOid(String t_RevisionOid) { this.t_RevisionOid = t_RevisionOid; this.linkObject.toRevOid = t_RevisionOid; } public void setT_NameOid(String t_NameOid) { this.t_NameOid = t_NameOid; this.linkObject.toNameOid = t_NameOid; } public void setT_BtwName(String t_BtwName) { this.t_BtwName = t_BtwName; this.linkObject.toBTName = t_BtwName; } public void setTs(long ts) { this.ts = ts; this.linkObject.ts = ts; } public void setLinkObject(LinkObject linkObject) { this.linkObject = linkObject; } private void dealLinkObjectNullValue() { this.linkObject.newAttrValList = this.linkObject.newAttrValList == null ? new AttributeValue[0] : this.linkObject.newAttrValList; this.linkObject.hisAttrValList = this.linkObject.hisAttrValList == null ? new AttributeValue[0] : this.linkObject.hisAttrValList; } public void setAttributeValue(String attributeName, String attrType, Object attributeValue) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { if (LinkConstants.LO_CONSTANTS.containsKey(attributeName)) { dealWithSystemAttributeValue(attributeName, attributeValue); attrType = LinkConstants.LO_CONSTANTS.get(attributeName); } dealWithLOAttributeValue(attributeName, attrType, attributeValue); } private void dealWithSystemAttributeValue(String attributeName, Object attributeValue) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { String changeValue = ServerObjectUtil.getInstance().tansferSystemDBDateToString(LinkConstants.LO_CONSTANTS, attributeName, attributeValue); Field[] fields=ServerLinkObject.class.getDeclaredFields(); for (Field field : fields) { String fieldName = field.getName(); if (!fieldName.toUpperCase().equals(attributeName.toUpperCase())) { continue; } //将属性名首字母转换成大写字母 String firstLetter = fieldName.substring(0, 1).toUpperCase(); String setMethodName = "set" + firstLetter + fieldName.substring(1); Method setMethod = ServerLinkObject.class.getMethod(setMethodName, new Class[]{changeValue.getClass()}); setMethod.invoke(this, new Object[]{changeValue}); break; } } private void dealWithLOAttributeValue(String attributeName, String attrType, Object attributeValue) { String changeValue = ServerObjectUtil.getInstance().tansferTypeDBDateToString(attrType, attributeValue); AttributeValue[] attrValues = linkObject.hisAttrValList; 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.toUpperCase().equals(attributeName.toUpperCase())) { attrVal.attrVal = changeValue; isExist = true; break; } } if (!isExist) { attrVal = new AttributeValue(); attrVal.attrName = attributeName.toUpperCase(); attrVal.attrVal = changeValue; attrValList.add(attrVal); } linkObject.hisAttrValList = attrValList.toArray(new AttributeValue[attrValList.size()]); } public String[] getQueryColumnAccordingToSQL(String sql, String start, String end) { sql = sql.toUpperCase(); sql = sql.substring(start.length()); sql = sql.substring(0, sql.indexOf(end)); sql = sql.replaceAll(" ", ""); return sql.split(","); } }