JDomTool是否有 没有参数的构造函数,不然newInstance()不能得到对象啊
解决方案 »
- 如何用Coroutine 实现 经典 producer/consumer 问题?
- spring的@PreDestroy与scope问题
- 特别急!!求助!!!这样的访问如何实现??(jsp+servlet)
- 用JAVA做一个小型数据库
- tomcat 越来越慢
- 利用JSCH進行SFTP傳輸,如何獲取buffer size?
- java FTP上传问题讨论
- 使用Jbuilder 2006和Weblogic, Oracle开发session bean的时候,有关datasource的jndi在xml配置文件中的信息能不能能通过Jbuilder自动声称
- 请问什么是cvs,vss??有什么区别
- weblogic8.1下如何调试ejb呀.
- 如何改变tomcat默认app:ROOT?
- xml的一个节点里不可以输入数组吗?
为什么又再用一次Class.forName()呢?
* Created on 2005-8-23
*/package com.milan.common;import java.io.IOException;
import java.io.Reader;
import java.io.Serializable;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;import com.milan.beans.MilanWebServiceCommand;
import com.milan.exceptions.MilanWebServiceRuntimeException;
import com.milan.exceptions.MilanXmValidateException;public class JDomTool implements Serializable
{ /**
* 将发送过来字符串命令解析成MilanWebServiceCommand对象放在ArrayList中;
*
* @param sCommand
* @return
* @throws JDOMException
* @throws MilanWebServiceRuntimeException
* @throws
*/
public ArrayList parseCommandToObject(String sCommand) throws JDOMException //throws MilanWebServiceRuntimeException
{ SAXBuilder builder = new SAXBuilder();
Document doc = null;
Reader in = new StringReader(sCommand);
ArrayList listCommand = new ArrayList();
MilanWebServiceCommand mc = new MilanWebServiceCommand(); try
{
doc = builder.build(in);
Element root = doc.getRootElement();
List ls = root.getChildren(); //注意此处取出的是root节点下面的一层的Element集合<Command>
for(Iterator iter = ls.iterator(); iter.hasNext();)
{ Element elCommand = (Element)iter.next();
//取得MilanWebServiceCommandID;
mc.setCommandID(elCommand.getAttributeValue("commandID")); List listChildren = elCommand.getChildren();
Element commandElement = null; for(Iterator iterChildren = listChildren.iterator(); iterChildren.hasNext();)
{
//为MilanWebServiceCommand对象负值;
commandElement = (Element)iterChildren.next();
mc.setKoaBeginDate(new Date(commandElement.getChild("koa-begin-date")
.getTextTrim()));
mc.setKoaCompanyAddress(commandElement.getChild("koa-company-address")
.getTextTrim());
mc.setKoaCompanyName(commandElement.getChild("koa-company-nam").getTextTrim());
mc.setKoaCompanyPos(commandElement.getChild("koa-company-pos").getTextTrim());
mc.setKoaCompanyTel(commandElement.getChildTextTrim("koa-company-tel"));
mc.setKoaCompanyFax(commandElement.getChildTextTrim("koa-company-fax"));
mc.setKoaEndDate(new Date(commandElement.getChildTextTrim("koa-end-date")));
mc.setKoaMaxSize(Integer.parseInt(commandElement
.getChildTextTrim("koa-max-size")));
mc.setKoaMaxUser(Integer.parseInt(commandElement
.getChildTextTrim("koa-max-user")));
mc.setKoaName(commandElement.getChildTextTrim("koa-name"));
mc.setKoaVer(commandElement.getChildTextTrim("koa-ver"));
mc.setOnlinenicUserID(commandElement.getChildTextTrim("onlinenic-user-id")); }
mc.validate();
listCommand.add(mc);
}
}
catch (IOException e)
{
e.printStackTrace();
//throw new MilanWebServiceRuntimeException(e);
}
catch (MilanXmValidateException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} return listCommand;
} public boolean XMLWithSchemaValidate(String sCommand)
{
String schema = "CommandSchema.xml"; Reader in = new StringReader(sCommand); SAXBuilder builder = new SAXBuilder(true); //指定约束方式为XML schema
builder.setFeature("http://localhost:9999/milanwebservice/xml/properties/schema/CommandSchema.xml", true); //导入schema文件
builder.setProperty("http://localhost:9999/milanwebservice/xml/properties/schema/CommandSchema.xml", schema); Document doc = null;
try
{
doc = builder.build(in);
System.out.println("ok");
}
catch (JDOMException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("NO");
return false;
}
XMLWithSchemaValidate()这个方法我测试没有成功
public class MilanCommandServiceTestCase extends junit.framework.TestCase
{ public MilanCommandServiceTestCase(java.lang.String name)
{
super(name);
} public void test1milanServicesExeMilanCommand() throws Exception
{ com.milan.webservices.client.MilanServicesSoapBindingStub binding;
try
{
binding = (com.milan.webservices.client.MilanServicesSoapBindingStub)new com.milan.webservices.client.MilanCommandServiceLocator()
.getmilanServices();
}
catch (javax.xml.rpc.ServiceException jre)
{
if(jre.getLinkedCause() != null)
jre.getLinkedCause().printStackTrace();
throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: "
+ jre);
}
assertNotNull("binding is null", binding); //Time out after a minute
binding.setTimeout(60000); java.lang.String value = "webWebSercies ok";
// Test operation
value = binding.exeMilanCommand(new java.lang.String());
// TBD - validate results
System.out.println(value);
}}
报异常;在倒数第6行,(包括挂号,空行和注释)
public class MilanCommandServiceTestCase extends junit.framework.TestCase
{ public MilanCommandServiceTestCase(java.lang.String name)
{
super(name);
} public void test1milanServicesExeMilanCommand() throws Exception
{ com.milan.webservices.client.MilanServicesSoapBindingStub binding;
try
{
binding = (com.milan.webservices.client.MilanServicesSoapBindingStub)new com.milan.webservices.client.MilanCommandServiceLocator()
.getmilanServices();
}
catch (javax.xml.rpc.ServiceException jre)
{
if(jre.getLinkedCause() != null)
jre.getLinkedCause().printStackTrace();
throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: "
+ jre);
}
assertNotNull("binding is null", binding); //Time out after a minute
binding.setTimeout(60000); java.lang.String value = "webWebSercies ok";
// Test operation
出错点1: value = binding.exeMilanCommand(new java.lang.String());
// TBD - validate results
System.out.println(value);
}}
在出错点1执行出现错误;
对着别的类的 Class 对象, 用不同的类的实例调用 方法,
如: String.Class.getMethod('trim()').invoke(integerObject) . // integerObject 不是String 类型.所以请检查参数.