Page Edited :
CXF20DOC :
Introduction to Aegis (2.1)
Introduction to Aegis (2.1) has been edited by Benson Margulies (Mar 02, 2008). Content:What is Aegis?Aegis is a databinding. That is, it is a subsystem that can map Java objects to XML documents described by XML schema, and vica-versa. Aegis is designed to give useful mappings with a minimum of programmer effort, while allowing detailed control and customization. Aegis began as part of XFire, and moved with XFire into Apache CXF. You can use Aegis independently of CXF as a mechanism for mapping Java objects to and from XML. This page, however, describes Aegis as used inside of CXF. Aegis has some advantages over JAXB for some applications. Some users find that it produces a more natural XML mapping for less configuration. For example, Aegis has a default setting for 'nillable', allowing you to declare it for your entire service in one place instead of having to annotate every single element. The biggest advantage of Aegis, however, is a convenient way to customize the mapping without adding (@)annotations to your Java code. This allows you to avoid class loading dependencies between your data classes and your web service binding. Getting Started: Basic Use of AegisYou can configure any web service to use the Aegis data binding. A service configured with Aegis will yield a valid WSDL description, and you can use that to configure any client that you like. You can talk to an Aegis service with JAXB, or .NET, or a scripted language, or ... Aegis itself. You can use Aegis as a client to talk to Aegis, by using the very same Java classes and configuration files in the client environment that you use on the server. However, it's not all that practical to use Aegis as a client to talk to some a service using some other data binding, since Aegis lacks a 'wsdl2java' tool. Every CXF service and client uses a front end: JAX-WS, Simple, etc. Each of these provides a place to configure the data binding, both in Spring and via Java code. For example, here is a Simple front-end service using Aegis as a data binding. <simple:server id="pojoservice" serviceClass="demo.hw.server.HelloWorld" address="/hello_world"> <simple:serviceBean> <bean class="demo.hw.server.HelloWorldImpl" /> </simple:serviceBean> <simple:dataBinding> <bean class="org.apache.cxf.aegis.databinding.AegisDatabinding" /> </simple:dataBinding> </simple:server> </bean>
Aegis can handle all of these. For all except interfaces, there are two mechanisms that involved: the root class list and xsi:type attributes. As explained above, Aegis can write 'anything', but it can only read objects of types that are mapped. You must give Aegis a list of all the types that you want to use over and above those visible from the service, and you must instruct Aegis to send xsi:type attributes. These type attributes allow Aegis to identify the type of these additional objects and look them up in the mappings. Interfaces require one further step. Obviously, Aegis cannot instantiate (run 'new') on an interface. So knowing that a particular XML Schema type maps to an interface is not enough information. To be able to read an XML element that corresponds to an interface, Aegis must know a 'proxy class' that implements the interface. You must give Aegis a mapping from interface types to proxy class names. How does this work? The core of Aegis is the AegisContext class. Each AegisDatabinding object has an AegisContext. (It is probably not possible to share an AegisContext amongst databindings.) By default, AegisDatabinding will create its own AegisContext with default properties. To configure additional types, as well control other options that we will examine later on, you must create the AegisContext for yourself and specify some of its properties. Then you pass your AegisContext object into your AegisDatabinding object. To use additional classes or interfaces, you need to set two (or three) properties of your AegisContext.
|
Unsubscribe or edit your notifications preferences