VoHelper
VoHelper
package com.isoftstone.pcis.policy.core.helper;
import com.isoftstone.fwk.dao.CommonDao;
import com.isoftstone.fwk.service.BusinessServiceException;
import com.isoftstone.fwk.util.BeanTool;
import com.isoftstone.fwk.util.SpringUtils;
import com.isoftstone.pcis.policy.core.exception.VoManipulateException;
import com.isoftstone.pcis.policy.vo.AbstractCvrgVO;
import com.isoftstone.pcis.prod.exception.ProductDefinitionException;
import com.isoftstone.pcis.prod.service.ProdService;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class VoHelper
{
public static String VO_TYPE_APP = "App";
public static String VO_TYPE_PLY = "Ply";
public static String ELEMENT_NAME = "Name";
public static String ELEMENT_CAPTION = "Caption";
public static String ELEMENT_NAME_PRODEF = "CNmeEn";
public static String ELEMENT_CAPTION_PRODEF = "CNmeCn";
private static final Log logger = LogFactory.getLog(VoHelper.class);
private static String voPkg = "com.isoftstone.pcis.policy.vo";
private static String voUdrPkg = "com.isoftstone.pcis.policy.app.underwrite.vo";
public static Class getVoClass(String componentName, String voType) {
String className = voPkg + "." + getVoClassName(componentName, voType);
try {
return Class.forName(className);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}return null;
}
public static Class getAppVoClass(String componentName)
{
String className = voPkg + "." + getAppVoClassName(componentName);
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
logger.error("Class.forName(" + className + ") 出现异常。");
}return null;
}
public static Class getPlyVoClass(String componentName)
{
String className = voPkg + "." + getPlyVoClassName(componentName);
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
logger.error("Class.forName(" + className + ") 出现异常。");
}return null;
}
public static Class getUdrVoClass(String componentName)
{
String className = voUdrPkg + "." + getUdrVoClassName(componentName);
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
logger.error("Class.forName(" + className + ") 出现异常。");
}return null;
}
public static Object createAppEntryVo(String componentName)
{
Class c = getAppVoClass(componentName);
try {
if (c != null) {
return c.newInstance();
}
return null;
} catch (InstantiationException e) {
logger.error(e.getMessage());
return null;
} catch (IllegalAccessException e) {
logger.error(e.getMessage());
}return null;
}
public static Object createPlyEntryVo(String componentName)
{
Class c = getPlyVoClass(componentName);
try {
if (c != null) {
return c.newInstance();
}
return null;
} catch (InstantiationException e) {
logger.error(e.getMessage());
return null;
} catch (IllegalAccessException e) {
logger.error(e.getMessage());
}return null;
}
public static Object createUdrEntryVo(String componentName)
{
Class c = getUdrVoClass(componentName);
try {
if (c != null) {
return c.newInstance();
}
return null;
} catch (InstantiationException e) {
logger.error(e.getMessage());
return null;
} catch (IllegalAccessException e) {
logger.error(e.getMessage());
}return null;
}
public static String getVoClassName(String componentName, String voType)
{
return voType + componentName + "VO";
}
public static String getAppVoClassName(String componentName)
{
return "App" + componentName + "VO";
}
public static String getPlyVoClassName(String componentName)
{
return "Ply" + componentName + "VO";
}
public static String getUdrVoClassName(String componentName)
{
return "Undr" + componentName + "VO";
}
public static String getComponentNameOfVo(Object entry)
{
String[] pathArray = entry.getClass().getName().split("\\.");
String voName = pathArray[(pathArray.length - 1)];
String featureName = null;
if ((voName.matches("^App")) || (!voName.matches("VO$")))
featureName = voName.replaceAll("^App", "").replaceAll("VO$", "");
else if ((voName.matches("^Ply")) || (!voName.matches("VO$"))) {
featureName = voName.replaceAll("^Ply", "").replaceAll("VO$", "");
}
return featureName;
}
public static void serializePlyVo() {
CommonDao dao = (CommonDao)SpringUtils.getSpringBean("commonDao");
}
public static boolean hasPkId(Object vo) throws VoManipulateException
{
try {
Map propertyMap = BeanUtils.describe(vo);
if (propertyMap.containsKey("CPkId")) {
return true;
}
return false;
}
catch (Exception e) {
throw new VoManipulateException("判断vo是否有CPkId字段时出错", e);
}
}
public static String getOrigPkId(Object vo)
throws VoManipulateException
{
try
{
String origRowId = BeanUtils.getProperty(vo, "CRowId");
if (origRowId != null) {
return origRowId;
}
return BeanUtils.getProperty(vo, "CPkId");
}
catch (Exception e)
{
throw new VoManipulateException("获得vo[" + vo.getClass().getName() + "]原始id时出错", e);
}
}
public static Long getSeqNoIgnoreException(Object vo) {
try {
return (Long)PropertyUtils.getProperty(vo, "NSeqNo");
} catch (Exception e) {
logger.warn("忽略获得seqno时出错");
}return null;
}
public static Map<String, Map<String, Object>> compareEntry(Object oldEntry, Object newEntry, Set<String> propSet)
throws VoManipulateException
{
try
{
propSet.remove("class");
Map diffMap = new HashMap();
for (String propName : propSet) {
Object oldValue = PropertyUtils.getProperty(oldEntry, propName);
Object newValue = PropertyUtils.getProperty(newEntry, propName);
if ((oldValue != null) || (newValue != null))
{
if ((oldValue != null) && (newValue != null))
{
if ((oldValue instanceof Date)) {
if (DateUtils.isSameDay((Date)oldValue, (Date)newValue)) {
continue;
}
}
else {
if ((oldValue instanceof Double) ?
Double.compare(((Double)oldValue).doubleValue(), ((Double)newValue).doubleValue()) == 0 :
oldValue.equals(newValue))
{
continue;
}
}
}
Map diff = new HashMap();
diff.put("old", oldValue);
diff.put("new", newValue);
diffMap.put(propName, diff);
}
}
return diffMap;
} catch (Exception e) {
throw new VoManipulateException("比较失败", e);
}
}
public static Map<String, Map<String, Object>> compareEntryEx(Object oldEntry, Object newEntry, Set<String> excludePropSet)
throws VoManipulateException
{
try
{
Map propMap = BeanUtils.describe(oldEntry);
Set propSet = new HashSet();
propSet.addAll((Collection)propMap.keySet());
propSet.removeAll(excludePropSet);
return compareEntry(oldEntry, newEntry, propSet);
} catch (Exception e) {
throw new VoManipulateException("比较失败", e);
}
}
public static Map<String, Map<String, Object>> compareEntry(Object oldEntry, Object newEntry)
throws VoManipulateException
{
try
{
Map propMap = BeanUtils.describe(oldEntry);
Set propSet = new HashSet();
propSet.addAll((Collection)propMap.keySet());
return compareEntry(oldEntry, newEntry, propSet);
} catch (Exception e) {
throw new VoManipulateException("比较失败", e);
}
}
public static List<String> getKeyNameList(String prodNo, String componentName)
throws ProductDefinitionException
{
try
{
ProdService prodService = (ProdService)SpringUtils.getSpringBean("prodService");
return prodService.getProdEleNmeEn(prodNo, componentName);
} catch (BusinessServiceException e) {
throw new ProductDefinitionException("获得保单要素分类关键字异常", e);
}
}
public static List<String> getCoverageKeyNameList(String prodNo, String cvrgNo)
throws ProductDefinitionException
{
try
{
ProdService prodService = (ProdService)SpringUtils.getSpringBean("prodService");
return prodService.getProdEleNmeEn(prodNo, "Cvrg",
cvrgNo);
} catch (BusinessServiceException e) {
throw new ProductDefinitionException("获得保单要素分类关键字异常", e);
}
}
public static List<Map<String, String>> getKeyNameCaptionMapList(String prodNo, String componentName)
throws ProductDefinitionException
{
try
{
ProdService prodService = (ProdService)SpringUtils.getSpringBean("prodService");
List elemNameMapList = prodService.getProdEleNme(prodNo, componentName, null);
List nameLabelMapList = new ArrayList();
for (Map elemNameMap : elemNameMapList) {
String complexName = (String)elemNameMap.get("CNmeEn");
String[] nameSects = complexName.split("\\.");
Map nameLabelMap = new HashMap();
nameLabelMap.put(ELEMENT_NAME_PRODEF, nameSects[1]);
nameLabelMap.put(ELEMENT_CAPTION_PRODEF, (String)elemNameMap.get(ELEMENT_CAPTION_PRODEF));
nameLabelMap.put(ELEMENT_NAME, nameSects[1]);
nameLabelMap.put(ELEMENT_CAPTION, (String)elemNameMap.get(ELEMENT_CAPTION_PRODEF));
nameLabelMapList.add(nameLabelMap);
}
return nameLabelMapList;
} catch (BusinessServiceException e) {
throw new ProductDefinitionException("获得保单要素分类关键字异常", e);
}
}
public static List<Map<String, String>> getCoverageKeyNameCaptionMapList(String prodNo, String cvrgNo)
throws ProductDefinitionException
{
try
{
ProdService prodService = (ProdService)SpringUtils.getSpringBean("prodService");
List elemNameMapList = prodService.getProdEleNme(prodNo,
"Cvrg", cvrgNo);
List nameLabelMapList = new ArrayList();
for (Map elemNameMap : elemNameMapList) {
String complexName = (String)elemNameMap.get("CNmeEn");
String[] nameSects = complexName.split("\\.");
Map nameLabelMap = new HashMap();
nameLabelMap.put(ELEMENT_NAME_PRODEF, nameSects[1]);
nameLabelMap.put(ELEMENT_CAPTION_PRODEF, (String)elemNameMap.get(ELEMENT_CAPTION_PRODEF));
nameLabelMap.put(ELEMENT_NAME, nameSects[1]);
nameLabelMap.put(ELEMENT_CAPTION, (String)elemNameMap.get(ELEMENT_CAPTION_PRODEF));
nameLabelMapList.add(nameLabelMap);
}
return nameLabelMapList;
} catch (BusinessServiceException e) {
throw new ProductDefinitionException("获得保单要素分类关键字异常", e);
}
}
public static String getKeyValueAsStr(Object entry, List<String> keyNameList)
throws VoManipulateException
{
try
{
if ((keyNameList != null) && (!keyNameList.isEmpty())) {
String[] elemValues = new String[keyNameList.size()];
for (int i = 0; i < keyNameList.size(); i++) {
String attrName = ((String)keyNameList.get(i)).substring(
((String)keyNameList.get(i)).indexOf(".") + 1);
String aValue = BeanTool.getAttributeValueAsString(entry, attrName);
elemValues[i] = aValue;
}
return StringUtils.join(elemValues, "-%-");
}
if ((entry instanceof AbstractCvrgVO)) {
return ((AbstractCvrgVO)entry).getCCvrgNo();
}
Long seqNo = getSeqNoIgnoreException(entry);
if (seqNo != null) {
return seqNo.toString();
}
return null;
}
catch (Exception e)
{
throw new VoManipulateException("生成要素关键标识描述时异常", e);
}
}
}
VoHelper的更多相关文章
随机推荐
- core--多线程
WINDOWS是一个多线程操作系统,所谓多线程,就是在同一时间里,有多个线程同时在运行.我们上一遍说到CPU的执行序列是严格按照顺序来执行,怎么能够同一时间来执行很多程序呢?在早期答案是:window ...
- 浅谈网络爬虫爬js动态加载网页(三)
上一篇讨论了web driver对动态网页的抓取与分析,可以很清楚的看出这是一种集中式处理方式,简单说,就是利用服务器,打开一个真正的brower,然后将需要解析的地址交给浏览器,浏览器去解析,然后将 ...
- (转载) jQuery 页面加载初始化的方法有3种
jQuery 页面加载初始化的方法有3种 ,页面在加载的时候都会执行脚本,应该没什么区别,主要看习惯吧,本人觉得第二种方法最好,比较简洁. 第一种: $(document).ready(functio ...
- WEBUS2.0 In Action - 搜索操作指南 - (1)
上一篇:WEBUS2.0 In Action - 索引操作指南(2) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(2) 1. IQueriable中内置的搜索功能 在Webus ...
- 【英语】Bingo口语笔记(80) - 记忆、忘记的表达
- 剑指offer-第三章高质量的代码(输出该链表中倒数第K个节点)
题目:输入一个链表,输出这个链表中倒数第K个节点.(代码的鲁棒性) 思路:用两个指针p1和p2,都指向头节点,开始的时候,p2不动,p1移动k-1次,指向第k个节点.此时,如果p1->next! ...
- 剑指offer—第三章高质量代码(o(1)时间删除链表节点)
题目:给定单向链表的头指针和一个节点指针,定义一个函数在O(1)时间删除该节点,链表节点与函数的定义如下:struct ListNode{int m_nValue;ListNode* m_pValue ...
- RequireJS入门(三)转
这篇来写一个具有依赖的事件模块event.event提供三个方法bind.unbind.trigger来管理DOM元素事件. event依赖于cache模块,cache模块类似于jQuery的$.da ...
- smarty缓存函数
原来在Smarty中在3.0以上版本中不在使用这个clear_all_cache(),而是以$smarty->clearAllCache(); 代替.其中$smarty->clear_ca ...
- UIView动画学习笔记
UIView的动画是通过修改控件的属性来达到动画的效果,如:渐变, 移动. 废话不多说,直接上代码: - (void)loadView{ [super loadView]; _leftView = [ ...