Aegis 是一个默认的 Xfire 绑定方式,它将 XML 映射为 POJO, 支持代码先行的开发.你开发服 务类与 POJO,它为你生成 XML schema/wsdl
XML 和 注解映射概览
默认情况下,你的 POJO 类被是基于他们的名字与命名空间被序列化。如果你有一个类在 "org.codehaus.xfire"包里,名字叫"Employee",它会被使用命名空间"http://xfire.codehaus.org" 和本地名字 "Employee"进行序列化。
举例:
public class Employee {
private String name;
private String title;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
在 XML 里它被转换成:
<Employee xmlns="http://xfire.codehaus.org">
<name>Santa Claus</name>
<title>Chief Present Officer (CPO)</title>
</Employee>
在 XML Schema 里变的更为复杂:
<xsd:complexType name="Employee">
<xsd:sequence>
<xsd:element name="name" type="xsd:string" minOccurs="0" maxOccurs="1/>
<xsd:element name="title" type="xsd:string" minOccurs="0" maxOccurs="1/>
</xsd:sequence>
</xsd:complexType>
支持的类型
-
基本类型: int, double, float, long, byte[], short, String, BigDecimal Arrays Collections
-
日期: java.util.Date, java.util.Calendar, java.sql.Timestamp, java.sql.Date, java.sql.Time
-
XML: org.w3c.dom.Docmument, org.jdom.Element, XMLStreamReader, Source
-
以上类型的聚合类
如果 Java bean 里定义了构造函数,一定不能忘记定义一个默认的构造函数(无参)。(Aegis 需要一个无参的构造器来初始化客户端 java 类)
使用 XML 控制映射
使用 Aegis 很容易控制从 bean 到 xml 的转换。 .aegis.xml 映射配置文件必须存在于和你的 bean 或者服务类相同的包中,且命名为与 bean 或服务类相同名字。
以上例子应当命名为"/org/codehaus/xfire/Employee.aegis.xml", 格式如下:
<mappings>
<mapping uri="" name="">
<method name="methodName">
<return-type mappedName="" componentType=""/>
<parameter index="" mappedName=""/>
</method>
<property name="" mappedName="" style="attribute|element" componentType=""/>
</mapping>
</mappings>
当你创建 ClassName.aegis.xml 来控制映射的时候, 你只会用到一个 mapping 元素, 并且你 不需要在 mapping 元素上使用任何的属性. 使用一到多个 property 元素指定属性的映射. 使 用 name=指明要映射的属性名(Pojo 中名字). <method> 用于配置服务类中的方法 <property> 用于配置 javabean 中的属性 用于配置 服务类中的方法, 中的属性.
上边的例子显示出了许多可能使用的元素, 上边的例子显示出了许多可能使用的元素,大部分都是可选的
控制命名
假设上边的例子需要元素首字母大写,并且使用"urn:north-pole:operations"命名空间. 配置文件 就修改成:
<mappings xmlns:np="urn:north-pole:operations">
<mapping name="np:Employee">
<property name="name" mappedName="Name"/>
<property name="title" mappedName="Title"/>
</mapping>
</mappings>
命名空间被定义在了 mappings 元素里。 之后这个前缀被用于为 name/title 指定 QNames 元素, 使映射变成以下:
<np:Employee xmlns:np="urn:north-pole:operations">
<np:Name>Santa Claus</np:Name>
<np:Title>Chief Present Officer (CPO)</np:Title>
</np:Employee>
忽略属性
如果要使某个属性不被序列化,可以加 ignore 来实现。:
<mappings>
<mapping>
<property name="propertyName" ignore="true"/>
</mapping>
</mappings>
控制 minOccurs 和 nillable
默认的 Aegis 的假设任意的 java 对象可以为空,那么相关的 schema 元素应当设为为 minOccurs=’0’ 且 nillable=’true’. 配置文件中也有属性对此进行控制。
<mappings>
<mapping>
<property name='everpresentProperty' minOccurs='1' nillable='false'/>
</mapping>
<mappings>
使用 Aegis 基本类型
为了使用在"org.codehaus.xfire.aegis.type.basic"包里 Aegis 提供的多种类型,接下来的例子使 wsdl 使用"xsd:date"而不是默认的"xsd:dateTime"
<mappings xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<mapping>
<property name="birthDate" type="org.codehaus.xfire.aegis.type.basic.DateType" typeName="xsd:date" />
</mapping>
</mappings>
在 java 代码里设置默认的 minOccurs 和 nillable 参数
如果你有大部分或者所有的属性都有一个非 0 的 minOccurs 或者非 false 的 nillable, 你可以在 java 代码里更改 Aegis 默认设置
示例:它从服务工厂得到了 binding provider,改变了配置参数
AnnotationServiceFactory serviceFactory = new AnnotationServiceFactory(); // We 'happen to know' what types are used.
AegisBindingProvider binder = (AegisBindingProvider)serviceFactory.getBindingProvider() ;
DefaultTypeMappingRegistry tmr = (DefaultTypeMappingRegistry)binder.getTypeMappingRegistry ();
// here we disuade XFire from its rather annoying tendency to assume that, just because
// anything in Java can be null, that we want to advertise all that
nullity all over. Configuration configuration = tmr.getConfiguration(); configuration.setDefaultMinOccurs(1);
configuration.setDefaultNillable(false);
nillable="true":该元素的值可以为空,但是该元素不能省略,也就是说,
只能:该元素的值可以为空,但是该元素不能省略,也就是说,只能: <minzero xsi:nil="true"><minzero> 而不能直接将 minzero 这个元素去掉 应该就是表示这个元素为空) (注意:xsi:nil="true"或者 xsi:nil="1"应该就是表示这个元素为空)
注意: 或者 应该就是表示这个元素为空 minOccurs="0":该元素可以直接被省略掉,但是不能让该元素 的值为空,也就是说,
不能: :该元素可以直接被省略掉,但是不能让该元素的值为空,也就是说,不能: <minzeroxsi:nil="true"><minzero>
分享到:
相关推荐
xfire-aegis-1.2.6.jar
webservice中用到的jar,xfire-aegis-1.2.6.jar
webservice_aegis.xml配置
支持将Web服务绑定到POJO、XMLBeans、JAXB1.1、JAXB2.0和Castor; 支持基于HTTP、JMS、XMPP等多种协议访问Web服务; 支持多种Web服务业界重要标准如SOAP、WSDL、Web服务寻址(WS-Addressing)、Web服务安全(WS-...
5 灵活的Binding机制,包括默认的Aegis,xmlbeans,jaxb2,castor; 6 高性能的SOAP 栈设计; 7 支持Spring、Pico、Plexus、Loom等容器。 8 XFire比Axis1.3快2-6倍; 9 XFire的响应时间是Axis1.3的1/2到1/5。
activation.jar ...xfire-aegis-1.2.2.jar xfire-annotations-1.2.2.jar xfire-core-1.2.2.jar xfire-java5-1.2.2.jar xfire-jsr181-api-1.0-M1.jar xfire-spring-1.2.2.jar xfire-xmlbeans-1.2.2.jar
进行WebService开发中所用到的xfire所有相关包如:xfire-jsr181-api-1.0-M1.jar、xfire-jaxws-1.2.6.jar、xfire-java5-1.2.6.jar、xfire-core-1.2.6.jar、xfire-annotations-1.2.6.jar、xfire-aegis-1.2.6.jar、...
xfire-aegis-1.2.6.jar xfire-annotations-1.2.6.jar xfire-core-1.2.6.jar xfire-java5-1.2.6.jar xfire-jsr181-api-1.0-M1.jar xfire-spring-1.2.6.jar xfire-xmlbeans-1.2.6.jar xstream-1.3.1.jar
cxf+aegis发布webService配置简单、开发周期短,开发不用太过关心接口具体发布的过程以及接口描述文件wsdl的定义,这些工作都由cxf与aegis完成,如果一个项目中有需要集成接口或者项目比较紧张,采用cxf+aegis发布...
NULL 博文链接:https://goooooooo.iteye.com/blog/463596
xfire-aegis-1.2.6.jar,xfire-annotations-1.2.6.jar,xfire-core-1.2.6.jar,xfire-java5-1.2.6.jar,xfire-jaxb2-1.2.6.jar,xfire-jaxws-1.2.6.jar,xfire-jsr181-api-1.0-M1.jar,xfire-spring-1.2.6.jar
xfire中有个BUG,会自动删除信息中后面的空字符串。这个包就是处理这个问题的,不再自动删除后面的空字符串,保证数据的原始性。删除空格是在org.codehaus.xfire.aegis.stax.ElementReader类的getValue()类中
NULL 博文链接:https://gatusso52.iteye.com/blog/482239
xfire开发webservices相关jar包: xfire-aegis-1.2.6.jar xfire-annotations-1.2.6.jar xfire-core-1.2.6.jar xfire-java5-1.2.6.jar xfire-jsr181-api-1.0-M1.jar xfire-spring-1.2.6.jar xfire-xmlbeans-1.2.6.jar
前端项目-aegis,Aegis CSS Framework
/*Aegis支持的类型*/ public int getInt(int a); public double getDouble(double a); public float getFloat(float a); public long getLong(long a); public byte[] getBytesArray(byte[] a); public short ...
使用Simple Frontend+Aegis方式发布并获取webservice.doc
aegis
此软件不是隐藏图片,而是通过16轮循环加密方式加密图片,加密强度高,只有唯一密匙才能打开. 锁屏自动完全退出.绝不留任何可泄露机会. 防止暴力破解,具有密匙输入错误超过3次销毁源文件.杜绝艳照门的发生. 居家旅行...
资源分类:Python库 所属语言:Python 资源全名:aegis_tools-0.9.9-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059