/**
* clone
* @param List:
* @return
*/
public static List cloneList(List inList) throws PsSystemException{
List outList = null;
try{
outList = (List)inList.getClass().newInstance();
Method[] methods = null;
if(inList.size() > 0){
methods = inList.get(0).getClass().getMethods();
}else{
return outList;
}
for(int i = 0 ; i < inList.size() ; i ++){
Object outObj = inList.get(0).getClass().newInstance();
for(int j = 0 ; j < methods.length ; j ++){
if(methods[j].getName().indexOf("get") > -1){
try{
Method setMethod = inList.get(i).getClass().getMethod("set" + methods[j].getName().substring(3), new Class[]{methods[j].getReturnType()});
boolean isAList = false;
Class[] returnInterfaces = methods[j].getReturnType().getInterfaces();
for(int k = 0; k < returnInterfaces.length ; k ++){
if("java.util.List".equals(returnInterfaces[k].getName())){
isAList = true;
break;
}
}
if(isAList){
setMethod.invoke(outObj, new Object[]{ cloneList((List)methods[j].invoke(inList.get(i), null))});
}else if((methods[j].getReturnType().getSuperclass() == null ||
methods[j].getReturnType().getPackage().getName().indexOf("java") > -1)){
setMethod.invoke(outObj, new Object[]{ methods[j].invoke(inList.get(i), null)});
}else{
setMethod.invoke(outObj, new Object[]{ copyObject(methods[j].invoke(inList.get(i), null),methods[j].getReturnType())});
}
}catch (NoSuchMethodException e) {
continue;
}
catch (InvocationTargetException e) {
continue;
}
}
}
outList.add(outObj);
}
}catch (IllegalAccessException e) {
throw new PsSystemException("");
}catch (InstantiationException e) {
throw new PsSystemException("");
}
return outList;
}
* clone
* @param List:
* @return
*/
public static List cloneList(List inList) throws PsSystemException{
List outList = null;
try{
outList = (List)inList.getClass().newInstance();
Method[] methods = null;
if(inList.size() > 0){
methods = inList.get(0).getClass().getMethods();
}else{
return outList;
}
for(int i = 0 ; i < inList.size() ; i ++){
Object outObj = inList.get(0).getClass().newInstance();
for(int j = 0 ; j < methods.length ; j ++){
if(methods[j].getName().indexOf("get") > -1){
try{
Method setMethod = inList.get(i).getClass().getMethod("set" + methods[j].getName().substring(3), new Class[]{methods[j].getReturnType()});
boolean isAList = false;
Class[] returnInterfaces = methods[j].getReturnType().getInterfaces();
for(int k = 0; k < returnInterfaces.length ; k ++){
if("java.util.List".equals(returnInterfaces[k].getName())){
isAList = true;
break;
}
}
if(isAList){
setMethod.invoke(outObj, new Object[]{ cloneList((List)methods[j].invoke(inList.get(i), null))});
}else if((methods[j].getReturnType().getSuperclass() == null ||
methods[j].getReturnType().getPackage().getName().indexOf("java") > -1)){
setMethod.invoke(outObj, new Object[]{ methods[j].invoke(inList.get(i), null)});
}else{
setMethod.invoke(outObj, new Object[]{ copyObject(methods[j].invoke(inList.get(i), null),methods[j].getReturnType())});
}
}catch (NoSuchMethodException e) {
continue;
}
catch (InvocationTargetException e) {
continue;
}
}
}
outList.add(outObj);
}
}catch (IllegalAccessException e) {
throw new PsSystemException("");
}catch (InstantiationException e) {
throw new PsSystemException("");
}
return outList;
}