package com.vci.server.omd.attribpool.delegate; import java.util.List; import java.util.ArrayList; import com.vci.common.exception.VciExceptionTool; import com.vci.common.log.ServerWithLog4j; import com.vci.corba.common.VCIError; import com.vci.corba.omd.atm.AttribItem; import com.vci.server.base.exception.ExceptionLocalHandler; import com.vci.server.cache.OMCacheProvider; import com.vci.server.omd.attribpool.cache.APServerCacheUtil; import com.vci.server.omd.attribpool.service.AttrPoolService; public class AttributeDelegate implements IAPServerDelegate{ private static AttributeDelegate instance; public static AttributeDelegate getInstance() { if (instance == null) { instance = new AttributeDelegate(); } return instance; } protected VCIError getLocalVciError(String key, Throwable e) { VCIError error = new VCIError(key, new String[]{VciExceptionTool.getExceptionStr(e), VciExceptionTool.getExceptionDetail(e)}); VCIError rsError = ExceptionLocalHandler.getInstance().getLocalString(error, "PLMAP"); return rsError; } /** * 查询属性 */ @Override public boolean addAttribItem(AttribItem attribItem) throws VCIError{ try{ boolean success = AttrPoolService.getInstance().addAttribItem(attribItem); if (success) APServerCacheUtil.setAttribute(attribItem); return success; }catch(Throwable e){ //e.printStackTrace(); ServerWithLog4j.logger.error(e); throw getLocalVciError("P0010PLMAP-00001", e); } } /** * 修改属性 */ @Override public boolean modifyAbItem(AttribItem attribItem) throws VCIError{ try{ boolean success = AttrPoolService.getInstance().modifyAbItem(attribItem); if (success) APServerCacheUtil.setAttribute(attribItem); return success; }catch(Throwable e){ ServerWithLog4j.logger.error(e); throw getLocalVciError("P0010PLMAP-00004", e); } } /** * 批量删除属性: abItems */ @Override public boolean deleteAbItems(AttribItem[] abItems) throws VCIError{ try{ boolean success = AttrPoolService.getInstance().deleteAbItems(abItems); if (success) { for (AttribItem ai : abItems) { APServerCacheUtil.delAttribute(ai.name); } } return success; }catch(Throwable e){ ServerWithLog4j.logger.error(e); throw getLocalVciError("P0010PLMAP-00005", e); } } @Override public boolean deleteAbItem(AttribItem att) throws VCIError { try{ boolean success = AttrPoolService.getInstance().deleteAbItem(att); if (success) APServerCacheUtil.delAttribute(att.name); return success; }catch(Throwable e){ ServerWithLog4j.logger.error(e); throw getLocalVciError("P0010BTM-00003", e); } } @Override public AttribItem[] getAttribItems(String filter, int start, int rows) throws VCIError { List attrList = new ArrayList(); AttribItem[] cAttributes = OMCacheProvider.getAttributes(); if(filter != null && !filter.equals("")){ for (AttribItem attr : cAttributes) { if (attr.name.indexOf(filter) >= 0) { attrList.add(attr); } } cAttributes = attrList.toArray(new AttribItem[attrList.size()]); } return cAttributes; } @Override public boolean checkRowIsExists(String name) throws VCIError { //return APServerCacheUtil.getInstance().checkRowIsExists(name); return OMCacheProvider.existAttribute(name); } @Override public AttribItem[] getAttribItemsByNames(String[] attNames) throws VCIError { //return APServerCacheUtil.getInstance().getAttribItemsByNames(attNames); return OMCacheProvider.getAttributes(attNames); } @Override public AttribItem getAttribItemByName(String abName) throws VCIError { //return APServerCacheUtil.getInstance().getAttribItemByName(abName); return OMCacheProvider.getAttribute(abName); } @Override public String getAttribItemDataType(String abName) throws VCIError { //return APServerCacheUtil.getInstance().getAttribItemDataType(abName); AttribItem attr = OMCacheProvider.getAttribute(abName); if (attr == null) return "VTString"; return attr.vtDataType; } @Override public String getAPData() throws VCIError { return ""; } @Override public String[] getAPNamesByEMName(String emName) throws VCIError { List attrNameList = new ArrayList(); AttribItem[] items = OMCacheProvider.getAttributes(); for (AttribItem attr : items) { if (attr.other.indexOf(emName) >= 0) { attrNameList.add(attr.name); } } return attrNameList.toArray(new String[attrNameList.size()]); //return APServerCacheUtil.getAPNamesByEMName(emName); } @Override public AttribItem[] getAttribItemsOutNames(String[] abNameArray, String text) throws VCIError { List abNameList = new ArrayList(); for (String ab : abNameArray) { abNameList.add(ab); } AttribItem[] items = OMCacheProvider.getAttributes(); List attrList = new ArrayList(); for (AttribItem attr : items) { if (attr.name.indexOf(text) >= 0 && !abNameList.contains(attr.name)) { attrList.add(attr); } } return attrList.toArray(new AttribItem[attrList.size()]); //return APServerCacheUtil.getAttribItemsOutNames(abNameArray, text); } public boolean xml2DB(String userName) throws VCIError { return AttrPoolService.getInstance().xml2DB(userName); } }