alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Axis 2 example source code file (ADBDatabindingTemplate.xsl)

This example Axis 2 source code file (ADBDatabindingTemplate.xsl) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Axis 2 tags/keywords

adb, apache, asf, asf, assumption, license, license, my_qname, my_qname,factory, my_qname,factory, see, the, the, you

The Axis 2 ADBDatabindingTemplate.xsl source code

<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one
  ~ or more contributor license agreements. See the NOTICE file
  ~ distributed with this work for additional information
  ~ regarding copyright ownership. The ASF licenses this file
  ~ to you under the Apache License, Version 2.0 (the
  ~ "License"); you may not use this file except in compliance
  ~ with the License. You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing,
  ~ software distributed under the License is distributed on an
  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~ KIND, either express or implied. See the License for the
  ~ specific language governing permissions and limitations
  ~ under the License.
  -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>
    <xsl:key name="paramsIn" match="//databinders/param[@direction='in']" use="@type"/>
    <xsl:key name="paramsOut" match="//databinders/param[@direction='out']" use="@type"/>
    <xsl:key name="innerParams" match="//databinders/param[@direction='in']/param" use="@partname"/>
    <xsl:key name="innerOutParams" match="//databinders/param[@direction='out']/param" use="@partname"/>
    <!--

    <!-- #################################################################################  -->
    <!-- ############################   ADB template   ##############################  -->
    <xsl:template match="databinders[@dbtype='adb']">
        <xsl:variable name="serverside"  select="@isserverside">
        <xsl:variable name="helpermode"  select="extra/@h">

        <!--  generate toOM for only non parts and non primitives!!! -->
        <xsl:for-each select="param[not(@type = preceding-sibling::param/@type) and @type!='' and not(@primitive)]">
            private  org.apache.axiom.om.OMElement  toOM(<xsl:value-of select="@type"/> param, boolean optimizeContent)
            throws org.apache.axis2.AxisFault {

            <xsl:choose>
                    <xsl:when test="$helpermode">
                         try{
                            return <xsl:value-of select="@type"/>Helper.getOMElement(
                                        param,
                                        <xsl:value-of select="@type"/>.MY_QNAME,
                                        org.apache.axiom.om.OMAbstractFactory.getOMFactory());
                            } catch(org.apache.axis2.databinding.ADBException e){
                                throw org.apache.axis2.AxisFault.makeFault(e);
                            }
                    </xsl:when>
                    <xsl:when test="@type = 'org.apache.axiom.om.OMElement'">
                     return param; 
                    </xsl:when>
                    <xsl:otherwise>
                        try{
                             return param.getOMElement(<xsl:value-of select="@type"/>.MY_QNAME,
                                          org.apache.axiom.om.OMAbstractFactory.getOMFactory());
                        } catch(org.apache.axis2.databinding.ADBException e){
                            throw org.apache.axis2.AxisFault.makeFault(e);
                        }
                    </xsl:otherwise>
            </xsl:choose>

            }
        </xsl:for-each>

        <xsl:for-each select="opnames/name">

            <xsl:variable name="opname" select="."/>
            <xsl:variable name="opnsuri" select="@opnsuri"/>
            <xsl:variable name="paramcount" select="count(../../param[@type!='' and @direction='in' and @opname=$opname])"/>

            <xsl:if test="not($serverside)">
                <xsl:choose>
                    <xsl:when test="$paramcount > 0">
                        <xsl:variable name="inputElement" select="../../param[@type!='' and @direction='in' and @opname=$opname]">
                        <xsl:variable name="inputElementType" select="../../param[@type!='' and @direction='in' and @opname=$opname]/@type">
                        <xsl:variable name="inputElementShortType" select="../../param[@type!='' and @direction='in' and @opname=$opname]/@shorttype">
                        <xsl:variable name="inputElementComplexType" select="../../param[@type!='' and @direction='in' and @opname=$opname]/@complextype">
                        <xsl:variable name="wrappedParameterCount" select="count(../../param[@type!='' and @direction='in' and @opname=$opname]/param)">
                        <xsl:if test="generate-id($inputElement) = generate-id(key('paramsIn', $inputElementType)[1])">

                         <!-- if the unwrapping mode is on then we have to generate the unwrapped methods -->
                         <xsl:choose>
                                <xsl:when test="$wrappedParameterCount > 0">
                                    <!-- geneate the toEnvelope method-->
                                private  org.apache.axiom.soap.SOAPEnvelope toEnvelope(org.apache.axiom.soap.SOAPFactory factory,
                                    <xsl:for-each select="../../param[@type!='' and @direction='in' and @opname=$opname]/param">
                                     <xsl:value-of select="@type"/> param,
                                    </xsl:for-each>
                                    <xsl:value-of select="$inputElementType"/> dummyWrappedType,
                                 boolean optimizeContent) throws org.apache.axis2.AxisFault{

                                try{
                                <xsl:value-of select="$inputElementType"/> wrappedType = new ();

                                 <xsl:choose>
                                     <xsl:when test="string-length(normalize-space($inputElementComplexType)) > 0">
                                          <xsl:value-of select="$inputElementComplexType"/> wrappedComplexType = new ();
                                          <xsl:for-each select="../../param[@type!='' and @direction='in' and @opname=$opname]/param">
                                              wrappedComplexType.set<xsl:value-of select="@partname"/>(param);
                                         </xsl:for-each>
                                         wrappedType.set<xsl:value-of select="$inputElementShortType"/>(wrappedComplexType);
                                     </xsl:when>
                                     <xsl:otherwise>
                                         <xsl:for-each select="../../param[@type!='' and @direction='in' and @opname=$opname]/param">
                                              wrappedType.set<xsl:value-of select="@partname"/>(param);
                                         </xsl:for-each>
                                     </xsl:otherwise>
                                 </xsl:choose>

                               org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope();
                                  <xsl:choose>
                                    <xsl:when test="$helpermode">
                                        emptyEnvelope.getBody().addChild(<xsl:value-of select="$inputElementType"/>Helper.getOMElement(
                                        wrappedType,
                                        <xsl:value-of select="$inputElementType"/>.MY_QNAME,factory));
                                    </xsl:when>
                                    <xsl:otherwise>
                                        emptyEnvelope.getBody().addChild(wrappedType.getOMElement(<xsl:value-of select="$inputElementType"/>.MY_QNAME,factory));
                                    </xsl:otherwise>
                                </xsl:choose>

                                return emptyEnvelope;
                               } catch(org.apache.axis2.databinding.ADBException e){
                                    throw org.apache.axis2.AxisFault.makeFault(e);
                               }
                               }



                                </xsl:when>

                         </xsl:choose>
                            <!-- Assumption - the parameter is always an ADB element-->
                            private  org.apache.axiom.soap.SOAPEnvelope toEnvelope(org.apache.axiom.soap.SOAPFactory factory, <xsl:value-of select="$inputElementType"/> param, boolean optimizeContent)
                            throws org.apache.axis2.AxisFault{

                                 <xsl:choose>
                                    <xsl:when test="$helpermode">
                                        try{
                                            org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope();
                                            emptyEnvelope.getBody().addChild(<xsl:value-of select="$inputElementType"/>Helper.getOMElement(
                                            param,
                                            <xsl:value-of select="$inputElementType"/>.MY_QNAME,factory));
                                            return emptyEnvelope;
                                            } catch(org.apache.axis2.databinding.ADBException e){
                                                throw org.apache.axis2.AxisFault.makeFault(e);
                                            }
                                    </xsl:when>
                                    <xsl:when test="$inputElementType = 'org.apache.axiom.om.OMElement'">
                                        org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope();
                                        emptyEnvelope.getBody().addChild(param);
                                        return emptyEnvelope;
                                     </xsl:when>
                                    <xsl:otherwise>
                                        try{

                                                org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope();
                                                emptyEnvelope.getBody().addChild(param.getOMElement(<xsl:value-of select="$inputElementType"/>.MY_QNAME,factory));
                                                return emptyEnvelope;
                                            } catch(org.apache.axis2.databinding.ADBException e){
                                                throw org.apache.axis2.AxisFault.makeFault(e);
                                            }
                                    </xsl:otherwise>
                            </xsl:choose>

                            }

                             <!-- to support for backword compatiblity we have to add and wrapp method-->
                             /* methods to provide back word compatibility */

                             <xsl:if test="string-length(normalize-space($inputElementComplexType)) > 0">
                                private <xsl:value-of select="$inputElementComplexType"/> get(
                                <xsl:value-of select="$inputElementType"/> wrappedType){
                                    return wrappedType.get<xsl:value-of select="$inputElementShortType"/>();
                                }

                                private <xsl:value-of select="$inputElementType"/> wrap(
                                <xsl:value-of select="$inputElementComplexType"/> innerType){
                                    <xsl:value-of select="$inputElementType"/> wrappedElement = new ();
                                    wrappedElement.set<xsl:value-of select="$inputElementShortType"/>(innerType);
                                    return wrappedElement;
                                }
                            </xsl:if>
                        </xsl:if>
                   </xsl:when>
                   <xsl:otherwise>
                      <!-- Do nothing here -->
                    </xsl:otherwise>
                </xsl:choose>
                <!-- generate additional getter and setter method to remove top element of the response
                    only usefull when -b option on-->
                <xsl:if test="count(../../param[@type!='' and @direction='out' and @opname=$opname])=1">
                        <!-- generate the get methods -->
                        <xsl:variable name="outputElement" select="../../param[@type!='' and @direction='out' and @opname=$opname]">
                        <xsl:variable name="outputElementType" select="../../param[@type!='' and @direction='out' and @opname=$opname]/@type">
                        <xsl:variable name="outputElementShortType" select="../../param[@type!='' and @direction='out' and @opname=$opname]/@shorttype">
                        <xsl:variable name="outputElementComplexType" select="../../param[@type!='' and @direction='out' and @opname=$opname]/@complextype">

                        <xsl:for-each select="../../param[@type!='' and @direction='out' and @opname=$opname]/param">

                            <xsl:variable name="paramElement" select=".">
                            <xsl:variable name="partName" select="@partname">

                            <xsl:if test="(generate-id($paramElement) = generate-id(key('innerOutParams', $partName)[1])) or
                                (generate-id($outputElement) = generate-id(key('paramsOut', $outputElementType)[1]))">

                                <!-- we put the out element type to the method signature to make it unique -->
                                private <xsl:value-of select="@type"/> get(
                                <xsl:value-of select="$outputElementType"/> wrappedType){
                                <xsl:choose>
                                    <xsl:when test="string-length(normalize-space($outputElementComplexType)) > 0">
                                        return wrappedType.get<xsl:value-of select="$outputElementShortType"/>().get();
                                    </xsl:when>
                                    <xsl:otherwise>
                                        return wrappedType.get<xsl:value-of select="@partname"/>();
                                    </xsl:otherwise>
                                </xsl:choose>
                                }
                             </xsl:if>
                        </xsl:for-each>

                        <xsl:if test="generate-id($outputElement) = generate-id(key('paramsOut', $outputElementType)[1])">
                            <xsl:if test="string-length(normalize-space($outputElementComplexType)) > 0">

                                private <xsl:value-of select="$outputElementComplexType"/> get(
                                <xsl:value-of select="$outputElementType"/> wrappedType){
                                    return wrappedType.get<xsl:value-of select="$outputElementShortType"/>();
                                }

                                <!-- in client side we donot have to wrap the out put messages -->
                                <!--
                                private <xsl:value-of select="$outputElementType"/> wrap(
                                <xsl:value-of select="$outputElementComplexType"/> innerType){
                                    <xsl:value-of select="$outputElementType"/> wrappedElement = new ();
                                    wrappedElement.set<xsl:value-of select="$outputElementShortType"/>(innerType);
                                    return wrappedElement;
                                } -->
                            </xsl:if>
                        </xsl:if>
                  </xsl:if>
            </xsl:if>
            <!-- this piece of logic needs to be generated only for the server side-->
            <xsl:if test="$serverside">
             <xsl:choose>
                  <xsl:when test="count(../../param[@type!='' and @direction='out' and @opname=$opname])=1">
                  <xsl:variable name="outElement" select="../../param[@type!='' and @direction='out' and @opname=$opname]">
                  <xsl:variable name="outElementType" select="../../param[@type!='' and @direction='out' and @opname=$opname]/@type">
                    <!-- Assumption - The ADBBean here is always an element based bean -->
                    <xsl:if test="generate-id($outElement) = generate-id(key('paramsOut', $outElementType)[1])">
                    private  org.apache.axiom.soap.SOAPEnvelope toEnvelope(org.apache.axiom.soap.SOAPFactory factory, <xsl:value-of select="../../param[@type!='' and @direction='out' and @opname=$opname]/@type"/> param, boolean optimizeContent)
                        throws org.apache.axis2.AxisFault{
                      try{
                          org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope();
                           <xsl:choose>
                                <xsl:when test="$helpermode">
                                    emptyEnvelope.getBody().addChild(
                                    <xsl:value-of select="../../param[@type!='' and @direction='out' and @opname=$opname]/@type"/>Helper.getOMElement(
                                    param,
                                    <xsl:value-of select="../../param[@type!='' and @direction='out' and @opname=$opname]/@type"/>.MY_QNAME,factory));
                                </xsl:when>
                                <xsl:otherwise>
                                    emptyEnvelope.getBody().addChild(param.getOMElement(<xsl:value-of select="../../param[@type!='' and @direction='out' and @opname=$opname]/@type"/>.MY_QNAME,factory));
                                </xsl:otherwise>
                        </xsl:choose>

                         return emptyEnvelope;
                    } catch(org.apache.axis2.databinding.ADBException e){
                        throw org.apache.axis2.AxisFault.makeFault(e);
                    }
                    }
                    </xsl:if>
                </xsl:when>
       </xsl:choose>

            <xsl:if test="count(../../param[@type!='' and @direction='in' and @opname=$opname])=1">
                <!-- generate the get methods -->
                <xsl:variable name="inputElement" select="../../param[@type!='' and @direction='in' and @opname=$opname]">
                <xsl:variable name="inputElementType" select="../../param[@type!='' and @direction='in' and @opname=$opname]/@type">
                <xsl:variable name="inputElementShortType" select="../../param[@type!='' and @direction='in' and @opname=$opname]/@shorttype">
                <xsl:variable name="inputElementComplexType" select="../../param[@type!='' and @direction='in' and @opname=$opname]/@complextype">

                <xsl:for-each select="../../param[@type!='' and @direction='in' and @opname=$opname]/param">

                    <xsl:variable name="paramElement" select=".">
                    <xsl:variable name="partName" select="@partname">

                    <xsl:if test="(generate-id($paramElement) = generate-id(key('innerParams', $partName)[1])) or
                        (generate-id($inputElement) = generate-id(key('paramsIn', $inputElementType)[1]))">

                        private <xsl:value-of select="@type"/> get(
                        <xsl:value-of select="../@type"/> wrappedType){
                        <xsl:choose>
                            <!--
                            <xsl:when test="string-length(normalize-space($inputElementComplexType)) > 0">
                                return wrappedType.get<xsl:value-of select="$inputElementShortType"/>().get();
                            </xsl:when>
                            <xsl:otherwise>
                                return wrappedType.get<xsl:value-of select="@partname"/>();
                            </xsl:otherwise>
                        </xsl:choose>
                        }
                     </xsl:if>
                </xsl:for-each>
                <xsl:if test="generate-id($inputElement) = generate-id(key('paramsIn', $inputElementType)[1])">
                    <xsl:if test="string-length(normalize-space($inputElementComplexType)) > 0">
                        private <xsl:value-of select="$inputElementComplexType"/> get(
                        <xsl:value-of select="$inputElementType"/> wrappedType){
                            return wrappedType.get<xsl:value-of select="$inputElementShortType"/>();
                        }
                        <!-- in server side we do not want to wrap input elements -->
                        <!--
                        private <xsl:value-of select="$inputElementType"/> wrap(
                        <xsl:value-of select="$inputElementComplexType"/> innerType){
                            <xsl:value-of select="$inputElementType"/> wrappedElement = new ();
                            wrappedElement.set<xsl:value-of select="$inputElementShortType"/>(innerType);
                            return wrappedElement;
                        } -->
                    </xsl:if>
                </xsl:if>
            </xsl:if>

            <xsl:if test="count(../../param[@type!='' and @direction='out' and @opname=$opname])=1">
            <!-- generate the get methods -->
            <xsl:variable name="outputElement" select="../../param[@type!='' and @direction='out' and @opname=$opname]">
            <xsl:variable name="outputElementType" select="../../param[@type!='' and @direction='out' and @opname=$opname]/@type">
            <xsl:variable name="outputElementShortType" select="../../param[@type!='' and @direction='out' and @opname=$opname]/@shorttype">
            <xsl:variable name="outputElementComplexType" select="../../param[@type!='' and @direction='out' and @opname=$opname]/@complextype">

            <xsl:for-each select="../../param[@type!='' and @direction='out' and @opname=$opname]/param">

                    <xsl:variable name="paramElement" select=".">
                    <xsl:variable name="partName" select="@partname">

                    <xsl:if test="(generate-id($paramElement) = generate-id(key('innerOutParams', $partName)[1])) or
                        (generate-id($outputElement) = generate-id(key('paramsOut', $outputElementType)[1]))">

                        <!-- we put the out element type to the method signature to make it unique -->
                        private <xsl:value-of select="$outputElementType"/> wrap(
                        <xsl:value-of select="@type"/> param){
                        <xsl:value-of select="$outputElementType"/> wrappedElement = new ();
                        <xsl:choose>
                            <xsl:when test="string-length(normalize-space($outputElementComplexType)) > 0">
                                <xsl:value-of select="$outputElementComplexType"/> innerType = new 
                    <!-- in server side we do not want to unwrap the output type -->
                    <!--
                    private <xsl:value-of select="$outputElementComplexType"/> get(
                    <xsl:value-of select="$outputElementType"/> wrappedType){
                        return wrappedType.get<xsl:value-of select="$outputElementShortType"/>();
                    } -->
                    private <xsl:value-of select="$outputElementType"/> wrap(
                    <xsl:value-of select="$outputElementComplexType"/> innerType){
                        <xsl:value-of select="$outputElementType"/> wrappedElement = new ();
                        wrappedElement.set<xsl:value-of select="$outputElementShortType"/>(innerType);
                        return wrappedElement;
                    }
                </xsl:if>
            </xsl:if>
            </xsl:if>
      </xsl:if>
      </xsl:for-each>


        /**
        *  get the default envelope
        */
        private org.apache.axiom.soap.SOAPEnvelope toEnvelope(org.apache.axiom.soap.SOAPFactory factory){
        return factory.getDefaultEnvelope();
        }


        private  java.lang.Object fromOM(
        org.apache.axiom.om.OMElement param,
        java.lang.Class type,
        java.util.Map extraNamespaces) throws org.apache.axis2.AxisFault{

        try {
        <xsl:for-each select="param[not(@primitive) and @type!='']">
                if (<xsl:value-of select="@type"/>.class.equals(type)){
                <xsl:choose>
                    <xsl:when test="$helpermode">
                           return <xsl:value-of select="@type"/>Helper.parse(param.getXMLStreamReaderWithoutCaching());
                    </xsl:when>
                    <xsl:when test="@type = 'org.apache.axiom.om.OMElement'">
                           return param;
                    </xsl:when>
                    <xsl:otherwise>
                           return <xsl:value-of select="@type"/>.Factory.parse(param.getXMLStreamReaderWithoutCaching());
                    </xsl:otherwise>
                </xsl:choose>

                }
           </xsl:for-each>
        } catch (java.lang.Exception e) {
        throw org.apache.axis2.AxisFault.makeFault(e);
        }
           return null;
        }



    </xsl:template>

</xsl:stylesheet>

Other Axis 2 examples (source code examples)

Here is a short list of links related to this Axis 2 ADBDatabindingTemplate.xsl source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.