扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
在本页阅读全文(共3页)
publicvoid setProxyObject(Object proxy) {
this.proxy = proxy;
//List all methods in <code>proxy</code>
setMethods( proxy );
}
privatevoid setMethods(Object proxy) {
Method[] methods = proxy.getClass().getMethods();
MyMethodInfo[] infos = new MyMethodInfo[methods.length];
for (int i = 0; i < methods.length; i++) {
infos[i] = new MyMethodInfo( methods[i] );
}
Arrays.sort( infos );
methodList.setListData( infos );
}
privatevoid onMethodChanged() {
argsPanel.removeAll();
MyMethodInfo mi = (MyMethodInfo) methodList.getSelectedValue();
if ( mi == null ) {
methodArgPanels = new MethodArgPanel[0];
return;
}
int argQty = mi.method.getParameterTypes().length;
methodArgPanels = new MethodArgPanel[argQty];
for (int i = 1; i <= argQty; i++) {
methodArgPanels[i - 1] = new MethodArgPanel();
argsPanel.add( methodArgPanels[i - 1] );
}
argsPanel.repaint();
argsPanel.revalidate();
}
privatevoid onExec() {
StringBuilder result = new StringBuilder();
result.append( "====================================\n" );
//get the method user selected
MyMethodInfo mi = (MyMethodInfo) methodList.getSelectedValue();
if ( mi == null ) {
result.append( "No method called" );
resultTextArea.setText( result.toString() );
return;
}
Object[] args = new Object[mi.method.getParameterTypes().length];
XStream xstream = new XStream( new DomDriver() );
try {
//convert the arg objects from xml text
for (int i = 0; i < this.methodArgPanels.length; i++) {
args[i] = xstream.fromXML( methodArgPanels[i].getText() );
}
//invoke the method
Object invokeResult = mi.method.invoke( proxy, args );
//convert the result to xml text
result.append( "Return val:\n" );
result.append( xstream.toXML( invokeResult ) );
}
catch ( Throwable e ) {
//Exception handle
StringWriter sw = new StringWriter();
PrintWriter printWriter = new PrintWriter( sw );
e.printStackTrace( printWriter );
result.append( "Cache Exception:\n" );
result.append( sw );
printWriter.close();
e.printStackTrace();
}
//show the invoke result in UI
resultTextArea.setText( result.toString() );
}
} // @jve:decl-index=0:visual-constraint="10,56"
|
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。