Tips and tricks for using JiBX
start > axis2-jibx > jibx2wsdl > example1

example1

Created by dsosnoski. Last edited by dsosnoski, 261 days ago. Viewed 4,424 times. #14
This example (included in the distribution} demonstrates using Jibx2Wsdl with a simple service class and Java 5 generic lists. To use it, follow the readme.txt instructions in the distribution. {link:This example (click to

Here's a quick look at the service code and data model classes (from the start directory):

public class BookServer1
{
    ...

/** * Get the book with a particular ISBN. * * @param isbn * @return book */ public synchronized Book getBook(String isbn) { return (Book)m_bookMap.get(isbn); }

/** * Get all books of a particular type. * * @param type short name of type * @return books */ public synchronized List<Book> getBooksByType(String type) { ArrayList<Book> matches = new ArrayList<Book>(); for (int i = 0; i < m_bookList.size(); i++) { Book book = (Book)m_bookList.get(i); if (type.equals(book.getType())) { matches.add(book); } } return matches; }

/** * Get information on all types. * * @return types */ public List<Type> getTypes() { ArrayList<Type> types = new ArrayList<Type>(); for (int i = 0; i < m_types.length; i++) { types.add(m_types[i]); } return types; }

/** * Add a new book. * * @param book * @throws AddDuplicateException */ public synchronized void addBook(Book book) throws AddDuplicateException { Book prior = getBook(book.getIsbn()); if (prior == null) { internalAdd(book); } else { throw new AddDuplicateException(prior); } } }

public class Book { /** Short name of type. */ private String m_type; private String m_isbn; private String m_title; private String[] m_authors;

public Book() {}

public Book(String type, String isbn, String title, String[] authors) { m_isbn = isbn; m_title = title; m_type = type; m_authors = authors; }

public String getType() { return m_type; }

public String getIsbn() { return m_isbn; }

public String getTitle() { return m_title; }

public String[] getAuthors() { return m_authors; } }

public class Type { /** Short name for type. */ private String m_name;

/** Text description of type. */ private String m_description;

/** Number of books of this type. */ private int m_count;

public Type() {}

public Type(String name, String description) { m_name = name; m_description = description; }

public String getName() { return m_name; }

public String getDescription() { return m_description; }

public int getCount() { return m_count; }

public void setCount(int count) { m_count = count; } }

Here's the generated WSDL and imported schema (the schema embedded in the WSDL is also generated as a standalone file, for convenience):

<wsdl:definitions xmlns:tns="http://sosnoski.com/ws/library/jibx2wsdl/BookServer1" …
    targetNamespace="http://sosnoski.com/ws/library/jibx2wsdl/BookServer1">
  <wsdl:types>

<xsd:schema … xmlns:tns="http://sosnoski.com/ws/library/jibx2wsdl/BookServer1" xmlns:ns1="http://sosnoski.com/ws/library/jibx2wsdl" elementFormDefault="qualified" targetNamespace="http://sosnoski.com/ws/library/jibx2wsdl/BookServer1"> <xsd:import namespace="http://sosnoski.com/ws/library/jibx2wsdl" schemaLocation="jibx2wsdl.xsd"/> <xsd:complexType name="bookList"> <xsd:sequence> <xsd:element type="ns1:book" name="book" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="typeList"> <xsd:sequence> <xsd:element type="ns1:type" name="type" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> <xsd:element name="addDuplicate"> <xsd:complexType> <xsd:sequence> <xsd:element type="ns1:book" name="book" minOccurs="0"> <xsd:annotation> <xsd:documentation>Details for duplicate book already present.</xsd:documentation> </xsd:annotation> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="getBook"> <xsd:complexType> <xsd:sequence> <xsd:element type="xsd:string" name="isbn" minOccurs="0"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="getBookResponse"> <xsd:complexType> <xsd:sequence> <xsd:element type="ns1:book" name="book" minOccurs="0"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="getBooksByType"> <xsd:complexType> <xsd:sequence> <xsd:element type="xsd:string" name="type" minOccurs="0"> <xsd:annotation> <xsd:documentation>short name of type</xsd:documentation> </xsd:annotation> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="getBooksByTypeResponse"> <xsd:complexType> <xsd:sequence> <xsd:element type="tns:bookList" name="bookList" minOccurs="0"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="getTypes"> <xsd:complexType> <xsd:sequence/> </xsd:complexType> </xsd:element> <xsd:element name="getTypesResponse"> <xsd:complexType> <xsd:sequence> <xsd:element type="tns:typeList" name="typeList" minOccurs="0"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="addBook"> <xsd:complexType> <xsd:sequence> <xsd:element type="ns1:book" name="book" minOccurs="0"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="addBookResponse"> <xsd:complexType> <xsd:sequence/> </xsd:complexType> </xsd:element> </xsd:schema>

</wsdl:types> <wsdl:message name="getBookMessage"> <wsdl:part name="part" element="tns:getBook"/> </wsdl:message> … <wsdl:message name="addDuplicateFault"> <wsdl:part name="fault" element="tns:addDuplicate"/> </wsdl:message> <wsdl:portType name="BookServer1PortType"> <wsdl:documentation>Book service implementation. This creates an initial library of books when the class is loaded, then supports method calls to access the library information (including adding new books).</wsdl:documentation> <wsdl:operation name="getBook"> <wsdl:documentation>Get the book with a particular ISBN.</wsdl:documentation> <wsdl:input message="tns:getBookMessage"/> <wsdl:output message="tns:getBookResponseMessage"/> </wsdl:operation> <wsdl:operation name="getBooksByType"> <wsdl:documentation>Get all books of a particular type.</wsdl:documentation> <wsdl:input message="tns:getBooksByTypeMessage"/> <wsdl:output message="tns:getBooksByTypeResponseMessage"/> </wsdl:operation> <wsdl:operation name="getTypes"> <wsdl:documentation>Get information on all types.</wsdl:documentation> <wsdl:input message="tns:getTypesMessage"/> <wsdl:output message="tns:getTypesResponseMessage"/> </wsdl:operation> <wsdl:operation name="addBook"> <wsdl:documentation>Add a new book.</wsdl:documentation> <wsdl:input message="tns:addBookMessage"/> <wsdl:output message="tns:addBookResponseMessage"/> <wsdl:fault message="tns:addDuplicateFault" name="addDuplicateFault"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="BookServer1Binding" type="tns:BookServer1PortType"> … <wsdl:service name="BookServer1"> <wsdl:port name="BookServer1Port" binding="tns:BookServer1Binding"> <soap:address location="http://localhost:8080/axis2/BookServer1"/> </wsdl:port> </wsdl:service> </wsdl:definitions>

<xsd:schema … xmlns:tns="http://sosnoski.com/ws/library/jibx2wsdl" elementFormDefault="qualified" targetNamespace="http://sosnoski.com/ws/library/jibx2wsdl"> <xsd:complexType name="type"> <xsd:sequence> <xsd:element type="xsd:string" name="description" minOccurs="0"> <xsd:annotation> <xsd:documentation>Text description of type.</xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element type="xsd:string" name="name" minOccurs="0"> <xsd:annotation> <xsd:documentation>Short name for type.</xsd:documentation> </xsd:annotation> </xsd:element> </xsd:sequence> <xsd:attribute type="xsd:int" use="required" name="count"> <xsd:annotation> <xsd:documentation>Number of books of this type.</xsd:documentation> </xsd:annotation> </xsd:attribute> </xsd:complexType> <xsd:complexType name="book"> <xsd:annotation> <xsd:documentation>Book details.</xsd:documentation> </xsd:annotation> <xsd:sequence> <xsd:element type="xsd:string" name="type" minOccurs="0"> <xsd:annotation> <xsd:documentation>Short name of type.</xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element type="xsd:string" name="title" minOccurs="0"/> <xsd:element type="xsd:string" name="isbn" minOccurs="0"/> <xsd:element name="authors" minOccurs="0"> <xsd:complexType> <xsd:sequence> <xsd:element type="xsd:string" name="author" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:schema>

Notice that Jibx2Wsdl has copied the JavaDoc information from the Java source code into the appropriate locations in the WSDL and schema documents. This is a very useful feature for working with WSDL analyzers or tools which are able to use the documentation information. Axis2 WSDL2Java unfortunately does not use this information, at present.

no comments
snipsnap.org | Copyright 2000-2002 Matthias L. Jugel and Stephan J. Schmidt