/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Netscape Public License
 * Version 1.1 (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.mozilla.org/NPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is mozilla.org code.
 *
 * The Initial Developer of the Original Code is 
 * Netscape Communications Corporation.
 * Portions created by the Initial Developer are Copyright (C) 2001
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   John Bandhauer (jband@netscape.com)
 *   Vidur Apparao (vidur@netscape.com)
 *
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the NPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the NPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#include "nsISupports.idl"
#include "nsIWSDL.idl"
#include "nsISimpleEnumerator.idl"
#include "nsIException.idl"
#include "nsISOAPResponse.idl"
#include "nsISOAPBlock.idl"
#include "nsIScriptableInterfaces.idl"

%{ C++
#include "nsAString.h"
%} 

interface nsIWebServiceProxy;
interface nsIWebServiceProxyCreationListener;
interface nsIInterfaceInfo;
interface nsIPropertyBag;

[scriptable, uuid(693611be-bb38-40e0-a98e-b46ff8a5bcca)]
interface nsIWebServiceProxyFactory : nsISupports {
  /**
   * Create a service proxy. Loading of the WSDL URL will occur
   * in a synchronous manner. Calls to web service can be made as
   * soon as this method completes.
   *
   * @param wsdlURL The URL of the WSDL service description. This
   *                description will be loaded and used as the basis
   *                for the service proxy.
   * @param portname The name of the port of the service that this 
   *                 service proxy represents. Currently the port
   *                 must represent a SOAP binding.
   * @param qualifier The user-specified qualifier is incorporated into
   *                  the names of XPCOM interfaces created for the 
   *                  service proxy. For C++ callers, this qualifier 
   *                  should be the  same one used in creating the IDL 
   *                  used at compile time. Script callers need not 
   *                  specify a qualifier.
   * @param isAsync If PR_TRUE, the method signatures of the service
   *                proxy represent an asynchronous calling convention.
   *                A callback instance must be registered with the proxy.
   *                A method call to a web service is only completed when
   *                the corresponding callback method is invoked.
   *                If PR_FALSE, the method signatures of the service
   *                proxy represent a synchronous callling convention.
   *                A method call to a web service is completed when the
   *                method call to the proxy returns.
   */
  nsIWebServiceProxy createProxy(in AString wsdlURL, in AString portname, 
                                 in AString qualifier, in boolean isAsync);

  /**
   * Create a service proxy. Loading of the WSDL URL will occur
   * in an asynchronous manner. Methods on the listener instance will
   * be invoked when the proxy has been created. Any method invocations
   * on the service proxy prior to asynchronous completion of the 
   * intialization step will fail. The caller is guaranteed that this
   * method will return before the listener is invoked.
   *
   * @param wsdlURL The URL of the WSDL service description. This
   *                description will be loaded and used as the basis
   *                for the service proxy.
   * @param portname The name of the port of the service that this 
   *                 service proxy represents. Currently the port
   *                 must represent a SOAP binding.
   * @param qualifier The user-specified qualifier is incorporated into
   *                  the names of XPCOM interfaces created for the 
   *                  service proxy. For C++ callers, this qualifier 
   *                  should be the same one used in creating the IDL 
   *                  used at compile time. Script callers need not 
   *                  specify a qualifier.
   * @param isAsync If PR_TRUE, the method signatures of the service
   *                proxy represent an asynchronous calling convention.
   *                A callback instance must be registered with the proxy.
   *                A method call to a web service is only completed when
   *                the corresponding callback method is invoked.
   *                If PR_FALSE, the method signatures of the service
   *                proxy represent a synchronous callling convention.
   *                A method call to a web service is completed when the
   *                method call to the proxy returns.
   * @param listener The callback instance which will be invoked when
   *                 the proxy is completely initialized.
   */
  void createProxyAsync(in AString wsdlURL, in AString portname, 
                        in AString qualifier, in boolean isAsync,
                        in nsIWebServiceProxyCreationListener listener);
};

/**
 * This interface should be implemented by a user who creates
 * a web service proxy in an asynchronous manner. An instance
 * of this interface is passed into the <code>initAsync</code>
 * method of the proxy.
 */
[scriptable, uuid(a711250b-47da-4f16-a1fd-593de16375a1)]
interface nsIWebServiceProxyCreationListener : nsISupports {
  /**
   * Invoked when the proxy is completely initialized. Method
   * calls on the proxy can be made once this method is called.
   * 
   * @param proxy The initialized web service proxy
   */
  void onLoad(in nsIWebServiceProxy proxy);

  /**
   * Invoked if an error occurs during web service proxy
   * initialization. This error code be a result of attempting
   * to load the specified WSDL URL or a result of processing
   * the WSDL and creating the interface information for the 
   * proxy.
   *
   * @param error The exception generated as a result of the
   *                  error. This object can be introspected
   *                  for further information.
   */ 
  void onError(in nsIException error);
};

[scriptable, uuid(2122421c-1326-41db-87f8-25519d8a12cb)]
interface nsIWebServiceProxy : nsISupports {
  
  [noscript] void Init(in nsIWSDLPort aPort, 
                       in nsIInterfaceInfo aPrimaryInterface,
                       in nsIInterfaceInfoManager aInterfaceInfoManager,
                       in AString aQualifier,
                       in boolean aIsAsync);

  /**
   * The WSDL port that this service proxy represents.
   *
   * @see nsIWSDLPort
   */
  readonly attribute nsIWSDLPort port;

  /**
   * PR_TRUE if the service proxy methods represent an asynchronous
   * calling convention. PR_FALSE if the methods are synchronous.
   */
  readonly attribute boolean isAsync;

  /**
   * The qualifier used for interface names related to
   * this service proxy.
   */
  readonly attribute AString qualifier;

  /**
   * An enumerator that returns the set of pending calls for the
   * service proxy. Each call is an instance of the 
   * <code>nsIWebServiceCallContext</code> interface.
   *
   * @see nsIWebServiceCallContext
   */
  readonly attribute nsISimpleEnumerator pendingCalls;  
  
  /**
   * The name of the primary interface for this proxy. This may or may not be
   * the async version depending on whether or not this is an async proxy.
   */
  readonly attribute string primaryInterfaceName;
  
  /**
   * The name of the primary async listener interface for this proxy. 
   * This will be null if this is not an async proxy.
   */
  readonly attribute string primaryAsyncListenerInterfaceName;

  /**
   * The collection of interfaces related to this service proxy. This
   * will include the primary interface implemented by the service
   * proxy as well as any listener or complex type interfaces required
   * for method parameters and return values.
   * NOTE: only interesting from JavaScript.
   */
  readonly attribute nsIScriptableInterfaces interfaces;
};


/**
 * A representation of a method invocation on a web service.
 * An instance of this interface is returned as a result of making
 * an asynchronous call and can be queried for status of the
 * call.
 */
[scriptable, uuid(87d87900-f102-4a15-b345-7b77a49d2df2)]
interface nsIWebServiceCallContext : nsISupports {
  
  /** 
   * Possible values of the <code>status</code> attribute. A pending
   * call has a status of PENDING. A completed call has a status of
   * SUCCEEDED or FAILED depending on the result of the call.
   */
  const PRUint32 PENDING = 0;
  const PRUint32 SUCCEEDED = 1;
  const PRUint32 FAILED = 2;
  const PRUint32 ABORTED = 3;

  /**
   * The proxy object on which the call was made.
   * 
   * @see nsIWebServiceProxy
   */
  readonly attribute nsIWebServiceProxy proxy;

  /**
   * The name of the method that was invoked.
   */
  readonly attribute AString methodName;

  /**
   * The status of the call, whether pending, completed successfully
   * or completed with a fault.
   */
  readonly attribute PRUint32 status;

  /**
   * The exception generated by the call if the status is FAILURE.
   * The exception object can be introspected for more information.
   * The <code>data</code> member can be QIed to a 
   * <code>nsISOAPFault</code> instance for calls that use a
   * SOAP binding.
   */ 
  readonly attribute nsIException pendingException;

  /**
   * The WSDL operation that correpsonds to the method being invoked.
   *
   * @see nsIWSDLOperation
   */
  readonly attribute nsIWSDLOperation operation;

  /**
   * Called to abort a pending call. If the call is still pending,
   * its callback instance's <code>onError</code> will be invoked,
   * passing in the specified exception.
   *
   * @param error The exception passed to the callback instance's
   *              <code>onError</code> method.
   */
  void abort(in nsIException error);
};

[scriptable, uuid(1ef83ece-b645-4b55-a501-df42c3333b47)]
interface nsIWebServiceSOAPCallContext : nsIWebServiceCallContext {
  /**
   * For users who want access to the lower-level constructs that
   * are used for the method invocation, this attributes provides
   * the SOAP response once the call has completed.
   *
   * @see nsISOAPResponse
   */
  readonly attribute nsISOAPResponse soapResponse;
};

[uuid(b16b15bc-bfad-43cf-b374-2e4651acbc3c)]
interface nsIWebServiceComplexTypeWrapper : nsISupports {
  void Init(in nsISupports aComplexTypeInstance,
            in nsIInterfaceInfo aInterfaceInfo);
};

[uuid(e0b1765e-c0be-4a28-aca3-b292c5c3788b)]
interface nsIWebServicePropertyBagWrapper : nsISupports {
  void Init(in nsIPropertyBag aPropertyBag,
            in nsIInterfaceInfo aInterfaceInfo);
};
 
%{ C++

#define NS_WEBSERVICEPROXYFACTORY_CLASSID           \
{ /* 4E557E69-CCE0-47da-A7D3-2A7ED666F566 */        \
 0x4e557e69, 0xcce0, 0x47da,                        \
 {0xa7, 0xd3, 0x2a, 0x7e, 0xd6, 0x66, 0xf5, 0x66}}
#define NS_WEBSERVICEPROXYFACTORY_CONTRACTID "@mozilla.org/xmlextras/proxy/webserviceproxyfactory;1"

#define NS_WEBSERVICEPROXY_CLASSID                  \
{ /* 1220efd4-8018-45b0-bfc1-0c0716ee0bfb */        \
 0x1220efd4, 0x8018, 0x45b0,                        \
 {0xbf, 0xc1, 0x0c, 0x07, 0x16, 0xee, 0x0b, 0xfb}}
#define NS_WEBSERVICEPROXY_CONTRACTID "@mozilla.org/xmlextras/proxy/webserviceproxy;1"

#define NS_WEBSERVICECOMPLEXTYPEWRAPPER_CLASSID     \
{ /* 615272eb-3908-4fcc-b8f6-94d5a146e2bc */        \
 0x615272eb, 0x3908, 0x4fcc,                        \
 {0xb8, 0xf6, 0x94, 0xd5, 0xa1, 0x46, 0xe2, 0xbc}}
#define NS_WEBSERVICECOMPLEXTYPEWRAPPER_CONTRACTID "@mozilla.org/xmlextras/proxy/webservicecomplextypewrapper;1"

#define NS_WEBSERVICEPROPERTYBAGWRAPPER_CLASSID     \
{ /* 1c76aea3-0810-45b7-bce9-03abc209eb8c */        \
 0x1c76aea3, 0x0810, 0x45b7,                        \
 {0xbc, 0xe9, 0x03, 0xab, 0xc2, 0x09, 0xeb, 0x8c}} 
#define NS_WEBSERVICEPROPERTYBAGWRAPPER_CONTRACTID "@mozilla.org/xmlextras/proxy/webservicepropertybagwrapper;1"

%} 
