axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Emberson <ember...@phc.net>
Subject AXIS FAQ: HOWTO HREF
Date Thu, 28 Mar 2002 01:41:09 GMT
There are three ways of doing HREFs in axis.

The first is to set doing multirefs property to true, the default (the
following does NOT have to be done):

msgContext.getAxisEngine().setOption(AxisEngine.PROP_DOMULTIREFS,
Boolean.TRUE);

In this case everything is multi-refed except "primitive" types. This is
safe but more than is
required.


The second way is to set the multirefs property to false, NOT the
default:

msgContext.getAxisEngine().setOption(AxisEngine.PROP_DOMULTIREFS,
Boolean.FALSE);

In this case, NOTHING is multi-refed. If you are real sure that none of
your objects share a
common, non "primitive" object this is ok .... but you'd better document
your assumption.


The third way and, it might add, the most appealing is to multi-ref only
when needed (greatly
enhanced readability of the soap xml in your log files among other
things).
Here you once again use the default multiref property value, true:

msgContext.getAxisEngine().setOption(AxisEngine.PROP_DOMULTIREFS,
Boolean.TRUE);

Then you do the following, you apply this patch to the file
org.apache.axis.encoding.SerializationContextImpl.java

116a117,124
>     private static HashMap primitives = null;
>     public static void addPrimitive(Class cls) {
>         if (primitives == null) {
>             primitives = new HashMap();
>         }
>         primitives.put(cls.getName(), cls);
>     }
>
445c453,455
<
---
> //System.out.println("isPrimitive: javaType = " +javaType.toString());

>         return primitives.containsKey(javaType.getName());
> /*
446a457
> */

You can either do this within the axis build directory or in some other
directory making sure your
patched file is first in the classpath during compile and execution.

Then for those object that you know are not shared, you simply enter
them into the
SerializationContextImpl class hashtable via the method
addPrimitive(Class cls)
(which really ought to be called "isnevershared"). Anyway, doing this
produces output like the following:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <SOAP-ENV:Body>
  <ns1:method1
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="urn:myNamespace">
   <type xsi:type="ns1:Type">
    <typeId xsi:type="xsd:long">44</typeId>
    <baseTypeId xsi:type="xsd:long">0</baseTypeId>
    <isAnonymous xsi:type="xsd:boolean">false</isAnonymous>
    <name xsi:type="xsd:string">string</name>
    <description xsi:type="xsd:string">a string type</description>
    <child xsi:type="ns1:RestrictionType">
     <facet xsi:type="ns1:Facet">
      <facetId xsi:type="xsd:long">23</facetId>
      <typeId xsi:type="xsd:long">44</typeId>
      <allowedFacets xsi:type="xsd:int">3072</allowedFacets>
      <pattern xsi:type="xsd:string">.*</pattern>
      <ordered xsi:type="xsd:short">1</ordered>
      <bounded xsi:type="xsd:boolean">true</bounded>
      <cardinality xsi:type="xsd:short">2</cardinality>
      <numeric xsi:type="xsd:boolean">false</numeric>
     </facet>
    </child>
   </type>
   <foo1 href="#id0"/>
   <foo2 href="#id1"/>
  </ns1:method1>
  <multiRef id="id0" SOAP-ENC:root="0" xsi:type="ns2:Foo"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns2="urn:myNamespace">
   <bar href="#id2"/>
  </multiRef>
  <multiRef id="id1" SOAP-ENC:root="0" xsi:type="ns3:Foo"
xmlns:ns3="urn:myNamespace"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
   <bar href="#id2"/>
  </multiRef>
  <multiRef id="id2" SOAP-ENC:root="0" xsi:type="ns4:Bar"
xmlns:ns4="urn:myNamespace"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
   <id xsi:type="xsd:int">2</id>
  </multiRef>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Where the Bar object is shared by two Foo objects but the Type's child
and its Facet are not
shared.

Issue: Is to bad that one has to do this at the SerializationContextImpl
class level rather
than the instance level - it is therefore JVM wide. But I could not find
any way to accomplish
this with the current axis system anyother way (href behavoir is not one
of Axis' user pluggable
interfaces). .... But it works (and I hope Axis is not modified to
disallow this approach).

Richard



Mime
View raw message