Back to index

lightning-sunbird  0.9+nobinonly
nsWSDLLoader.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.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications.
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  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef __nsWSDLLoader_h__
00040 #define __nsWSDLLoader_h__
00041 
00042 #include "nsIWebServiceErrorHandler.h"
00043 
00044 #include "nsIWSDLLoader.h"
00045 #include "nsWSDLPrivate.h"
00046 
00047 #include "nsDOMUtils.h"
00048 
00049 // XPCOM Includes
00050 #include "nsCOMPtr.h"
00051 #include "nsString.h"
00052 #include "nsIAtom.h"
00053 #include "nsHashtable.h"
00054 #include "nsError.h"
00055 
00056 // Loading includes
00057 #include "nsIURI.h"
00058 #include "nsIXMLHttpRequest.h"
00059 #include "nsIDOMEventListener.h"
00060 
00061 // schema includes
00062 #include "nsISchemaLoader.h"
00063 
00064 // DOM includes
00065 #include "nsIDOMDocument.h"
00066 
00067 #define NS_ERROR_WSDL_LOADPENDING NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_GENERAL, 1)
00068 
00069 class nsWSDLAtoms 
00070 {
00071 public:
00072   static nsresult AddRefAtoms();
00073 
00074 #define WSDL_ATOM(_name, _value) static nsIAtom* _name;
00075 #include "nsWSDLAtomList.h"
00076 #undef WSDL_ATOM
00077 };
00078 
00079 class nsWSDLLoader : public nsIWSDLLoader
00080 {
00081 public:
00082   nsWSDLLoader();
00083   virtual ~nsWSDLLoader();
00084 
00085   NS_DECL_ISUPPORTS
00086   NS_DECL_NSIWSDLLOADER
00087 
00088   nsresult Init();
00089 
00090 protected:
00091   nsresult doLoad(const nsAString& wsdlURI, const nsAString& portName,
00092                   nsIWSDLLoadListener *aListener, nsIWSDLPort **_retval);
00093 
00094   nsresult GetResolvedURI(const nsAString& aSchemaURI,
00095                           const char* aMethod,
00096                           nsIURI** aURI);
00097 
00098   nsWSDLPort* mPort;
00099 };
00100 
00101 
00102 class nsWSDLLoadingContext
00103 {
00104 public:
00105   nsWSDLLoadingContext(nsIDOMDocument* aDocument,
00106                        const nsAString& aLocation)
00107     : mDocument(aDocument), mChildIndex(0), mDocumentLocation(aLocation)
00108   {
00109   }
00110   ~nsWSDLLoadingContext()
00111   {
00112   }
00113 
00114   void GetRootElement(nsIDOMElement** aElement)
00115   {
00116     mDocument->GetDocumentElement(aElement);
00117   }
00118 
00119   PRUint32 GetChildIndex()
00120   {
00121     return mChildIndex;
00122   }
00123   void SetChildIndex(PRUint32 aChildIndex)
00124   {
00125     mChildIndex = aChildIndex;
00126   }
00127 
00128   void GetTargetNamespace(nsAString& aNamespace)
00129   {
00130     nsCOMPtr<nsIDOMElement> element;
00131     GetRootElement(getter_AddRefs(element));
00132     if (element) {
00133       element->GetAttribute(NS_LITERAL_STRING("targetNamespace"), aNamespace);
00134     }
00135     else {
00136       aNamespace.Truncate();
00137     }
00138   }
00139 
00140   void GetDocumentLocation(nsAString& aLocation)
00141   {
00142     aLocation.Assign(mDocumentLocation);
00143   }
00144 
00145 protected:
00146   // XXX hold onto the document till issues related to dangling
00147   // document pointers in content are fixed. After that, just
00148   // hold onto the root element.
00149   nsCOMPtr<nsIDOMDocument> mDocument; 
00150   PRUint32 mChildIndex;
00151   nsString mDocumentLocation;
00152 };
00153 
00154 class nsWSDLLoadRequest : public nsIDOMEventListener
00155 {
00156 public:
00157   nsWSDLLoadRequest(PRBool aIsSync, nsIWSDLLoadListener* aListener,
00158                     const nsAString& aPortName);
00159   virtual ~nsWSDLLoadRequest();
00160 
00161   NS_DECL_ISUPPORTS
00162   NS_DECL_NSIDOMEVENTLISTENER
00163 
00164   nsresult LoadDefinition(const nsAString& aURI);
00165   nsresult ResumeProcessing();
00166   nsresult ContineProcessingTillDone();
00167   nsresult GetPort(nsIWSDLPort** aPort);
00168 
00169   nsresult PushContext(nsIDOMDocument* aDocument, const nsAString& aLocation);
00170   nsWSDLLoadingContext* GetCurrentContext();
00171   void PopContext();
00172 
00173   nsresult GetSchemaElement(const nsAString& aName,
00174                             const nsAString& aNamespace,
00175                             nsISchemaElement** aSchemaComponent);
00176   nsresult GetSchemaType(const nsAString& aName, const nsAString& aNamespace,
00177                          nsISchemaType** aSchemaComponent);
00178   nsresult GetMessage(const nsAString& aName, const nsAString& aNamespace,
00179                       nsIWSDLMessage** aMessage);
00180   nsresult GetPortType(const nsAString& aName, const nsAString& aNamespace,
00181                        nsIWSDLPort** aPort);
00182 
00183   nsresult ProcessImportElement(nsIDOMElement* aElement, PRUint32 aIndex);
00184   nsresult ProcessTypesElement(nsIDOMElement* aElement);
00185   nsresult ProcessMessageElement(nsIDOMElement* aElement);
00186   nsresult ProcessAbstractPartElement(nsIDOMElement* aElement,
00187                                       nsWSDLMessage* aMessage);
00188   nsresult ProcessPortTypeElement(nsIDOMElement* aElement);
00189   nsresult ProcessAbstractOperation(nsIDOMElement* aElement,
00190                                     nsWSDLPort* aPort);
00191   nsresult ProcessOperationComponent(nsIDOMElement* aElement,
00192                                      nsIWSDLMessage** aMessage);
00193   nsresult ProcessMessageBinding(nsIDOMElement* aElement, 
00194                                  nsIWSDLMessage* aMessage);
00195   nsresult ProcessOperationBinding(nsIDOMElement* aElement,
00196                                    nsIWSDLPort* aPort);
00197   nsresult ProcessBindingElement(nsIDOMElement* aElement);
00198   nsresult ProcessPortBinding(nsIDOMElement* aElement);
00199   nsresult ProcessServiceElement(nsIDOMElement* aElement);
00200   
00201 protected:
00202   nsCOMPtr<nsIWSDLLoadListener> mListener;
00203   nsCOMPtr<nsIXMLHttpRequest> mRequest;
00204   nsCOMPtr<nsISchemaLoader> mSchemaLoader;
00205   nsCOMPtr<nsIWSDLPort> mPort;
00206   nsCOMArray<nsIURI> mImportList;
00207   nsCOMPtr<nsIWebServiceErrorHandler> mErrorHandler;
00208   
00209   PRPackedBool mIsSync;
00210 
00211   nsString mPortName;
00212   nsString mBindingName;
00213   nsString mBindingNamespace;
00214   nsString mAddress;
00215 
00216   nsVoidArray mContextStack;
00217 
00218   nsSupportsHashtable mTypes;
00219   nsSupportsHashtable mMessages;
00220   nsSupportsHashtable mPortTypes;
00221 };
00222 
00223 #endif // __nsWSDLLoader_h__