自动生成Xfire的.aegis.xml文件

Xml代码 
1.<?xml version="1.0" encoding="UTF-8"?> 
2.<mappings> 
3.    <mapping> 
4.          <method name="getDutyPlanByCondition"> 
5.            <parameter index="0" mappedName="dutyPlanId" /> 
6.            <parameter index="1" mappedName="organizationId" /> 
7.            <parameter index="2" mappedName="dutyUserId" /> 
8.            <parameter index="3" mappedName="tabulateUserId" /> 
9.            <parameter index="4" mappedName="dictRoadSectionId" /> 
10.            <parameter index="5" mappedName="assessorUserId" /> 
11.            <parameter index="6" mappedName="dutyDate" /> 
12.            <parameter index="7" mappedName="startTime" /> 
13.            <parameter index="8" mappedName="stopTime" /> 
14.            <parameter index="9" mappedName="startPoint" /> 
15.            <parameter index="10" mappedName="stopPoint" /> 
16.            <parameter index="11" mappedName="xh" /> 
17.            <parameter index="12" mappedName="tabulateDate" /> 
18.            <parameter index="13" mappedName="isAudit" /> 
19.            <parameter index="14" mappedName="auditingDate" /> 
20.            <parameter index="15" mappedName="isPreAudit" /> 
21.            <return-type 
22.                componentType="com.boco.itms.ws.value.duty.DutyPlanValue" /> 
23.        </method> 
24.    </mapping> 
25.</mappings> 
<?xml version="1.0" encoding="UTF-8"?>
<mappings>
    <mapping>
          <method name="getDutyPlanByCondition">
<parameter index="0" mappedName="dutyPlanId" />
<parameter index="1" mappedName="organizationId" />
<parameter index="2" mappedName="dutyUserId" />
<parameter index="3" mappedName="tabulateUserId" />
<parameter index="4" mappedName="dictRoadSectionId" />
<parameter index="5" mappedName="assessorUserId" />
<parameter index="6" mappedName="dutyDate" />
<parameter index="7" mappedName="startTime" />
<parameter index="8" mappedName="stopTime" />
<parameter index="9" mappedName="startPoint" />
<parameter index="10" mappedName="stopPoint" />
<parameter index="11" mappedName="xh" />
<parameter index="12" mappedName="tabulateDate" />
<parameter index="13" mappedName="isAudit" />
<parameter index="14" mappedName="auditingDate" />
<parameter index="15" mappedName="isPreAudit" />
<return-type
componentType="com.boco.itms.ws.value.duty.DutyPlanValue" />
</method>
    </mapping>
</mappings>


很普通的一个配置文件。
"getDutyPlanByCondition”这个方法总共有16个参数,默认情况下,客户端自动生成的代码中,参数形如:arg0,arg1...arg15,极不容易将每个参数及顺序填写正确,故配置以上文件,将wsdl中的参数赋予有意义的单词。

<parameter index="0" mappedName="dutyPlanId" />
<parameter index="1" mappedName="organizationId" />

......


编写如此的配置实在令人有点不耐烦,想点办法,自动生成?

OK,观察一下有什么规律:
1.<method name="getDutyPlanByCondition"> 方法名,反射呗。
2.<return-type componentType="com.boco.itms.ws.value.duty.DutyPlanValue" />返回值,反射呗。
3.xml文件名,反射呗。

通过反射,这些信息我们都能取到,再组织一下结构,循环一下,生成配置文件,小菜一碟!


但还有个东西别忘了,参数名(不是参数类型)。



Java代码 
1.public void save(int id , String name){ ... } 
public void save(int id , String name){ ... }


以上代码我们通过反射,能取到参数中的int,String,但就是取不到id,name。
别问为什么要取到参数名,总有用的上的时候,例如这篇文章……


先找个包:axis2-kernel-1.4.1.jar(明明是用Xfire,还是得拖个axis下水啊)

直接上代码:


Java代码 
1.ChainedParamReader paramReader = new ChainedParamReader(clazz);  
2.Method[] methods = clazz.getMethods();  
3.for(int i=0 ; i<methods.length ; i++){  
4.     String[] params = paramReader.getParameterNames(methods[i]);     
5.} 
ChainedParamReader paramReader = new ChainedParamReader(clazz);
Method[] methods = clazz.getMethods();
for(int i=0 ; i<methods.length ; i++){
     String[] params = paramReader.getParameterNames(methods[i]);
}


OK,已经取到{id , name}了,该干嘛干嘛了 .

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值