" + error + "");
}
catch(IOException ex) { }
}
public Object getBean(String beanName,Object scope,String scopeName) throws Exception {
Object object = null;
if(beanName.indexOf(".") > 0) {
String cscope = beanName.substring(0,beanName.indexOf("."));
object = getBean(cscope,scope,scopeName);
scopeName = scopeName.length() == 0 ? scopeName : scopeName + ".";
if(object != null) {
object = getBean(beanName.substring(beanName.indexOf(".")+1),object,scopeName);
}
else {
printError("Bean " + scopeName + cscope + " is null!");
}
}
else if(scope != null) {
object = getValue(scope,beanName);
}
else {
object = session.getValue(beanName);
}
return object;
}
public Object getValue(Object bean,String property) throws Exception {
Object value = null;
if(bean == null) return value;
if(bean instanceof Map) {
return ((Map)bean).get(property);
}
try {
BeanInfo info = Introspector.getBeanInfo (bean.getClass ());
if(info == null) {
printError("
Bean info is null!");
return null;
}
PropertyDescriptor[] pd = info.getPropertyDescriptors ();
if(pd == null) {
printError("
Property Descriptors is null!");
return null;
}
boolean isArray = false;
int index = 0;
if(property.indexOf('[') > 0) {
if(property.indexOf(']') == property.length()-1) {
isArray = true;
try {
index = Integer.parseInt(property.substring(property.indexOf('[')+1,
property.indexOf(']')));
property = property.substring(0,property.indexOf('['));
}
catch(Exception ex) { throw new Exception("Wrong index format for array!"); }
}
else
throw new Exception("Wrong format for the bean!");
}
for (int i = 0; i < pd.length; i++) {
if(property.equals(pd[i].getName())) {
Method method = pd[i].getReadMethod();
if(method == null) continue;
value = method.invoke(bean, new Object[] { });
if(isArray) {
if(value instanceof Vector) {
Vector vec = (Vector)value;
if(index >= 0 && index < vec.size())
return vec.elementAt(index);
else
throw new Exception("Index out of bound for vector of size " + vec.size());
}
else if(value instanceof Object[]) {
Object [] vec = (Object[])value;
if(index >= 0 && index < vec.length)
return vec[index];
else
throw new Exception("Index out of bound for array of size " + vec.length);
} else {
ArrayInterfaceClass clas = tempclass.getArrayInterfaceClass(value);
if(clas == null)
throw new Exception("Index can be used only for arrays and collections and classes with array interface metadata");
Object lengthValue = clas.getSize.invoke(value, new Object[] { });
if(lengthValue instanceof Integer) {
int length = ((Integer)lengthValue).intValue();
if(index >= 0 && index < length) {
Object args[] = new Object[1];
args[0] = new Integer(index);
return clas.getItem.invoke(value,args);
}
else
throw new Exception("Index out of bound for vector of size " + length);
}
}
}
break;
}
}
}
catch(IntrospectionException ex) { }
catch(InvocationTargetException ex) { }
catch(IllegalAccessException ex) { }
return value;
}
public void printBreadCrumbs(String beanName) throws Exception {
out.print("/ » ");
String beans[] = beanName.split("[.]");
for(int i=0;i" + beans[i] + " » ");
}
out.println(beans[beans.length-1]);
}
public void printProperties(String beanName) throws Exception {
Object bean = getBean(beanName,null,"");
printProperties(bean,beanName);
}
public void printArray(Object array[],String beanName) throws IOException {
out.println("");
for(int i=0;i" + array[i]);
else
out.println("- " + array[i] + "");
out.println("
");
}
public void printAbstractList(AbstractList alist,String beanName) throws IOException {
out.println("");
for(int i=0;i" + value);
else
out.println("- " + value + "");
}
out.println("
");
}
public void printProperties(Object bean,String beanName) {
String propertyName = null;
try {
if(bean == null) {
printError("
Bean " + beanName + " doesn't exist in the session or it is null!");
return;
}
BeanInfo info = Introspector.getBeanInfo (bean.getClass ());
if(info == null) {
printError("
Bean info is null!");
return;
}
PropertyDescriptor[] pd = info.getPropertyDescriptors ();
if(pd == null) {
printError("
Property Descriptors is null!");
return;
}
out.println("");
try {
out.println("| RCS_ID | " + bean.getClass().getField("RCS_ID")+" |
");
}
catch(NoSuchFieldException ex) {
// out.println("| RCS_ID doesn't exist for this bean |
");
}
for (int i = 0; i < pd.length; i++) {
try {
propertyName = pd[i].getName();
Method method = pd[i].getReadMethod();
if(method == null) continue;
if(method.getReturnType().isArray()) {
out.println("| " + pd[i].getName() + " | ");
Object value[] = (Object [])method.invoke(bean, new Object[] { });
if(value != null)
printArray(value,beanName+"."+pd[i].getName());
else
out.println(value);
out.println(" |
");
}
else {
Object value = method.invoke(bean, new Object[] { });
if(isPrimitive(value))
out.println("| " + pd[i].getName() + " | " + value + " |
");
else
out.println("| " + pd[i].getName() + " | " + value + " |
");
}
}
catch(InvocationTargetException ex) { printError("InvocationTargetException for " + propertyName + " " + ex.getMessage()); }
catch(IllegalAccessException ex) { printError("IllegalAccessException for " + propertyName + " " + ex.getMessage()); }
catch(Exception ex) {
}
}
if(bean instanceof AbstractList)
printAbstractList((AbstractList)bean,beanName);
else if(bean instanceof Object[])
printArray((Object[])bean,beanName);
else if(bean instanceof Map) {
Map map = (Map)bean;
out.println("{");
for(Iterator iter=map.keySet().iterator();iter.hasNext();) {
Object key = iter.next();
if(key instanceof String) {
out.println("" + key + " ");
}
}
out.println("}");
}
else {
ArrayInterfaceClass clas = tempclass.getArrayInterfaceClass(bean);
if(clas != null) {
Object lengthValue = clas.getSize.invoke(bean, new Object[] { });
if(lengthValue instanceof Integer) {
int length = ((Integer)lengthValue).intValue();
Object args[] = new Object[1];
out.println("");
for(int i=0;i" + item);
else
out.println("- " + item + "");
out.println("
");
}
}
}
}
}
catch(IOException ex) { }
catch(IntrospectionException ex) { printError("Introspection Exception"); }
catch(InvocationTargetException ex) { printError("InvocationTargetException for " + propertyName + " " + ex.getMessage()); }
catch(IllegalAccessException ex) { printError("IllegalAccessException for " + propertyName + " " + ex.getMessage()); }
finally {
try {
out.println("
");
}
catch(IOException ex) { };
}
}
public boolean isPrimitive(Object value) {
return (value == null ||
value instanceof String ||
value instanceof Integer ||
value instanceof Boolean ||
value instanceof Double ||
value instanceof Short ||
value instanceof Long ||
value instanceof Float);
}
public void printVersion(String className) {
try {
out.println("Version of " + className + " = " + Class.forName(className).getField("RCS_ID").get(null));
}
catch(Exception ex) {
try {
out.println(ex.getClass().getName() + " " + ex.getMessage());
}
catch(IOException e) { }
}
}
}
Debugger debugger = new Debugger(session,request.getRequestURI(),out);
if(request.getParameter("beans") != null) {
beans = beans.trim();
Vector beanNames = new Vector();
while(beans != null) {
if(beans.indexOf(",") > 0) {
beanNames.addElement(beans.substring(0,beans.indexOf(",")));
beans = beans.substring(beans.indexOf(",")+1);
}
else {
beanNames.addElement(beans);
beans = null;
}
}
Enumeration elms = beanNames.elements();
while(elms.hasMoreElements()) {
String elm = (String)elms.nextElement();
try {
debugger.printBreadCrumbs(elm);
%>
|
<%
debugger.printProperties(elm);
%>
|
<%
}
catch(Exception er) {
out.println(""+er+":"+er.getMessage()+"
");
er.printStackTrace();
}
}
}
if(request.getParameter("version") != null) {
debugger.printVersion(request.getParameter("version"));
}
%>
Session beans
<%
Enumeration attrs = session.getAttributeNames();
boolean hasAttrs = false;
while(attrs.hasMoreElements()) {
String attr = (String)attrs.nextElement();
hasAttrs = true;
%>
<%= attr %>
<%
}
if(!hasAttrs) {
%>
There are no session beans
<% } %>
|
<% // Add your debugging code here.
%>
<%
if(request.getParameter("beans") == null
&&request.getParameter("version") == null) {
%>
Help: various parameters can be passed to the url
beans=<list of beans that can be accessed from the session vars>
E.g. debug.jsp?beans=abc.fielda.fieldb
if the object is an array or a vector, possible to access ith element
E.g. debug.jsp?beans=xyz.abc.def[1]
if the object is a Map, possible to access keyed value if the key is a string
E.g. debug.jsp?beans=tablemap.USERS
version=<fully qualified path name> to get the RCS_ID
E.g. debug.jsp?version=com.abcxyz.util.xml.XS
<%
}
%>
© 2007 Dirisala.Net