Back to index

lightning-sunbird  0.9+nobinonly
wspprivate.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Vidur Apparao (vidur@netscape.com) (Original author)
00024  *   John Bandhauer (jband@netscape.com)
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef __wspprivate_h__
00041 #define __wspprivate_h__
00042 
00043 // XPCOM includes
00044 #include "nsCOMPtr.h"
00045 #include "nsCOMArray.h"
00046 #include "nsIPropertyBag.h"
00047 #include "nsIException.h"
00048 #include "nsIExceptionService.h"
00049 #include "nsIServiceManager.h"
00050 #include "nsAString.h"
00051 
00052 // SOAP includes
00053 #include "nsISOAPCall.h"
00054 #include "nsISOAPResponse.h"
00055 #include "nsISOAPResponseListener.h"
00056 #include "nsISOAPCallCompletion.h"
00057 #include "nsISOAPFault.h"
00058 #include "nsSOAPUtils.h"
00059 
00060 // interface info includes
00061 #include "xptcall.h"
00062 #include "nsIInterfaceInfo.h"
00063 
00064 // WSDL includes
00065 #include "nsIWSDL.h"
00066 #include "nsIWSDLLoader.h"
00067 #include "nsIWSDLSOAPBinding.h"
00068 
00069 // iix includes
00070 #include "nsIGenericInterfaceInfoSet.h"
00071 
00072 // Proxy includes
00073 #include "nsIWebServiceProxy.h"
00074 #include "nsIWSPInterfaceInfoService.h"
00075 
00076 // Forward decls
00077 class WSPCallContext;
00078 
00079 class WSPFactory : public nsIWebServiceProxyFactory
00080 {
00081 public:
00082   WSPFactory();
00083   virtual ~WSPFactory();
00084 
00085   NS_DECL_ISUPPORTS
00086   NS_DECL_NSIWEBSERVICEPROXYFACTORY  
00087 
00088   static nsresult C2XML(const nsACString& aCIdentifier,
00089                         nsAString& aXMLIdentifier);
00090   static void XML2C(const nsAString& aXMLIndentifier,
00091                     nsACString& aCIdentifier);
00092 };
00093 
00094 class WSPProxy : public nsXPTCStubBase,
00095                  public nsIWebServiceProxy,
00096                  public nsIClassInfo
00097 {
00098 public:
00099   WSPProxy();
00100   virtual ~WSPProxy();
00101 
00102   NS_DECL_ISUPPORTS
00103   NS_DECL_NSIWEBSERVICEPROXY
00104   NS_DECL_NSICLASSINFO
00105 
00106   // Would be nice to have a NS_DECL_NSXPTCSTUBBASE
00107   NS_IMETHOD CallMethod(PRUint16 methodIndex,
00108                         const nsXPTMethodInfo* info,
00109                         nsXPTCMiniVariant* params);
00110   NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info);
00111 
00112   void GetListenerInterfaceInfo(nsIInterfaceInfo** aInfo);
00113   void CallCompleted(WSPCallContext* aContext);
00114 
00115   static NS_METHOD
00116   Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
00117 
00118   static nsresult XPTCMiniVariantToVariant(uint8 aTypeTag,
00119                                            nsXPTCMiniVariant aResult,
00120                                            nsIInterfaceInfo* aInterfaceInfo,
00121                                            nsIVariant** aVariant);
00122   static nsresult ArrayXPTCMiniVariantToVariant(uint8 aTypeTag,
00123                                                 nsXPTCMiniVariant aResult,
00124                                                 PRUint32 aLength,
00125                                                 nsIInterfaceInfo* aIfaceInfo,
00126                                                 nsIVariant** aVariant);
00127 
00128   static nsresult VariantToValue(uint8 aTypeTag,
00129                                  void* aValue,
00130                                  nsIInterfaceInfo* aInterfaceInfo,
00131                                  nsIVariant* aProperty);
00132   static nsresult VariantToArrayValue(uint8 aTypeTag,
00133                                       nsXPTCMiniVariant* aResultSize,
00134                                       nsXPTCMiniVariant* aResultArray,
00135                                       nsIInterfaceInfo* aInterfaceInfo,
00136                                       nsIVariant* aProperty);
00137 
00138   static nsresult ParameterToVariant(nsIInterfaceInfo* aInterfaceInfo,
00139                                      PRUint32 aMethodIndex,
00140                                      const nsXPTParamInfo* aParamInfo,
00141                                      nsXPTCMiniVariant aMiniVariant,
00142                                      PRUint32 aArrayLength,
00143                                      nsIVariant** aVariant);
00144   static nsresult VariantToInParameter(nsIInterfaceInfo* aInterfaceInfo,
00145                                        PRUint32 aMethodIndex,
00146                                        const nsXPTParamInfo* aParamInfo,
00147                                        nsIVariant* aVariant,
00148                                        nsXPTCVariant* aXPTCVariant);
00149   static nsresult VariantToOutParameter(nsIInterfaceInfo* aInterfaceInfo,
00150                                         PRUint32 aMethodIndex,
00151                                         const nsXPTParamInfo* aParamInfo,
00152                                         nsIVariant* aVariant,
00153                                         nsXPTCMiniVariant* aMiniVariant);
00154   static nsresult WrapInPropertyBag(nsISupports* aInstance,
00155                                     nsIInterfaceInfo* aInterfaceInfo,
00156                                     nsIPropertyBag** aPropertyBag);
00157   static nsresult WrapInComplexType(nsIPropertyBag* aPropertyBag,
00158                                     nsIInterfaceInfo* aInterfaceInfo,
00159                                     nsISupports** aComplexType);
00160 
00161 
00162 protected:
00163   nsresult GetInterfaceName(PRBool listener, char** retval);
00164 
00165 protected:
00166   nsCOMPtr<nsIWSDLPort> mPort;
00167   nsCOMPtr<nsIInterfaceInfo> mPrimaryInterface;
00168   nsCOMPtr<nsIInterfaceInfoManager> mInterfaceInfoManager;
00169   nsString mQualifier;
00170   PRBool mIsAsync;
00171   nsCOMArray<nsIWebServiceCallContext> mPendingCalls;
00172   const nsIID* mIID;
00173   nsCOMPtr<nsISupports> mAsyncListener;
00174   nsCOMPtr<nsIInterfaceInfo> mListenerInterfaceInfo;
00175   nsCOMPtr<nsIScriptableInterfaces> mInterfaces;
00176 };
00177 
00178 class WSPCallContext : public nsIWebServiceSOAPCallContext,
00179                        public nsISOAPResponseListener
00180 {
00181 public:
00182   WSPCallContext(WSPProxy* aProxy,
00183                  nsISOAPCall* aSOAPCall,
00184                  const nsAString& aMethodName,
00185                  nsIWSDLOperation* aOperation);
00186   virtual ~WSPCallContext();
00187 
00188   NS_DECL_ISUPPORTS
00189   NS_DECL_NSIWEBSERVICECALLCONTEXT
00190   NS_DECL_NSIWEBSERVICESOAPCALLCONTEXT
00191   NS_DECL_NSISOAPRESPONSELISTENER
00192   
00193   nsresult CallAsync(PRUint32 aListenerMethodIndex,
00194                      nsISupports* aListener);
00195   nsresult CallSync(PRUint32 aMethodIndex,
00196                     nsXPTCMiniVariant* params);
00197 
00198 protected:
00199   nsresult CallCompletionListener();
00200 
00201 protected:
00202   WSPProxy* mProxy;
00203   nsCOMPtr<nsISOAPCall> mCall;
00204   nsString mMethodName;
00205   nsCOMPtr<nsIWSDLOperation> mOperation;
00206   nsCOMPtr<nsISOAPCallCompletion> mCompletion;
00207   nsCOMPtr<nsISOAPResponse> mResponse;
00208   nsresult mStatus;
00209   nsCOMPtr<nsIException> mException;
00210   nsCOMPtr<nsISupports> mAsyncListener;
00211   PRUint32 mListenerMethodIndex;
00212 };
00213 
00214 class WSPException : public nsIException 
00215 {
00216 public:
00217   WSPException(nsISOAPFault* aFault, nsresult aStatus);
00218   WSPException(nsresult aStatus, const char* aMsg, nsISupports* aData);
00219   virtual ~WSPException();
00220 
00221   NS_DECL_ISUPPORTS
00222   NS_DECL_NSIEXCEPTION
00223 
00224 protected:
00225   nsCOMPtr<nsISOAPFault> mFault;
00226   nsCOMPtr<nsISupports> mData;
00227   nsresult mStatus;
00228   char* mMsg;
00229 };
00230 
00231 class WSPComplexTypeWrapper : public nsIWebServiceComplexTypeWrapper,
00232                               public nsIPropertyBag
00233 {
00234 public:
00235   WSPComplexTypeWrapper();
00236   virtual ~WSPComplexTypeWrapper();
00237 
00238   NS_DECL_ISUPPORTS
00239   NS_DECL_NSIPROPERTYBAG
00240   NS_DECL_NSIWEBSERVICECOMPLEXTYPEWRAPPER
00241 
00242   static NS_METHOD
00243   Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
00244 
00245   nsresult GetPropertyValue(PRUint32 aMethodIndex,
00246                             const nsXPTMethodInfo* aMethodInfo,
00247                             nsIVariant** _retval);
00248 
00249 protected:
00250   nsCOMPtr<nsISupports> mComplexTypeInstance;
00251   nsCOMPtr<nsIInterfaceInfo> mInterfaceInfo;
00252 };
00253 
00254 class WSPPropertyBagWrapper : public nsXPTCStubBase,
00255                               public nsIWebServicePropertyBagWrapper,
00256                               public nsIClassInfo
00257 {
00258 public:
00259   WSPPropertyBagWrapper();
00260   virtual ~WSPPropertyBagWrapper();
00261 
00262   NS_DECL_ISUPPORTS
00263   NS_DECL_NSIWEBSERVICEPROPERTYBAGWRAPPER
00264   NS_DECL_NSICLASSINFO
00265 
00266   // Would be nice to have a NS_DECL_NSXPTCSTUBBASE
00267   NS_IMETHOD CallMethod(PRUint16 methodIndex,
00268                         const nsXPTMethodInfo* info,
00269                         nsXPTCMiniVariant* params);
00270   NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info);
00271 
00272   static NS_METHOD
00273   Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
00274 
00275 protected:
00276   nsCOMPtr<nsIPropertyBag> mPropertyBag;
00277   nsCOMPtr<nsIInterfaceInfo> mInterfaceInfo;
00278   const nsIID* mIID;
00279 };
00280 
00281 class nsWSPInterfaceInfoService : public nsIWSPInterfaceInfoService
00282 {
00283 public:
00284   NS_DECL_ISUPPORTS
00285   NS_DECL_NSIWSPINTERFACEINFOSERVICE
00286 
00287   nsWSPInterfaceInfoService();
00288   virtual ~nsWSPInterfaceInfoService();
00289 };
00290 
00291 #define NS_WEBSERVICECALLCONTEXT_CLASSID          \
00292 { /* a42e9bf3-6bae-4c59-8f76-9dc175eec5b1 */      \
00293  0xa42e9bf3, 0x6bae, 0x4c59,                      \
00294  {0x8f, 0x76, 0x9d, 0xc1, 0x75, 0xee, 0xc5, 0xb1}}
00295 #define NS_WEBSERVICECALLCONTEXT_CONTRACTID "@mozilla.org/xmlextras/proxy/webservicecallcontext;1"
00296 #define NS_WEBSERVICEEXCEPTION_CLASSID            \
00297 { /* 07c2bf7b-376e-4629-b9c0-dbb17630b98d */      \
00298  0x07c2bf7b, 0x376e, 0x4629,                      \
00299  {0xb9, 0xc0, 0xdb, 0xb1, 0x76, 0x30, 0xb9, 0x8d}}
00300 #define NS_WEBSERVICEEXCEPTION_CONTRACTID "@mozilla.org/xmlextras/proxy/webserviceexception;1"
00301 
00302 #endif // __wspprivate_h__