package com.vci.server.bof.histroy; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import com.vci.common.log.ServerWithLog4j; import com.vci.corba.common.VCIError; import com.vci.corba.omd.data.AttributeValue; import com.vci.corba.omd.data.BusinessObject; import com.vci.server.bof.delegate.BOFactoryServerBODelegate; import com.vci.server.bof.delegate.BOFactoryServerDelegate; /** * 操作业务对象历史数据 * @author lmh * */ public class BOHistroyService { /** * 保存修改历史记录的业务类型 */ private static final String BTMNAME = "objecthistoryinfo"; private static BOHistroyService service = null; private BOFactoryServerBODelegate bsb = BOFactoryServerBODelegate.getInstance(); private BOFactoryServerDelegate bsd = BOFactoryServerDelegate.getInstance(); public static BOHistroyService getInstance() { if(service == null) { service = new BOHistroyService(); } return service; } /** * 保存对象的信息到objecthistoryinfo这个业务类型中 * @param bo */ public void saveHistroy(BusinessObject bo) { if(bo != null) { List list = new ArrayList(); list.add(new AttributeValue("hoid",bo.oid)); list.add(new AttributeValue("hrevisionoid",bo.revisionid)); list.add(new AttributeValue("hnameoid",bo.nameoid)); list.add(new AttributeValue("btmtype",bo.btName)); String s = "";; try { s = getString(bo); } catch (Exception e) { //e.printStackTrace(); ServerWithLog4j.logger.error(e); } list.add(new AttributeValue("plhistory", s)); BusinessObject saveBo = null; try { saveBo = bsb.initBusinessObject(BTMNAME); saveBo.newAttrValList = list.toArray(new AttributeValue[0]); bsd.createBusinessObject(saveBo, false, false); } catch (VCIError e1) { e1.printStackTrace(); } } } private String getString(BusinessObject bo) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream ops = new ObjectOutputStream(baos); ops.writeObject(bo); String s = baos.toString("ISO-8859-1"); ops.flush(); ops.close(); baos.close(); return URLEncoder.encode(s,"UTF-8"); } }