You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by sa...@apache.org on 2001/03/07 05:56:36 UTC

cvs commit: xml-soap/java/samples/addressbook2 Address.java AddressBook.wsdl AddressBookProxy.java AddressSerializer.java DeploymentDescriptor.xml Main.java Phone.java PhoneSerializer.java

sanjiva     01/03/06 20:56:36

  Added:       java/samples/addressbook2 Address.java AddressBook.wsdl
                        AddressBookProxy.java AddressSerializer.java
                        DeploymentDescriptor.xml Main.java Phone.java
                        PhoneSerializer.java
  Log:
  sample illustrating how to use SOAPHTTPConnection's HTTP session
  maintenance capability that I just committed.
  
  Revision  Changes    Path
  1.1                  xml-soap/java/samples/addressbook2/Address.java
  
  Index: Address.java
  ===================================================================
  /*
   *This class is automatically generated by schema to Java program.
   *Only a subset of schema is handled and some of the schema information
   *may be lost during translation
   */
  
  package samples.addressbook2;
  
  public class Address{
  
  	//instance variables
  	public int	streetNum_Elem;
  	public java.lang.String	streetName_Elem;
  	public java.lang.String	city_Elem;
  	public java.lang.String	state_Elem;
  	public int	zip_Elem;
  	public Phone	phoneNumber_Elem;
  
  	//constructors
  	public Address () { }
  
  	public Address (int streetNum_Elem, java.lang.String streetName_Elem, java.lang.String city_Elem, java.lang.String state_Elem, int zip_Elem, Phone phoneNumber_Elem) {
  		this.streetNum_Elem	= streetNum_Elem;
  		this.streetName_Elem	= streetName_Elem;
  		this.city_Elem	= city_Elem;
  		this.state_Elem	= state_Elem;
  		this.zip_Elem	= zip_Elem;
  		this.phoneNumber_Elem	= phoneNumber_Elem;
  	}
  
  }
  
  
  1.1                  xml-soap/java/samples/addressbook2/AddressBook.wsdl
  
  Index: AddressBook.wsdl
  ===================================================================
  <?xml version="1.0" ?>
  
  <definitions name="urn:AddressFetcher" 
               targetNamespace="urn:AddressFetcher2"
               xmlns:typens="urn:xml-soap-address-demo"
               xmlns:xsd="http://www.w3.org/1999/XMLSchema"
               xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
               xmlns="http://schemas.xmlsoap.org/wsdl/">
  
    <!-- type defs -->
    <types>
      <xsd:schema targetNamespace="urn:xml-soap-address-demo"
                  xmlns:xsd="http://www.w3.org/1999/XMLSchema">
        <xsd:complexType name="phone">
          <xsd:element name="areaCode" type="xsd:int"/>
          <xsd:element name="exchange" type="xsd:string"/>
          <xsd:element name="number" type="xsd:string"/>
        </xsd:complexType>
  
        <xsd:complexType name="address">
          <xsd:element name="streetNum" type="xsd:int"/>
          <xsd:element name="streetName" type="xsd:string"/>
          <xsd:element name="city" type="xsd:string"/>
          <xsd:element name="state" type="xsd:string"/>
          <xsd:element name="zip" type="xsd:int"/>
          <xsd:element name="phoneNumber" type="typens:phone"/>
        </xsd:complexType>
      </xsd:schema>
    </types>
  
    <!-- message declns -->
    <message name="AddEntryRequest">
      <part name="name" type="xsd:string"/>
      <part name="address" type="typens:address"/>
    </message>
  
    <message name="GetAddressFromNameRequest">
      <part name="name" type="xsd:string"/>
    </message>
  
    <message name="GetAddressFromNameResponse">
      <part name="address" type="typens:address"/>
    </message>
  
    <!-- port type declns -->
    <portType name="AddressBook">
      <operation name="addEntry">
        <input message="AddEntryRequest"/>
      </operation>
      <operation name="getAddressFromName">
        <input message="GetAddressFromNameRequest"/>
        <output message="GetAddressFromNameResponse"/>
      </operation>
    </portType>
  
    <!-- binding declns -->
    <binding name="AddressBookSOAPBinding" type="AddressBook">
      <soap:binding style="rpc" 
                    transport="http://schemas.xmlsoap.org/soap/http"/>
      <operation name="addEntry">
        <soap:operation soapAction=""/>
        <input>
          <soap:body use="encoded" 
                     namespace="urn:AddressFetcher2" 
                     encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </input>
        <output>
          <soap:body use="encoded" 
                     namespace="urn:AddressFetcher2"
                     encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </output>
      </operation>
      <operation name="getAddressFromName">
        <soap:operation soapAction=""/>
        <input>
          <soap:body use="encoded"
                     namespace="urn:AddressFetcher2"
                     encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </input>
        <output>
          <soap:body use="encoded" 
                     namespace="urn:AddressFetcher2"
                     encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </output>
      </operation>
    </binding>
  
    <!-- service decln -->
    <service name="AddressBookService">
      <port name="AddressBook" binding="AddressBookSOAPBinding">
        <soap:address location="http://localhost:2020/soap/servlet/rpcrouter"/>
      </port>
    </service>
  
  </definitions>
  
  
  
  1.1                  xml-soap/java/samples/addressbook2/AddressBookProxy.java
  
  Index: AddressBookProxy.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "SOAP" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2000, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package samples.addressbook2;
  
  import java.net.*;
  import java.util.*;
  import org.apache.soap.*;
  import org.apache.soap.encoding.*;
  import org.apache.soap.rpc.*;
  import org.apache.soap.util.xml.*;
  import org.apache.soap.transport.*;
  
  /**
   * Proxy for the address book service described in the AddressBook.wsdl
   * file found in this directory. The base proxy was generated using 
   * IBM's WSDL Toolkit v1.1 using the following command:
   *	java com.ibm.wsdl.Main -in AddressBook.wsdl \
   *                             -package samples.addressbook2 \
   *                             -dir ../..
   * The generated proxy was hand edited to add the setSOAPTransport
   * method and the generated serializer was hand edited to have the 
   * SOAPContext argument required by Apache SOAP v2.1 (the WSDL 
   * Toolkit v1.1 assumes Apache SOAP v2.0).
   *
   * @author Sanjiva Weerawarana <sa...@watson.ibm.com>
   */
  public class AddressBookProxy
  {
    private Call call = new Call();
    private URL url = null;
    private String SOAPActionURI = "";
    private SOAPMappingRegistry smr = call.getSOAPMappingRegistry();
  
    public AddressBookProxy() throws MalformedURLException
    {
      call.setTargetObjectURI("urn:AddressFetcher2");
      call.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encoding/");
      this.url = new URL("http://localhost:2020/soap/servlet/rpcrouter");
      this.SOAPActionURI = "";
    }
  
    public synchronized void setEndPoint(URL url)
    {
      this.url = url;
    }
  
    public synchronized URL getEndPoint()
    {
      return url;
    }
  
    public synchronized void setSOAPTransport (SOAPTransport st)
    {
      call.setSOAPTransport (st);
    }
  
    public synchronized void addEntry(java.lang.String name,
      samples.addressbook2.Address address) throws SOAPException
    {
      if (url == null)
      {
        throw new SOAPException(Constants.FAULT_CODE_CLIENT,
        "A URL must be specified via " +
        "AddressBookProxy.setEndPoint(URL).");
      }
  
      call.setMethodName("addEntry");
      Vector params = new Vector();
      Parameter nameParam = new Parameter("name", java.lang.String.class, name,
        null);
      params.addElement(nameParam);
      Parameter addressParam = new Parameter("address",
        samples.addressbook2.Address.class, address, null);
      params.addElement(addressParam);
      call.setParams(params);
      Response resp = call.invoke(url, SOAPActionURI);
  
      // Check the response.
      if (resp.generatedFault())
      {
        Fault fault = resp.getFault();
  
        throw new SOAPException(fault.getFaultCode(), fault.getFaultString());
      }
    }
  
    public synchronized samples.addressbook2.Address getAddressFromName
      (java.lang.String name) throws SOAPException
    {
      if (url == null)
      {
        throw new SOAPException(Constants.FAULT_CODE_CLIENT,
        "A URL must be specified via " +
        "AddressBookProxy.setEndPoint(URL).");
      }
  
      call.setMethodName("getAddressFromName");
      Vector params = new Vector();
      Parameter nameParam = new Parameter("name", java.lang.String.class, name,
        null);
      params.addElement(nameParam);
      call.setParams(params);
      Response resp = call.invoke(url, SOAPActionURI);
  
      // Check the response.
      if (resp.generatedFault())
      {
        Fault fault = resp.getFault();
  
        throw new SOAPException(fault.getFaultCode(), fault.getFaultString());
      }
      else
      {
        Parameter retValue = resp.getReturnValue();
        return (samples.addressbook2.Address)retValue.getValue();
      }
    }
  
    {
      samples.addressbook2.PhoneSerializer ser_0 = new samples.addressbook2.PhoneSerializer
        ();
      smr.mapTypes("http://schemas.xmlsoap.org/soap/encoding/", new QName(
        "urn:xml-soap-address-demo", "phone"), samples.addressbook2.Phone.class,
        ser_0, ser_0);
      samples.addressbook2.AddressSerializer ser_1 = new samples.addressbook2.AddressSerializer
        ();
      smr.mapTypes("http://schemas.xmlsoap.org/soap/encoding/", new QName(
        "urn:xml-soap-address-demo", "address"),
        samples.addressbook2.Address.class, ser_1, ser_1);
    }
  
  }
  
  
  
  1.1                  xml-soap/java/samples/addressbook2/AddressSerializer.java
  
  Index: AddressSerializer.java
  ===================================================================
  package samples.addressbook2;
  
  import java.io.*;
  import org.w3c.dom.*;
  import org.apache.soap.*;
  import org.apache.soap.encoding.soapenc.*;
  import org.apache.soap.rpc.*;
  import org.apache.soap.util.*;
  import org.apache.soap.util.xml.*;
  
  public class AddressSerializer implements Serializer, Deserializer
  {
    private XMLParserLiaison xpl = new XercesParserLiaison();
  
    public void marshall(String inScopeEncStyle, Class javaType,
    Object src, Object context, Writer sink,
    NSStack nsStack, XMLJavaMappingRegistry xjmr, SOAPContext ctx)
    throws IllegalArgumentException, IOException
    {
      nsStack.pushScope();
  
      SoapEncUtils.generateStructureHeader(inScopeEncStyle, javaType, context,
        sink, nsStack, xjmr);
  
      sink.write(StringUtils.lineSeparator);
  
      samples.addressbook2.Address src2 = (samples.addressbook2.Address)src;
      Parameter param;
  
      param = new Parameter("streetNum", int.class, new Integer
        (src2.streetNum_Elem), null);
      xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
      sink, nsStack, ctx);
      sink.write(StringUtils.lineSeparator);
  
      param = new Parameter("streetName", java.lang.String.class,
        src2.streetName_Elem, null);
      xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
      sink, nsStack, ctx);
      sink.write(StringUtils.lineSeparator);
  
      param = new Parameter("city", java.lang.String.class, src2.city_Elem, null);
      xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
      sink, nsStack, ctx);
      sink.write(StringUtils.lineSeparator);
  
      param = new Parameter("state", java.lang.String.class, src2.state_Elem,
        null);
      xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
      sink, nsStack, ctx);
      sink.write(StringUtils.lineSeparator);
  
      param = new Parameter("zip", int.class, new Integer(src2.zip_Elem), null);
      xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
      sink, nsStack, ctx);
      sink.write(StringUtils.lineSeparator);
  
      param = new Parameter("phoneNumber", samples.addressbook2.Phone.class,
        src2.phoneNumber_Elem, null);
      xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
      sink, nsStack, ctx);
      sink.write(StringUtils.lineSeparator);
  
  
      sink.write("</" + context + '>');
  
      nsStack.popScope();
    }
  
    public Bean unmarshall(String inScopeEncStyle, QName elementType,
    Node src, XMLJavaMappingRegistry xjmr, SOAPContext ctx)
    throws IllegalArgumentException
    {
      Element root = (Element)src;
      Element tempEl = DOMUtils.getFirstChildElement(root);
      samples.addressbook2.Address target;
  
      try
      {
        target =
          (samples.addressbook2.Address)samples.addressbook2.Address.class.newInstance
          ();
      }
      catch (Exception e)
      {
        throw new IllegalArgumentException("Problem instantiating bean: "
          + e.getMessage());
      }
  
      while (tempEl != null)
      {
        Bean paramBean = xjmr.unmarshall(inScopeEncStyle,
        RPCConstants.Q_ELEM_PARAMETER,
        tempEl, ctx);
        Parameter param = (Parameter)paramBean.value;
        String tagName = tempEl.getTagName();
  
  
        if (tagName.equals("streetNum"))
        {
          target.streetNum_Elem = ((Integer)param.getValue()).intValue();
        }
  
        if (tagName.equals("streetName"))
        {
          target.streetName_Elem = (java.lang.String)param.getValue();
        }
  
        if (tagName.equals("city"))
        {
          target.city_Elem = (java.lang.String)param.getValue();
        }
  
        if (tagName.equals("state"))
        {
          target.state_Elem = (java.lang.String)param.getValue();
        }
  
        if (tagName.equals("zip"))
        {
          target.zip_Elem = ((Integer)param.getValue()).intValue();
        }
  
        if (tagName.equals("phoneNumber"))
        {
          target.phoneNumber_Elem = (samples.addressbook2.Phone)param.getValue();
        }
  
  
        tempEl = DOMUtils.getNextSiblingElement(tempEl);
      }
  
      return new Bean(samples.addressbook2.Address.class, target);
    }
  }
  
  
  
  1.1                  xml-soap/java/samples/addressbook2/DeploymentDescriptor.xml
  
  Index: DeploymentDescriptor.xml
  ===================================================================
  <isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
               id="urn:AddressFetcher2">
    <isd:provider type="java"
                  scope="Session"
                  methods="getAddressFromName addEntry getAllListings putListings">
      <isd:java class="samples.addressbook.AddressBook" static="false"/>
    </isd:provider>
  
    <isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListener>
  
    <isd:mappings>
      <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
               xmlns:x="urn:xml-soap-address-demo" qname="x:address"
               javaType="samples.addressbook.Address"
               java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"
               xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
      <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
               xmlns:x="urn:xml-soap-address-demo" qname="x:phone"
               javaType="samples.addressbook.PhoneNumber"
               java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"
               xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
    </isd:mappings>    
  </isd:service>
  
  
  
  1.1                  xml-soap/java/samples/addressbook2/Main.java
  
  Index: Main.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "SOAP" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2000, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package samples.addressbook2;
  
  import java.net.*;
  import org.apache.soap.transport.http.*;
  
  /**
   * This class shows how to use the SOAPHTTPConnection's ability to
   * maintain an http session. 
   *
   * @author Sanjiva Weerawarana <sa...@watson.ibm.com>
   */
  public class Main {
    static String name1 = "Purdue Boilermaker";
    static Address addr1 = new Address (1, "University Drive", 
  				      "West Lafayette", "IN", 47907,
  				      new Phone (765, "494", "4900"));
  
    private static void doit (AddressBookProxy ab) throws Exception {
      System.err.println (">> Storing address for '" + name1 + "'");
      ab.addEntry (name1, addr1);
      System.err.println (">> Querying address for '" + name1 + "'");
      Address resp = ab.getAddressFromName (name1);
      System.err.println (">> Response is = " + resp);
      System.err.println ("\n");
    }
  
    public static void main (String[] args) throws Exception {
      URL serviceURL = null;
  
      if (args.length > 1) {
        System.err.println ("Usage: java " + Main.class.getName () + 
  			  " [Service-URL]");
        System.exit (1);
      } else if (args.length == 1) {
        serviceURL = new URL (args[0]);
      }
  
      System.err.println ("Using proxy without session maintenance.\n");
      AddressBookProxy ab1 = new AddressBookProxy ();
      if (serviceURL != null) {
        ab1.setEndPoint (serviceURL);
      }
      doit (ab1);
  
      System.err.println ("Using proxy with session maintenance.\n");
      AddressBookProxy ab2 = new AddressBookProxy ();
      if (serviceURL != null) {
        ab2.setEndPoint (serviceURL);
      }
      SOAPHTTPConnection shc = new SOAPHTTPConnection ();
      shc.setMaintainSession (true);
      ab2.setSOAPTransport (shc);
      doit (ab2);
    }
  }
  
  
  
  1.1                  xml-soap/java/samples/addressbook2/Phone.java
  
  Index: Phone.java
  ===================================================================
  /*
   *This class is automatically generated by schema to Java program.
   *Only a subset of schema is handled and some of the schema information
   *may be lost during translation
   */
  
  package samples.addressbook2;
  
  public class Phone{
  
  	//instance variables
  	public int	areaCode_Elem;
  	public java.lang.String	exchange_Elem;
  	public java.lang.String	number_Elem;
  
  	//constructors
  	public Phone () { }
  
  	public Phone (int areaCode_Elem, java.lang.String exchange_Elem, java.lang.String number_Elem) {
  		this.areaCode_Elem	= areaCode_Elem;
  		this.exchange_Elem	= exchange_Elem;
  		this.number_Elem	= number_Elem;
  	}
  
  }
  
  
  1.1                  xml-soap/java/samples/addressbook2/PhoneSerializer.java
  
  Index: PhoneSerializer.java
  ===================================================================
  package samples.addressbook2;
  
  import java.io.*;
  import org.w3c.dom.*;
  import org.apache.soap.*;
  import org.apache.soap.encoding.soapenc.*;
  import org.apache.soap.rpc.*;
  import org.apache.soap.util.*;
  import org.apache.soap.util.xml.*;
  
  public class PhoneSerializer implements Serializer, Deserializer
  {
    private XMLParserLiaison xpl = new XercesParserLiaison();
  
    public void marshall(String inScopeEncStyle, Class javaType,
    Object src, Object context, Writer sink,
    NSStack nsStack, XMLJavaMappingRegistry xjmr, SOAPContext ctx)
    throws IllegalArgumentException, IOException
    {
      nsStack.pushScope();
  
      SoapEncUtils.generateStructureHeader(inScopeEncStyle, javaType, context,
        sink, nsStack, xjmr);
  
      sink.write(StringUtils.lineSeparator);
  
      samples.addressbook2.Phone src2 = (samples.addressbook2.Phone)src;
      Parameter param;
  
      param = new Parameter("areaCode", int.class, new Integer
        (src2.areaCode_Elem), null);
      xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
      sink, nsStack, ctx);
      sink.write(StringUtils.lineSeparator);
  
      param = new Parameter("exchange", java.lang.String.class,
        src2.exchange_Elem, null);
      xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
      sink, nsStack, ctx);
      sink.write(StringUtils.lineSeparator);
  
      param = new Parameter("number", java.lang.String.class, src2.number_Elem,
        null);
      xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
      sink, nsStack, ctx);
      sink.write(StringUtils.lineSeparator);
  
  
      sink.write("</" + context + '>');
  
      nsStack.popScope();
    }
  
    public Bean unmarshall(String inScopeEncStyle, QName elementType,
    Node src, XMLJavaMappingRegistry xjmr, SOAPContext ctx)
    throws IllegalArgumentException
    {
      Element root = (Element)src;
      Element tempEl = DOMUtils.getFirstChildElement(root);
      samples.addressbook2.Phone target;
  
      try
      {
        target =
          (samples.addressbook2.Phone)samples.addressbook2.Phone.class.newInstance
          ();
      }
      catch (Exception e)
      {
        throw new IllegalArgumentException("Problem instantiating bean: "
          + e.getMessage());
      }
  
      while (tempEl != null)
      {
        Bean paramBean = xjmr.unmarshall(inScopeEncStyle,
        RPCConstants.Q_ELEM_PARAMETER,
        tempEl, ctx);
        Parameter param = (Parameter)paramBean.value;
        String tagName = tempEl.getTagName();
  
  
        if (tagName.equals("areaCode"))
        {
          target.areaCode_Elem = ((Integer)param.getValue()).intValue();
        }
  
        if (tagName.equals("exchange"))
        {
          target.exchange_Elem = (java.lang.String)param.getValue();
        }
  
        if (tagName.equals("number"))
        {
          target.number_Elem = (java.lang.String)param.getValue();
        }
  
  
        tempEl = DOMUtils.getNextSiblingElement(tempEl);
      }
  
      return new Bean(samples.addressbook2.Phone.class, target);
    }
  }