BPEL实例运行[3]——流程的调用

 

首先需要得到相应的 WSDL ,通过这些文件可以生成 WSDL 文件中定义的 Type 所对应的 Java 类,这些类有些类似于 Bean ,用于存储数据(如果知道 Type WSDL 中的定义的话也可以手工完成相应类的定义,实现相应的方法即可)。使用 Apache 的包 org.apache.axis.wsdl 中的 WSDL2Java.java 将本例中的 3 WSDL 文件转化为 java 文件。

WSDL2Java.java

 

/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed 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.
 
*/

package  org.apache.axis.wsdl;

import  org.apache.axis.constants.Scope;
import  org.apache.axis.utils.CLOption;
import  org.apache.axis.utils.CLOptionDescriptor;
import  org.apache.axis.utils.ClassUtils;
import  org.apache.axis.utils.JavaUtils;
import  org.apache.axis.utils.Messages;
import  org.apache.axis.wsdl.gen.Parser;
import  org.apache.axis.wsdl.gen.WSDL2;
import  org.apache.axis.wsdl.toJava.Emitter;
import  org.apache.axis.wsdl.toJava.NamespaceSelector;

/**
 * Command line interface to the WSDL2Java utility
 
*/

public   class  WSDL2Java  extends  WSDL2  {

    
// Define our short one-letter option identifiers.

    
/** Field SERVER_OPT */
    
protected static final int SERVER_OPT = 's';

    
/** Field SKELETON_DEPLOY_OPT */
    
protected static final int SKELETON_DEPLOY_OPT = 'S';

    
/** Field NAMESPACE_OPT */
    
protected static final int NAMESPACE_OPT = 'N';

    
/** Field NAMESPACE_FILE_OPT */
    
protected static final int NAMESPACE_FILE_OPT = 'f';

    
/** Field OUTPUT_OPT */
    
protected static final int OUTPUT_OPT = 'o';

    
/** Field SCOPE_OPT */
    
protected static final int SCOPE_OPT = 'd';

    
/** Field TEST_OPT */
    
protected static final int TEST_OPT = 't';
    
/** Field BUILDFILE_OPT */
    
protected static final int BUILDFILE_OPT = 'B';
    
/** Field PACKAGE_OPT */
    
protected static final int PACKAGE_OPT = 'p';

    
/** Field ALL_OPT */
    
protected static final int ALL_OPT = 'a';

    
/** Field TYPEMAPPING_OPT */
    
protected static final int TYPEMAPPING_OPT = 'T';

    
/** Field FACTORY_CLASS_OPT */
    
protected static final int FACTORY_CLASS_OPT = 'F';

    
/** Field HELPER_CLASS_OPT */
    
protected static final int HELPER_CLASS_OPT = 'H';

    
/** Field USERNAME_OPT */
    
protected static final int USERNAME_OPT = 'U';

    
/** Field PASSWORD_OPT */
    
protected static final int PASSWORD_OPT = 'P';

    
protected static final int CLASSPATH_OPT = 'X';

    
/** Field bPackageOpt */
    
protected boolean bPackageOpt = false;

    
/** Field namespace include */
    
protected static final int NS_INCLUDE_OPT = 'i';
    
    
/** Filed namespace exclude */
    
protected static final int NS_EXCLUDE_OPT = 'x';
    
    
/** Field IMPL_CLASS_OPT */
    
protected static final int IMPL_CLASS_OPT = 'c';

    
/** Field ALLOW_INVALID_URL_OPT */
    
protected static final int ALLOW_INVALID_URL_OPT = 'u';
    
    
/** Wrap arrays option */
    
protected static final int WRAP_ARRAYS_OPT = 'w';

    
/** Field emitter */
    
private Emitter emitter;
    
    
/**
     * Define the understood options. Each CLOptionDescriptor contains:
     * - The "long" version of the option. Eg, "help" means that "--help" will
     * be recognised.
     * - The option flags, governing the option's argument(s).
     * - The "short" version of the option. Eg, 'h' means that "-h" will be
     * recognised.
     * - A description of the option for the usage message
     
*/


    
protected static final CLOptionDescriptor[] options =
            
new CLOptionDescriptor[]{
                
new CLOptionDescriptor("server-side",
                        CLOptionDescriptor.ARGUMENT_DISALLOWED,
                        SERVER_OPT, Messages.getMessage(
"optionSkel00")),
                
new CLOptionDescriptor("skeletonDeploy",
                        CLOptionDescriptor.ARGUMENT_REQUIRED,
                        SKELETON_DEPLOY_OPT,
                        Messages.getMessage(
"optionSkeletonDeploy00")),
                
new CLOptionDescriptor("NStoPkg",
                        CLOptionDescriptor.DUPLICATES_ALLOWED
                        
+ CLOptionDescriptor.ARGUMENTS_REQUIRED_2,
                        NAMESPACE_OPT,
                        Messages.getMessage(
"optionNStoPkg00")),
                
new CLOptionDescriptor("fileNStoPkg",
                        CLOptionDescriptor.ARGUMENT_REQUIRED,
                        NAMESPACE_FILE_OPT,
                        Messages.getMessage(
"optionFileNStoPkg00")),
                
new CLOptionDescriptor("package", CLOptionDescriptor.ARGUMENT_REQUIRED,
                        PACKAGE_OPT,
                        Messages.getMessage(
"optionPackage00")),
                
new CLOptionDescriptor("output", CLOptionDescriptor.ARGUMENT_REQUIRED,
                        OUTPUT_OPT,
                        Messages.getMessage(
"optionOutput00")),
                
new CLOptionDescriptor("deployScope",
                        CLOptionDescriptor.ARGUMENT_REQUIRED, SCOPE_OPT,
                        Messages.getMessage(
"optionScope00")),
                
new CLOptionDescriptor("testCase",
                        CLOptionDescriptor.ARGUMENT_DISALLOWED,
                        TEST_OPT, Messages.getMessage(
"optionTest00")),
                
new CLOptionDescriptor("all", CLOptionDescriptor.ARGUMENT_DISALLOWED,
                        ALL_OPT, Messages.getMessage(
"optionAll00")),
                
new CLOptionDescriptor("typeMappingVersion",
                        CLOptionDescriptor.ARGUMENT_REQUIRED,
                        TYPEMAPPING_OPT,
                        Messages.getMessage(
"optionTypeMapping00")),
                
new CLOptionDescriptor("factory", CLOptionDescriptor.ARGUMENT_REQUIRED,
                        FACTORY_CLASS_OPT,
                        Messages.getMessage(
"optionFactory00")),
                
new CLOptionDescriptor("helperGen",
                        CLOptionDescriptor.ARGUMENT_DISALLOWED,
                        HELPER_CLASS_OPT,
                        Messages.getMessage(
"optionHelper00")),
                
new CLOptionDescriptor("buildFile", CLOptionDescriptor.ARGUMENT_DISALLOWED,
                        BUILDFILE_OPT,
                        Messages.getMessage(
"optionBuildFile00")),        
                
new CLOptionDescriptor("user", CLOptionDescriptor.ARGUMENT_REQUIRED,
                        USERNAME_OPT,
                        Messages.getMessage(
"optionUsername")),
                
new CLOptionDescriptor("password",
                        CLOptionDescriptor.ARGUMENT_REQUIRED,
                        PASSWORD_OPT,
                        Messages.getMessage(
"optionPassword")),
                
new CLOptionDescriptor("classpath",
                        CLOptionDescriptor.ARGUMENT_OPTIONAL,
                        CLASSPATH_OPT,
                        Messages.getMessage(
"optionClasspath")),
                
new CLOptionDescriptor("nsInclude",
                        CLOptionDescriptor.DUPLICATES_ALLOWED
                        
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
                        NS_INCLUDE_OPT,
                        Messages.getMessage(
"optionNSInclude")),
                
new CLOptionDescriptor("nsExclude",
                        CLOptionDescriptor.DUPLICATES_ALLOWED
                        
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
                        NS_EXCLUDE_OPT,
                        Messages.getMessage(
"optionNSExclude")),
                
new CLOptionDescriptor("implementationClassName",
                        CLOptionDescriptor.ARGUMENT_REQUIRED,
                        IMPL_CLASS_OPT,
                        Messages.getMessage(
"implementationClassName")),
                
new CLOptionDescriptor("allowInvalidURL", CLOptionDescriptor.ARGUMENT_DISALLOWED,
                        ALLOW_INVALID_URL_OPT, Messages.getMessage(
"optionAllowInvalidURL")),
                
new CLOptionDescriptor("wrapArrays",
                                       CLOptionDescriptor.ARGUMENT_OPTIONAL,
                                       WRAP_ARRAYS_OPT,
                                       Messages.getMessage(
"optionWrapArrays")),
                }
;

    
/**
     * Instantiate a WSDL2Java emitter.
     
*/

    
protected WSDL2Java() {

        
// emitter is the same as the parent's parser variable.  Just cast it
        
// here once so we don't have to cast it every time we use it.
        emitter = (Emitter) parser;

        addOptions(options);
    }
    // ctor

    
/**
     * Instantiate an extension of the Parser
     * 
     * 
@return 
     
*/

    
protected Parser createParser() {
        
return new Emitter();
    }
    // createParser
    
    
/**
     * Parse an option
     * 
     * 
@param option is the option
     
*/

    
protected void parseOption(CLOption option) {

        
switch (option.getId()) {

            
case FACTORY_CLASS_OPT:
                emitter.setFactory(option.getArgument());
                
break;

            
case HELPER_CLASS_OPT:
                emitter.setHelperWanted(
true);
                
break;

            
case SKELETON_DEPLOY_OPT:
                emitter.setSkeletonWanted(
                        JavaUtils.isTrueExplicitly(option.getArgument(
0)));

                
// --skeletonDeploy assumes --server-side, so fall thru
            case SERVER_OPT:
                emitter.setServerSide(
true);
                
break;

            
case NAMESPACE_OPT:
                String namespace 
= option.getArgument(0);
                String packageName 
= option.getArgument(1);

                emitter.getNamespaceMap().put(namespace, packageName);
                
break;

            
case NAMESPACE_FILE_OPT:
                emitter.setNStoPkg(option.getArgument());
                
break;

            
case PACKAGE_OPT:
                bPackageOpt 
= true;

                emitter.setPackageName(option.getArgument());
                
break;

            
case OUTPUT_OPT:
                emitter.setOutputDir(option.getArgument());
                
break;

            
case SCOPE_OPT:
                String arg 
= option.getArgument();

                
// Provide 'null' default, prevents logging internal error.
                
// we have something different to report here.
                Scope scope = Scope.getScope(arg, null);

                
if (scope != null{
                    emitter.setScope(scope);
                }
 else {
                    System.err.println(Messages.getMessage(
"badScope00", arg));
                }

                
break;

            
case TEST_OPT:
                emitter.setTestCaseWanted(
true);
                
break;
            
case BUILDFILE_OPT:
                emitter.setBuildFileWanted(
true);
                
break;
            
case ALL_OPT:
                emitter.setAllWanted(
true);
                
break;

            
case TYPEMAPPING_OPT:
                String tmValue 
= option.getArgument();

                
if (tmValue.equals("1.0")) {
                    emitter.setTypeMappingVersion(
"1.0");
                }
 else if (tmValue.equals("1.1")) {
                        emitter.setTypeMappingVersion(
"1.1");
                }
 else if (tmValue.equals("1.2")) {
                    emitter.setTypeMappingVersion(
"1.2");
                }
 else if (tmValue.equals("1.3")) {
                    emitter.setTypeMappingVersion(
"1.3");
                }
 else {
                    System.out.println(
                            Messages.getMessage(
"badTypeMappingOption00"));
                }

                
break;

            
case USERNAME_OPT:
                emitter.setUsername(option.getArgument());
                
break;

            
case PASSWORD_OPT:
                emitter.setPassword(option.getArgument());
                
break;

            
case CLASSPATH_OPT:
                ClassUtils.setDefaultClassLoader(ClassUtils.createClassLoader(
                        option.getArgument(),
                        
this.getClass().getClassLoader()));
                
break;

            
case NS_INCLUDE_OPT:
                NamespaceSelector include 
= new NamespaceSelector();
                include.setNamespace(option.getArgument());
                emitter.getNamespaceIncludes().add(include);
                
break;
            
case NS_EXCLUDE_OPT:
                NamespaceSelector exclude 
= new NamespaceSelector();
                exclude.setNamespace(option.getArgument());
                emitter.getNamespaceExcludes().add(exclude);
                
break;

            
case IMPL_CLASS_OPT:
                emitter.setImplementationClassName(option.getArgument());
                
break;

            
case ALLOW_INVALID_URL_OPT:
                emitter.setAllowInvalidURL(
true);
                
break;

            
case WRAP_ARRAYS_OPT:
                emitter.setWrapArrays(
true);
                
break;

            
default :
                
super.parseOption(option);
        }

    }
    // parseOption

    
/**
     * validateOptions
     * This method is invoked after the options are set to validate
     * the option settings.
     
*/

    
protected void validateOptions() {

        
super.validateOptions();

        
// validate argument combinations
        if (emitter.isSkeletonWanted() && !emitter.isServerSide()) {
            System.out.println(Messages.getMessage(
"badSkeleton00"));
            printUsage();
        }


        
if (!emitter.getNamespaceMap().isEmpty() && bPackageOpt) {
            System.out.println(Messages.getMessage(
"badpackage00"));
            printUsage();
        }

    }
    // validateOptions

    
/**
     * Main
     * Run the WSDL2Java emitter with the specified command-line arguments
     * 
     * 
@param args command-line arguments
     
*/

    
public static void main(String args[]) {
        
        WSDL2Java wsdl2java 
= new WSDL2Java();
                
        
//wsdl2java.run(args);
        
        String[] v
={"E:/Program Files/activeBPEL/Designer/workspace/airline/wsdl/Travel.wsdl"};
        
        wsdl2java.run(v);
    }

}

生成4个文件,分别如下:

airline包中

FlightConfirmationType.java

 

/**
 * FlightConfirmationType.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis #axisVersion# #today# WSDL2Java emitter.
 
*/


package  com.packtpub.service.airline;

public   class  FlightConfirmationType   implements  java.io.Serializable  {
    
private java.lang.String flightNo;

    
private com.packtpub.service.airline.TravelClassType travelClass;

    
private float price;

    
private java.util.Calendar departureDateTime;

    
private java.util.Calendar returnDateTime;

    
private boolean approved;

    
public FlightConfirmationType() {
    }


    
public FlightConfirmationType(
           java.lang.String flightNo,
           com.packtpub.service.airline.TravelClassType travelClass,
           
float price,
           java.util.Calendar departureDateTime,
           java.util.Calendar returnDateTime,
           
boolean approved) {
           
this.flightNo = flightNo;
           
this.travelClass = travelClass;
           
this.price = price;
           
this.departureDateTime = departureDateTime;
           
this.returnDateTime = returnDateTime;
           
this.approved = approved;
    }



    
/**
     * Gets the flightNo value for this FlightConfirmationType.
     * 
     * 
@return flightNo
     
*/

    
public java.lang.String getFlightNo() {
        
return flightNo;
    }



    
/**
     * Sets the flightNo value for this FlightConfirmationType.
     * 
     * 
@param flightNo
     
*/

    
public void setFlightNo(java.lang.String flightNo) {
        
this.flightNo = flightNo;
    }



    
/**
     * Gets the travelClass value for this FlightConfirmationType.
     * 
     * 
@return travelClass
     
*/

    
public com.packtpub.service.airline.TravelClassType getTravelClass() {
        
return travelClass;
    }



    
/**
     * Sets the travelClass value for this FlightConfirmationType.
     * 
     * 
@param travelClass
     
*/

    
public void setTravelClass(com.packtpub.service.airline.TravelClassType travelClass) {
        
this.travelClass = travelClass;
    }



    
/**
     * Gets the price value for this FlightConfirmationType.
     * 
     * 
@return price
     
*/

    
public float getPrice() {
        
return price;
    }



    
/**
     * Sets the price value for this FlightConfirmationType.
     * 
     * 
@param price
     
*/

    
public void setPrice(float price) {
        
this.price = price;
    }



    
/**
     * Gets the departureDateTime value for this FlightConfirmationType.
     * 
     * 
@return departureDateTime
     
*/

    
public java.util.Calendar getDepartureDateTime() {
        
return departureDateTime;
    }



    
/**
     * Sets the departureDateTime value for this FlightConfirmationType.
     * 
     * 
@param departureDateTime
     
*/

    
public void setDepartureDateTime(java.util.Calendar departureDateTime) {
        
this.departureDateTime = departureDateTime;
    }



    
/**
     * Gets the returnDateTime value for this FlightConfirmationType.
     * 
     * 
@return returnDateTime
     
*/

    
public java.util.Calendar getReturnDateTime() {
        
return returnDateTime;
    }



    
/**
     * Sets the returnDateTime value for this FlightConfirmationType.
     * 
     * 
@param returnDateTime
     
*/

    
public void setReturnDateTime(java.util.Calendar returnDateTime) {
        
this.returnDateTime = returnDateTime;
    }



    
/**
     * Gets the approved value for this FlightConfirmationType.
     * 
     * 
@return approved
     
*/

    
public boolean isApproved() {
        
return approved;
    }



    
/**
     * Sets the approved value for this FlightConfirmationType.
     * 
     * 
@param approved
     
*/

    
public void setApproved(boolean approved) {
        
this.approved = approved;
    }


    
private java.lang.Object __equalsCalc = null;
    
public synchronized boolean equals(java.lang.Object obj) {
        
if (!(obj instanceof FlightConfirmationType)) return false;
        FlightConfirmationType other 
= (FlightConfirmationType) obj;
        
if (obj == nullreturn false;
        
if (this == obj) return true;
        
if (__equalsCalc != null{
            
return (__equalsCalc == obj);
        }

        __equalsCalc 
= obj;
        
boolean _equals;
        _equals 
= true && 
            ((
this.flightNo==null && other.getFlightNo()==null|| 
             (
this.flightNo!=null &&
              
this.flightNo.equals(other.getFlightNo()))) &&
            ((
this.travelClass==null && other.getTravelClass()==null|| 
             (
this.travelClass!=null &&
              
this.travelClass.equals(other.getTravelClass()))) &&
            
this.price == other.getPrice() &&
            ((
this.departureDateTime==null && other.getDepartureDateTime()==null|| 
             (
this.departureDateTime!=null &&
              
this.departureDateTime.equals(other.getDepartureDateTime()))) &&
            ((
this.returnDateTime==null && other.getReturnDateTime()==null|| 
             (
this.returnDateTime!=null &&
              
this.returnDateTime.equals(other.getReturnDateTime()))) &&
            
this.approved == other.isApproved();
        __equalsCalc 
= null;
        
return _equals;
    }


    
private boolean __hashCodeCalc = false;
    
public synchronized int hashCode() {
        
if (__hashCodeCalc) {
            
return 0;
        }

        __hashCodeCalc 
= true;
        
int _hashCode = 1;
        
if (getFlightNo() != null{
            _hashCode 
+= getFlightNo().hashCode();
        }

        
if (getTravelClass() != null{
            _hashCode 
+= getTravelClass().hashCode();
        }

        _hashCode 
+= new Float(getPrice()).hashCode();
        
if (getDepartureDateTime() != null{
            _hashCode 
+= getDepartureDateTime().hashCode();
        }

        
if (getReturnDateTime() != null{
            _hashCode 
+= getReturnDateTime().hashCode();
        }

        _hashCode 
+= (isApproved() ? Boolean.TRUE : Boolean.FALSE).hashCode();
        __hashCodeCalc 
= false;
        
return _hashCode;
    }


    
// Type metadata
    private static org.apache.axis.description.TypeDesc typeDesc =
        
new org.apache.axis.description.TypeDesc(FlightConfirmationType.classtrue);

    
static {
        typeDesc.setXmlType(
new javax.xml.namespace.QName("http://packtpub.com/service/airline/""FlightConfirmationType"));
        org.apache.axis.description.ElementDesc elemField 
= new org.apache.axis.description.ElementDesc();
        elemField.setFieldName(
"flightNo");
        elemField.setXmlName(
new javax.xml.namespace.QName("http://packtpub.com/service/airline/""FlightNo"));
        elemField.setXmlType(
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema""string"));
        elemField.setNillable(
false);
        typeDesc.addFieldDesc(elemField);
        elemField 
= new org.apache.axis.description.ElementDesc();
        elemField.setFieldName(
"travelClass");
        elemField.setXmlName(
new javax.xml.namespace.QName("http://packtpub.com/service/airline/""TravelClass"));
        elemField.setXmlType(
new javax.xml.namespace.QName("http://packtpub.com/service/airline/""TravelClassType"));
        elemField.setNillable(
false);
        typeDesc.addFieldDesc(elemField);
        elemField 
= new org.apache.axis.description.ElementDesc();
        elemField.setFieldName(
"price");
        elemField.setXmlName(
new javax.xml.namespace.QName("http://packtpub.com/service/airline/""Price"));
        elemField.setXmlType(
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema""float"));
        elemField.setNillable(
false);
        typeDesc.addFieldDesc(elemField);
        elemField 
= new org.apache.axis.description.ElementDesc();
        elemField.setFieldName(
"departureDateTime");
        elemField.setXmlName(
new javax.xml.namespace.QName("http://packtpub.com/service/airline/""DepartureDateTime"));
        elemField.setXmlType(
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema""dateTime"));
        elemField.setNillable(
false);
        typeDesc.addFieldDesc(elemField);
        elemField 
= new org.apache.axis.description.ElementDesc();
        elemField.setFieldName(
"returnDateTime");
        elemField.setXmlName(
new javax.xml.namespace.QName("http://packtpub.com/service/airline/""ReturnDateTime"));
        elemField.setXmlType(
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema""dateTime"));
        elemField.setNillable(
false);
        typeDesc.addFieldDesc(elemField);
        elemField 
= new org.apache.axis.description.ElementDesc();
        elemField.setFieldName(
"approved");
        elemField.setXmlName(
new javax.xml.namespace.QName("http://packtpub.com/service/airline/""Approved"));
        elemField.setXmlType(
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema""boolean"));
        elemField.setNillable(
false);
        typeDesc.addFieldDesc(elemField);
    }


    
/**
     * Return type metadata object
     
*/

    
public static org.apache.axis.description.TypeDesc getTypeDesc() {
        
return typeDesc;
    }


    
/**
     * Get Custom Serializer
     
*/

    
public static org.apache.axis.encoding.Serializer getSerializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) 
{
        
return 
          
new  org.apache.axis.encoding.ser.BeanSerializer(
            _javaType, _xmlType, typeDesc);
    }


    
/**
     * Get Custom Deserializer
     
*/

    
public static org.apache.axis.encoding.Deserializer getDeserializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) 
{
        
return 
          
new  org.apache.axis.encoding.ser.BeanDeserializer(
            _javaType, _xmlType, typeDesc);
    }


}

 

FlightRequestType.java

/**
 * FlightRequestType.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis #axisVersion# #today# WSDL2Java emitter.
 
*/


package  com.packtpub.service.airline;

public   class  FlightRequestType   implements  java.io.Serializable  {
    
private java.lang.String originFrom;

    
private java.lang.String destinationTo;

    
private java.util.Date desiredDepartureDate;

    
private java.util.Date desiredReturnDate;

    
public FlightRequestType() {
    }


    
public FlightRequestType(
           java.lang.String originFrom,
           java.lang.String destinationTo,
           java.util.Date desiredDepartureDate,
           java.util.Date desiredReturnDate) 
{
           
this.originFrom = originFrom;
           
this.destinationTo = destinationTo;
           
this.desiredDepartureDate = desiredDepartureDate;
           
this.desiredReturnDate = desiredReturnDate;
    }



    
/**
     * Gets the originFrom value for this FlightRequestType.
     * 
     * 
@return originFrom
     
*/

    
public java.lang.String getOriginFrom() {
        
return originFrom;
    }



    
/**
     * Sets the originFrom value for this FlightRequestType.
     * 
     * 
@param originFrom
     
*/

    
public void setOriginFrom(java.lang.String originFrom) {
        
this.originFrom = originFrom;
    }



    
/**
     * Gets the destinationTo value for this FlightRequestType.
     * 
     * 
@return destinationTo
     
*/

    
public java.lang.String getDestinationTo() {
        
return destinationTo;
    }



    
/**
     * Sets the destinationTo value for this FlightRequestType.
     * 
     * 
@param destinationTo
     
*/

    
public void setDestinationTo(java.lang.String destinationTo) {
        
this.destinationTo = destinationTo;
    }



    
/**
     * Gets the desiredDepartureDate value for this FlightRequestType.
     * 
     * 
@return desiredDepartureDate
     
*/

    
public java.util.Date getDesiredDepartureDate() {
        
return desiredDepartureDate;
    }



    
/**
     * Sets the desiredDepartureDate value for this FlightRequestType.
     * 
     * 
@param desiredDepartureDate
     
*/

    
public void setDesiredDepartureDate(java.util.Date desiredDepartureDate) {
        
this.desiredDepartureDate = desiredDepartureDate;
    }



    
/**
     * Gets the desiredReturnDate value for this FlightRequestType.
     * 
     * 
@return desiredReturnDate
     
*/

    
public java.util.Date getDesiredReturnDate() {
        
return desiredReturnDate;
    }



    
/**
     * Sets the desiredReturnDate value for this FlightRequestType.
     * 
     * 
@param desiredReturnDate
     
*/

    
public void setDesiredReturnDate(java.util.Date desiredReturnDate) {
        
this.desiredReturnDate = desiredReturnDate;
    }


    
private java.lang.Object __equalsCalc = null;
    
public synchronized boolean equals(java.lang.Object obj) {
        
if (!(obj instanceof FlightRequestType)) return false;
        FlightRequestType other 
= (FlightRequestType) obj;
        
if (obj == nullreturn false;
        
if (this == obj) return true;
        
if (__equalsCalc != null{
            
return (__equalsCalc == obj);
        }

        __equalsCalc 
= obj;
        
boolean _equals;
        _equals 
= true && 
            ((
this.originFrom==null && other.getOriginFrom()==null|| 
             (
this.originFrom!=null &&
              
this.originFrom.equals(other.getOriginFrom()))) &&
            ((
this.destinationTo==null && other.getDestinationTo()==null|| 
             (
this.destinationTo!=null &&
              
this.destinationTo.equals(other.getDestinationTo()))) &&
            ((
this.desiredDepartureDate==null && other.getDesiredDepartureDate()==null|| 
             (
this.desiredDepartureDate!=null &&
              
this.desiredDepartureDate.equals(other.getDesiredDepartureDate()))) &&
            ((
this.desiredReturnDate==null && other.getDesiredReturnDate()==null|| 
             (
this.desiredReturnDate!=null &&
              
this.desiredReturnDate.equals(other.getDesiredReturnDate())));
        __equalsCalc 
= null;
        
return _equals;
    }


    
private boolean __hashCodeCalc = false;
    
public synchronized int hashCode() {
        
if (__hashCodeCalc) {
            
return 0;
        }

        __hashCodeCalc 
= true;
        
int _hashCode = 1;
        
if (getOriginFrom() != null{
            _hashCode 
+= getOriginFrom().hashCode();
        }

        
if (getDestinationTo() != null{
            _hashCode 
+= getDestinationTo().hashCode();
        }

        
if (getDesiredDepartureDate() != null{
            _hashCode 
+= getDesiredDepartureDate().hashCode();
        }

        
if (getDesiredReturnDate() != null{
            _hashCode 
+= getDesiredReturnDate().hashCode();
        }

        __hashCodeCalc 
= false;
        
return _hashCode;
    }


    
// Type metadata
    private static org.apache.axis.description.TypeDesc typeDesc =
        
new org.apache.axis.description.TypeDesc(FlightRequestType.classtrue);

    
static {
        typeDesc.setXmlType(
new javax.xml.namespace.QName("http://packtpub.com/service/airline/""FlightRequestType"));
        org.apache.axis.description.ElementDesc elemField 
= new org.apache.axis.description.ElementDesc();
        elemField.setFieldName(
"originFrom");
        elemField.setXmlName(
new javax.xml.namespace.QName("http://packtpub.com/service/airline/""OriginFrom"));
        elemField.setXmlType(
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema""string"));
        elemField.setNillable(
false);
        typeDesc.addFieldDesc(elemField);
        elemField 
= new org.apache.axis.description.ElementDesc();
        elemField.setFieldName(
"destinationTo");
        elemField.setXmlName(
new javax.xml.namespace.QName("http://packtpub.com/service/airline/""DestinationTo"));
        elemField.setXmlType(
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema""string"));
        elemField.setNillable(
false);
        typeDesc.addFieldDesc(elemField);
        elemField 
= new org.apache.axis.description.ElementDesc();
        elemField.setFieldName(
"desiredDepartureDate");
        elemField.setXmlName(
new javax.xml.namespace.QName("http://packtpub.com/service/airline/""DesiredDepartureDate"));
        elemField.setXmlType(
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema""date"));
        elemField.setNillable(
false);
        typeDesc.addFieldDesc(elemField);
        elemField 
= new org.apache.axis.description.ElementDesc();
        elemField.setFieldName(
"desiredReturnDate");
        elemField.setXmlName(
new javax.xml.namespace.QName("http://packtpub.com/service/airline/""DesiredReturnDate"));
        elemField.setXmlType(
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema""date"));
        elemField.setNillable(
false);
        typeDesc.addFieldDesc(elemField);
    }


    
/**
     * Return type metadata object
     
*/

    
public static org.apache.axis.description.TypeDesc getTypeDesc() {
        
return typeDesc;
    }


    
/**
     * Get Custom Serializer
     
*/

    
public static org.apache.axis.encoding.Serializer getSerializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) 
{
        
return 
          
new  org.apache.axis.encoding.ser.BeanSerializer(
            _javaType, _xmlType, typeDesc);
    }


    
/**
     * Get Custom Deserializer
     
*/

    
public static org.apache.axis.encoding.Deserializer getDeserializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) 
{
        
return 
          
new  org.apache.axis.encoding.ser.BeanDeserializer(
            _javaType, _xmlType, typeDesc);
    }


}

 

TravelClassType.java

employee包中

/**
 * TravelClassType.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis #axisVersion# #today# WSDL2Java emitter.
 
*/


package  com.packtpub.service.airline;

public   class  TravelClassType  implements  java.io.Serializable  {
    
private java.lang.String _value_;
    
private static java.util.HashMap _table_ = new java.util.HashMap();

    
// Constructor
    protected TravelClassType(java.lang.String value) {
        _value_ 
= value;
        _table_.put(_value_,
this);
    }


    
public static final java.lang.String _Economy = "Economy";
    
public static final java.lang.String _Business = "Business";
    
public static final java.lang.String _First = "First";
    
public static final TravelClassType Economy = new TravelClassType(_Economy);
    
public static final TravelClassType Business = new TravelClassType(_Business);
    
public static final TravelClassType First = new TravelClassType(_First);
    
public java.lang.String getValue() return _value_;}
    
public static TravelClassType fromValue(java.lang.String value)
          
throws java.lang.IllegalArgumentException {
        TravelClassType enumeration 
= (TravelClassType)
            _table_.get(value);
        
if (enumeration==nullthrow new java.lang.IllegalArgumentException();
        
return enumeration;
    }

    
public static TravelClassType fromString(java.lang.String value)
          
throws java.lang.IllegalArgumentException {
        
return fromValue(value);
    }

    
public boolean equals(java.lang.Object obj) {return (obj == this);}
    
public int hashCode() return toString().hashCode();}
    
public java.lang.String toString() return _value_;}
    
public java.lang.Object readResolve() throws java.io.ObjectStreamException return fromValue(_value_);}
    
public static org.apache.axis.encoding.Serializer getSerializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) 
{
        
return 
          
new org.apache.axis.encoding.ser.EnumSerializer(
            _javaType, _xmlType);
    }

    
public static org.apache.axis.encoding.Deserializer getDeserializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) 
{
        
return 
          
new org.apache.axis.encoding.ser.EnumDeserializer(
            _javaType, _xmlType);
    }

    
// Type metadata
    private static org.apache.axis.description.TypeDesc typeDesc =
        
new org.apache.axis.description.TypeDesc(TravelClassType.class);

    
static {
        typeDesc.setXmlType(
new javax.xml.namespace.QName("http://packtpub.com/service/airline/""TravelClassType"));
    }

    
/**
     * Return type metadata object
     
*/

    
public static org.apache.axis.description.TypeDesc getTypeDesc() {
        
return typeDesc;
    }


}

 

EmployeeType.java

 

/**
 * EmployeeType.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis #axisVersion# #today# WSDL2Java emitter.
 
*/


package  com.packtpub.service.employee;

public   class  EmployeeType   implements  java.io.Serializable  {
    
private java.lang.String firstName;

    
private java.lang.String lastName;

    
private java.lang.String departement;

    
public EmployeeType() {
    }


    
public EmployeeType(
           java.lang.String firstName,
           java.lang.String lastName,
           java.lang.String departement) 
{
           
this.firstName = firstName;
           
this.lastName = lastName;
           
this.departement = departement;
    }



    
/**
     * Gets the firstName value for this EmployeeType.
     * 
     * 
@return firstName
     
*/

    
public java.lang.String getFirstName() {
        
return firstName;
    }



    
/**
     * Sets the firstName value for this EmployeeType.
     * 
     * 
@param firstName
     
*/

    
public void setFirstName(java.lang.String firstName) {
        
this.firstName = firstName;
    }



    
/**
     * Gets the lastName value for this EmployeeType.
     * 
     * 
@return lastName
     
*/

    
public java.lang.String getLastName() {
        
return lastName;
    }



    
/**
     * Sets the lastName value for this EmployeeType.
     * 
     * 
@param lastName
     
*/

    
public void setLastName(java.lang.String lastName) {
        
this.lastName = lastName;
    }



    
/**
     * Gets the departement value for this EmployeeType.
     * 
     * 
@return departement
     
*/

    
public java.lang.String getDepartement() {
        
return departement;
    }



    
/**
     * Sets the departement value for this EmployeeType.
     * 
     * 
@param departement
     
*/

    
public void setDepartement(java.lang.String departement) {
        
this.departement = departement;
    }


    
private java.lang.Object __equalsCalc = null;
    
public synchronized boolean equals(java.lang.Object obj) {
        
if (!(obj instanceof EmployeeType)) return false;
        EmployeeType other 
= (EmployeeType) obj;
        
if (obj == nullreturn false;
        
if (this == obj) return true;
        
if (__equalsCalc != null{
            
return (__equalsCalc == obj);
        }

        __equalsCalc 
= obj;
        
boolean _equals;
        _equals 
= true && 
            ((
this.firstName==null && other.getFirstName()==null|| 
             (
this.firstName!=null &&
              
this.firstName.equals(other.getFirstName()))) &&
            ((
this.lastName==null && other.getLastName()==null|| 
             (
this.lastName!=null &&
              
this.lastName.equals(other.getLastName()))) &&
            ((
this.departement==null && other.getDepartement()==null|| 
             (
this.departement!=null &&
              
this.departement.equals(other.getDepartement())));
        __equalsCalc 
= null;
        
return _equals;
    }


    
private boolean __hashCodeCalc = false;
    
public synchronized int hashCode() {
        
if (__hashCodeCalc) {
            
return 0;
        }

        __hashCodeCalc 
= true;
        
int _hashCode = 1;
        
if (getFirstName() != null{
            _hashCode 
+= getFirstName().hashCode();
        }

        
if (getLastName() != null{
            _hashCode 
+= getLastName().hashCode();
        }

        
if (getDepartement() != null{
            _hashCode 
+= getDepartement().hashCode();
        }

        __hashCodeCalc 
= false;
        
return _hashCode;
    }


    
// Type metadata
    private static org.apache.axis.description.TypeDesc typeDesc =
        
new org.apache.axis.description.TypeDesc(EmployeeType.classtrue);

    
static {
        typeDesc.setXmlType(
new javax.xml.namespace.QName("http://packtpub.com/service/employee/""EmployeeType"));
        org.apache.axis.description.ElementDesc elemField 
= new org.apache.axis.description.ElementDesc();
        elemField.setFieldName(
"firstName");
        elemField.setXmlName(
new javax.xml.namespace.QName("http://packtpub.com/service/employee/""FirstName"));
        elemField.setXmlType(
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema""string"));
        elemField.setNillable(
false);
        typeDesc.addFieldDesc(elemField);
        elemField 
= new org.apache.axis.description.ElementDesc();
        elemField.setFieldName(
"lastName");
        elemField.setXmlName(
new javax.xml.namespace.QName("http://packtpub.com/service/employee/""LastName"));
        elemField.setXmlType(
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema""string"));
        elemField.setNillable(
false);
        typeDesc.addFieldDesc(elemField);
        elemField 
= new org.apache.axis.description.ElementDesc();
        elemField.setFieldName(
"departement");
        elemField.setXmlName(
new javax.xml.namespace.QName("http://packtpub.com/service/employee/""Departement"));
        elemField.setXmlType(
new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema""string"));
        elemField.setNillable(
false);
        typeDesc.addFieldDesc(elemField);
    }


    
/**
     * Return type metadata object
     
*/

    
public static org.apache.axis.description.TypeDesc getTypeDesc() {
        
return typeDesc;
    }


    
/**
     * Get Custom Serializer
     
*/

    
public static org.apache.axis.encoding.Serializer getSerializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) 
{
        
return 
          
new  org.apache.axis.encoding.ser.BeanSerializer(
            _javaType, _xmlType, typeDesc);
    }


    
/**
     * Get Custom Deserializer
     
*/

    
public static org.apache.axis.encoding.Deserializer getDeserializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) 
{
        
return 
          
new  org.apache.axis.encoding.ser.BeanDeserializer(
            _javaType, _xmlType, typeDesc);
    }


}

调用相应的Web服务。以下是一个调用航空售票流程的例子。

 

import  java.net.URL;
import  javax.xml.rpc.ParameterMode;
import  org.apache.axis.client.Call;
import  org.apache.axis.client.Service;
import  com.packtpub.service.airline. * ;
import  com.packtpub.service.employee. * ;
import  javax.xml.namespace.QName;
import  org.apache.axis.encoding.ser.BeanDeserializerFactory;
import  org.apache.axis.encoding.ser.BeanSerializerFactory;

public   class  AirLineUse  {


    
public static void main(String args[])
    
{
        
try
        
{
            AriLineUse client 
= new AriLineUse();
            client.run();  
        }

        
catch(Exception e)
        
{
            e.printStackTrace();
        }

    }


    
public void run()
        
throws Exception
    
{
        
//创建一个Call的实例,并配置相应的参数
Call call = createCall();
        
try
        
{
        
/*创建输入参数的实例,在本例中,调用的Operation是TravelApprovalPT(Port Type)中的TravelApproval,输入的Massage是trv:TravelRequestMessage,输出的Message是aln:TravelResponseMessage(消息的定义参考相应的wsdl)*/

            EmployeeType et 
= new EmployeeType("d","dd","spk");
            FlightRequestType frt 
= new FlightRequestType("bj","sh",new java.util.Date(),new java.util.Date());
        
//调用web服务,并接受返回的数值
            FlightConfirmationType fct = (FlightConfirmationType)call.invoke(new Object[] {et,frt});

            System.out.println(
"Here is the response from the AirLine : ");
            System.out.println(
" FlightNo : " + fct.getFlightNo());
            System.out.println(
" TravelClass : " + fct.getTravelClass()); 
            System.out.println(
" Price : " + fct.getPrice()); 
            System.out.println(
" DepartureDateTime : " +  fct.getDepartureDateTime().getTime().toString());
            System.out.println(
" ReturnDateTime : " + fct.getReturnDateTime().getTime().toString());
            System.out.println(
" Approved : " + (fct.isApproved() == true?"yes":"no"));
        }

        
catch(Exception e)
        
{
            System.out.println(
"unexpected exception seen: " + e.toString());
            
        }

    }



    
//创建一个Call 的实例用于调用相应的web服务
    protected Call createCall()
        
throws Exception
    
{
        Service service 
= new Service();
        Call call 
= (Call)service.createCall();
        
//WebService的URL
        String urlString = "http://localhost:8085/active-bpel/services/clientService";
        call.setTargetEndpointAddress(
new URL(urlString));
        
//需要调用的PortType中的Operation
        call.setOperationName("TravelApproval");
        
//为每个ComplexType定义相应的Qualified Name
        QName qq  = new QName("http://packtpub.com/service/employee/","EmployeeType");
        QName frt 
= new QName("http://packtpub.com/service/airline/","FlightRequestType");
        QName fct 
= new QName("http://packtpub.com/service/airline/","FlightConfirmationType");
        
//将定义的Type注册到call中,同时生成并注册构造器和反构造器。
        call.registerTypeMapping(EmployeeType.class,qq,

                
new BeanSerializerFactory(EmployeeType.class, qq),

                      
new BeanDeserializerFactory(EmployeeType.class, qq) );
        
        call.registerTypeMapping(FlightRequestType.
class,frt,

                
new BeanSerializerFactory(FlightRequestType.class, frt),

                      
new BeanDeserializerFactory(FlightRequestType.class, frt) );
        
        call.registerTypeMapping(FlightConfirmationType.
class,fct,

                
new BeanSerializerFactory(FlightConfirmationType.class, fct),

                      
new BeanDeserializerFactory ( FlightConfirmationType.class , fct) );

        
//设置参数类型和返回值类型
        call.addParameter("employee", qq, ParameterMode.IN);
        call.addParameter(
"flightData", frt, ParameterMode.IN);
        call.setReturnType(fct);
        
        
return call;
    }


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值