package com.vci.client.uif.engine.common; import java.text.SimpleDateFormat; import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; import com.vci.client.bof.ClientBusinessObject; import com.vci.client.bof.ClientLinkObject; import com.vci.client.framework.delegate.RightManagementClientDelegate; import com.vci.client.ui.exception.VCIException; import com.vci.corba.omd.data.AttributeValue; import com.vci.corba.omd.data.BusinessObject; import com.vci.corba.omd.data.LinkObject; public class CBOHelper { /** * 根据传入的DataNode获取其上bo对象的OID * @return */ public static String getBusinessObjectOid(IDataNode dataNode) { String boOid = ""; if (dataNode.getMaterObject() instanceof ClientBusinessObject) { boOid = ((ClientBusinessObject)dataNode.getMaterObject()).getOid(); } else if (dataNode.getMaterObject() instanceof ClientLinkObject) { if (dataNode.isForward()) { boOid = dataNode.getValueMap().get("t_oid"); } else { boOid = dataNode.getValueMap().get("f_oid"); } } else if (dataNode.getMaterObject() instanceof String) { return (String) dataNode.getMaterObject(); } return boOid; } public static String getLinkObjectOid(IDataNode dataNode) { String loOid = ""; if (dataNode.getMaterObject() instanceof ClientLinkObject) { loOid = dataNode.getValueMap().get("oid"); } return loOid; } /** * 根据传入的DataNode获取其上bo对象的type * @return */ public static String getBusinessObjectType(IDataNode dataNode) { String boType = ""; if (dataNode.getMaterObject() instanceof ClientBusinessObject) { boType = ((ClientBusinessObject)dataNode.getMaterObject()).getBtmName(); } else if (dataNode.getMaterObject() instanceof ClientLinkObject) { if (dataNode.isForward()) { boType = ((ClientLinkObject)dataNode.getMaterObject()).getToBTMName(); } else { boType = ((ClientLinkObject)dataNode.getMaterObject()).getFromBTMName(); } } return boType; } public static Map[] getLOValueMap(LinkObject[] los){ @SuppressWarnings("unchecked") Map[] res = new LinkedHashMap[los.length]; for (int i = 0; i < res.length; i++) { res[i] = getLOValueMap(los[i]); } return res; } public static Map getLOValueMap(LinkObject lo){ Map res = new LinkedHashMap(); for(AttributeValue av : lo.hisAttrValList){ res.put(av.attrName.toLowerCase(), av.attrVal); } return res; } public static Map[] getBOValueMap(BusinessObject[] bos){ @SuppressWarnings("unchecked") Map[] res = new LinkedHashMap[bos.length]; for (int i = 0; i < res.length; i++) { res[i] = getBOValueMap(bos[i]); } return res; } public static Map getBOValueMap(BusinessObject bo){ Map res = new LinkedHashMap(); for(AttributeValue av : bo.hisAttrValList){ res.put(av.attrName.toLowerCase(), av.attrVal); } return res; } /** * 返回服务器端的日期 yyyy-MM-dd * @return */ public static String getDBDateString(){ return getDBDateTimeString("yyyy-MM-dd"); } public static String getDBTimeString(String format){ return getDBDateTimeString("hh:mm:ss"); } /** * 返回服务器端时间字符串 * @param dateFormat 日期&时间格式字符串 yyyy-MM-dd * @return */ private static String getDBDateTimeString(String format){ String res = ""; try { long time = new RightManagementClientDelegate().getSystemTime(); SimpleDateFormat sdf = new SimpleDateFormat(format); res = sdf.format(new Date(time)); } catch (VCIException e) { // TODO Auto-generated catch block e.printStackTrace(); } return res; } }