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的更多相关文章
随机推荐
- Qt之自定义搜索框
简述 关于搜索框,大家都经常接触.例如:浏览器搜索.Windows资源管理器搜索等. 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定. 方案一:调用QLineEdit现有接口 void ...
- ASP.NET MVC+EasyUI+Entity FrameWork 整合开发
本文详细讲解怎么用ASP.NET MVC+EasyUI+Entity FrameWork 来开发一个项目 对于ASP.NET MVC的Jscript库,主要引用 <script type=.mi ...
- LeetCode Reverse Linked List II 反置链表2
题意:将指定的一段位置[m,n]的链表反置,返回链表头. 思路:主要麻烦在链表头,如果要从链表头就开始,比较特殊. 目前用DFS实现,先找到m-1的位置,再找到n+1的位置,中间这段就是否要反置的,交 ...
- PS4破解
1.输入序列号: # 序列号: # 1330-1082-3503-2270-3738-6738# 1330-1776-8671-6289-7706-2916# 1330-1567-6599-8775- ...
- (六) 6.2 Neurons Networks Backpropagation Algorithm
今天得主题是BP算法.大规模的神经网络可以使用batch gradient descent算法求解,也可以使用 stochastic gradient descent 算法,求解的关键问题在于求得每层 ...
- 【英语】Bingo口语笔记(10) - 常见词汇的缩读
- 《Write Optimized B-Trees》读书报告
论文原作者:Goetz Graefe, Microsoft.我读完这篇论文后颇有收获,所以写了一篇论文报告,旨在更精炼准确地阐述论文核心思想. 摘要:论文提出了一种方法,这种方法可以优化B树索引写性能 ...
- 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:2.搭建环境-2.1创建虚拟机
2.1.创建虚拟机 2.1.1. 创建虚拟机节点1 2.1.2. 创建虚拟机节点2 操作如节点1. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境所有链 ...
- Android中弹出输入法界面不影响app界面布局
默认情况下,输入法弹出的时候,原来的view会被挤扁.有些应用不想被挤,它们可以接受被输入法view覆盖在上面.这时候需要在AndroidManifest.xml acitivty里面加上一句: an ...
- myeclipse 打开xml jsp页面慢 有时候会自动退出
Myeclipse默认打开文件的方式是 jsp design,每次双击或者使用Ctrl+Shift+R打开 就会用这个打开 ,太慢了而且多次导致Myeclipse挂掉.可以通过以下的方式转化成你想要的 ...