/**
*debugObject
* Method for debug the specified Object such as ValueObject, ValueObjectList, ValueObject[] and etc.
* @param Object object
* @param String[] printingFieldList
* @param boolean printClassNameFlag
* @param boolean printSizeFlag
*/
public static void debugObject(Object object
, String[] printingFieldList
, boolean printClassNameFlag
, boolean printSizeFlag) {
try {
if (printClassNameFlag) {
System.out.println("<<<<<<<<<<<<<<< Start debug the specified Object >>>>>>>>>>>>>>>");
}
if (object != null) {
if (object instanceof ValueObjectList) {
ValueObjectList valueObjectList = (ValueObjectList) object;
//System.out.println();
//System.out.println("<========== Start ValueObjectList ==========>");
//System.out.println();
if (printSizeFlag) {
System.out.println("+++ ValueObjectList Size = "+valueObjectList.getList().size()+" +++");
}
for (int j = 0; j < valueObjectList.getList().size(); j++) {
System.out.println("<--------------- Start ValueObjectList["+j+"] --------------->");
ValueObject valueObject = (ValueObject) valueObjectList.getList().get(j);
debugObject(valueObject, printingFieldList, printClassNameFlag , printSizeFlag);
System.out.println("<--------------- End ValueObjectList["+j+"] --------------->");
System.out.println();
}
//System.out.println("<========== End ValueObjectList ==========>");
//System.out.println();
} else if (object instanceof Object[]) {
Object[] objectList = (Object[]) object;
if (printSizeFlag) {
System.out.println("+++ Object[] Size = "+objectList.length+" +++");
}
for (int j = 0; j < objectList.length; j++) {
System.out.println("<--------------- Start Object["+j+"] --------------->");
debugObject(objectList[j], printingFieldList, printClassNameFlag, printSizeFlag);
System.out.println("<--------------- End Object["+j+"] --------------->");
System.out.println();
}
//System.out.println();
//System.out.println("<========== Start Object[] ==========>");
//System.out.println();
//System.out.println("<========== End Object[] ==========>");
//System.out.println();
} else if (object instanceof List) {
List lists = (List) object;
if (printSizeFlag) {
System.out.println("+++ List[] Size = "+lists.size()+" +++");
}
for (int j = 0; j < lists.size(); j++) {
System.out.println("<--------------- Start List["+j+"] --------------->");
debugObject(lists.get(j), printingFieldList, printClassNameFlag, printSizeFlag);
System.out.println("<--------------- End List["+j+"] --------------->");
System.out.println();
}
} else if (object instanceof String) {
System.out.println("String = "+object);
} else if (object instanceof Integer) {
System.out.println("Integer = "+object.toString());
} else if (object instanceof BigDecimal) {
BigDecimal bigDecimal = (BigDecimal) object;
System.out.println("BigDecimal = "+bigDecimal.toString());
} else {
Class dbClass = object.getClass();
Method[] newMethod = dbClass.getMethods();
if (printClassNameFlag) {
System.out.println("*** Class Name = "+dbClass.getName()+" ***");
}
for (int i = 0; i < newMethod.length; i++) {
Method getMethod = newMethod[i];
String getMethodName = getMethod.getName();
if (getMethodName != null) {
if (getMethodName.length() > 3 && getMethodName.startsWith("is")) {
Method subMethod = dbClass.getMethod(getMethodName, null);
Object objectre = subMethod.invoke(object, null);
System.out.println(getMethodName.substring(2)+" = "+objectre);
} else if (getMethodName.length() > 4
&& getMethodName.startsWith("get")
&& !"Class".equals(getMethodName.substring(3))) {
Method subMethod = dbClass.getMethod(getMethodName, null);
Object objectre = subMethod.invoke(object, null);
String fieldName = getMethodName.substring(3);
if (printingFieldList != null && fieldName != null) {
for (String field : printingFieldList) {
if (fieldName.equalsIgnoreCase(field)) {
System.out.println(fieldName+" = "+objectre);
if (objectre instanceof ValueObjectList) {
ValueObjectList voList = (ValueObjectList) objectre;
if (printSizeFlag) {
System.out.println("+++ ValueObjectList Size = "
+voList.getList().size()+" +++");
}
//System.out.println();
//System.out.println("======================= Start Debug Inner ValueObjectList ==================== ");
for (int j = 0; j < voList.getList().size(); j++) {
//System.out.println();
System.out.println("<--- Start "+
getMethodName.substring(3)+"["+j+"] --->");
ValueObject valueObject = (ValueObject) voList.getList().get(j);
debugObject(valueObject, null, false, printSizeFlag);
System.out.println("<--- End "+
getMethodName.substring(3)+"["+j+"] --->");
//System.out.println();
}
//System.out.println("======================= End Debug Inner ValueObjectList ==================== ");
//System.out.println();
} else if (objectre instanceof Object[]) {
Object[] objectList = (Object[]) objectre;
if (printSizeFlag) {
System.out.println("+++ Object[] Size = "+objectList.length+" +++");
}
for (int j = 0; j < objectList.length; j++) {
System.out.println("<--- Start "+
getMethodName.substring(3)+"["+j+"] --->");
debugObject(objectList[j], null, false, printSizeFlag);
System.out.println("<--- End "+
getMethodName.substring(3)+"["+j+"] --->");
//System.out.println();
}
//System.out.println();
//System.out.println("======================= Start Debug Inner Object[] ==================== ");
//System.out.println("======================= End Debug Inner Object[] ==================== ");
//System.out.println();
} else if (objectre instanceof List) {
List lists = (List) objectre;
if (printSizeFlag) {
System.out.println("+++ List[] Size = "+lists.size()+" +++");
}
for (int j = 0; j < lists.size(); j++) {
System.out.println("<--- Start "+
getMethodName.substring(3)+"["+j+"] --->");
debugObject(lists.get(j), null, false, printSizeFlag);
System.out.println("<--- End "+
getMethodName.substring(3)+"["+j+"] --->");
//System.out.println();
}
} else if (objectre instanceof ValueObject) {
//System.out.println();
System.out.println("<--- Start "+getMethodName.substring(3)+" --->");
debugObject(objectre, null, false, printSizeFlag);
System.out.println("<--- End "+getMethodName.substring(3)+" --->");
//System.out.println();
}
}
}
} else {
System.out.println(fieldName+" = "+objectre);
if (objectre instanceof ValueObjectList) {
ValueObjectList voList = (ValueObjectList) objectre;
if (printSizeFlag) {
System.out.println("+++ ValueObjectList Size = "+voList.getList().size()+" +++");
}
//System.out.println();
//System.out.println("======================= Start Debug Inner ValueObjectList ==================== ");
for (int j = 0; j < voList.getList().size(); j++) {
//System.out.println();
System.out.println("<--- Start "+getMethodName.substring(3)+"["+j+"] --->");
ValueObject valueObject = (ValueObject) voList.getList().get(j);
debugObject(valueObject, null, false, printSizeFlag);
System.out.println("<--- End "+getMethodName.substring(3)+"["+j+"] --->");
//System.out.println();
}
//System.out.println("======================= End Debug Inner ValueObjectList ==================== ");
//System.out.println();
} else if (objectre instanceof Object[]) {
Object[] objectList = (Object[]) objectre;
if (printSizeFlag) {
System.out.println("+++ Object[] Size = "+objectList.length+" +++");
}
//System.out.println();
//System.out.println("======================= Start Debug Inner Object[] ==================== ");
for (int j = 0; j < objectList.length; j++) {
System.out.println("<--- Start "+getMethodName.substring(3)+"["+j+"] --->");
debugObject(objectList[j], null, false, printSizeFlag);
System.out.println("<--- End "+getMethodName.substring(3)+"["+j+"] --->");
//System.out.println();
}
//System.out.println("======================= End Debug Inner Object[] ==================== ");
//System.out.println();
} else if (objectre instanceof List) {
List lists = (List) objectre;
if (printSizeFlag) {
System.out.println("+++ List[] Size = "+lists.size()+" +++");
}
for (int j = 0; j < lists.size(); j++) {
System.out.println("<--- Start "+
getMethodName.substring(3)+"["+j+"] --->");
debugObject(lists.get(j), null, false, printSizeFlag);
System.out.println("<--- End "+
getMethodName.substring(3)+"["+j+"] --->");
//System.out.println();
}
} else if (objectre instanceof ValueObject) {
//System.out.println();
System.out.println("<--- Start "+getMethodName.substring(3)+" --->");
debugObject(objectre, null, false, printSizeFlag);
System.out.println("<--- End "+getMethodName.substring(3)+" --->");
//System.out.println();
}
}
}
}
}
}
} else {
System.out.println("<<<<<<<<<<<<<<< The specified object is null !!! >>>>>>>>>>>>>>>");
}
if (printClassNameFlag) {
System.out.println("<<<<<<<<<<<<<<< End debug the specified Object >>>>>>>>>>>>>>>");
}
} catch (Exception e) {
e.printStackTrace();
}
}
Monday, June 2, 2008
Java > Track name & value in ValueObject
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment