diff --git a/mozilla/extensions/webservices/public/nsIWSDL.idl b/mozilla/extensions/webservices/public/nsIWSDL.idl index 380e119cd4a..2405760e172 100644 --- a/mozilla/extensions/webservices/public/nsIWSDL.idl +++ b/mozilla/extensions/webservices/public/nsIWSDL.idl @@ -22,42 +22,29 @@ */ #include "nsISupports.idl" +#include "nsISchema.idl" %{ C++ #include "nsAWritableString.h" %} -interface nsIWSDLService; +interface nsIWSDLBinding; interface nsIWSDLPort; interface nsIWSDLOperation; interface nsIWSDLMessage; interface nsIWSDLPart; interface nsIDOMElement; -interface nsISchemaComponent; -interface nsISchema; - -[scriptable, uuid(0458dac0-65de-11d5-9b42-00104bdf5339)] -interface nsIWSDLService : nsISupports { - readonly attribute AString name; - readonly attribute nsIDOMElement documentation; - readonly attribute PRUint32 portCount; - nsIWSDLPort getPort(in PRUint32 index); -}; [scriptable, uuid(0458dac1-65de-11d5-9b42-00104bdf5339)] -interface nsIWSDLPort : nsISupports { - const unsigned short STYLE_RPC = 1; - const unsigned short STYLE_DOCUMENT = 2; - +interface nsIWSDLPort : nsISupports { readonly attribute AString name; readonly attribute nsIDOMElement documentation; - readonly attribute AString bindingName; - readonly attribute unsigned short style; - readonly attribute AString transport; + readonly attribute nsIWSDLBinding binding; readonly attribute PRUint32 operationCount; nsIWSDLOperation getOperation(in PRUint32 index); + nsIWSDLOperation getOperationByName(in AString name); }; [scriptable, uuid(0458dac2-65de-11d5-9b42-00104bdf5339)] @@ -65,38 +52,32 @@ interface nsIWSDLOperation : nsISupports { readonly attribute AString name; readonly attribute nsIDOMElement documentation; - readonly attribute unsigned short style; - readonly attribute AString soapAction; + readonly attribute nsIWSDLBinding binding; readonly attribute nsIWSDLMessage input; readonly attribute nsIWSDLMessage output; - readonly attribute nsIWSDLMessage fault; + readonly attribute PRUint32 faultCount; + nsIWSDLMessage getFault(in PRUint32 index); + + readonly attribute PRUint32 parameterCount; + AString getParameter(in PRUint32 index); }; [scriptable, uuid(0458dac3-65de-11d5-9b42-00104bdf5339)] interface nsIWSDLMessage : nsISupports { - const unsigned short LOCATION_SOAP_BODY = 1; - const unsigned short LOCATION_SOAP_HEADER = 2; - const unsigned short LOCATION_SOAP_FAULT = 3; - - const unsigned short USE_LITERAL = 1; - const unsigned short USE_ENCODED = 2; - readonly attribute AString name; readonly attribute nsIDOMElement documentation; - readonly attribute unsigned short location; - readonly attribute unsigned short use; - readonly attribute AString encodingStyle; - readonly attribute AString namespace; - readonly attribute PRUint32 partCount; nsIWSDLPart getPart(in PRUint32 index); + nsIWSDLPart getPartByName(in AString name); }; [scriptable, uuid(0458dac4-65de-11d5-9b42-00104bdf5339)] interface nsIWSDLPart : nsISupports { readonly attribute AString name; + + readonly attribute nsIWSDLBinding binding; readonly attribute AString type; readonly attribute AString elementName; @@ -107,9 +88,11 @@ interface nsIWSDLPart : nsISupports { * elementName attribute is used, it is a nsISchemaElement. */ readonly attribute nsISchemaComponent schemaComponent; - - /** - * The containing schema for the schemaComponent - */ - readonly attribute nsISchema schema; }; + +[scriptable, uuid(0458dac0-65de-11d5-9b42-00104bdf5339)] +interface nsIWSDLBinding : nsISupports { + readonly attribute AString protocol; + readonly attribute nsIDOMElement documentation; +}; + diff --git a/mozilla/extensions/webservices/public/nsIWSDLLoader.idl b/mozilla/extensions/webservices/public/nsIWSDLLoader.idl index 99f3d6db796..32af9bbd4c6 100644 --- a/mozilla/extensions/webservices/public/nsIWSDLLoader.idl +++ b/mozilla/extensions/webservices/public/nsIWSDLLoader.idl @@ -27,21 +27,37 @@ #include "nsAWritableString.h" %} -interface nsIWSDLService; -interface nsIURI; -interface nsIWSDLLoaderListener; +interface nsIWSDLPort; +interface nsIWSDLLoadListener; [scriptable, uuid(0458dac5-65de-11d5-9b42-00104bdf5339)] interface nsIWSDLLoader : nsISupports { - nsIWSDLService load(in nsIURI wsdlURI); - void loadAsync(in nsIURI wsdlURI, in nsIWSDLLoaderListener listener); - nsISupports createServiceProxy(in nsIWSDLService service, - in AString nameSpace); + nsIWSDLPort load(in AString wsdlURI, in AString portName); + void loadAsync(in AString wsdlURI, in AString portName, + in nsIWSDLLoadListener listener); + nsISupports createPortProxy(in nsIWSDLPort service, + in AString nameSpace); }; -[scriptable, uuid(0458dac6-65de-11d5-9b42-00104bdf5339)] -interface nsIWSDLLoaderListener : nsISupports { +[scriptable, function, uuid(0458dac6-65de-11d5-9b42-00104bdf5339)] +interface nsIWSDLLoadListener : nsISupports { + void onLoad(in nsIWSDLPort service); void onError(in PRInt32 status, in AString statusMessage); - void onComplete(in nsIWSDLService service); }; + +%{ C++ +#define NS_WSDLLOADER_CID \ +{ /* 0a5af577-a61e-4492-ba0e-dd3c7b657e18 */ \ + 0x0a5af577, 0xa61e, 0x4492, \ + {0xba, 0x0e, 0xdd, 0x3c, 0x7b, 0x65, 0x7e, 0x18}} + +#define NS_WSDLLOADER_CONTRACTID "@mozilla.org/xmlextras/wsdl/wsdlloader;1" + +#define NS_ERROR_WSDL_NOT_WSDL_ELEMENT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 1) +#define NS_ERROR_WSDL_SCHEMA_PROCESSING_ERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 2) +#define NS_ERROR_WSDL_BINDING_NOT_FOUND NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 3) +#define NS_ERROR_WSDL_UNKNOWN_SCHEMA_COMPONENT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 4) +#define NS_ERROR_WSDL_UNKNOWN_WSDL_COMPONENT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 5) +#define NS_ERROR_WSDL_LOADING_ERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 6) +%} diff --git a/mozilla/extensions/webservices/public/nsIWSDLSOAPBinding.idl b/mozilla/extensions/webservices/public/nsIWSDLSOAPBinding.idl new file mode 100644 index 00000000000..71ee6aae6b1 --- /dev/null +++ b/mozilla/extensions/webservices/public/nsIWSDLSOAPBinding.idl @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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. + * + * The Initial Developer of the Original Code is Netscape + * Communications. Portions created by Netscape Communications are + * Copyright (C) 2001 by Netscape Communications. All + * Rights Reserved. + * + * Contributor(s): + * Vidur Apparao (original author) + */ + +#include "nsISupports.idl" +#include "nsIWSDL.idl" + +%{ C++ +#include "nsAWritableString.h" +%} + +[scriptable, uuid(0458dac7-65de-11d5-9b42-00104bdf5339)] +interface nsISOAPPortBinding : nsIWSDLBinding { + const unsigned short STYLE_RPC = 1; + const unsigned short STYLE_DOCUMENT = 2; + + readonly attribute AString name; + readonly attribute AString address; + readonly attribute unsigned short style; + readonly attribute AString transport; +}; + +[scriptable, uuid(0458dac8-65de-11d5-9b42-00104bdf5339)] +interface nsISOAPOperationBinding : nsIWSDLBinding { + readonly attribute unsigned short style; + readonly attribute AString soapAction; +}; + +[scriptable, uuid(0458dac9-65de-11d5-9b42-00104bdf5339)] +interface nsISOAPPartBinding : nsIWSDLBinding { + const unsigned short LOCATION_BODY = 1; + const unsigned short LOCATION_HEADER = 2; + const unsigned short LOCATION_FAULT = 3; + + const unsigned short USE_LITERAL = 1; + const unsigned short USE_ENCODED = 2; + + readonly attribute unsigned short location; + readonly attribute unsigned short use; + readonly attribute AString encodingStyle; + readonly attribute AString namespace; +}; diff --git a/mozilla/extensions/webservices/wsdl/src/Makefile.in b/mozilla/extensions/webservices/wsdl/src/Makefile.in index 62935fdc744..858005cc36a 100644 --- a/mozilla/extensions/webservices/wsdl/src/Makefile.in +++ b/mozilla/extensions/webservices/wsdl/src/Makefile.in @@ -31,7 +31,8 @@ LIBRARY_NAME = xmlextraswsdl_s REQUIRES = xpcom string dom caps necko xpconnect CPPSRCS = \ - nsWSDLLoader.cpp \ + nsWSDLLoader.cpp \ + nsWSDLDefinitions.cpp \ $(NULL) # we don't want the shared lib, but we want to force the creation of a @@ -39,3 +40,7 @@ CPPSRCS = \ FORCE_STATIC_LIB = 1 include $(topsrcdir)/config/rules.mk + +INCLUDES += \ + -I$(srcdir)/../../schema/src \ + $(NULL) diff --git a/mozilla/extensions/webservices/wsdl/src/nsWSDLDefinitions.cpp b/mozilla/extensions/webservices/wsdl/src/nsWSDLDefinitions.cpp new file mode 100644 index 00000000000..be095bd5b98 --- /dev/null +++ b/mozilla/extensions/webservices/wsdl/src/nsWSDLDefinitions.cpp @@ -0,0 +1,785 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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. + * + * The Initial Developer of the Original Code is Netscape + * Communications. Portions created by Netscape Communications are + * Copyright (C) 2001 by Netscape Communications. All + * Rights Reserved. + * + * Contributor(s): + * Vidur Apparao (original author) + */ + +#include "nsWSDLPrivate.h" + +//////////////////////////////////////////////////////////// +// +// nsWSDLPort implementation +// +//////////////////////////////////////////////////////////// +nsWSDLPort::nsWSDLPort(const nsAReadableString& aName) + : mName(aName) +{ + NS_INIT_ISUPPORTS(); +} + +nsWSDLPort::~nsWSDLPort() +{ +} + +NS_IMPL_ISUPPORTS1_CI(nsWSDLPort, nsIWSDLPort) + +/* readonly attribute AString name; */ +NS_IMETHODIMP +nsWSDLPort::GetName(nsAWritableString & aName) +{ + aName.Assign(mName); + + return NS_OK; +} + +/* readonly attribute nsIDOMElement documentation; */ +NS_IMETHODIMP +nsWSDLPort::GetDocumentation(nsIDOMElement * *aDocumentation) +{ + NS_ENSURE_ARG_POINTER(aDocumentation); + + *aDocumentation = mDocumentationElement; + NS_IF_ADDREF(*aDocumentation); + + return NS_OK; +} + +/* readonly attribute PRUint32 operationCount; */ +NS_IMETHODIMP +nsWSDLPort::GetOperationCount(PRUint32 *aOperationCount) +{ + NS_ENSURE_ARG_POINTER(aOperationCount); + + return mOperations.Count(aOperationCount); +} + +/* nsIWSDLOperation getOperation (in PRUint32 index); */ +NS_IMETHODIMP +nsWSDLPort::GetOperation(PRUint32 index, nsIWSDLOperation **_retval) +{ + NS_ENSURE_ARG_POINTER(_retval); + + return mOperations.QueryElementAt(index, NS_GET_IID(nsIWSDLOperation), + (void**)_retval); +} + +/* nsIWSDLOperation getOperationByName(in AString name); */ +NS_IMETHODIMP +nsWSDLPort::GetOperationByName(const nsAReadableString& aName, + nsIWSDLOperation** aOperation) +{ + nsresult rv; + + *aOperation = nsnull; + + // XXX Do a linear search for now. If more efficiency is needed + // we can store the opeartions in a hash as well. + PRUint32 index, count; + mOperations.Count(&count); + + for (index = 0; index < count; index++) { + nsCOMPtr operation; + + rv = mOperations.QueryElementAt(index, NS_GET_IID(nsIWSDLOperation), + getter_AddRefs(operation)); + if (NS_SUCCEEDED(rv)) { + nsAutoString name; + operation->GetName(name); + + if (name.Equals(aName)) { + *aOperation = operation; + NS_ADDREF(*aOperation); + break; + } + } + } + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLPort::GetBinding(nsIWSDLBinding** aBinding) +{ + NS_ENSURE_ARG_POINTER(aBinding); + + *aBinding = mBinding; + NS_IF_ADDREF(*aBinding); + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLPort::SetDocumentationElement(nsIDOMElement* aElement) +{ + mDocumentationElement = aElement; + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLPort::AddOperation(nsIWSDLOperation* aOperation) +{ + NS_ENSURE_ARG(aOperation); + + return mOperations.AppendElement(aOperation); +} + +NS_IMETHODIMP +nsWSDLPort::SetBinding(nsIWSDLBinding* aBinding) +{ + mBinding = aBinding; + + return NS_OK; +} + +//////////////////////////////////////////////////////////// +// +// nsSOAPPortBinding implementation +// +//////////////////////////////////////////////////////////// +nsSOAPPortBinding::nsSOAPPortBinding(const nsAReadableString& aName) + : mName(aName), mStyle(STYLE_RPC) +{ + NS_INIT_ISUPPORTS(); +} + +nsSOAPPortBinding::~nsSOAPPortBinding() +{ +} + +NS_IMPL_ISUPPORTS2_CI(nsSOAPPortBinding, + nsIWSDLBinding, + nsISOAPPortBinding) + +/* readonly attribute AString protocol; */ +NS_IMETHODIMP +nsSOAPPortBinding::GetProtocol(nsAWritableString& aProtocol) +{ + aProtocol.Assign(NS_LITERAL_STRING("soap")); + + return NS_OK; +} + +/* readonly attribute nsIDOMElement documentation; */ +NS_IMETHODIMP +nsSOAPPortBinding::GetDocumentation(nsIDOMElement * *aDocumentation) +{ + NS_ENSURE_ARG_POINTER(aDocumentation); + + *aDocumentation = mDocumentationElement; + NS_IF_ADDREF(*aDocumentation); + + return NS_OK; +} + +/* readonly attribute AString bindingName; */ +NS_IMETHODIMP +nsSOAPPortBinding::GetName(nsAWritableString & aBindingName) +{ + aBindingName.Assign(mName); + + return NS_OK; +} + +/* readonly attribute AString address; */ +NS_IMETHODIMP +nsSOAPPortBinding::GetAddress(nsAWritableString & aAddress) +{ + aAddress.Assign(mAddress); + + return NS_OK; +} + +/* readonly attribute unsigned short style; */ +NS_IMETHODIMP +nsSOAPPortBinding::GetStyle(PRUint16 *aStyle) +{ + NS_ENSURE_ARG_POINTER(aStyle); + + *aStyle = mStyle; + + return NS_OK; +} + +/* readonly attribute AString transport; */ +NS_IMETHODIMP +nsSOAPPortBinding::GetTransport(nsAWritableString & aTransport) +{ + aTransport.Assign(mTransport); + + return NS_OK; +} + + +NS_IMETHODIMP +nsSOAPPortBinding::SetDocumentationElement(nsIDOMElement* aElement) +{ + mDocumentationElement = aElement; + + return NS_OK; +} + +NS_IMETHODIMP +nsSOAPPortBinding::SetAddress(const nsAReadableString& aAddress) +{ + mAddress.Assign(aAddress); + + return NS_OK; +} + +NS_IMETHODIMP +nsSOAPPortBinding::SetStyle(PRUint16 aStyle) +{ + mStyle = aStyle; + + return NS_OK; +} + +NS_IMETHODIMP +nsSOAPPortBinding::SetTransport(const nsAReadableString& aTransport) +{ + mTransport.Assign(aTransport); + + return NS_OK; +} + +//////////////////////////////////////////////////////////// +// +// nsWSDLOperation implementation +// +//////////////////////////////////////////////////////////// +nsWSDLOperation::nsWSDLOperation(const nsAReadableString &aName) + : mName(aName) +{ + NS_INIT_ISUPPORTS(); +} + +nsWSDLOperation::~nsWSDLOperation() +{ +} + +NS_IMPL_ISUPPORTS1_CI(nsWSDLOperation, nsIWSDLOperation) + +/* readonly attribute AString name; */ +NS_IMETHODIMP +nsWSDLOperation::GetName(nsAWritableString & aName) +{ + aName.Assign(mName); + + return NS_OK; +} + +/* readonly attribute nsIDOMElement documentation; */ +NS_IMETHODIMP +nsWSDLOperation::GetDocumentation(nsIDOMElement * *aDocumentation) +{ + NS_ENSURE_ARG_POINTER(aDocumentation); + + *aDocumentation = mDocumentationElement; + NS_IF_ADDREF(*aDocumentation); + + return NS_OK; +} + +/* readonly attribute nsIWSDLMessage input; */ +NS_IMETHODIMP +nsWSDLOperation::GetInput(nsIWSDLMessage * *aInput) +{ + NS_ENSURE_ARG_POINTER(aInput); + + *aInput = mInputMessage; + NS_IF_ADDREF(*aInput); + + return NS_OK; +} + +/* readonly attribute nsIWSDLMessage output; */ +NS_IMETHODIMP +nsWSDLOperation::GetOutput(nsIWSDLMessage * *aOutput) +{ + NS_ENSURE_ARG_POINTER(aOutput); + + *aOutput = mOutputMessage; + NS_IF_ADDREF(*aOutput); + + return NS_OK; +} + +/* readonly attribute PRUint32 faultCount; */ +NS_IMETHODIMP +nsWSDLOperation::GetFaultCount(PRUint32* aCount) +{ + NS_ENSURE_ARG_POINTER(aCount); + + return mFaultMessages.Count(aCount); +} + +/* nsIWSDLMessage getFault(in PRUint32 index); */ +NS_IMETHODIMP +nsWSDLOperation::GetFault(PRUint32 aIndex, nsIWSDLMessage * *aFault) +{ + NS_ENSURE_ARG_POINTER(aFault); + + return mFaultMessages.QueryElementAt(aIndex, NS_GET_IID(nsIWSDLMessage), + (void**)aFault); +} + +NS_IMETHODIMP +nsWSDLOperation::GetBinding(nsIWSDLBinding** aBinding) +{ + NS_ENSURE_ARG_POINTER(aBinding); + + *aBinding = mBinding; + NS_IF_ADDREF(*aBinding); + + return NS_OK; +} + +/* readonly attribute PRUint32 parameterCount; */ +NS_IMETHODIMP +nsWSDLOperation::GetParameterCount(PRUint32 *aParameterCount) +{ + NS_ENSURE_ARG_POINTER(aParameterCount); + + *aParameterCount = (PRUint32)mParameters.Count(); + + return NS_OK; +} + +/* AString getParameter (in PRUint32 index); */ +NS_IMETHODIMP +nsWSDLOperation::GetParameter(PRUint32 index, nsAWritableString & _retval) +{ + nsString* str = mParameters.StringAt((PRInt32)index); + if (!str) { + return NS_ERROR_FAILURE; + } + _retval.Assign(*str); + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLOperation::SetDocumentationElement(nsIDOMElement* aElement) +{ + mDocumentationElement = aElement; + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLOperation::SetInput(nsIWSDLMessage* aInputMessage) +{ + mInputMessage = aInputMessage; + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLOperation::SetOutput(nsIWSDLMessage* aOutputMessage) +{ + mOutputMessage = aOutputMessage; + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLOperation::AddFault(nsIWSDLMessage* aFaultMessage) +{ + NS_ENSURE_ARG(aFaultMessage); + + return mFaultMessages.AppendElement(aFaultMessage); +} + +NS_IMETHODIMP +nsWSDLOperation::SetBinding(nsIWSDLBinding* aBinding) +{ + mBinding = aBinding; + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLOperation::AddParameter(const nsAReadableString& aParameter) +{ + mParameters.AppendString(aParameter); + + return NS_OK; +} + +//////////////////////////////////////////////////////////// +// +// nsSOAPOperationBinding implementation +// +//////////////////////////////////////////////////////////// +nsSOAPOperationBinding::nsSOAPOperationBinding() + : mStyle(nsISOAPPortBinding::STYLE_RPC) +{ + NS_INIT_ISUPPORTS(); +} + +nsSOAPOperationBinding::~nsSOAPOperationBinding() +{ +} + +NS_IMPL_ISUPPORTS2_CI(nsSOAPOperationBinding, + nsIWSDLBinding, + nsISOAPOperationBinding) + +/* readonly attribute AString protocol; */ +NS_IMETHODIMP +nsSOAPOperationBinding::GetProtocol(nsAWritableString& aProtocol) +{ + aProtocol.Assign(NS_LITERAL_STRING("soap")); + + return NS_OK; +} + +/* readonly attribute nsIDOMElement documentation; */ +NS_IMETHODIMP +nsSOAPOperationBinding::GetDocumentation(nsIDOMElement * *aDocumentation) +{ + NS_ENSURE_ARG_POINTER(aDocumentation); + + *aDocumentation = mDocumentationElement; + NS_IF_ADDREF(*aDocumentation); + + return NS_OK; +} + +/* readonly attribute unsigned short style; */ +NS_IMETHODIMP +nsSOAPOperationBinding::GetStyle(PRUint16 *aStyle) +{ + NS_ENSURE_ARG_POINTER(aStyle); + + *aStyle = mStyle; + + return NS_OK; +} + +/* readonly attribute AString soapAction; */ +NS_IMETHODIMP +nsSOAPOperationBinding::GetSoapAction(nsAWritableString & aSoapAction) +{ + aSoapAction.Assign(mSoapAction); + + return NS_OK; +} + +NS_IMETHODIMP +nsSOAPOperationBinding::SetDocumentationElement(nsIDOMElement* aElement) +{ + mDocumentationElement = aElement; + + return NS_OK; +} + +NS_IMETHODIMP +nsSOAPOperationBinding::SetStyle(PRUint16 aStyle) +{ + mStyle = aStyle; + + return NS_OK; +} + +NS_IMETHODIMP +nsSOAPOperationBinding::SetSoapAction(const nsAReadableString& aAction) +{ + mSoapAction.Assign(aAction); + + return NS_OK; +} + +//////////////////////////////////////////////////////////// +// +// nsWSDLMessage implementation +// +//////////////////////////////////////////////////////////// +nsWSDLMessage::nsWSDLMessage(const nsAReadableString& aName) + : mName(aName) +{ + NS_INIT_ISUPPORTS(); +} + +nsWSDLMessage::~nsWSDLMessage() +{ +} + +NS_IMPL_ISUPPORTS1_CI(nsWSDLMessage, nsIWSDLMessage) + +/* readonly attribute AString name; */ +NS_IMETHODIMP +nsWSDLMessage::GetName(nsAWritableString & aName) +{ + aName.Assign(mName); + + return NS_OK; +} + +/* readonly attribute nsIDOMElement documentation; */ +NS_IMETHODIMP +nsWSDLMessage::GetDocumentation(nsIDOMElement * *aDocumentation) +{ + NS_ENSURE_ARG_POINTER(aDocumentation); + + *aDocumentation = mDocumentationElement; + NS_IF_ADDREF(*aDocumentation); + + return NS_OK; +} + +/* readonly attribute PRUint32 partCount; */ +NS_IMETHODIMP +nsWSDLMessage::GetPartCount(PRUint32 *aPartCount) +{ + NS_ENSURE_ARG_POINTER(aPartCount); + + return mParts.Count(aPartCount); +} + +/* nsIWSDLPart getPart (in PRUint32 index); */ +NS_IMETHODIMP +nsWSDLMessage::GetPart(PRUint32 index, nsIWSDLPart **_retval) +{ + NS_ENSURE_ARG_POINTER(_retval); + + return mParts.QueryElementAt(index, NS_GET_IID(nsIWSDLPart), + (void**)_retval); + +} + +/* nsIWSDLPart getPartByName(in AString name); */ +NS_IMETHODIMP +nsWSDLMessage::GetPartByName(const nsAReadableString& aName, + nsIWSDLPart** aPart) +{ + nsresult rv; + + *aPart = nsnull; + // XXX Do a linear search for now. If more efficiency is needed + // we can store the part in a hash as well. + PRUint32 index, count; + mParts.Count(&count); + + for (index = 0; index < count; index++) { + nsCOMPtr part; + + rv = mParts.QueryElementAt(index, NS_GET_IID(nsIWSDLPart), + getter_AddRefs(part)); + if (NS_SUCCEEDED(rv)) { + nsAutoString name; + part->GetName(name); + + if (name.Equals(aName)) { + *aPart = part; + NS_ADDREF(*aPart); + break; + } + } + } + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLMessage::SetDocumentationElement(nsIDOMElement* aElement) +{ + mDocumentationElement = aElement; + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLMessage::AddPart(nsIWSDLPart* aPart) +{ + NS_ENSURE_ARG(aPart); + + return mParts.AppendElement(aPart); +} + +//////////////////////////////////////////////////////////// +// +// nsWSDLPart implementation +// +//////////////////////////////////////////////////////////// +nsWSDLPart::nsWSDLPart(const nsAReadableString& aName) + : mName(aName) +{ + NS_INIT_ISUPPORTS(); +} + +nsWSDLPart::~nsWSDLPart() +{ +} + +NS_IMPL_ISUPPORTS1_CI(nsWSDLPart, nsIWSDLPart) + +/* readonly attribute AString name; */ +NS_IMETHODIMP +nsWSDLPart::GetName(nsAWritableString & aName) +{ + aName.Assign(mName); + + return NS_OK; +} + +/* readonly attribute AString type; */ +NS_IMETHODIMP +nsWSDLPart::GetType(nsAWritableString & aType) +{ + aType.Assign(mType); + + return NS_OK; +} + +/* readonly attribute AString elementName; */ +NS_IMETHODIMP +nsWSDLPart::GetElementName(nsAWritableString & aElementName) +{ + aElementName.Assign(mElementName); + + return NS_OK; +} + +/* readonly attribute nsISchemaComponent schemaComponent; */ +NS_IMETHODIMP +nsWSDLPart::GetSchemaComponent(nsISchemaComponent * *aSchemaComponent) +{ + NS_ENSURE_ARG_POINTER(aSchemaComponent); + + *aSchemaComponent = mSchemaComponent; + NS_IF_ADDREF(*aSchemaComponent); + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLPart::GetBinding(nsIWSDLBinding** aBinding) +{ + NS_ENSURE_ARG_POINTER(aBinding); + + *aBinding = mBinding; + NS_IF_ADDREF(*aBinding); + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLPart::SetTypeInfo(const nsAReadableString& aType, + const nsAReadableString& aElementName, + nsISchemaComponent* aSchemaComponent) +{ + mType.Assign(aType); + mElementName.Assign(aElementName); + mSchemaComponent = aSchemaComponent; + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLPart::SetBinding(nsIWSDLBinding* aBinding) +{ + mBinding = aBinding; + + return NS_OK; +} + +//////////////////////////////////////////////////////////// +// +// nsSOAPPartBinding implementation +// +//////////////////////////////////////////////////////////// +nsSOAPPartBinding::nsSOAPPartBinding(PRUint16 aLocation, PRUint16 aUse, + const nsAReadableString& aEncodingStyle, + const nsAReadableString& aNamespace) + : mLocation(aLocation), mUse(aUse), + mEncodingStyle(aEncodingStyle), mNamespace(aNamespace) +{ + NS_INIT_ISUPPORTS(); +} + +nsSOAPPartBinding::~nsSOAPPartBinding() +{ +} + +NS_IMPL_ISUPPORTS2_CI(nsSOAPPartBinding, + nsIWSDLBinding, + nsISOAPPartBinding) + +/* readonly attribute AString protocol; */ +NS_IMETHODIMP +nsSOAPPartBinding::GetProtocol(nsAWritableString& aProtocol) +{ + aProtocol.Assign(NS_LITERAL_STRING("soap")); + + return NS_OK; +} + +/* readonly attribute nsIDOMElement documentation; */ +NS_IMETHODIMP +nsSOAPPartBinding::GetDocumentation(nsIDOMElement * *aDocumentation) +{ + NS_ENSURE_ARG_POINTER(aDocumentation); + + *aDocumentation = nsnull; + + return NS_OK; +} + +/* readonly attribute unsigned short location; */ +NS_IMETHODIMP +nsSOAPPartBinding::GetLocation(PRUint16 *aLocation) +{ + NS_ENSURE_ARG_POINTER(aLocation); + + *aLocation = mLocation; + + return NS_OK; +} + +/* readonly attribute unsigned short use; */ +NS_IMETHODIMP +nsSOAPPartBinding::GetUse(PRUint16 *aUse) +{ + NS_ENSURE_ARG_POINTER(aUse); + + *aUse = mUse; + + return NS_OK; +} + +/* readonly attribute AString encodingStyle; */ +NS_IMETHODIMP +nsSOAPPartBinding::GetEncodingStyle(nsAWritableString & aEncodingStyle) +{ + aEncodingStyle.Assign(mEncodingStyle); + + return NS_OK; +} + +/* readonly attribute AString namespace; */ +NS_IMETHODIMP +nsSOAPPartBinding::GetNamespace(nsAWritableString & aNamespace) +{ + aNamespace.Assign(mNamespace); + + return NS_OK; +} diff --git a/mozilla/extensions/webservices/wsdl/src/nsWSDLLoader.cpp b/mozilla/extensions/webservices/wsdl/src/nsWSDLLoader.cpp index 232f3990246..013be15be4b 100644 --- a/mozilla/extensions/webservices/wsdl/src/nsWSDLLoader.cpp +++ b/mozilla/extensions/webservices/wsdl/src/nsWSDLLoader.cpp @@ -21,40 +21,1460 @@ * Vidur Apparao (original author) */ -#include "nsWSDLPrivate.h" -#include "nsIXMLHttpRequest.h" +#include "nsWSDLLoader.h" + +// loading includes +#include "nsIDOMEvent.h" +#include "nsIDOMEventTarget.h" +#include "nsNetUtil.h" + +// content includes +#include "nsIContent.h" +#include "nsINameSpaceManager.h" +#include "nsINodeInfo.h" +#include "nsIDOMDocument.h" + +// string includes +#include "nsReadableUtils.h" + +// XPConnect includes +#include "nsIXPConnect.h" +#include "nsIScriptSecurityManager.h" +#include "nsICodebasePrincipal.h" + +// XPCOM includes +#include "nsIServiceManager.h" +#include "nsIComponentManager.h" + +//////////////////////////////////////////////////////////// +// +// nsWSDLAtoms implementation +// +//////////////////////////////////////////////////////////// + +// Statics +nsIAtom* nsWSDLAtoms::sDefinitions_atom = nsnull; +nsIAtom* nsWSDLAtoms::sImport_atom = nsnull; +nsIAtom* nsWSDLAtoms::sTypes_atom = nsnull; +nsIAtom* nsWSDLAtoms::sMessage_atom = nsnull; +nsIAtom* nsWSDLAtoms::sPortType_atom = nsnull; +nsIAtom* nsWSDLAtoms::sBinding_atom = nsnull; +nsIAtom* nsWSDLAtoms::sService_atom = nsnull; +nsIAtom* nsWSDLAtoms::sPort_atom = nsnull; +nsIAtom* nsWSDLAtoms::sOperation_atom = nsnull; +nsIAtom* nsWSDLAtoms::sPart_atom = nsnull; +nsIAtom* nsWSDLAtoms::sDocumentation_atom = nsnull; +nsIAtom* nsWSDLAtoms::sInput_atom = nsnull; +nsIAtom* nsWSDLAtoms::sOutput_atom = nsnull; +nsIAtom* nsWSDLAtoms::sFault_atom = nsnull; + +nsIAtom* nsWSDLAtoms::sBody_atom = nsnull; +nsIAtom* nsWSDLAtoms::sHeader_atom = nsnull; +nsIAtom* nsWSDLAtoms::sHeaderFault_atom = nsnull; +nsIAtom* nsWSDLAtoms::sAddress_atom = nsnull; + +void +nsWSDLAtoms::CreateWSDLAtoms() +{ + sDefinitions_atom = NS_NewAtom("definitions"); + sImport_atom = NS_NewAtom("import"); + sTypes_atom = NS_NewAtom("types"); + sMessage_atom = NS_NewAtom("message"); + sPortType_atom = NS_NewAtom("portType"); + sBinding_atom = NS_NewAtom("binding"); + sService_atom = NS_NewAtom("service"); + sPort_atom = NS_NewAtom("port"); + sOperation_atom = NS_NewAtom("operation"); + sPart_atom = NS_NewAtom("part"); + sDocumentation_atom = NS_NewAtom("documentation"); + sInput_atom = NS_NewAtom("input"); + sOutput_atom = NS_NewAtom("output"); + sFault_atom = NS_NewAtom("fault"); + + sBody_atom = NS_NewAtom("body"); + sHeader_atom = NS_NewAtom("header"); + sHeaderFault_atom = NS_NewAtom("headerFault"); + sAddress_atom = NS_NewAtom("address"); +} + +void +nsWSDLAtoms::DestroyWSDLAtoms() +{ + if (sDefinitions_atom) { + NS_RELEASE(sDefinitions_atom); + NS_RELEASE(sImport_atom); + NS_RELEASE(sTypes_atom); + NS_RELEASE(sMessage_atom); + NS_RELEASE(sPortType_atom); + NS_RELEASE(sBinding_atom); + NS_RELEASE(sService_atom); + NS_RELEASE(sPort_atom); + NS_RELEASE(sOperation_atom); + NS_RELEASE(sPart_atom); + NS_RELEASE(sDocumentation_atom); + NS_RELEASE(sInput_atom); + NS_RELEASE(sOutput_atom); + NS_RELEASE(sFault_atom); + + NS_RELEASE(sBody_atom); + NS_RELEASE(sHeader_atom); + NS_RELEASE(sHeaderFault_atom); + NS_RELEASE(sAddress_atom); + } +} + +//////////////////////////////////////////////////////////// +// +// nsWSDLLoader implementation +// +//////////////////////////////////////////////////////////// nsWSDLLoader::nsWSDLLoader() { NS_INIT_ISUPPORTS(); + if (!nsWSDLAtoms::sDefinitions_atom) { + nsWSDLAtoms::CreateWSDLAtoms(); + } } nsWSDLLoader::~nsWSDLLoader() { } -NS_IMPL_ISUPPORTS1(nsWSDLLoader, nsIWSDLLoader) +NS_IMPL_ISUPPORTS1_CI(nsWSDLLoader, nsIWSDLLoader) -/* nsIWSDLService load (in nsIURI wsdlURI); */ +nsresult +nsWSDLLoader::GetResolvedURI(const nsAReadableString& aWSDLURI, + const char* aMethod, + nsIURI** aURI) +{ + nsresult rv; + nsCOMPtr cc; + nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID(), &rv)); + if(NS_SUCCEEDED(rv)) { + rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc)); + } + + if (NS_SUCCEEDED(rv) && cc) { + JSContext* cx; + rv = cc->GetJSContext(&cx); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr secMan(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr baseURI; + nsCOMPtr principal; + rv = secMan->GetSubjectPrincipal(getter_AddRefs(principal)); + if (NS_SUCCEEDED(rv)) { + nsCOMPtr codebase = do_QueryInterface(principal); + if (codebase) { + codebase->GetURI(getter_AddRefs(baseURI)); + } + } + + rv = NS_NewURI(aURI, aWSDLURI, baseURI); + if (NS_FAILED(rv)) return rv; + + rv = secMan->CheckConnect(cx, *aURI, "nsWSDLLoader", aMethod); + if (NS_FAILED(rv)) + { + // Security check failed. The above call set a JS exception. The + // following lines ensure that the exception is propagated. + cc->SetExceptionWasThrown(PR_TRUE); + return rv; + } + } + else { + rv = NS_NewURI(aURI, aWSDLURI, nsnull); + if (NS_FAILED(rv)) return rv; + } + + return NS_OK; +} + +/* nsIWSDLService load (in AString wsdlURI, in AString portName); */ NS_IMETHODIMP -nsWSDLLoader::Load(nsIURI *wsdlURI, nsIWSDLService **_retval) +nsWSDLLoader::Load(const nsAReadableString& wsdlURI, + const nsAReadableString& portName, + nsIWSDLPort **_retval) +{ + NS_ENSURE_ARG_POINTER(_retval); + + nsCOMPtr resolvedURI; + nsresult rv = GetResolvedURI(wsdlURI, "load", getter_AddRefs(resolvedURI)); + if (NS_FAILED(rv)) { + return rv; + } + nsXPIDLCString spec; + resolvedURI->GetSpec(getter_Copies(spec)); + + nsCOMPtr listener; + nsWSDLLoadRequest* request = new nsWSDLLoadRequest(PR_TRUE, nsnull, + portName); + if (!request) { + return NS_ERROR_OUT_OF_MEMORY; + } + listener = request; + + rv = request->LoadDefinition(NS_ConvertASCIItoUCS2(spec.get())); + + if (NS_SUCCEEDED(rv)) { + request->GetPort(_retval); + } + + return rv; +} + +/* void loadAsync (in AString wsdlURI, in AString portName, + in nsIWSDLLoadListener listener); */ +NS_IMETHODIMP +nsWSDLLoader::LoadAsync(const nsAReadableString& wsdlURI, + const nsAReadableString& portName, + nsIWSDLLoadListener *aListener) +{ + NS_ENSURE_ARG(aListener); + + nsCOMPtr resolvedURI; + nsresult rv = GetResolvedURI(wsdlURI, "loadAsync", getter_AddRefs(resolvedURI)); + if (NS_FAILED(rv)) { + return rv; + } + nsXPIDLCString spec; + resolvedURI->GetSpec(getter_Copies(spec)); + + nsCOMPtr listener; + nsWSDLLoadRequest* request = new nsWSDLLoadRequest(PR_FALSE, aListener, + portName); + if (!request) { + return NS_ERROR_OUT_OF_MEMORY; + } + listener = request; + + return request->LoadDefinition(NS_ConvertASCIItoUCS2(spec.get())); +} + +/* nsISupports createPortProxy(in nsIWSDLPort service, in AString nameSpace); */ +NS_IMETHODIMP +nsWSDLLoader::CreatePortProxy(nsIWSDLPort *port, + const nsAReadableString& nameSpace, + nsISupports **_retval) { return NS_ERROR_NOT_IMPLEMENTED; } -/* void loadAsync (in nsIURI wsdlURI, in nsIWSDLLoaderListener listener); */ -NS_IMETHODIMP -nsWSDLLoader::LoadAsync(nsIURI *wsdlURI, nsIWSDLLoaderListener *listener) +//////////////////////////////////////////////////////////// +// +// nsWSDLLoadRequest implementation +// +//////////////////////////////////////////////////////////// +nsWSDLLoadRequest::nsWSDLLoadRequest(PRBool aIsSync, + nsIWSDLLoadListener* aListener, + const nsAReadableString& aPortName) + : mListener(aListener), mIsSync(aIsSync), mPortName(aPortName) { - return NS_ERROR_NOT_IMPLEMENTED; + NS_INIT_ISUPPORTS(); } -/* nsISupports createServiceProxy (in nsIWSDLService service, in AString nameSpace); */ -NS_IMETHODIMP -nsWSDLLoader::CreateServiceProxy(nsIWSDLService *service, - const nsAReadableString& nameSpace, - nsISupports **_retval) +nsWSDLLoadRequest::~nsWSDLLoadRequest() { - return NS_ERROR_NOT_IMPLEMENTED; + while (GetCurrentContext() != nsnull) { + PopContext(); + } } +NS_IMPL_ISUPPORTS1(nsWSDLLoadRequest, + nsIDOMEventListener) + +static inline PRBool +IsElementOfNamespace(nsIDOMElement* aElement, + const nsAReadableString& aNamespace) +{ + nsAutoString namespaceURI; + aElement->GetNamespaceURI(namespaceURI); + return namespaceURI.Equals(aNamespace); +} + +nsresult +nsWSDLLoadRequest::LoadDefinition(const nsAReadableString& aURI) +{ + nsresult rv; + + if (!mSchemaLoader) { + mSchemaLoader = do_GetService(NS_SCHEMALOADER_CONTRACTID, &rv); + if (NS_FAILED(rv)) { + return rv; + } + } + + mRequest = do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv); + if (!mRequest) { + return rv; + } + + rv = mRequest->OpenRequest("GET", + NS_ConvertUCS2toUTF8(aURI).get(), + !mIsSync, nsnull, nsnull); + if (NS_FAILED(rv)) { + return rv; + } + + if (!mIsSync) { + nsCOMPtr target(do_QueryInterface(mRequest)); + if (!target) { + return NS_ERROR_UNEXPECTED; + } + + rv = target->AddEventListener(NS_LITERAL_STRING("load"), + this, PR_FALSE); + if (NS_FAILED(rv)) { + return rv; + } + + rv = target->AddEventListener(NS_LITERAL_STRING("error"), + this, PR_FALSE); + if (NS_FAILED(rv)) { + return rv; + } + } + + rv = mRequest->Send(nsnull); + if (NS_FAILED(rv)) { + return rv; + } + + if (mIsSync) { + nsCOMPtr document; + rv = mRequest->GetResponseXML(getter_AddRefs(document)); + if (NS_FAILED(rv)) { + return rv; + } + + nsCOMPtr element; + document->GetDocumentElement(getter_AddRefs(element)); + if (element) { + if (IsElementOfNamespace(element, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + rv = PushContext(document, aURI); + if (NS_FAILED(rv)) { + return rv; + } + + rv = ResumeProcessing(); + + PopContext(); + + if (NS_FAILED(rv)) { + return rv; + } + } + else if (IsElementOfNamespace(element, + NS_LITERAL_STRING(NS_WSDL_SCHEMA_NAMESPACE))) { + nsCOMPtr schema; + rv = mSchemaLoader->ProcessSchemaElement(element, + getter_AddRefs(schema)); + if (NS_FAILED(rv)) { + return NS_ERROR_WSDL_SCHEMA_PROCESSING_ERROR; + } + + nsAutoString targetNamespace; + schema->GetTargetNamespace(targetNamespace); + + nsStringKey key(targetNamespace); + mTypes.Put(&key, schema); + } + else { + rv = NS_ERROR_WSDL_NOT_WSDL_ELEMENT; // element of unknown namespace + } + } + else { + return NS_ERROR_WSDL_NOT_WSDL_ELEMENT; + } + } + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ContineProcessingTillDone() +{ + nsresult rv; + do { + rv = ResumeProcessing(); + + if (NS_FAILED(rv) || (rv == NS_ERROR_WSDL_LOADPENDING)) { + break; + } + + PopContext(); + + } while (GetCurrentContext() != nsnull); + + return rv; +} + +/* void handleEvent (in nsIDOMEvent event); */ +NS_IMETHODIMP +nsWSDLLoadRequest::HandleEvent(nsIDOMEvent *event) +{ + nsresult rv; + nsAutoString eventType; + + event->GetType(eventType); + + if (eventType.Equals(NS_LITERAL_STRING("load"))) { + nsCOMPtr document; + + rv = mRequest->GetResponseXML(getter_AddRefs(document)); + if (NS_SUCCEEDED(rv)) { + nsCOMPtr element; + + document->GetDocumentElement(getter_AddRefs(element)); + if (element) { + if (IsElementOfNamespace(element, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + + nsCOMPtr channel; + nsCOMPtr uri; + nsXPIDLCString spec; + + mRequest->GetChannel(getter_AddRefs(channel)); + + if (channel) { + channel->GetURI(getter_AddRefs(uri)); + if (uri) { + uri->GetSpec(getter_Copies(spec)); + } + } + + rv = PushContext(document, NS_ConvertASCIItoUCS2(spec.get())); + + if (NS_SUCCEEDED(rv)) { + rv = ContineProcessingTillDone(); + } + } + else if (IsElementOfNamespace(element, + NS_LITERAL_STRING(NS_WSDL_SCHEMA_NAMESPACE))) { + nsCOMPtr schema; + rv = mSchemaLoader->ProcessSchemaElement(element, + getter_AddRefs(schema)); + if (NS_FAILED(rv)) { + return NS_ERROR_WSDL_SCHEMA_PROCESSING_ERROR; + } + + nsAutoString targetNamespace; + schema->GetTargetNamespace(targetNamespace); + + nsStringKey key(targetNamespace); + mTypes.Put(&key, schema); + + rv = ContineProcessingTillDone(); + } + else { + rv = NS_ERROR_WSDL_NOT_WSDL_ELEMENT; // element of unknown namespace + } + } + else { + rv = NS_ERROR_WSDL_NOT_WSDL_ELEMENT; + } + } + + if (NS_FAILED(rv)) { + mListener->OnError(rv, NS_LITERAL_STRING("Failure processing WSDL document")); + return NS_OK; + } + } + else if (eventType.Equals(NS_LITERAL_STRING("error"))) { + mListener->OnError(NS_ERROR_WSDL_LOADING_ERROR, + NS_LITERAL_STRING("Failure loading")); + return NS_OK; + } + + if (GetCurrentContext() == nsnull) { + if (mPort) { + mListener->OnLoad(mPort); + } + else { + mListener->OnError(NS_ERROR_WSDL_BINDING_NOT_FOUND, + NS_LITERAL_STRING("Binding not found")); + } + mRequest = nsnull; + } + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ResumeProcessing() +{ + nsresult rv = NS_OK; + + nsWSDLLoadingContext* context = GetCurrentContext(); + if (!context) { + return NS_ERROR_UNEXPECTED; + } + + nsCOMPtr element; + context->GetRootElement(getter_AddRefs(element)); + PRUint32 childIndex = context->GetChildIndex(); + + nsChildElementIterator iterator(element, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE)); + nsCOMPtr childElement; + nsCOMPtr tagName; + + // If we don't yet have a port, find the service element, create one + // and record the port's its binding name + if (mBindingName.IsEmpty()) { + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if (tagName == nsWSDLAtoms::sService_atom) { + rv = ProcessServiceElement(childElement); + if (NS_FAILED(rv)) { + return rv; + } + } + } + } + + iterator.Reset(childIndex); + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if (tagName == nsWSDLAtoms::sImport_atom) { + rv = ProcessImportElement(childElement, + iterator.GetCurrentIndex()+1); + if (NS_FAILED(rv) || + (rv == NS_ERROR_WSDL_LOADPENDING)) { + return rv; + } + } + else if (tagName == nsWSDLAtoms::sTypes_atom) { + rv = ProcessTypesElement(childElement); + if (NS_FAILED(rv)) { + return rv; + } + } + else if (tagName == nsWSDLAtoms::sMessage_atom) { + rv = ProcessMessageElement(childElement); + if (NS_FAILED(rv)) { + return rv; + } + } + else if (tagName == nsWSDLAtoms::sPortType_atom) { + rv = ProcessPortTypeElement(childElement); + if (NS_FAILED(rv)) { + return rv; + } + } + else if (tagName == nsWSDLAtoms::sBinding_atom) { + nsAutoString name, targetNamespace; + childElement->GetAttribute(NS_LITERAL_STRING("name"), name); + context->GetTargetNamespace(targetNamespace); + + // Only process binding for the requested port + // XXX We should be checking the binding namespace as + // well, but some authors are not qualifying their + // binding names + if (mBindingName.Equals(name)) { + rv = ProcessBindingElement(childElement); + if (NS_FAILED(rv)) { + return rv; + } + } + } + } + + return rv; +} + +nsresult +nsWSDLLoadRequest::GetPort(nsIWSDLPort** aPort) +{ + *aPort = mPort; + NS_IF_ADDREF(*aPort); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::PushContext(nsIDOMDocument* aDocument, + const nsAReadableString& aURISpec) +{ + nsWSDLLoadingContext* context = new nsWSDLLoadingContext(aDocument, + aURISpec); + if (!context) { + return NS_ERROR_OUT_OF_MEMORY; + } + + mContextStack.AppendElement((void*)context); + + return NS_OK; +} + +nsWSDLLoadingContext* +nsWSDLLoadRequest::GetCurrentContext() +{ + PRUint32 count = mContextStack.Count(); + if (count > 0) { + return NS_STATIC_CAST(nsWSDLLoadingContext*, + mContextStack.ElementAt(count-1)); + } + + return nsnull; +} + +void +nsWSDLLoadRequest::PopContext() +{ + PRUint32 count = mContextStack.Count(); + if (count > 0) { + nsWSDLLoadingContext* context = NS_STATIC_CAST(nsWSDLLoadingContext*, + mContextStack.ElementAt(count-1)); + delete context; + mContextStack.RemoveElementAt(count-1); + } +} + +nsresult +nsWSDLLoadRequest::GetSchemaElement(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsISchemaElement** aSchemaComponent) +{ + nsStringKey key(aNamespace); + nsCOMPtr sup = dont_AddRef(mTypes.Get(&key)); + nsCOMPtr schema(do_QueryInterface(sup)); + if (!schema) { + return NS_ERROR_WSDL_UNKNOWN_SCHEMA_COMPONENT; + } + + nsCOMPtr element; + schema->GetElementByName(aName, getter_AddRefs(element)); + if (!element) { + return NS_ERROR_WSDL_UNKNOWN_SCHEMA_COMPONENT; + } + + *aSchemaComponent = element; + NS_IF_ADDREF(*aSchemaComponent); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::GetSchemaType(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsISchemaType** aSchemaComponent) +{ + if (aNamespace.Equals(NS_LITERAL_STRING(NS_WSDL_SCHEMA_NAMESPACE))) { + nsCOMPtr collection(do_QueryInterface(mSchemaLoader)); + return collection->GetType(aName, aNamespace, aSchemaComponent); + } + + nsStringKey key(aNamespace); + nsCOMPtr sup = dont_AddRef(mTypes.Get(&key)); + nsCOMPtr schema(do_QueryInterface(sup)); + if (!schema) { + return NS_ERROR_WSDL_UNKNOWN_SCHEMA_COMPONENT; + } + + nsCOMPtr type; + schema->GetTypeByName(aName, getter_AddRefs(type)); + if (!type) { + return NS_ERROR_WSDL_UNKNOWN_SCHEMA_COMPONENT; + } + + *aSchemaComponent = type; + NS_IF_ADDREF(*aSchemaComponent); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::GetMessage(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsIWSDLMessage** aMessage) +{ + nsAutoString keyStr; + keyStr.Assign(aName); + keyStr.Append(aNamespace); + nsStringKey key(keyStr); + + nsCOMPtr sup = dont_AddRef(mMessages.Get(&key)); + nsCOMPtr message(do_QueryInterface(sup)); + if (!message) { + return NS_ERROR_WSDL_UNKNOWN_WSDL_COMPONENT; + } + + *aMessage = message; + NS_IF_ADDREF(*aMessage); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::GetPortType(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsIWSDLPort** aPort) +{ + nsAutoString keyStr; + keyStr.Assign(aName); + keyStr.Append(aNamespace); + nsStringKey key(keyStr); + + nsCOMPtr sup = dont_AddRef(mPortTypes.Get(&key)); + nsCOMPtr port(do_QueryInterface(sup)); + if (!port) { + return NS_ERROR_WSDL_UNKNOWN_WSDL_COMPONENT; + } + + *aPort = port; + NS_IF_ADDREF(*aPort); + + return NS_OK; +} + +static nsresult +ParseQualifiedName(nsIDOMElement* aContext, + const nsAReadableString& aQualifiedName, + nsAWritableString& aPrefix, + nsAWritableString& aLocalName, + nsAWritableString& aNamespaceURI) +{ + nsReadingIterator pos, begin, end; + + aQualifiedName.BeginReading(begin); + aQualifiedName.EndReading(end); + pos = begin; + + if (FindCharInReadable(PRUnichar(':'), pos, end)) { + CopyUnicodeTo(begin, pos, aPrefix); + CopyUnicodeTo(++pos, end, aLocalName); + } + else { + CopyUnicodeTo(begin, end, aLocalName); + } + + nsCOMPtr node(do_QueryInterface(aContext)); + if (!node) { + return NS_ERROR_UNEXPECTED; + } + + return node->LookupNamespaceURI(aPrefix, aNamespaceURI); +} + + +nsresult +nsWSDLLoadRequest::ProcessImportElement(nsIDOMElement* aElement, + PRUint32 aIndex) +{ + nsresult rv = NS_OK; + + // XXX Is there a need to record the namespace? Can it be different + // from the targetNamespace of the imported file? + + nsAutoString location, documentLocation; + aElement->GetAttribute(NS_LITERAL_STRING("location"), location); + + nsWSDLLoadingContext* context = GetCurrentContext(); + if (!context) { + return NS_ERROR_UNEXPECTED; + } + context->GetDocumentLocation(documentLocation); + + nsCOMPtr uri, baseURI; + rv = NS_NewURI(getter_AddRefs(baseURI), documentLocation); + if (NS_FAILED(rv)) { + return rv; + } + + rv = NS_NewURI(getter_AddRefs(uri), location, baseURI); + if (NS_FAILED(rv)) { + return rv; + } + + nsXPIDLCString spec; + uri->GetSpec(getter_Copies(spec)); + + rv = LoadDefinition(NS_ConvertUTF8toUCS2(spec.get())); + if (NS_FAILED(rv)) { + return rv; + } + + if (!mIsSync) { + context->SetChildIndex(aIndex); + return NS_ERROR_WSDL_LOADPENDING; + } + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessTypesElement(nsIDOMElement* aElement) +{ + nsresult rv = NS_OK; + + nsChildElementIterator iterator(aElement, + NS_LITERAL_STRING(NS_WSDL_SCHEMA_NAMESPACE)); + nsCOMPtr childElement; + nsCOMPtr tagName; + + nsCOMPtr schemaAtom(dont_AddRef(NS_NewAtom("schema"))); + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if (tagName == schemaAtom) { + nsCOMPtr schema; + rv = mSchemaLoader->ProcessSchemaElement(childElement, + getter_AddRefs(schema)); + if (NS_FAILED(rv)) { + return NS_ERROR_WSDL_SCHEMA_PROCESSING_ERROR; + } + + nsAutoString targetNamespace; + schema->GetTargetNamespace(targetNamespace); + + nsStringKey key(targetNamespace); + mTypes.Put(&key, schema); + + break; + } + } + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessAbstractPartElement(nsIDOMElement* aElement, + nsWSDLMessage* aMessage) +{ + nsresult rv = NS_OK; + + nsAutoString name; + aElement->GetAttribute(NS_LITERAL_STRING("name"), name); + + nsCOMPtr part; + nsWSDLPart* partInst = new nsWSDLPart(name); + if (!partInst) { + return NS_ERROR_OUT_OF_MEMORY; + } + part = partInst; + + nsCOMPtr schemaComponent; + nsAutoString elementQName, typeQName; + aElement->GetAttribute(NS_LITERAL_STRING("element"), elementQName); + aElement->GetAttribute(NS_LITERAL_STRING("type"), typeQName); + + if (!elementQName.IsEmpty()) { + nsAutoString elementPrefix, elementLocalName, elementNamespace; + + rv = ParseQualifiedName(aElement, + elementQName, + elementPrefix, + elementLocalName, + elementNamespace); + if (NS_FAILED(rv)) { + return rv; + } + + nsCOMPtr schemaElement; + rv = GetSchemaElement(elementLocalName, elementNamespace, + getter_AddRefs(schemaElement)); + if (NS_FAILED(rv)) { + return rv; + } + + schemaComponent = schemaElement; + } + else if (!typeQName.IsEmpty()) { + nsAutoString typePrefix, typeLocalName, typeNamespace; + + rv = ParseQualifiedName(aElement, + typeQName, + typePrefix, + typeLocalName, + typeNamespace); + if (NS_FAILED(rv)) { + return rv; + } + + nsCOMPtr schemaType; + rv = GetSchemaType(typeLocalName, typeNamespace, + getter_AddRefs(schemaType)); + if (NS_FAILED(rv)) { + return rv; + } + + schemaComponent = schemaType; + } + + partInst->SetTypeInfo(typeQName, elementQName, + schemaComponent); + aMessage->AddPart(part); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessMessageElement(nsIDOMElement* aElement) +{ + nsresult rv = NS_OK; + + nsAutoString name; + aElement->GetAttribute(NS_LITERAL_STRING("name"), name); + + nsCOMPtr message; + nsWSDLMessage* messageInst = new nsWSDLMessage(name); + if (!messageInst) { + return NS_ERROR_OUT_OF_MEMORY; + } + message = messageInst; + + nsChildElementIterator iterator(aElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE)); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if (tagName == nsWSDLAtoms::sDocumentation_atom) { + messageInst->SetDocumentationElement(childElement); + } + else if (tagName == nsWSDLAtoms::sPart_atom) { + rv = ProcessAbstractPartElement(childElement, messageInst); + if (NS_FAILED(rv)) { + return rv; + } + } + } + + nsAutoString targetNamespace; + nsWSDLLoadingContext* context = GetCurrentContext(); + if (!context) { + return NS_ERROR_UNEXPECTED; + } + context->GetTargetNamespace(targetNamespace); + + name.Append(targetNamespace); + nsStringKey key(name); + mMessages.Put(&key, message); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessOperationComponent(nsIDOMElement* aElement, + nsIWSDLMessage** aMessage) +{ + nsresult rv; + + nsAutoString messageQName, messagePrefix, messageLocalName, messageNamespace; + aElement->GetAttribute(NS_LITERAL_STRING("message"), messageQName); + + rv = ParseQualifiedName(aElement, + messageQName, + messagePrefix, + messageLocalName, + messageNamespace); + if (NS_FAILED(rv)) { + return rv; + } + + rv = GetMessage(messageLocalName, messageNamespace, aMessage); + if (NS_FAILED(rv)) { + // XXX It seem that some WSDL authors eliminate prefixes + // from qualified names in attribute values, assuming that + // the names will resolve to the targetNamespace, while + // they should technically resolve to the default namespace. + if (messagePrefix.IsEmpty()) { + nsAutoString targetNamespace; + nsWSDLLoadingContext* context = GetCurrentContext(); + if (!context) { + return NS_ERROR_UNEXPECTED; + } + context->GetTargetNamespace(targetNamespace); + rv = GetMessage(messageLocalName, targetNamespace, aMessage); + if (NS_FAILED(rv)) { + return rv; + } + } + } + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessAbstractOperation(nsIDOMElement* aElement, + nsWSDLPort* aPort) +{ + nsresult rv = NS_OK; + + nsAutoString name; + aElement->GetAttribute(NS_LITERAL_STRING("name"), name); + + nsCOMPtr operation; + nsWSDLOperation* operationInst = new nsWSDLOperation(name); + if (!operationInst) { + return NS_ERROR_OUT_OF_MEMORY; + } + operation = operationInst; + + nsAutoString parameterOrder; + aElement->GetAttribute(NS_LITERAL_STRING("parameterOrder"), parameterOrder); + if (!parameterOrder.IsEmpty()) { + nsReadingIterator start, end, delimiter; + parameterOrder.BeginReading(start); + parameterOrder.EndReading(end); + + PRBool found; + do { + delimiter = start; + + // Find the next delimiter + found = FindCharInReadable(PRUnichar(' '), delimiter, end); + + // Use the string from the current start position to the + // delimiter. + nsAutoString paramName; + CopyUnicodeTo(start, delimiter, paramName); + + if (!paramName.IsEmpty()) { + operationInst->AddParameter(paramName); + } + + // If we did find a delimeter, advance past it + if (found) { + start = delimiter; + ++start; + } + } while (found); + } + + nsChildElementIterator iterator(aElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE)); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + nsCOMPtr message; + if (tagName == nsWSDLAtoms::sDocumentation_atom) { + operationInst->SetDocumentationElement(childElement); + } + else if (tagName == nsWSDLAtoms::sInput_atom) { + rv = ProcessOperationComponent(childElement, + getter_AddRefs(message)); + if (NS_FAILED(rv)) { + return rv; + } + operationInst->SetInput(message); + } + else if (tagName == nsWSDLAtoms::sOutput_atom) { + rv = ProcessOperationComponent(childElement, + getter_AddRefs(message)); + if (NS_FAILED(rv)) { + return rv; + } + operationInst->SetOutput(message); + } + else if (tagName == nsWSDLAtoms::sFault_atom) { + rv = ProcessOperationComponent(childElement, + getter_AddRefs(message)); + if (NS_FAILED(rv)) { + return rv; + } + operationInst->AddFault(message); + } + } + + aPort->AddOperation(operation); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessPortTypeElement(nsIDOMElement* aElement) +{ + nsresult rv = NS_OK; + + nsAutoString name; + aElement->GetAttribute(NS_LITERAL_STRING("name"), name); + + nsCOMPtr port; + nsWSDLPort* portInst = new nsWSDLPort(name); + if (!portInst) { + return NS_ERROR_OUT_OF_MEMORY; + } + port = portInst; + + nsChildElementIterator iterator(aElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE)); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if (tagName == nsWSDLAtoms::sDocumentation_atom) { + portInst->SetDocumentationElement(childElement); + } + else if (tagName == nsWSDLAtoms::sOperation_atom) { + rv = ProcessAbstractOperation(childElement, portInst); + if (NS_FAILED(rv)) { + return rv; + } + } + } + + nsAutoString targetNamespace; + nsWSDLLoadingContext* context = GetCurrentContext(); + if (!context) { + return NS_ERROR_UNEXPECTED; + } + context->GetTargetNamespace(targetNamespace); + + name.Append(targetNamespace); + nsStringKey key(name); + mPortTypes.Put(&key, port); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessMessageBinding(nsIDOMElement* aElement, + nsIWSDLMessage* aMessage) +{ + + nsChildElementIterator iterator(aElement, + NS_LITERAL_STRING(NS_WSDL_SOAP_NAMESPACE)); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if (tagName == nsWSDLAtoms::sBody_atom) { + nsAutoString partsStr, useStr, encodingStyle, namespaceStr; + childElement->GetAttribute(NS_LITERAL_STRING("parts"), partsStr); + childElement->GetAttribute(NS_LITERAL_STRING("use"), useStr); + childElement->GetAttribute(NS_LITERAL_STRING("encodingStyle"), + encodingStyle); + childElement->GetAttribute(NS_LITERAL_STRING("namespace"), namespaceStr); + + PRUint16 use = nsISOAPPartBinding::USE_LITERAL; + if (useStr.Equals(NS_LITERAL_STRING("encoded"))) { + use = nsISOAPPartBinding::USE_ENCODED; + } + + nsCOMPtr binding; + nsSOAPPartBinding* bindingInst = new nsSOAPPartBinding(nsISOAPPartBinding::LOCATION_BODY, + use, + encodingStyle, + namespaceStr); + if (!bindingInst) { + return NS_ERROR_OUT_OF_MEMORY; + } + binding = bindingInst; + + nsCOMPtr part; + nsWSDLPart* partInst; + if (partsStr.IsEmpty()) { + PRUint32 index, count; + + aMessage->GetPartCount(&count); + for (index = 0; index < count; index++) { + aMessage->GetPart(index, getter_AddRefs(part)); + partInst = NS_REINTERPRET_CAST(nsWSDLPart*, part.get()); + if (partInst) { + partInst->SetBinding(binding); + } + } + } + else { + nsReadingIterator start, end, delimiter; + partsStr.BeginReading(start); + partsStr.EndReading(end); + + PRBool found; + do { + delimiter = start; + + // Find the next delimiter + found = FindCharInReadable(PRUnichar(' '), delimiter, end); + + // Use the string from the current start position to the + // delimiter. + nsAutoString partName; + CopyUnicodeTo(start, delimiter, partName); + + if (!partName.IsEmpty()) { + aMessage->GetPartByName(partName, getter_AddRefs(part)); + partInst = NS_REINTERPRET_CAST(nsWSDLPart*, part.get()); + if (partInst) { + partInst->SetBinding(binding); + } + } + + // If we did find a delimeter, advance past it + if (found) { + start = delimiter; + ++start; + } + } while (found); + } + } + } + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessOperationBinding(nsIDOMElement* aElement, + nsIWSDLPort* aPort) +{ + nsresult rv = NS_OK; + + nsAutoString name; + aElement->GetAttribute(NS_LITERAL_STRING("name"), name); + + nsCOMPtr operation; + aPort->GetOperationByName(name, getter_AddRefs(operation)); + if (!operation) { + return NS_ERROR_WSDL_UNKNOWN_WSDL_COMPONENT; + } + nsWSDLOperation* operationInst = NS_REINTERPRET_CAST(nsWSDLOperation*, + operation.get()); + + nsCOMPtr binding; + nsSOAPOperationBinding* bindingInst = new nsSOAPOperationBinding(); + if (!bindingInst) { + return NS_ERROR_OUT_OF_MEMORY; + } + binding = bindingInst; + + nsChildElementIterator iterator(aElement); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if ((tagName == nsWSDLAtoms::sDocumentation_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + bindingInst->SetDocumentationElement(childElement); + } + else if ((tagName == nsWSDLAtoms::sOperation_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_SOAP_NAMESPACE))) { + nsAutoString action, style; + childElement->GetAttribute(NS_LITERAL_STRING("soapAction"), action); + childElement->GetAttribute(NS_LITERAL_STRING("style"), style); + + bindingInst->SetSoapAction(action); + if (style.Equals(NS_LITERAL_STRING("rpc"))) { + bindingInst->SetStyle(nsISOAPPortBinding::STYLE_RPC); + } + else if (style.Equals(NS_LITERAL_STRING("document"))) { + bindingInst->SetStyle(nsISOAPPortBinding::STYLE_DOCUMENT); + } + } + else if ((tagName == nsWSDLAtoms::sInput_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + nsCOMPtr input; + + operation->GetInput(getter_AddRefs(input)); + rv = ProcessMessageBinding(childElement, input); + if (NS_FAILED(rv)) { + return rv; + } + } + else if ((tagName == nsWSDLAtoms::sOutput_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + nsCOMPtr output; + + operation->GetOutput(getter_AddRefs(output)); + rv = ProcessMessageBinding(childElement, output); + if (NS_FAILED(rv)) { + return rv; + } + } + else if ((tagName == nsWSDLAtoms::sFault_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + // XXX TO BE IMPLEMENTED + } + } + + operationInst->SetBinding(binding); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessBindingElement(nsIDOMElement* aElement) +{ + nsresult rv = NS_OK; + + nsAutoString name; + aElement->GetAttribute(NS_LITERAL_STRING("name"), name); + + PRBool foundSOAPBinding; + nsCOMPtr binding; + nsSOAPPortBinding* bindingInst = new nsSOAPPortBinding(name); + if (!bindingInst) { + return NS_ERROR_OUT_OF_MEMORY; + } + binding = bindingInst; + bindingInst->SetAddress(mAddress); + + nsCOMPtr port; + nsAutoString typeQName, typePrefix, typeLocalName, typeNamespace; + aElement->GetAttribute(NS_LITERAL_STRING("type"), typeQName); + rv = ParseQualifiedName(aElement, + typeQName, + typePrefix, + typeLocalName, + typeNamespace); + if (NS_FAILED(rv)) { + return rv; + } + + rv = GetPortType(typeLocalName, typeNamespace, getter_AddRefs(port)); + if (NS_FAILED(rv)) { + // XXX It seem that some WSDL authors eliminate prefixes + // from qualified names in attribute values, assuming that + // the names will resolve to the targetNamespace, while + // they should technically resolve to the default namespace. + if (typePrefix.IsEmpty()) { + nsAutoString targetNamespace; + nsWSDLLoadingContext* context = GetCurrentContext(); + if (!context) { + return NS_ERROR_UNEXPECTED; + } + context->GetTargetNamespace(targetNamespace); + rv = GetPortType(typeLocalName, targetNamespace, getter_AddRefs(port)); + if (NS_FAILED(rv)) { + return rv; // Can't find a port type of the specified name + } + } + } + + nsChildElementIterator iterator(aElement); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if ((tagName == nsWSDLAtoms::sDocumentation_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + bindingInst->SetDocumentationElement(childElement); + } + else if ((tagName == nsWSDLAtoms::sBinding_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_SOAP_NAMESPACE))) { + nsAutoString style, transport; + childElement->GetAttribute(NS_LITERAL_STRING("style"), style); + childElement->GetAttribute(NS_LITERAL_STRING("transport"), transport); + + if (style.Equals(NS_LITERAL_STRING("rpc"))) { + bindingInst->SetStyle(nsISOAPPortBinding::STYLE_RPC); + } + else if (style.Equals(NS_LITERAL_STRING("document"))) { + bindingInst->SetStyle(nsISOAPPortBinding::STYLE_DOCUMENT); + } + bindingInst->SetTransport(transport); + foundSOAPBinding = PR_TRUE; + } + else if ((tagName == nsWSDLAtoms::sOperation_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + rv = ProcessOperationBinding(childElement, + port); + if (NS_FAILED(rv)) { + return rv; + } + } + } + + if (!foundSOAPBinding) { + // If we don't have a SOAP binding, we can't continue + return NS_ERROR_WSDL_BINDING_NOT_FOUND; + } + nsWSDLPort* portInst = NS_REINTERPRET_CAST(nsWSDLPort*, port.get()); + portInst->SetBinding(binding); + + mPort = port; + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessPortBinding(nsIDOMElement* aElement) +{ + nsChildElementIterator iterator(aElement); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if ((tagName == nsWSDLAtoms::sAddress_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_SOAP_NAMESPACE))) { + childElement->GetAttribute(NS_LITERAL_STRING("location"), + mAddress); + } + } + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessServiceElement(nsIDOMElement* aElement) +{ + nsresult rv; + + nsChildElementIterator iterator(aElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE)); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if (tagName == nsWSDLAtoms::sPort_atom) { + nsAutoString name; + childElement->GetAttribute(NS_LITERAL_STRING("name"), name); + if (name.Equals(mPortName)) { + nsAutoString bindingQName, bindingPrefix; + + childElement->GetAttribute(NS_LITERAL_STRING("binding"), bindingQName); + rv = ParseQualifiedName(childElement, + bindingQName, + bindingPrefix, + mBindingName, + mBindingNamespace); + if (NS_FAILED(rv)) { + return rv; // binding of an unknown namespace + } + + rv = ProcessPortBinding(childElement); + if (NS_FAILED(rv)) { + return rv; + } + + break; + } + } + } + + return NS_OK; +} diff --git a/mozilla/extensions/webservices/wsdl/src/nsWSDLLoader.h b/mozilla/extensions/webservices/wsdl/src/nsWSDLLoader.h new file mode 100644 index 00000000000..8e04bf19fd7 --- /dev/null +++ b/mozilla/extensions/webservices/wsdl/src/nsWSDLLoader.h @@ -0,0 +1,211 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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. + * + * The Initial Developer of the Original Code is Netscape + * Communications. Portions created by Netscape Communications are + * Copyright (C) 2001 by Netscape Communications. All + * Rights Reserved. + * + * Contributor(s): + * Vidur Apparao (original author) + */ + +#ifndef __nsWSDLLoader_h__ +#define __nsWSDLLoader_h__ + +#include "nsIWSDLLoader.h" +#include "nsWSDLPrivate.h" + +#include "nsDOMUtils.h" + +// XPCOM Includes +#include "nsCOMPtr.h" +#include "nsSupportsArray.h" +#include "nsString.h" +#include "nsIAtom.h" +#include "nsHashtable.h" +#include "nsError.h" + +// Loading includes +#include "nsIURI.h" +#include "nsIXMLHTTPRequest.h" +#include "nsIDOMEventListener.h" + +// schema includes +#include "nsISchemaLoader.h" + +// DOM includes +#include "nsIDOMDocument.h" + +#define NS_ERROR_WSDL_LOADPENDING NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_GENERAL, 1) + +class nsWSDLAtoms { +public: + static void CreateWSDLAtoms(); + static void DestroyWSDLAtoms(); + + static nsIAtom* sDefinitions_atom; + static nsIAtom* sTypes_atom; + static nsIAtom* sMessage_atom; + static nsIAtom* sPortType_atom; + static nsIAtom* sBinding_atom; + static nsIAtom* sService_atom; + static nsIAtom* sPort_atom; + static nsIAtom* sOperation_atom; + static nsIAtom* sPart_atom; + static nsIAtom* sDocumentation_atom; + static nsIAtom* sImport_atom; + static nsIAtom* sInput_atom; + static nsIAtom* sOutput_atom; + static nsIAtom* sFault_atom; + + static nsIAtom* sBody_atom; + static nsIAtom* sHeader_atom; + static nsIAtom* sHeaderFault_atom; + static nsIAtom* sAddress_atom; +}; + +class nsWSDLLoader : public nsIWSDLLoader { +public: + nsWSDLLoader(); + virtual ~nsWSDLLoader(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIWSDLLOADER + +protected: + nsresult GetResolvedURI(const nsAReadableString& aSchemaURI, + const char* aMethod, + nsIURI** aURI); + +protected: + nsWSDLPort* mPort; +}; + + +class nsWSDLLoadingContext { +public: + nsWSDLLoadingContext(nsIDOMDocument* aDocument, + const nsAReadableString& aLocation) : + mDocument(aDocument), mChildIndex(0), mDocumentLocation(aLocation) { + } + ~nsWSDLLoadingContext() { + } + + void GetRootElement(nsIDOMElement** aElement) { + mDocument->GetDocumentElement(aElement); + } + + PRUint32 GetChildIndex() { return mChildIndex; } + void SetChildIndex(PRUint32 aChildIndex) { mChildIndex = aChildIndex; } + + void GetTargetNamespace(nsAWritableString& aNamespace) { + nsCOMPtr element; + GetRootElement(getter_AddRefs(element)); + if (element) { + element->GetAttribute(NS_LITERAL_STRING("targetNamespace"), + aNamespace); + } + else { + aNamespace.Truncate(); + } + } + + void GetDocumentLocation(nsAWritableString& aLocation) { + aLocation.Assign(mDocumentLocation); + } + +protected: + // XXX hold onto the document till issues related to dangling + // document pointers in content are fixed. After that, just + // hold onto the root element. + nsCOMPtr mDocument; + PRUint32 mChildIndex; + nsString mDocumentLocation; +}; + +class nsWSDLLoadRequest : public nsIDOMEventListener +{ +public: + nsWSDLLoadRequest(PRBool aIsSync, + nsIWSDLLoadListener* aListener, + const nsAReadableString& aPortName); + virtual ~nsWSDLLoadRequest(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIDOMEVENTLISTENER + + nsresult LoadDefinition(const nsAReadableString& aURI); + nsresult ResumeProcessing(); + nsresult ContineProcessingTillDone(); + nsresult GetPort(nsIWSDLPort** aPort); + + nsresult PushContext(nsIDOMDocument* aDocument, + const nsAReadableString& aLocation); + nsWSDLLoadingContext* GetCurrentContext(); + void PopContext(); + + nsresult GetSchemaElement(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsISchemaElement** aSchemaComponent); + nsresult GetSchemaType(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsISchemaType** aSchemaComponent); + nsresult GetMessage(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsIWSDLMessage** aMessage); + nsresult GetPortType(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsIWSDLPort** aPort); + + nsresult ProcessImportElement(nsIDOMElement* aElement, + PRUint32 aIndex); + nsresult ProcessTypesElement(nsIDOMElement* aElement); + nsresult ProcessMessageElement(nsIDOMElement* aElement); + nsresult ProcessAbstractPartElement(nsIDOMElement* aElement, + nsWSDLMessage* aMessage); + nsresult ProcessPortTypeElement(nsIDOMElement* aElement); + nsresult ProcessAbstractOperation(nsIDOMElement* aElement, + nsWSDLPort* aPort); + nsresult ProcessOperationComponent(nsIDOMElement* aElement, + nsIWSDLMessage** aMessage); + nsresult ProcessMessageBinding(nsIDOMElement* aElement, + nsIWSDLMessage* aMessage); + nsresult ProcessOperationBinding(nsIDOMElement* aElement, + nsIWSDLPort* aPort); + nsresult ProcessBindingElement(nsIDOMElement* aElement); + nsresult ProcessPortBinding(nsIDOMElement* aElement); + nsresult ProcessServiceElement(nsIDOMElement* aElement); + +protected: + nsCOMPtr mListener; + nsCOMPtr mRequest; + nsCOMPtr mSchemaLoader; + + PRBool mIsSync; + + nsCOMPtr mPort; + nsString mPortName; + nsString mBindingName; + nsString mBindingNamespace; + nsString mAddress; + + nsVoidArray mContextStack; + + nsSupportsHashtable mTypes; + nsSupportsHashtable mMessages; + nsSupportsHashtable mPortTypes; +}; + +#endif // __nsWSDLLoader_h__ diff --git a/mozilla/extensions/webservices/wsdl/src/nsWSDLPrivate.h b/mozilla/extensions/webservices/wsdl/src/nsWSDLPrivate.h index d8d80182b71..d714715bbaf 100644 --- a/mozilla/extensions/webservices/wsdl/src/nsWSDLPrivate.h +++ b/mozilla/extensions/webservices/wsdl/src/nsWSDLPrivate.h @@ -25,138 +25,220 @@ #define __nsWSDLPrivate_h__ #include "nsIWSDL.h" -#include "nsIWSDLLoader.h" +#include "nsIWSDLSOAPBinding.h" // DOM Includes #include "nsIDOMElement.h" +// Schema includes +#include "nsISchema.h" + // XPCOM Includes #include "nsCOMPtr.h" +#include "nsVoidArray.h" #include "nsSupportsArray.h" #include "nsString.h" -class nsWSDLLoader : public nsIWSDLLoader { +#define NS_WSDL_SCHEMA_NAMESPACE "http://www.w3.org/2001/XMLSchema" +#define NS_WSDL_NAMESPACE "http://schemas.xmlsoap.org/wsdl/" +#define NS_WSDL_SOAP_NAMESPACE "http://schemas.xmlsoap.org/wsdl/soap/" + +class nsSOAPPortBinding : public nsISOAPPortBinding { public: - nsWSDLLoader(); - virtual ~nsWSDLLoader(); - + nsSOAPPortBinding(const nsAReadableString& aName); + virtual ~nsSOAPPortBinding(); + NS_DECL_ISUPPORTS - NS_DECL_NSIWSDLLOADER -}; + NS_DECL_NSIWSDLBINDING + NS_DECL_NSISOAPPORTBINDING -class nsWSDLService : public nsIWSDLService { -public: - nsWSDLService(); - virtual ~nsWSDLService(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIWSDLSERVICE - - NS_IMETHOD SetName(const nsAReadableString& aName); NS_IMETHOD SetDocumentationElement(nsIDOMElement* aElement); - NS_IMETHOD AddPort(nsIWSDLPort* aPort); + NS_IMETHOD SetAddress(const nsAReadableString& aAddress); + NS_IMETHOD SetStyle(PRUint16 aStyle); + NS_IMETHOD SetTransport(const nsAReadableString& aTransport); protected: nsString mName; + nsString mAddress; + PRUint16 mStyle; + nsString mTransport; nsCOMPtr mDocumentationElement; - nsSupportsArray mPorts; }; class nsWSDLPort : public nsIWSDLPort { public: - nsWSDLPort(); + nsWSDLPort(const nsAReadableString &aName); virtual ~nsWSDLPort(); NS_DECL_ISUPPORTS NS_DECL_NSIWSDLPORT - NS_IMETHOD SetName(const nsAReadableString& aName); NS_IMETHOD SetDocumentationElement(nsIDOMElement* aElement); - NS_IMETHOD SetBindingInfo(const nsAReadableString& aBindingName, - PRUint16 aStyle, - const nsAReadableString& aTransport); NS_IMETHOD AddOperation(nsIWSDLOperation* aOperation); + NS_IMETHOD SetBinding(nsIWSDLBinding* aBinding); protected: nsString mName; nsCOMPtr mDocumentationElement; - nsString mBindingName; - PRUint16 mStyle; - nsString mTransport; nsSupportsArray mOperations; + nsCOMPtr mBinding; +}; + +class nsSOAPOperationBinding : public nsISOAPOperationBinding { +public: + nsSOAPOperationBinding(); + virtual ~nsSOAPOperationBinding(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIWSDLBINDING + NS_DECL_NSISOAPOPERATIONBINDING + + NS_IMETHOD SetDocumentationElement(nsIDOMElement* aElement); + NS_IMETHOD SetStyle(PRUint16 aStyle); + NS_IMETHOD SetSoapAction(const nsAReadableString& aAction); + +protected: + PRUint16 mStyle; + nsString mSoapAction; + nsCOMPtr mDocumentationElement; }; class nsWSDLOperation : public nsIWSDLOperation { public: - nsWSDLOperation(); + nsWSDLOperation(const nsAReadableString &aName); virtual ~nsWSDLOperation(); NS_DECL_ISUPPORTS NS_DECL_NSIWSDLOPERATION - NS_IMETHOD SetName(const nsAReadableString& aName); NS_IMETHOD SetDocumentationElement(nsIDOMElement* aElement); - NS_IMETHOD SetBindingInfo(PRUint16 aStyle, - const nsAReadableString& aSoapAction); - NS_IMETHOD SetInputMessage(nsIWSDLMessage* aInputMessage); - NS_IMETHOD SetOutputMessage(nsIWSDLMessage* aOutputMessage); - NS_IMETHOD SetFaultMessage(nsIWSDLMessage* aFaultMessage); + NS_IMETHOD SetInput(nsIWSDLMessage* aInputMessage); + NS_IMETHOD SetOutput(nsIWSDLMessage* aOutputMessage); + NS_IMETHOD AddFault(nsIWSDLMessage* aFaultMessage); + NS_IMETHOD AddParameter(const nsAReadableString& aParameter); + NS_IMETHOD SetBinding(nsIWSDLBinding* aBinding); protected: nsString mName; nsCOMPtr mDocumentationElement; - PRUint16 mStyle; - nsString mSoapAction; nsCOMPtr mInputMessage; nsCOMPtr mOutputMessage; - nsCOMPtr mFaultMessage; + nsSupportsArray mFaultMessages; + nsStringArray mParameters; + nsCOMPtr mBinding; }; class nsWSDLMessage : public nsIWSDLMessage { public: - nsWSDLMessage(); + nsWSDLMessage(const nsAReadableString& aName); virtual ~nsWSDLMessage(); NS_DECL_ISUPPORTS NS_DECL_NSIWSDLMESSAGE - NS_IMETHOD SetName(const nsAReadableString& aName); NS_IMETHOD SetDocumentationElement(nsIDOMElement* aElement); - NS_IMETHOD SetBindingInfo(PRUint16 aLocation, PRUint16 aUse, - const nsAReadableString& aEncodingStyle, - const nsAReadableString& aNamespace); NS_IMETHOD AddPart(nsIWSDLPart* aPart); protected: nsString mName; nsCOMPtr mDocumentationElement; + nsSupportsArray mParts; +}; + +class nsSOAPPartBinding : public nsISOAPPartBinding { +public: + nsSOAPPartBinding(PRUint16 aLocation, PRUint16 aUse, + const nsAReadableString& aEncodingStyle, + const nsAReadableString& aNamespace); + virtual ~nsSOAPPartBinding(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIWSDLBINDING + NS_DECL_NSISOAPPARTBINDING + +protected: PRUint16 mLocation; PRUint16 mUse; nsString mEncodingStyle; - nsString mNamespace; - nsSupportsArray mParts; + nsString mNamespace; }; class nsWSDLPart : public nsIWSDLPart { public: - nsWSDLPart(); + nsWSDLPart(const nsAReadableString& aName); virtual ~nsWSDLPart(); NS_DECL_ISUPPORTS NS_DECL_NSIWSDLPART - NS_IMETHOD SetName(const nsAReadableString& aName); NS_IMETHOD SetTypeInfo(const nsAReadableString& aType, const nsAReadableString& aElementName, - nsIDOMElement* aSchema, - nsIDOMElement* aSchemaRoot); + nsISchemaComponent* aSchemaComponent); + NS_IMETHOD SetBinding(nsIWSDLBinding* aBinding); protected: nsString mName; nsString mType; nsString mElementName; - nsCOMPtr mSchema; - nsCOMPtr mSchemaRoot; + nsCOMPtr mSchemaComponent; + nsCOMPtr mBinding; }; + +#define NS_WSDLPORT_CID \ +{ /* c1dfb250-0c19-4339-8211-24eabc0103e5 */ \ + 0xc1dfb250, 0x0c19, 0x4339, \ + {0x82, 0x11, 0x24, 0xea, 0xbc, 0x01, 0x03, 0xe5}} + +#define NS_WSDLPORT_CONTRACTID \ +"@mozilla/xmlextras/wsdl/wsdlport;1" + +#define NS_WSDLOPERATION_CID \ +{ /* cf54bdf5-20de-45ef-b6c8-aa535007549a */ \ + 0xcf54bdf5, 0x20de, 0x45ef, \ + {0xb6, 0xc8, 0xaa, 0x53, 0x50, 0x07, 0x54, 0x9a}} + +#define NS_WSDLOPERATION_CONTRACTID \ +"@mozilla/xmlextras/wsdl/wsdloperation;1" + +#define NS_WSDLMESSAGE_CID \ +{ /* 36b26cab-3eed-4c7c-81ad-94c8b1eb9ebe */ \ + 0x36b26cab, 0x3eed, 0x4c7c, \ + {0x81, 0xad, 0x94, 0xc8, 0xb1, 0xeb, 0x9e, 0xbe}} + +#define NS_WSDLMESSAGE_CONTRACTID \ +"@mozilla/xmlextras/wsdl/wsdlmessage;1" + +#define NS_WSDLPART_CID \ +{ /* 1841ebe8-5bdc-4e79-bcf4-329785318491 */ \ + 0x1841ebe8, 0x5bdc, 0x4e79, \ + {0xbc, 0xf4, 0x32, 0x97, 0x85, 0x31, 0x84, 0x91}} + +#define NS_WSDLPART_CONTRACTID \ +"@mozilla/xmlextras/wsdl/wsdlpart;1" + +#define NS_SOAPPORTBINDING_CID \ +{ /* a9155950-e49d-4123-93b7-e263a3af2b32 */ \ + 0xa9155950, 0xe49d, 0x4123, \ + {0x93, 0xb7, 0xe2, 0x63, 0xa3, 0xaf, 0x2b, 0x32}} + +#define NS_SOAPPORTBINDING_CONTRACTID \ +"@mozilla/xmlextras/wsdl/soapportbinding;1" + +#define NS_SOAPOPERATIONBINDING_CID \ +{ /* f5230937-4af6-43fb-9766-1890896632b2 */ \ + 0xf5230937, 0x4af6, 0x43fb, \ + {0x97, 0x66, 0x18, 0x90, 0x89, 0x66, 0x32, 0xb2}} + +#define NS_SOAPOPERATIONBINDING_CONTRACTID \ +"@mozilla/xmlextras/wsdl/soapoperationbinding;1" + +#define NS_SOAPPARTBINDING_CID \ +{ /* b7698d5c-06cc-45fe-b6bc-88e32a9f970e */ \ + 0xb7698d5c, 0x06cc, 0x45fe, \ + {0xb6, 0xbc, 0x88, 0xe3, 0x2a, 0x9f, 0x97, 0x0e}} + +#define NS_SOAPPARTBINDING_CONTRACTID \ +"@mozilla/xmlextras/wsdl/soappartbinding;1" + #endif // __nsWSDLPrivate_h__ diff --git a/mozilla/extensions/xmlextras/wsdl/public/Makefile.in b/mozilla/extensions/xmlextras/wsdl/public/Makefile.in index c8e15639670..b969da9c214 100644 --- a/mozilla/extensions/xmlextras/wsdl/public/Makefile.in +++ b/mozilla/extensions/xmlextras/wsdl/public/Makefile.in @@ -27,10 +27,12 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk MODULE = xmlextras +XPIDL_MODULE = wsdl XPIDLSRCS = \ - .\nsIWSDL.idl \ - .\nsIWSDLLoader.idl \ + nsIWSDL.idl \ + nsIWSDLSOAPBinding.idl \ + nsIWSDLLoader.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/extensions/xmlextras/wsdl/public/makefile.win b/mozilla/extensions/xmlextras/wsdl/public/makefile.win index 343ffbd3e19..f165a214b3f 100644 --- a/mozilla/extensions/xmlextras/wsdl/public/makefile.win +++ b/mozilla/extensions/xmlextras/wsdl/public/makefile.win @@ -22,9 +22,11 @@ DEPTH=..\..\..\.. XPIDLSRCS = .\nsIWSDL.idl \ + .\nsIWSDLSOAPBinding.idl \ .\nsIWSDLLoader.idl \ $(NULL) MODULE=xmlextras +XPIDL_MODULE=wsdl include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/extensions/xmlextras/wsdl/public/nsIWSDL.idl b/mozilla/extensions/xmlextras/wsdl/public/nsIWSDL.idl index 380e119cd4a..2405760e172 100644 --- a/mozilla/extensions/xmlextras/wsdl/public/nsIWSDL.idl +++ b/mozilla/extensions/xmlextras/wsdl/public/nsIWSDL.idl @@ -22,42 +22,29 @@ */ #include "nsISupports.idl" +#include "nsISchema.idl" %{ C++ #include "nsAWritableString.h" %} -interface nsIWSDLService; +interface nsIWSDLBinding; interface nsIWSDLPort; interface nsIWSDLOperation; interface nsIWSDLMessage; interface nsIWSDLPart; interface nsIDOMElement; -interface nsISchemaComponent; -interface nsISchema; - -[scriptable, uuid(0458dac0-65de-11d5-9b42-00104bdf5339)] -interface nsIWSDLService : nsISupports { - readonly attribute AString name; - readonly attribute nsIDOMElement documentation; - readonly attribute PRUint32 portCount; - nsIWSDLPort getPort(in PRUint32 index); -}; [scriptable, uuid(0458dac1-65de-11d5-9b42-00104bdf5339)] -interface nsIWSDLPort : nsISupports { - const unsigned short STYLE_RPC = 1; - const unsigned short STYLE_DOCUMENT = 2; - +interface nsIWSDLPort : nsISupports { readonly attribute AString name; readonly attribute nsIDOMElement documentation; - readonly attribute AString bindingName; - readonly attribute unsigned short style; - readonly attribute AString transport; + readonly attribute nsIWSDLBinding binding; readonly attribute PRUint32 operationCount; nsIWSDLOperation getOperation(in PRUint32 index); + nsIWSDLOperation getOperationByName(in AString name); }; [scriptable, uuid(0458dac2-65de-11d5-9b42-00104bdf5339)] @@ -65,38 +52,32 @@ interface nsIWSDLOperation : nsISupports { readonly attribute AString name; readonly attribute nsIDOMElement documentation; - readonly attribute unsigned short style; - readonly attribute AString soapAction; + readonly attribute nsIWSDLBinding binding; readonly attribute nsIWSDLMessage input; readonly attribute nsIWSDLMessage output; - readonly attribute nsIWSDLMessage fault; + readonly attribute PRUint32 faultCount; + nsIWSDLMessage getFault(in PRUint32 index); + + readonly attribute PRUint32 parameterCount; + AString getParameter(in PRUint32 index); }; [scriptable, uuid(0458dac3-65de-11d5-9b42-00104bdf5339)] interface nsIWSDLMessage : nsISupports { - const unsigned short LOCATION_SOAP_BODY = 1; - const unsigned short LOCATION_SOAP_HEADER = 2; - const unsigned short LOCATION_SOAP_FAULT = 3; - - const unsigned short USE_LITERAL = 1; - const unsigned short USE_ENCODED = 2; - readonly attribute AString name; readonly attribute nsIDOMElement documentation; - readonly attribute unsigned short location; - readonly attribute unsigned short use; - readonly attribute AString encodingStyle; - readonly attribute AString namespace; - readonly attribute PRUint32 partCount; nsIWSDLPart getPart(in PRUint32 index); + nsIWSDLPart getPartByName(in AString name); }; [scriptable, uuid(0458dac4-65de-11d5-9b42-00104bdf5339)] interface nsIWSDLPart : nsISupports { readonly attribute AString name; + + readonly attribute nsIWSDLBinding binding; readonly attribute AString type; readonly attribute AString elementName; @@ -107,9 +88,11 @@ interface nsIWSDLPart : nsISupports { * elementName attribute is used, it is a nsISchemaElement. */ readonly attribute nsISchemaComponent schemaComponent; - - /** - * The containing schema for the schemaComponent - */ - readonly attribute nsISchema schema; }; + +[scriptable, uuid(0458dac0-65de-11d5-9b42-00104bdf5339)] +interface nsIWSDLBinding : nsISupports { + readonly attribute AString protocol; + readonly attribute nsIDOMElement documentation; +}; + diff --git a/mozilla/extensions/xmlextras/wsdl/public/nsIWSDL2.idl b/mozilla/extensions/xmlextras/wsdl/public/nsIWSDL2.idl new file mode 100644 index 00000000000..d79880c3cb9 --- /dev/null +++ b/mozilla/extensions/xmlextras/wsdl/public/nsIWSDL2.idl @@ -0,0 +1,171 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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. + * + * The Initial Developer of the Original Code is Netscape + * Communications. Portions created by Netscape Communications are + * Copyright (C) 2001 by Netscape Communications. All + * Rights Reserved. + * + * Contributor(s): + * Vidur Apparao (original author) + */ + +#include "nsISupports.idl" + +/* + * XXX Currently not in use, but a better representation of a WSDL + * definition. In this case, the binding refers to the abstract + * construct for each of port, operation, message and part, not the + * other way. The SOAP-specific binding data is retrieved using a + * set of interfaces derived from the base binding interfaces. + * + * This scheme would probably yield a more efficient and reusable + * internal structure, but is more complex to use relative to the one + * where the abstract constructs refer to the corresponding binding + * information. + */ + +%{ C++ +#include "nsAWritableString.h" +%} + +interface nsIWSDLPort; +interface nsIWSDLOperation; +interface nsIWSDLMessage; +interface nsIWSDLPart; +interface nsIDOMElement; +interface nsISchemaComponent; +interface nsISchema; + +[scriptable, uuid(0458dac1-65de-11d5-9b42-00104bdf5339)] +interface nsIWSDLPortType : nsISupports { + readonly attribute AString name; + readonly attribute nsIDOMElement documentation; + + readonly attribute PRUint32 operationCount; + nsIWSDLOperation getOperation(in PRUint32 index); + nsIWSDLOperation getOperationByName(in AString name); +}; + +[scriptable, uuid(0458daca-65de-11d5-9b42-00104bdf5339)] +interface nsIWSDLPortBinding : nsISupports { + readonly attribute AString name; + readonly attribute AString protocol; + readonly attribute nsIDOMElement documentation; + + readonly attribute nsIWSDLPortType; + readonly attribute PRUint32 operationCount; + nsIWSDLOperationBinding getOperation(in PRUint32 index); +}; + +[scriptable, uuid(0458dac2-65de-11d5-9b42-00104bdf5339)] +interface nsIWSDLOperation : nsISupports { + readonly attribute AString name; + readonly attribute nsIDOMElement documentation; + + readonly attribute nsIWSDLMessage input; + readonly attribute nsIWSDLMessage output; + readonly attribute PRUint32 faultCount; + nsIWSDLMessage getFault(in PRUint32 index); + + readonly attribute PRUint32 parameterCount; + AString getParameter(in PRUint32 index); +}; + +[scriptable, uuid(0458dacb-65de-11d5-9b42-00104bdf5339)] +interface nsIWSDLOperationBinding : nsISupports { + readonly attribute AString protocol; + readonly attribute nsIDOMElement documentation; + + readonly attribute nsIWSDLOperation; + + readonly attribute nsIWSDLMessageBinding input; + readonly attribute nsIWSDLMessageBinding output; + readonly attribute PRUint32 faultCount; + nsIWSDLMessageBinding getFault(in PRUint32 index); +}; + +[scriptable, uuid(0458dac3-65de-11d5-9b42-00104bdf5339)] +interface nsIWSDLMessage : nsISupports { + readonly attribute AString name; + readonly attribute nsIDOMElement documentation; + + readonly attribute PRUint32 partCount; + nsIWSDLPart getPart(in PRUint32 index); + nsIWSDLPart getPartByName(in AString name); +}; + +[scriptable, uuid(0458dacc-65de-11d5-9b42-00104bdf5339)] +interface nsIWSDLMessageBinding : nsISupports { + readonly attribute AString protocol; + readonly attribute nsIDOMElement documentation; + + readonly attribute nsIWSDLMessage; + + readonly attribute PRUint32 partCount; + nsIWSDLPartBinding getPart(in PRUint32 index); +}; + +[scriptable, uuid(0458dac4-65de-11d5-9b42-00104bdf5339)] +interface nsIWSDLPart : nsISupports { + readonly attribute AString name; + + readonly attribute AString type; + readonly attribute AString elementName; + + /** + * The schema component that corresponds to this part. If the + * type attribute is used, this is a nsISchemaType. If the + * elementName attribute is used, it is a nsISchemaElement. + */ + readonly attribute nsISchemaComponent schemaComponent; +}; + +[scriptable, uuid(0458dacd-65de-11d5-9b42-00104bdf5339)] +interface nsIWSDLPartBinding : nsISupports { + readonly attribute AString protocol; + + readonly attribute nsIWSDLPart; +}; + +[scriptable, uuid(0458dac7-65de-11d5-9b42-00104bdf5339)] +interface nsISOAPPortBinding : nsIWSDLPortBinding { + const unsigned short STYLE_RPC = 1; + const unsigned short STYLE_DOCUMENT = 2; + + readonly attribute AString address; + readonly attribute unsigned short style; + readonly attribute AString transport; +}; + +[scriptable, uuid(0458dac8-65de-11d5-9b42-00104bdf5339)] +interface nsISOAPOperationBinding : nsIWSDLOperationBinding { + readonly attribute unsigned short style; + readonly attribute AString soapAction; +}; + +[scriptable, uuid(0458dac9-65de-11d5-9b42-00104bdf5339)] +interface nsISOAPPartBinding : nsIWSDLPartBinding { + const unsigned short LOCATION_BODY = 1; + const unsigned short LOCATION_HEADER = 2; + const unsigned short LOCATION_FAULT = 3; + + const unsigned short USE_LITERAL = 1; + const unsigned short USE_ENCODED = 2; + + readonly attribute unsigned short location; + readonly attribute unsigned short use; + readonly attribute AString encodingStyle; + readonly attribute AString namespace; +}; diff --git a/mozilla/extensions/xmlextras/wsdl/public/nsIWSDLLoader.idl b/mozilla/extensions/xmlextras/wsdl/public/nsIWSDLLoader.idl index 99f3d6db796..32af9bbd4c6 100644 --- a/mozilla/extensions/xmlextras/wsdl/public/nsIWSDLLoader.idl +++ b/mozilla/extensions/xmlextras/wsdl/public/nsIWSDLLoader.idl @@ -27,21 +27,37 @@ #include "nsAWritableString.h" %} -interface nsIWSDLService; -interface nsIURI; -interface nsIWSDLLoaderListener; +interface nsIWSDLPort; +interface nsIWSDLLoadListener; [scriptable, uuid(0458dac5-65de-11d5-9b42-00104bdf5339)] interface nsIWSDLLoader : nsISupports { - nsIWSDLService load(in nsIURI wsdlURI); - void loadAsync(in nsIURI wsdlURI, in nsIWSDLLoaderListener listener); - nsISupports createServiceProxy(in nsIWSDLService service, - in AString nameSpace); + nsIWSDLPort load(in AString wsdlURI, in AString portName); + void loadAsync(in AString wsdlURI, in AString portName, + in nsIWSDLLoadListener listener); + nsISupports createPortProxy(in nsIWSDLPort service, + in AString nameSpace); }; -[scriptable, uuid(0458dac6-65de-11d5-9b42-00104bdf5339)] -interface nsIWSDLLoaderListener : nsISupports { +[scriptable, function, uuid(0458dac6-65de-11d5-9b42-00104bdf5339)] +interface nsIWSDLLoadListener : nsISupports { + void onLoad(in nsIWSDLPort service); void onError(in PRInt32 status, in AString statusMessage); - void onComplete(in nsIWSDLService service); }; + +%{ C++ +#define NS_WSDLLOADER_CID \ +{ /* 0a5af577-a61e-4492-ba0e-dd3c7b657e18 */ \ + 0x0a5af577, 0xa61e, 0x4492, \ + {0xba, 0x0e, 0xdd, 0x3c, 0x7b, 0x65, 0x7e, 0x18}} + +#define NS_WSDLLOADER_CONTRACTID "@mozilla.org/xmlextras/wsdl/wsdlloader;1" + +#define NS_ERROR_WSDL_NOT_WSDL_ELEMENT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 1) +#define NS_ERROR_WSDL_SCHEMA_PROCESSING_ERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 2) +#define NS_ERROR_WSDL_BINDING_NOT_FOUND NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 3) +#define NS_ERROR_WSDL_UNKNOWN_SCHEMA_COMPONENT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 4) +#define NS_ERROR_WSDL_UNKNOWN_WSDL_COMPONENT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 5) +#define NS_ERROR_WSDL_LOADING_ERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 6) +%} diff --git a/mozilla/extensions/xmlextras/wsdl/public/nsIWSDLSOAPBinding.idl b/mozilla/extensions/xmlextras/wsdl/public/nsIWSDLSOAPBinding.idl new file mode 100644 index 00000000000..71ee6aae6b1 --- /dev/null +++ b/mozilla/extensions/xmlextras/wsdl/public/nsIWSDLSOAPBinding.idl @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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. + * + * The Initial Developer of the Original Code is Netscape + * Communications. Portions created by Netscape Communications are + * Copyright (C) 2001 by Netscape Communications. All + * Rights Reserved. + * + * Contributor(s): + * Vidur Apparao (original author) + */ + +#include "nsISupports.idl" +#include "nsIWSDL.idl" + +%{ C++ +#include "nsAWritableString.h" +%} + +[scriptable, uuid(0458dac7-65de-11d5-9b42-00104bdf5339)] +interface nsISOAPPortBinding : nsIWSDLBinding { + const unsigned short STYLE_RPC = 1; + const unsigned short STYLE_DOCUMENT = 2; + + readonly attribute AString name; + readonly attribute AString address; + readonly attribute unsigned short style; + readonly attribute AString transport; +}; + +[scriptable, uuid(0458dac8-65de-11d5-9b42-00104bdf5339)] +interface nsISOAPOperationBinding : nsIWSDLBinding { + readonly attribute unsigned short style; + readonly attribute AString soapAction; +}; + +[scriptable, uuid(0458dac9-65de-11d5-9b42-00104bdf5339)] +interface nsISOAPPartBinding : nsIWSDLBinding { + const unsigned short LOCATION_BODY = 1; + const unsigned short LOCATION_HEADER = 2; + const unsigned short LOCATION_FAULT = 3; + + const unsigned short USE_LITERAL = 1; + const unsigned short USE_ENCODED = 2; + + readonly attribute unsigned short location; + readonly attribute unsigned short use; + readonly attribute AString encodingStyle; + readonly attribute AString namespace; +}; diff --git a/mozilla/extensions/xmlextras/wsdl/src/Makefile.in b/mozilla/extensions/xmlextras/wsdl/src/Makefile.in index 62935fdc744..858005cc36a 100644 --- a/mozilla/extensions/xmlextras/wsdl/src/Makefile.in +++ b/mozilla/extensions/xmlextras/wsdl/src/Makefile.in @@ -31,7 +31,8 @@ LIBRARY_NAME = xmlextraswsdl_s REQUIRES = xpcom string dom caps necko xpconnect CPPSRCS = \ - nsWSDLLoader.cpp \ + nsWSDLLoader.cpp \ + nsWSDLDefinitions.cpp \ $(NULL) # we don't want the shared lib, but we want to force the creation of a @@ -39,3 +40,7 @@ CPPSRCS = \ FORCE_STATIC_LIB = 1 include $(topsrcdir)/config/rules.mk + +INCLUDES += \ + -I$(srcdir)/../../schema/src \ + $(NULL) diff --git a/mozilla/extensions/xmlextras/wsdl/src/makefile.win b/mozilla/extensions/xmlextras/wsdl/src/makefile.win index bfa6a0ab141..af877e50001 100644 --- a/mozilla/extensions/xmlextras/wsdl/src/makefile.win +++ b/mozilla/extensions/xmlextras/wsdl/src/makefile.win @@ -28,17 +28,19 @@ DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN CPPSRCS= \ nsWSDLLoader.cpp \ + nsWSDLDefinitions.cpp \ $(NULL) CPP_OBJS= \ .\$(OBJDIR)\nsWSDLLoader.obj \ + .\$(OBJDIR)\nsWSDLDefinitions.obj \ $(NULL) EXPORTS = \ $(NULL) LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\js \ - -I$(PUBLIC)\dom -I$(PUBLIC)\uconv + -I$(PUBLIC)\dom -I$(PUBLIC)\uconv -I..\..\schema\src LCFLAGS = \ $(LCFLAGS) \ diff --git a/mozilla/extensions/xmlextras/wsdl/src/nsWSDLDefinitions.cpp b/mozilla/extensions/xmlextras/wsdl/src/nsWSDLDefinitions.cpp new file mode 100644 index 00000000000..be095bd5b98 --- /dev/null +++ b/mozilla/extensions/xmlextras/wsdl/src/nsWSDLDefinitions.cpp @@ -0,0 +1,785 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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. + * + * The Initial Developer of the Original Code is Netscape + * Communications. Portions created by Netscape Communications are + * Copyright (C) 2001 by Netscape Communications. All + * Rights Reserved. + * + * Contributor(s): + * Vidur Apparao (original author) + */ + +#include "nsWSDLPrivate.h" + +//////////////////////////////////////////////////////////// +// +// nsWSDLPort implementation +// +//////////////////////////////////////////////////////////// +nsWSDLPort::nsWSDLPort(const nsAReadableString& aName) + : mName(aName) +{ + NS_INIT_ISUPPORTS(); +} + +nsWSDLPort::~nsWSDLPort() +{ +} + +NS_IMPL_ISUPPORTS1_CI(nsWSDLPort, nsIWSDLPort) + +/* readonly attribute AString name; */ +NS_IMETHODIMP +nsWSDLPort::GetName(nsAWritableString & aName) +{ + aName.Assign(mName); + + return NS_OK; +} + +/* readonly attribute nsIDOMElement documentation; */ +NS_IMETHODIMP +nsWSDLPort::GetDocumentation(nsIDOMElement * *aDocumentation) +{ + NS_ENSURE_ARG_POINTER(aDocumentation); + + *aDocumentation = mDocumentationElement; + NS_IF_ADDREF(*aDocumentation); + + return NS_OK; +} + +/* readonly attribute PRUint32 operationCount; */ +NS_IMETHODIMP +nsWSDLPort::GetOperationCount(PRUint32 *aOperationCount) +{ + NS_ENSURE_ARG_POINTER(aOperationCount); + + return mOperations.Count(aOperationCount); +} + +/* nsIWSDLOperation getOperation (in PRUint32 index); */ +NS_IMETHODIMP +nsWSDLPort::GetOperation(PRUint32 index, nsIWSDLOperation **_retval) +{ + NS_ENSURE_ARG_POINTER(_retval); + + return mOperations.QueryElementAt(index, NS_GET_IID(nsIWSDLOperation), + (void**)_retval); +} + +/* nsIWSDLOperation getOperationByName(in AString name); */ +NS_IMETHODIMP +nsWSDLPort::GetOperationByName(const nsAReadableString& aName, + nsIWSDLOperation** aOperation) +{ + nsresult rv; + + *aOperation = nsnull; + + // XXX Do a linear search for now. If more efficiency is needed + // we can store the opeartions in a hash as well. + PRUint32 index, count; + mOperations.Count(&count); + + for (index = 0; index < count; index++) { + nsCOMPtr operation; + + rv = mOperations.QueryElementAt(index, NS_GET_IID(nsIWSDLOperation), + getter_AddRefs(operation)); + if (NS_SUCCEEDED(rv)) { + nsAutoString name; + operation->GetName(name); + + if (name.Equals(aName)) { + *aOperation = operation; + NS_ADDREF(*aOperation); + break; + } + } + } + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLPort::GetBinding(nsIWSDLBinding** aBinding) +{ + NS_ENSURE_ARG_POINTER(aBinding); + + *aBinding = mBinding; + NS_IF_ADDREF(*aBinding); + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLPort::SetDocumentationElement(nsIDOMElement* aElement) +{ + mDocumentationElement = aElement; + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLPort::AddOperation(nsIWSDLOperation* aOperation) +{ + NS_ENSURE_ARG(aOperation); + + return mOperations.AppendElement(aOperation); +} + +NS_IMETHODIMP +nsWSDLPort::SetBinding(nsIWSDLBinding* aBinding) +{ + mBinding = aBinding; + + return NS_OK; +} + +//////////////////////////////////////////////////////////// +// +// nsSOAPPortBinding implementation +// +//////////////////////////////////////////////////////////// +nsSOAPPortBinding::nsSOAPPortBinding(const nsAReadableString& aName) + : mName(aName), mStyle(STYLE_RPC) +{ + NS_INIT_ISUPPORTS(); +} + +nsSOAPPortBinding::~nsSOAPPortBinding() +{ +} + +NS_IMPL_ISUPPORTS2_CI(nsSOAPPortBinding, + nsIWSDLBinding, + nsISOAPPortBinding) + +/* readonly attribute AString protocol; */ +NS_IMETHODIMP +nsSOAPPortBinding::GetProtocol(nsAWritableString& aProtocol) +{ + aProtocol.Assign(NS_LITERAL_STRING("soap")); + + return NS_OK; +} + +/* readonly attribute nsIDOMElement documentation; */ +NS_IMETHODIMP +nsSOAPPortBinding::GetDocumentation(nsIDOMElement * *aDocumentation) +{ + NS_ENSURE_ARG_POINTER(aDocumentation); + + *aDocumentation = mDocumentationElement; + NS_IF_ADDREF(*aDocumentation); + + return NS_OK; +} + +/* readonly attribute AString bindingName; */ +NS_IMETHODIMP +nsSOAPPortBinding::GetName(nsAWritableString & aBindingName) +{ + aBindingName.Assign(mName); + + return NS_OK; +} + +/* readonly attribute AString address; */ +NS_IMETHODIMP +nsSOAPPortBinding::GetAddress(nsAWritableString & aAddress) +{ + aAddress.Assign(mAddress); + + return NS_OK; +} + +/* readonly attribute unsigned short style; */ +NS_IMETHODIMP +nsSOAPPortBinding::GetStyle(PRUint16 *aStyle) +{ + NS_ENSURE_ARG_POINTER(aStyle); + + *aStyle = mStyle; + + return NS_OK; +} + +/* readonly attribute AString transport; */ +NS_IMETHODIMP +nsSOAPPortBinding::GetTransport(nsAWritableString & aTransport) +{ + aTransport.Assign(mTransport); + + return NS_OK; +} + + +NS_IMETHODIMP +nsSOAPPortBinding::SetDocumentationElement(nsIDOMElement* aElement) +{ + mDocumentationElement = aElement; + + return NS_OK; +} + +NS_IMETHODIMP +nsSOAPPortBinding::SetAddress(const nsAReadableString& aAddress) +{ + mAddress.Assign(aAddress); + + return NS_OK; +} + +NS_IMETHODIMP +nsSOAPPortBinding::SetStyle(PRUint16 aStyle) +{ + mStyle = aStyle; + + return NS_OK; +} + +NS_IMETHODIMP +nsSOAPPortBinding::SetTransport(const nsAReadableString& aTransport) +{ + mTransport.Assign(aTransport); + + return NS_OK; +} + +//////////////////////////////////////////////////////////// +// +// nsWSDLOperation implementation +// +//////////////////////////////////////////////////////////// +nsWSDLOperation::nsWSDLOperation(const nsAReadableString &aName) + : mName(aName) +{ + NS_INIT_ISUPPORTS(); +} + +nsWSDLOperation::~nsWSDLOperation() +{ +} + +NS_IMPL_ISUPPORTS1_CI(nsWSDLOperation, nsIWSDLOperation) + +/* readonly attribute AString name; */ +NS_IMETHODIMP +nsWSDLOperation::GetName(nsAWritableString & aName) +{ + aName.Assign(mName); + + return NS_OK; +} + +/* readonly attribute nsIDOMElement documentation; */ +NS_IMETHODIMP +nsWSDLOperation::GetDocumentation(nsIDOMElement * *aDocumentation) +{ + NS_ENSURE_ARG_POINTER(aDocumentation); + + *aDocumentation = mDocumentationElement; + NS_IF_ADDREF(*aDocumentation); + + return NS_OK; +} + +/* readonly attribute nsIWSDLMessage input; */ +NS_IMETHODIMP +nsWSDLOperation::GetInput(nsIWSDLMessage * *aInput) +{ + NS_ENSURE_ARG_POINTER(aInput); + + *aInput = mInputMessage; + NS_IF_ADDREF(*aInput); + + return NS_OK; +} + +/* readonly attribute nsIWSDLMessage output; */ +NS_IMETHODIMP +nsWSDLOperation::GetOutput(nsIWSDLMessage * *aOutput) +{ + NS_ENSURE_ARG_POINTER(aOutput); + + *aOutput = mOutputMessage; + NS_IF_ADDREF(*aOutput); + + return NS_OK; +} + +/* readonly attribute PRUint32 faultCount; */ +NS_IMETHODIMP +nsWSDLOperation::GetFaultCount(PRUint32* aCount) +{ + NS_ENSURE_ARG_POINTER(aCount); + + return mFaultMessages.Count(aCount); +} + +/* nsIWSDLMessage getFault(in PRUint32 index); */ +NS_IMETHODIMP +nsWSDLOperation::GetFault(PRUint32 aIndex, nsIWSDLMessage * *aFault) +{ + NS_ENSURE_ARG_POINTER(aFault); + + return mFaultMessages.QueryElementAt(aIndex, NS_GET_IID(nsIWSDLMessage), + (void**)aFault); +} + +NS_IMETHODIMP +nsWSDLOperation::GetBinding(nsIWSDLBinding** aBinding) +{ + NS_ENSURE_ARG_POINTER(aBinding); + + *aBinding = mBinding; + NS_IF_ADDREF(*aBinding); + + return NS_OK; +} + +/* readonly attribute PRUint32 parameterCount; */ +NS_IMETHODIMP +nsWSDLOperation::GetParameterCount(PRUint32 *aParameterCount) +{ + NS_ENSURE_ARG_POINTER(aParameterCount); + + *aParameterCount = (PRUint32)mParameters.Count(); + + return NS_OK; +} + +/* AString getParameter (in PRUint32 index); */ +NS_IMETHODIMP +nsWSDLOperation::GetParameter(PRUint32 index, nsAWritableString & _retval) +{ + nsString* str = mParameters.StringAt((PRInt32)index); + if (!str) { + return NS_ERROR_FAILURE; + } + _retval.Assign(*str); + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLOperation::SetDocumentationElement(nsIDOMElement* aElement) +{ + mDocumentationElement = aElement; + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLOperation::SetInput(nsIWSDLMessage* aInputMessage) +{ + mInputMessage = aInputMessage; + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLOperation::SetOutput(nsIWSDLMessage* aOutputMessage) +{ + mOutputMessage = aOutputMessage; + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLOperation::AddFault(nsIWSDLMessage* aFaultMessage) +{ + NS_ENSURE_ARG(aFaultMessage); + + return mFaultMessages.AppendElement(aFaultMessage); +} + +NS_IMETHODIMP +nsWSDLOperation::SetBinding(nsIWSDLBinding* aBinding) +{ + mBinding = aBinding; + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLOperation::AddParameter(const nsAReadableString& aParameter) +{ + mParameters.AppendString(aParameter); + + return NS_OK; +} + +//////////////////////////////////////////////////////////// +// +// nsSOAPOperationBinding implementation +// +//////////////////////////////////////////////////////////// +nsSOAPOperationBinding::nsSOAPOperationBinding() + : mStyle(nsISOAPPortBinding::STYLE_RPC) +{ + NS_INIT_ISUPPORTS(); +} + +nsSOAPOperationBinding::~nsSOAPOperationBinding() +{ +} + +NS_IMPL_ISUPPORTS2_CI(nsSOAPOperationBinding, + nsIWSDLBinding, + nsISOAPOperationBinding) + +/* readonly attribute AString protocol; */ +NS_IMETHODIMP +nsSOAPOperationBinding::GetProtocol(nsAWritableString& aProtocol) +{ + aProtocol.Assign(NS_LITERAL_STRING("soap")); + + return NS_OK; +} + +/* readonly attribute nsIDOMElement documentation; */ +NS_IMETHODIMP +nsSOAPOperationBinding::GetDocumentation(nsIDOMElement * *aDocumentation) +{ + NS_ENSURE_ARG_POINTER(aDocumentation); + + *aDocumentation = mDocumentationElement; + NS_IF_ADDREF(*aDocumentation); + + return NS_OK; +} + +/* readonly attribute unsigned short style; */ +NS_IMETHODIMP +nsSOAPOperationBinding::GetStyle(PRUint16 *aStyle) +{ + NS_ENSURE_ARG_POINTER(aStyle); + + *aStyle = mStyle; + + return NS_OK; +} + +/* readonly attribute AString soapAction; */ +NS_IMETHODIMP +nsSOAPOperationBinding::GetSoapAction(nsAWritableString & aSoapAction) +{ + aSoapAction.Assign(mSoapAction); + + return NS_OK; +} + +NS_IMETHODIMP +nsSOAPOperationBinding::SetDocumentationElement(nsIDOMElement* aElement) +{ + mDocumentationElement = aElement; + + return NS_OK; +} + +NS_IMETHODIMP +nsSOAPOperationBinding::SetStyle(PRUint16 aStyle) +{ + mStyle = aStyle; + + return NS_OK; +} + +NS_IMETHODIMP +nsSOAPOperationBinding::SetSoapAction(const nsAReadableString& aAction) +{ + mSoapAction.Assign(aAction); + + return NS_OK; +} + +//////////////////////////////////////////////////////////// +// +// nsWSDLMessage implementation +// +//////////////////////////////////////////////////////////// +nsWSDLMessage::nsWSDLMessage(const nsAReadableString& aName) + : mName(aName) +{ + NS_INIT_ISUPPORTS(); +} + +nsWSDLMessage::~nsWSDLMessage() +{ +} + +NS_IMPL_ISUPPORTS1_CI(nsWSDLMessage, nsIWSDLMessage) + +/* readonly attribute AString name; */ +NS_IMETHODIMP +nsWSDLMessage::GetName(nsAWritableString & aName) +{ + aName.Assign(mName); + + return NS_OK; +} + +/* readonly attribute nsIDOMElement documentation; */ +NS_IMETHODIMP +nsWSDLMessage::GetDocumentation(nsIDOMElement * *aDocumentation) +{ + NS_ENSURE_ARG_POINTER(aDocumentation); + + *aDocumentation = mDocumentationElement; + NS_IF_ADDREF(*aDocumentation); + + return NS_OK; +} + +/* readonly attribute PRUint32 partCount; */ +NS_IMETHODIMP +nsWSDLMessage::GetPartCount(PRUint32 *aPartCount) +{ + NS_ENSURE_ARG_POINTER(aPartCount); + + return mParts.Count(aPartCount); +} + +/* nsIWSDLPart getPart (in PRUint32 index); */ +NS_IMETHODIMP +nsWSDLMessage::GetPart(PRUint32 index, nsIWSDLPart **_retval) +{ + NS_ENSURE_ARG_POINTER(_retval); + + return mParts.QueryElementAt(index, NS_GET_IID(nsIWSDLPart), + (void**)_retval); + +} + +/* nsIWSDLPart getPartByName(in AString name); */ +NS_IMETHODIMP +nsWSDLMessage::GetPartByName(const nsAReadableString& aName, + nsIWSDLPart** aPart) +{ + nsresult rv; + + *aPart = nsnull; + // XXX Do a linear search for now. If more efficiency is needed + // we can store the part in a hash as well. + PRUint32 index, count; + mParts.Count(&count); + + for (index = 0; index < count; index++) { + nsCOMPtr part; + + rv = mParts.QueryElementAt(index, NS_GET_IID(nsIWSDLPart), + getter_AddRefs(part)); + if (NS_SUCCEEDED(rv)) { + nsAutoString name; + part->GetName(name); + + if (name.Equals(aName)) { + *aPart = part; + NS_ADDREF(*aPart); + break; + } + } + } + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLMessage::SetDocumentationElement(nsIDOMElement* aElement) +{ + mDocumentationElement = aElement; + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLMessage::AddPart(nsIWSDLPart* aPart) +{ + NS_ENSURE_ARG(aPart); + + return mParts.AppendElement(aPart); +} + +//////////////////////////////////////////////////////////// +// +// nsWSDLPart implementation +// +//////////////////////////////////////////////////////////// +nsWSDLPart::nsWSDLPart(const nsAReadableString& aName) + : mName(aName) +{ + NS_INIT_ISUPPORTS(); +} + +nsWSDLPart::~nsWSDLPart() +{ +} + +NS_IMPL_ISUPPORTS1_CI(nsWSDLPart, nsIWSDLPart) + +/* readonly attribute AString name; */ +NS_IMETHODIMP +nsWSDLPart::GetName(nsAWritableString & aName) +{ + aName.Assign(mName); + + return NS_OK; +} + +/* readonly attribute AString type; */ +NS_IMETHODIMP +nsWSDLPart::GetType(nsAWritableString & aType) +{ + aType.Assign(mType); + + return NS_OK; +} + +/* readonly attribute AString elementName; */ +NS_IMETHODIMP +nsWSDLPart::GetElementName(nsAWritableString & aElementName) +{ + aElementName.Assign(mElementName); + + return NS_OK; +} + +/* readonly attribute nsISchemaComponent schemaComponent; */ +NS_IMETHODIMP +nsWSDLPart::GetSchemaComponent(nsISchemaComponent * *aSchemaComponent) +{ + NS_ENSURE_ARG_POINTER(aSchemaComponent); + + *aSchemaComponent = mSchemaComponent; + NS_IF_ADDREF(*aSchemaComponent); + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLPart::GetBinding(nsIWSDLBinding** aBinding) +{ + NS_ENSURE_ARG_POINTER(aBinding); + + *aBinding = mBinding; + NS_IF_ADDREF(*aBinding); + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLPart::SetTypeInfo(const nsAReadableString& aType, + const nsAReadableString& aElementName, + nsISchemaComponent* aSchemaComponent) +{ + mType.Assign(aType); + mElementName.Assign(aElementName); + mSchemaComponent = aSchemaComponent; + + return NS_OK; +} + +NS_IMETHODIMP +nsWSDLPart::SetBinding(nsIWSDLBinding* aBinding) +{ + mBinding = aBinding; + + return NS_OK; +} + +//////////////////////////////////////////////////////////// +// +// nsSOAPPartBinding implementation +// +//////////////////////////////////////////////////////////// +nsSOAPPartBinding::nsSOAPPartBinding(PRUint16 aLocation, PRUint16 aUse, + const nsAReadableString& aEncodingStyle, + const nsAReadableString& aNamespace) + : mLocation(aLocation), mUse(aUse), + mEncodingStyle(aEncodingStyle), mNamespace(aNamespace) +{ + NS_INIT_ISUPPORTS(); +} + +nsSOAPPartBinding::~nsSOAPPartBinding() +{ +} + +NS_IMPL_ISUPPORTS2_CI(nsSOAPPartBinding, + nsIWSDLBinding, + nsISOAPPartBinding) + +/* readonly attribute AString protocol; */ +NS_IMETHODIMP +nsSOAPPartBinding::GetProtocol(nsAWritableString& aProtocol) +{ + aProtocol.Assign(NS_LITERAL_STRING("soap")); + + return NS_OK; +} + +/* readonly attribute nsIDOMElement documentation; */ +NS_IMETHODIMP +nsSOAPPartBinding::GetDocumentation(nsIDOMElement * *aDocumentation) +{ + NS_ENSURE_ARG_POINTER(aDocumentation); + + *aDocumentation = nsnull; + + return NS_OK; +} + +/* readonly attribute unsigned short location; */ +NS_IMETHODIMP +nsSOAPPartBinding::GetLocation(PRUint16 *aLocation) +{ + NS_ENSURE_ARG_POINTER(aLocation); + + *aLocation = mLocation; + + return NS_OK; +} + +/* readonly attribute unsigned short use; */ +NS_IMETHODIMP +nsSOAPPartBinding::GetUse(PRUint16 *aUse) +{ + NS_ENSURE_ARG_POINTER(aUse); + + *aUse = mUse; + + return NS_OK; +} + +/* readonly attribute AString encodingStyle; */ +NS_IMETHODIMP +nsSOAPPartBinding::GetEncodingStyle(nsAWritableString & aEncodingStyle) +{ + aEncodingStyle.Assign(mEncodingStyle); + + return NS_OK; +} + +/* readonly attribute AString namespace; */ +NS_IMETHODIMP +nsSOAPPartBinding::GetNamespace(nsAWritableString & aNamespace) +{ + aNamespace.Assign(mNamespace); + + return NS_OK; +} diff --git a/mozilla/extensions/xmlextras/wsdl/src/nsWSDLLoader.cpp b/mozilla/extensions/xmlextras/wsdl/src/nsWSDLLoader.cpp index 232f3990246..013be15be4b 100644 --- a/mozilla/extensions/xmlextras/wsdl/src/nsWSDLLoader.cpp +++ b/mozilla/extensions/xmlextras/wsdl/src/nsWSDLLoader.cpp @@ -21,40 +21,1460 @@ * Vidur Apparao (original author) */ -#include "nsWSDLPrivate.h" -#include "nsIXMLHttpRequest.h" +#include "nsWSDLLoader.h" + +// loading includes +#include "nsIDOMEvent.h" +#include "nsIDOMEventTarget.h" +#include "nsNetUtil.h" + +// content includes +#include "nsIContent.h" +#include "nsINameSpaceManager.h" +#include "nsINodeInfo.h" +#include "nsIDOMDocument.h" + +// string includes +#include "nsReadableUtils.h" + +// XPConnect includes +#include "nsIXPConnect.h" +#include "nsIScriptSecurityManager.h" +#include "nsICodebasePrincipal.h" + +// XPCOM includes +#include "nsIServiceManager.h" +#include "nsIComponentManager.h" + +//////////////////////////////////////////////////////////// +// +// nsWSDLAtoms implementation +// +//////////////////////////////////////////////////////////// + +// Statics +nsIAtom* nsWSDLAtoms::sDefinitions_atom = nsnull; +nsIAtom* nsWSDLAtoms::sImport_atom = nsnull; +nsIAtom* nsWSDLAtoms::sTypes_atom = nsnull; +nsIAtom* nsWSDLAtoms::sMessage_atom = nsnull; +nsIAtom* nsWSDLAtoms::sPortType_atom = nsnull; +nsIAtom* nsWSDLAtoms::sBinding_atom = nsnull; +nsIAtom* nsWSDLAtoms::sService_atom = nsnull; +nsIAtom* nsWSDLAtoms::sPort_atom = nsnull; +nsIAtom* nsWSDLAtoms::sOperation_atom = nsnull; +nsIAtom* nsWSDLAtoms::sPart_atom = nsnull; +nsIAtom* nsWSDLAtoms::sDocumentation_atom = nsnull; +nsIAtom* nsWSDLAtoms::sInput_atom = nsnull; +nsIAtom* nsWSDLAtoms::sOutput_atom = nsnull; +nsIAtom* nsWSDLAtoms::sFault_atom = nsnull; + +nsIAtom* nsWSDLAtoms::sBody_atom = nsnull; +nsIAtom* nsWSDLAtoms::sHeader_atom = nsnull; +nsIAtom* nsWSDLAtoms::sHeaderFault_atom = nsnull; +nsIAtom* nsWSDLAtoms::sAddress_atom = nsnull; + +void +nsWSDLAtoms::CreateWSDLAtoms() +{ + sDefinitions_atom = NS_NewAtom("definitions"); + sImport_atom = NS_NewAtom("import"); + sTypes_atom = NS_NewAtom("types"); + sMessage_atom = NS_NewAtom("message"); + sPortType_atom = NS_NewAtom("portType"); + sBinding_atom = NS_NewAtom("binding"); + sService_atom = NS_NewAtom("service"); + sPort_atom = NS_NewAtom("port"); + sOperation_atom = NS_NewAtom("operation"); + sPart_atom = NS_NewAtom("part"); + sDocumentation_atom = NS_NewAtom("documentation"); + sInput_atom = NS_NewAtom("input"); + sOutput_atom = NS_NewAtom("output"); + sFault_atom = NS_NewAtom("fault"); + + sBody_atom = NS_NewAtom("body"); + sHeader_atom = NS_NewAtom("header"); + sHeaderFault_atom = NS_NewAtom("headerFault"); + sAddress_atom = NS_NewAtom("address"); +} + +void +nsWSDLAtoms::DestroyWSDLAtoms() +{ + if (sDefinitions_atom) { + NS_RELEASE(sDefinitions_atom); + NS_RELEASE(sImport_atom); + NS_RELEASE(sTypes_atom); + NS_RELEASE(sMessage_atom); + NS_RELEASE(sPortType_atom); + NS_RELEASE(sBinding_atom); + NS_RELEASE(sService_atom); + NS_RELEASE(sPort_atom); + NS_RELEASE(sOperation_atom); + NS_RELEASE(sPart_atom); + NS_RELEASE(sDocumentation_atom); + NS_RELEASE(sInput_atom); + NS_RELEASE(sOutput_atom); + NS_RELEASE(sFault_atom); + + NS_RELEASE(sBody_atom); + NS_RELEASE(sHeader_atom); + NS_RELEASE(sHeaderFault_atom); + NS_RELEASE(sAddress_atom); + } +} + +//////////////////////////////////////////////////////////// +// +// nsWSDLLoader implementation +// +//////////////////////////////////////////////////////////// nsWSDLLoader::nsWSDLLoader() { NS_INIT_ISUPPORTS(); + if (!nsWSDLAtoms::sDefinitions_atom) { + nsWSDLAtoms::CreateWSDLAtoms(); + } } nsWSDLLoader::~nsWSDLLoader() { } -NS_IMPL_ISUPPORTS1(nsWSDLLoader, nsIWSDLLoader) +NS_IMPL_ISUPPORTS1_CI(nsWSDLLoader, nsIWSDLLoader) -/* nsIWSDLService load (in nsIURI wsdlURI); */ +nsresult +nsWSDLLoader::GetResolvedURI(const nsAReadableString& aWSDLURI, + const char* aMethod, + nsIURI** aURI) +{ + nsresult rv; + nsCOMPtr cc; + nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID(), &rv)); + if(NS_SUCCEEDED(rv)) { + rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc)); + } + + if (NS_SUCCEEDED(rv) && cc) { + JSContext* cx; + rv = cc->GetJSContext(&cx); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr secMan(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr baseURI; + nsCOMPtr principal; + rv = secMan->GetSubjectPrincipal(getter_AddRefs(principal)); + if (NS_SUCCEEDED(rv)) { + nsCOMPtr codebase = do_QueryInterface(principal); + if (codebase) { + codebase->GetURI(getter_AddRefs(baseURI)); + } + } + + rv = NS_NewURI(aURI, aWSDLURI, baseURI); + if (NS_FAILED(rv)) return rv; + + rv = secMan->CheckConnect(cx, *aURI, "nsWSDLLoader", aMethod); + if (NS_FAILED(rv)) + { + // Security check failed. The above call set a JS exception. The + // following lines ensure that the exception is propagated. + cc->SetExceptionWasThrown(PR_TRUE); + return rv; + } + } + else { + rv = NS_NewURI(aURI, aWSDLURI, nsnull); + if (NS_FAILED(rv)) return rv; + } + + return NS_OK; +} + +/* nsIWSDLService load (in AString wsdlURI, in AString portName); */ NS_IMETHODIMP -nsWSDLLoader::Load(nsIURI *wsdlURI, nsIWSDLService **_retval) +nsWSDLLoader::Load(const nsAReadableString& wsdlURI, + const nsAReadableString& portName, + nsIWSDLPort **_retval) +{ + NS_ENSURE_ARG_POINTER(_retval); + + nsCOMPtr resolvedURI; + nsresult rv = GetResolvedURI(wsdlURI, "load", getter_AddRefs(resolvedURI)); + if (NS_FAILED(rv)) { + return rv; + } + nsXPIDLCString spec; + resolvedURI->GetSpec(getter_Copies(spec)); + + nsCOMPtr listener; + nsWSDLLoadRequest* request = new nsWSDLLoadRequest(PR_TRUE, nsnull, + portName); + if (!request) { + return NS_ERROR_OUT_OF_MEMORY; + } + listener = request; + + rv = request->LoadDefinition(NS_ConvertASCIItoUCS2(spec.get())); + + if (NS_SUCCEEDED(rv)) { + request->GetPort(_retval); + } + + return rv; +} + +/* void loadAsync (in AString wsdlURI, in AString portName, + in nsIWSDLLoadListener listener); */ +NS_IMETHODIMP +nsWSDLLoader::LoadAsync(const nsAReadableString& wsdlURI, + const nsAReadableString& portName, + nsIWSDLLoadListener *aListener) +{ + NS_ENSURE_ARG(aListener); + + nsCOMPtr resolvedURI; + nsresult rv = GetResolvedURI(wsdlURI, "loadAsync", getter_AddRefs(resolvedURI)); + if (NS_FAILED(rv)) { + return rv; + } + nsXPIDLCString spec; + resolvedURI->GetSpec(getter_Copies(spec)); + + nsCOMPtr listener; + nsWSDLLoadRequest* request = new nsWSDLLoadRequest(PR_FALSE, aListener, + portName); + if (!request) { + return NS_ERROR_OUT_OF_MEMORY; + } + listener = request; + + return request->LoadDefinition(NS_ConvertASCIItoUCS2(spec.get())); +} + +/* nsISupports createPortProxy(in nsIWSDLPort service, in AString nameSpace); */ +NS_IMETHODIMP +nsWSDLLoader::CreatePortProxy(nsIWSDLPort *port, + const nsAReadableString& nameSpace, + nsISupports **_retval) { return NS_ERROR_NOT_IMPLEMENTED; } -/* void loadAsync (in nsIURI wsdlURI, in nsIWSDLLoaderListener listener); */ -NS_IMETHODIMP -nsWSDLLoader::LoadAsync(nsIURI *wsdlURI, nsIWSDLLoaderListener *listener) +//////////////////////////////////////////////////////////// +// +// nsWSDLLoadRequest implementation +// +//////////////////////////////////////////////////////////// +nsWSDLLoadRequest::nsWSDLLoadRequest(PRBool aIsSync, + nsIWSDLLoadListener* aListener, + const nsAReadableString& aPortName) + : mListener(aListener), mIsSync(aIsSync), mPortName(aPortName) { - return NS_ERROR_NOT_IMPLEMENTED; + NS_INIT_ISUPPORTS(); } -/* nsISupports createServiceProxy (in nsIWSDLService service, in AString nameSpace); */ -NS_IMETHODIMP -nsWSDLLoader::CreateServiceProxy(nsIWSDLService *service, - const nsAReadableString& nameSpace, - nsISupports **_retval) +nsWSDLLoadRequest::~nsWSDLLoadRequest() { - return NS_ERROR_NOT_IMPLEMENTED; + while (GetCurrentContext() != nsnull) { + PopContext(); + } } +NS_IMPL_ISUPPORTS1(nsWSDLLoadRequest, + nsIDOMEventListener) + +static inline PRBool +IsElementOfNamespace(nsIDOMElement* aElement, + const nsAReadableString& aNamespace) +{ + nsAutoString namespaceURI; + aElement->GetNamespaceURI(namespaceURI); + return namespaceURI.Equals(aNamespace); +} + +nsresult +nsWSDLLoadRequest::LoadDefinition(const nsAReadableString& aURI) +{ + nsresult rv; + + if (!mSchemaLoader) { + mSchemaLoader = do_GetService(NS_SCHEMALOADER_CONTRACTID, &rv); + if (NS_FAILED(rv)) { + return rv; + } + } + + mRequest = do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv); + if (!mRequest) { + return rv; + } + + rv = mRequest->OpenRequest("GET", + NS_ConvertUCS2toUTF8(aURI).get(), + !mIsSync, nsnull, nsnull); + if (NS_FAILED(rv)) { + return rv; + } + + if (!mIsSync) { + nsCOMPtr target(do_QueryInterface(mRequest)); + if (!target) { + return NS_ERROR_UNEXPECTED; + } + + rv = target->AddEventListener(NS_LITERAL_STRING("load"), + this, PR_FALSE); + if (NS_FAILED(rv)) { + return rv; + } + + rv = target->AddEventListener(NS_LITERAL_STRING("error"), + this, PR_FALSE); + if (NS_FAILED(rv)) { + return rv; + } + } + + rv = mRequest->Send(nsnull); + if (NS_FAILED(rv)) { + return rv; + } + + if (mIsSync) { + nsCOMPtr document; + rv = mRequest->GetResponseXML(getter_AddRefs(document)); + if (NS_FAILED(rv)) { + return rv; + } + + nsCOMPtr element; + document->GetDocumentElement(getter_AddRefs(element)); + if (element) { + if (IsElementOfNamespace(element, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + rv = PushContext(document, aURI); + if (NS_FAILED(rv)) { + return rv; + } + + rv = ResumeProcessing(); + + PopContext(); + + if (NS_FAILED(rv)) { + return rv; + } + } + else if (IsElementOfNamespace(element, + NS_LITERAL_STRING(NS_WSDL_SCHEMA_NAMESPACE))) { + nsCOMPtr schema; + rv = mSchemaLoader->ProcessSchemaElement(element, + getter_AddRefs(schema)); + if (NS_FAILED(rv)) { + return NS_ERROR_WSDL_SCHEMA_PROCESSING_ERROR; + } + + nsAutoString targetNamespace; + schema->GetTargetNamespace(targetNamespace); + + nsStringKey key(targetNamespace); + mTypes.Put(&key, schema); + } + else { + rv = NS_ERROR_WSDL_NOT_WSDL_ELEMENT; // element of unknown namespace + } + } + else { + return NS_ERROR_WSDL_NOT_WSDL_ELEMENT; + } + } + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ContineProcessingTillDone() +{ + nsresult rv; + do { + rv = ResumeProcessing(); + + if (NS_FAILED(rv) || (rv == NS_ERROR_WSDL_LOADPENDING)) { + break; + } + + PopContext(); + + } while (GetCurrentContext() != nsnull); + + return rv; +} + +/* void handleEvent (in nsIDOMEvent event); */ +NS_IMETHODIMP +nsWSDLLoadRequest::HandleEvent(nsIDOMEvent *event) +{ + nsresult rv; + nsAutoString eventType; + + event->GetType(eventType); + + if (eventType.Equals(NS_LITERAL_STRING("load"))) { + nsCOMPtr document; + + rv = mRequest->GetResponseXML(getter_AddRefs(document)); + if (NS_SUCCEEDED(rv)) { + nsCOMPtr element; + + document->GetDocumentElement(getter_AddRefs(element)); + if (element) { + if (IsElementOfNamespace(element, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + + nsCOMPtr channel; + nsCOMPtr uri; + nsXPIDLCString spec; + + mRequest->GetChannel(getter_AddRefs(channel)); + + if (channel) { + channel->GetURI(getter_AddRefs(uri)); + if (uri) { + uri->GetSpec(getter_Copies(spec)); + } + } + + rv = PushContext(document, NS_ConvertASCIItoUCS2(spec.get())); + + if (NS_SUCCEEDED(rv)) { + rv = ContineProcessingTillDone(); + } + } + else if (IsElementOfNamespace(element, + NS_LITERAL_STRING(NS_WSDL_SCHEMA_NAMESPACE))) { + nsCOMPtr schema; + rv = mSchemaLoader->ProcessSchemaElement(element, + getter_AddRefs(schema)); + if (NS_FAILED(rv)) { + return NS_ERROR_WSDL_SCHEMA_PROCESSING_ERROR; + } + + nsAutoString targetNamespace; + schema->GetTargetNamespace(targetNamespace); + + nsStringKey key(targetNamespace); + mTypes.Put(&key, schema); + + rv = ContineProcessingTillDone(); + } + else { + rv = NS_ERROR_WSDL_NOT_WSDL_ELEMENT; // element of unknown namespace + } + } + else { + rv = NS_ERROR_WSDL_NOT_WSDL_ELEMENT; + } + } + + if (NS_FAILED(rv)) { + mListener->OnError(rv, NS_LITERAL_STRING("Failure processing WSDL document")); + return NS_OK; + } + } + else if (eventType.Equals(NS_LITERAL_STRING("error"))) { + mListener->OnError(NS_ERROR_WSDL_LOADING_ERROR, + NS_LITERAL_STRING("Failure loading")); + return NS_OK; + } + + if (GetCurrentContext() == nsnull) { + if (mPort) { + mListener->OnLoad(mPort); + } + else { + mListener->OnError(NS_ERROR_WSDL_BINDING_NOT_FOUND, + NS_LITERAL_STRING("Binding not found")); + } + mRequest = nsnull; + } + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ResumeProcessing() +{ + nsresult rv = NS_OK; + + nsWSDLLoadingContext* context = GetCurrentContext(); + if (!context) { + return NS_ERROR_UNEXPECTED; + } + + nsCOMPtr element; + context->GetRootElement(getter_AddRefs(element)); + PRUint32 childIndex = context->GetChildIndex(); + + nsChildElementIterator iterator(element, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE)); + nsCOMPtr childElement; + nsCOMPtr tagName; + + // If we don't yet have a port, find the service element, create one + // and record the port's its binding name + if (mBindingName.IsEmpty()) { + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if (tagName == nsWSDLAtoms::sService_atom) { + rv = ProcessServiceElement(childElement); + if (NS_FAILED(rv)) { + return rv; + } + } + } + } + + iterator.Reset(childIndex); + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if (tagName == nsWSDLAtoms::sImport_atom) { + rv = ProcessImportElement(childElement, + iterator.GetCurrentIndex()+1); + if (NS_FAILED(rv) || + (rv == NS_ERROR_WSDL_LOADPENDING)) { + return rv; + } + } + else if (tagName == nsWSDLAtoms::sTypes_atom) { + rv = ProcessTypesElement(childElement); + if (NS_FAILED(rv)) { + return rv; + } + } + else if (tagName == nsWSDLAtoms::sMessage_atom) { + rv = ProcessMessageElement(childElement); + if (NS_FAILED(rv)) { + return rv; + } + } + else if (tagName == nsWSDLAtoms::sPortType_atom) { + rv = ProcessPortTypeElement(childElement); + if (NS_FAILED(rv)) { + return rv; + } + } + else if (tagName == nsWSDLAtoms::sBinding_atom) { + nsAutoString name, targetNamespace; + childElement->GetAttribute(NS_LITERAL_STRING("name"), name); + context->GetTargetNamespace(targetNamespace); + + // Only process binding for the requested port + // XXX We should be checking the binding namespace as + // well, but some authors are not qualifying their + // binding names + if (mBindingName.Equals(name)) { + rv = ProcessBindingElement(childElement); + if (NS_FAILED(rv)) { + return rv; + } + } + } + } + + return rv; +} + +nsresult +nsWSDLLoadRequest::GetPort(nsIWSDLPort** aPort) +{ + *aPort = mPort; + NS_IF_ADDREF(*aPort); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::PushContext(nsIDOMDocument* aDocument, + const nsAReadableString& aURISpec) +{ + nsWSDLLoadingContext* context = new nsWSDLLoadingContext(aDocument, + aURISpec); + if (!context) { + return NS_ERROR_OUT_OF_MEMORY; + } + + mContextStack.AppendElement((void*)context); + + return NS_OK; +} + +nsWSDLLoadingContext* +nsWSDLLoadRequest::GetCurrentContext() +{ + PRUint32 count = mContextStack.Count(); + if (count > 0) { + return NS_STATIC_CAST(nsWSDLLoadingContext*, + mContextStack.ElementAt(count-1)); + } + + return nsnull; +} + +void +nsWSDLLoadRequest::PopContext() +{ + PRUint32 count = mContextStack.Count(); + if (count > 0) { + nsWSDLLoadingContext* context = NS_STATIC_CAST(nsWSDLLoadingContext*, + mContextStack.ElementAt(count-1)); + delete context; + mContextStack.RemoveElementAt(count-1); + } +} + +nsresult +nsWSDLLoadRequest::GetSchemaElement(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsISchemaElement** aSchemaComponent) +{ + nsStringKey key(aNamespace); + nsCOMPtr sup = dont_AddRef(mTypes.Get(&key)); + nsCOMPtr schema(do_QueryInterface(sup)); + if (!schema) { + return NS_ERROR_WSDL_UNKNOWN_SCHEMA_COMPONENT; + } + + nsCOMPtr element; + schema->GetElementByName(aName, getter_AddRefs(element)); + if (!element) { + return NS_ERROR_WSDL_UNKNOWN_SCHEMA_COMPONENT; + } + + *aSchemaComponent = element; + NS_IF_ADDREF(*aSchemaComponent); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::GetSchemaType(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsISchemaType** aSchemaComponent) +{ + if (aNamespace.Equals(NS_LITERAL_STRING(NS_WSDL_SCHEMA_NAMESPACE))) { + nsCOMPtr collection(do_QueryInterface(mSchemaLoader)); + return collection->GetType(aName, aNamespace, aSchemaComponent); + } + + nsStringKey key(aNamespace); + nsCOMPtr sup = dont_AddRef(mTypes.Get(&key)); + nsCOMPtr schema(do_QueryInterface(sup)); + if (!schema) { + return NS_ERROR_WSDL_UNKNOWN_SCHEMA_COMPONENT; + } + + nsCOMPtr type; + schema->GetTypeByName(aName, getter_AddRefs(type)); + if (!type) { + return NS_ERROR_WSDL_UNKNOWN_SCHEMA_COMPONENT; + } + + *aSchemaComponent = type; + NS_IF_ADDREF(*aSchemaComponent); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::GetMessage(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsIWSDLMessage** aMessage) +{ + nsAutoString keyStr; + keyStr.Assign(aName); + keyStr.Append(aNamespace); + nsStringKey key(keyStr); + + nsCOMPtr sup = dont_AddRef(mMessages.Get(&key)); + nsCOMPtr message(do_QueryInterface(sup)); + if (!message) { + return NS_ERROR_WSDL_UNKNOWN_WSDL_COMPONENT; + } + + *aMessage = message; + NS_IF_ADDREF(*aMessage); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::GetPortType(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsIWSDLPort** aPort) +{ + nsAutoString keyStr; + keyStr.Assign(aName); + keyStr.Append(aNamespace); + nsStringKey key(keyStr); + + nsCOMPtr sup = dont_AddRef(mPortTypes.Get(&key)); + nsCOMPtr port(do_QueryInterface(sup)); + if (!port) { + return NS_ERROR_WSDL_UNKNOWN_WSDL_COMPONENT; + } + + *aPort = port; + NS_IF_ADDREF(*aPort); + + return NS_OK; +} + +static nsresult +ParseQualifiedName(nsIDOMElement* aContext, + const nsAReadableString& aQualifiedName, + nsAWritableString& aPrefix, + nsAWritableString& aLocalName, + nsAWritableString& aNamespaceURI) +{ + nsReadingIterator pos, begin, end; + + aQualifiedName.BeginReading(begin); + aQualifiedName.EndReading(end); + pos = begin; + + if (FindCharInReadable(PRUnichar(':'), pos, end)) { + CopyUnicodeTo(begin, pos, aPrefix); + CopyUnicodeTo(++pos, end, aLocalName); + } + else { + CopyUnicodeTo(begin, end, aLocalName); + } + + nsCOMPtr node(do_QueryInterface(aContext)); + if (!node) { + return NS_ERROR_UNEXPECTED; + } + + return node->LookupNamespaceURI(aPrefix, aNamespaceURI); +} + + +nsresult +nsWSDLLoadRequest::ProcessImportElement(nsIDOMElement* aElement, + PRUint32 aIndex) +{ + nsresult rv = NS_OK; + + // XXX Is there a need to record the namespace? Can it be different + // from the targetNamespace of the imported file? + + nsAutoString location, documentLocation; + aElement->GetAttribute(NS_LITERAL_STRING("location"), location); + + nsWSDLLoadingContext* context = GetCurrentContext(); + if (!context) { + return NS_ERROR_UNEXPECTED; + } + context->GetDocumentLocation(documentLocation); + + nsCOMPtr uri, baseURI; + rv = NS_NewURI(getter_AddRefs(baseURI), documentLocation); + if (NS_FAILED(rv)) { + return rv; + } + + rv = NS_NewURI(getter_AddRefs(uri), location, baseURI); + if (NS_FAILED(rv)) { + return rv; + } + + nsXPIDLCString spec; + uri->GetSpec(getter_Copies(spec)); + + rv = LoadDefinition(NS_ConvertUTF8toUCS2(spec.get())); + if (NS_FAILED(rv)) { + return rv; + } + + if (!mIsSync) { + context->SetChildIndex(aIndex); + return NS_ERROR_WSDL_LOADPENDING; + } + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessTypesElement(nsIDOMElement* aElement) +{ + nsresult rv = NS_OK; + + nsChildElementIterator iterator(aElement, + NS_LITERAL_STRING(NS_WSDL_SCHEMA_NAMESPACE)); + nsCOMPtr childElement; + nsCOMPtr tagName; + + nsCOMPtr schemaAtom(dont_AddRef(NS_NewAtom("schema"))); + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if (tagName == schemaAtom) { + nsCOMPtr schema; + rv = mSchemaLoader->ProcessSchemaElement(childElement, + getter_AddRefs(schema)); + if (NS_FAILED(rv)) { + return NS_ERROR_WSDL_SCHEMA_PROCESSING_ERROR; + } + + nsAutoString targetNamespace; + schema->GetTargetNamespace(targetNamespace); + + nsStringKey key(targetNamespace); + mTypes.Put(&key, schema); + + break; + } + } + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessAbstractPartElement(nsIDOMElement* aElement, + nsWSDLMessage* aMessage) +{ + nsresult rv = NS_OK; + + nsAutoString name; + aElement->GetAttribute(NS_LITERAL_STRING("name"), name); + + nsCOMPtr part; + nsWSDLPart* partInst = new nsWSDLPart(name); + if (!partInst) { + return NS_ERROR_OUT_OF_MEMORY; + } + part = partInst; + + nsCOMPtr schemaComponent; + nsAutoString elementQName, typeQName; + aElement->GetAttribute(NS_LITERAL_STRING("element"), elementQName); + aElement->GetAttribute(NS_LITERAL_STRING("type"), typeQName); + + if (!elementQName.IsEmpty()) { + nsAutoString elementPrefix, elementLocalName, elementNamespace; + + rv = ParseQualifiedName(aElement, + elementQName, + elementPrefix, + elementLocalName, + elementNamespace); + if (NS_FAILED(rv)) { + return rv; + } + + nsCOMPtr schemaElement; + rv = GetSchemaElement(elementLocalName, elementNamespace, + getter_AddRefs(schemaElement)); + if (NS_FAILED(rv)) { + return rv; + } + + schemaComponent = schemaElement; + } + else if (!typeQName.IsEmpty()) { + nsAutoString typePrefix, typeLocalName, typeNamespace; + + rv = ParseQualifiedName(aElement, + typeQName, + typePrefix, + typeLocalName, + typeNamespace); + if (NS_FAILED(rv)) { + return rv; + } + + nsCOMPtr schemaType; + rv = GetSchemaType(typeLocalName, typeNamespace, + getter_AddRefs(schemaType)); + if (NS_FAILED(rv)) { + return rv; + } + + schemaComponent = schemaType; + } + + partInst->SetTypeInfo(typeQName, elementQName, + schemaComponent); + aMessage->AddPart(part); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessMessageElement(nsIDOMElement* aElement) +{ + nsresult rv = NS_OK; + + nsAutoString name; + aElement->GetAttribute(NS_LITERAL_STRING("name"), name); + + nsCOMPtr message; + nsWSDLMessage* messageInst = new nsWSDLMessage(name); + if (!messageInst) { + return NS_ERROR_OUT_OF_MEMORY; + } + message = messageInst; + + nsChildElementIterator iterator(aElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE)); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if (tagName == nsWSDLAtoms::sDocumentation_atom) { + messageInst->SetDocumentationElement(childElement); + } + else if (tagName == nsWSDLAtoms::sPart_atom) { + rv = ProcessAbstractPartElement(childElement, messageInst); + if (NS_FAILED(rv)) { + return rv; + } + } + } + + nsAutoString targetNamespace; + nsWSDLLoadingContext* context = GetCurrentContext(); + if (!context) { + return NS_ERROR_UNEXPECTED; + } + context->GetTargetNamespace(targetNamespace); + + name.Append(targetNamespace); + nsStringKey key(name); + mMessages.Put(&key, message); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessOperationComponent(nsIDOMElement* aElement, + nsIWSDLMessage** aMessage) +{ + nsresult rv; + + nsAutoString messageQName, messagePrefix, messageLocalName, messageNamespace; + aElement->GetAttribute(NS_LITERAL_STRING("message"), messageQName); + + rv = ParseQualifiedName(aElement, + messageQName, + messagePrefix, + messageLocalName, + messageNamespace); + if (NS_FAILED(rv)) { + return rv; + } + + rv = GetMessage(messageLocalName, messageNamespace, aMessage); + if (NS_FAILED(rv)) { + // XXX It seem that some WSDL authors eliminate prefixes + // from qualified names in attribute values, assuming that + // the names will resolve to the targetNamespace, while + // they should technically resolve to the default namespace. + if (messagePrefix.IsEmpty()) { + nsAutoString targetNamespace; + nsWSDLLoadingContext* context = GetCurrentContext(); + if (!context) { + return NS_ERROR_UNEXPECTED; + } + context->GetTargetNamespace(targetNamespace); + rv = GetMessage(messageLocalName, targetNamespace, aMessage); + if (NS_FAILED(rv)) { + return rv; + } + } + } + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessAbstractOperation(nsIDOMElement* aElement, + nsWSDLPort* aPort) +{ + nsresult rv = NS_OK; + + nsAutoString name; + aElement->GetAttribute(NS_LITERAL_STRING("name"), name); + + nsCOMPtr operation; + nsWSDLOperation* operationInst = new nsWSDLOperation(name); + if (!operationInst) { + return NS_ERROR_OUT_OF_MEMORY; + } + operation = operationInst; + + nsAutoString parameterOrder; + aElement->GetAttribute(NS_LITERAL_STRING("parameterOrder"), parameterOrder); + if (!parameterOrder.IsEmpty()) { + nsReadingIterator start, end, delimiter; + parameterOrder.BeginReading(start); + parameterOrder.EndReading(end); + + PRBool found; + do { + delimiter = start; + + // Find the next delimiter + found = FindCharInReadable(PRUnichar(' '), delimiter, end); + + // Use the string from the current start position to the + // delimiter. + nsAutoString paramName; + CopyUnicodeTo(start, delimiter, paramName); + + if (!paramName.IsEmpty()) { + operationInst->AddParameter(paramName); + } + + // If we did find a delimeter, advance past it + if (found) { + start = delimiter; + ++start; + } + } while (found); + } + + nsChildElementIterator iterator(aElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE)); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + nsCOMPtr message; + if (tagName == nsWSDLAtoms::sDocumentation_atom) { + operationInst->SetDocumentationElement(childElement); + } + else if (tagName == nsWSDLAtoms::sInput_atom) { + rv = ProcessOperationComponent(childElement, + getter_AddRefs(message)); + if (NS_FAILED(rv)) { + return rv; + } + operationInst->SetInput(message); + } + else if (tagName == nsWSDLAtoms::sOutput_atom) { + rv = ProcessOperationComponent(childElement, + getter_AddRefs(message)); + if (NS_FAILED(rv)) { + return rv; + } + operationInst->SetOutput(message); + } + else if (tagName == nsWSDLAtoms::sFault_atom) { + rv = ProcessOperationComponent(childElement, + getter_AddRefs(message)); + if (NS_FAILED(rv)) { + return rv; + } + operationInst->AddFault(message); + } + } + + aPort->AddOperation(operation); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessPortTypeElement(nsIDOMElement* aElement) +{ + nsresult rv = NS_OK; + + nsAutoString name; + aElement->GetAttribute(NS_LITERAL_STRING("name"), name); + + nsCOMPtr port; + nsWSDLPort* portInst = new nsWSDLPort(name); + if (!portInst) { + return NS_ERROR_OUT_OF_MEMORY; + } + port = portInst; + + nsChildElementIterator iterator(aElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE)); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if (tagName == nsWSDLAtoms::sDocumentation_atom) { + portInst->SetDocumentationElement(childElement); + } + else if (tagName == nsWSDLAtoms::sOperation_atom) { + rv = ProcessAbstractOperation(childElement, portInst); + if (NS_FAILED(rv)) { + return rv; + } + } + } + + nsAutoString targetNamespace; + nsWSDLLoadingContext* context = GetCurrentContext(); + if (!context) { + return NS_ERROR_UNEXPECTED; + } + context->GetTargetNamespace(targetNamespace); + + name.Append(targetNamespace); + nsStringKey key(name); + mPortTypes.Put(&key, port); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessMessageBinding(nsIDOMElement* aElement, + nsIWSDLMessage* aMessage) +{ + + nsChildElementIterator iterator(aElement, + NS_LITERAL_STRING(NS_WSDL_SOAP_NAMESPACE)); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if (tagName == nsWSDLAtoms::sBody_atom) { + nsAutoString partsStr, useStr, encodingStyle, namespaceStr; + childElement->GetAttribute(NS_LITERAL_STRING("parts"), partsStr); + childElement->GetAttribute(NS_LITERAL_STRING("use"), useStr); + childElement->GetAttribute(NS_LITERAL_STRING("encodingStyle"), + encodingStyle); + childElement->GetAttribute(NS_LITERAL_STRING("namespace"), namespaceStr); + + PRUint16 use = nsISOAPPartBinding::USE_LITERAL; + if (useStr.Equals(NS_LITERAL_STRING("encoded"))) { + use = nsISOAPPartBinding::USE_ENCODED; + } + + nsCOMPtr binding; + nsSOAPPartBinding* bindingInst = new nsSOAPPartBinding(nsISOAPPartBinding::LOCATION_BODY, + use, + encodingStyle, + namespaceStr); + if (!bindingInst) { + return NS_ERROR_OUT_OF_MEMORY; + } + binding = bindingInst; + + nsCOMPtr part; + nsWSDLPart* partInst; + if (partsStr.IsEmpty()) { + PRUint32 index, count; + + aMessage->GetPartCount(&count); + for (index = 0; index < count; index++) { + aMessage->GetPart(index, getter_AddRefs(part)); + partInst = NS_REINTERPRET_CAST(nsWSDLPart*, part.get()); + if (partInst) { + partInst->SetBinding(binding); + } + } + } + else { + nsReadingIterator start, end, delimiter; + partsStr.BeginReading(start); + partsStr.EndReading(end); + + PRBool found; + do { + delimiter = start; + + // Find the next delimiter + found = FindCharInReadable(PRUnichar(' '), delimiter, end); + + // Use the string from the current start position to the + // delimiter. + nsAutoString partName; + CopyUnicodeTo(start, delimiter, partName); + + if (!partName.IsEmpty()) { + aMessage->GetPartByName(partName, getter_AddRefs(part)); + partInst = NS_REINTERPRET_CAST(nsWSDLPart*, part.get()); + if (partInst) { + partInst->SetBinding(binding); + } + } + + // If we did find a delimeter, advance past it + if (found) { + start = delimiter; + ++start; + } + } while (found); + } + } + } + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessOperationBinding(nsIDOMElement* aElement, + nsIWSDLPort* aPort) +{ + nsresult rv = NS_OK; + + nsAutoString name; + aElement->GetAttribute(NS_LITERAL_STRING("name"), name); + + nsCOMPtr operation; + aPort->GetOperationByName(name, getter_AddRefs(operation)); + if (!operation) { + return NS_ERROR_WSDL_UNKNOWN_WSDL_COMPONENT; + } + nsWSDLOperation* operationInst = NS_REINTERPRET_CAST(nsWSDLOperation*, + operation.get()); + + nsCOMPtr binding; + nsSOAPOperationBinding* bindingInst = new nsSOAPOperationBinding(); + if (!bindingInst) { + return NS_ERROR_OUT_OF_MEMORY; + } + binding = bindingInst; + + nsChildElementIterator iterator(aElement); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if ((tagName == nsWSDLAtoms::sDocumentation_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + bindingInst->SetDocumentationElement(childElement); + } + else if ((tagName == nsWSDLAtoms::sOperation_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_SOAP_NAMESPACE))) { + nsAutoString action, style; + childElement->GetAttribute(NS_LITERAL_STRING("soapAction"), action); + childElement->GetAttribute(NS_LITERAL_STRING("style"), style); + + bindingInst->SetSoapAction(action); + if (style.Equals(NS_LITERAL_STRING("rpc"))) { + bindingInst->SetStyle(nsISOAPPortBinding::STYLE_RPC); + } + else if (style.Equals(NS_LITERAL_STRING("document"))) { + bindingInst->SetStyle(nsISOAPPortBinding::STYLE_DOCUMENT); + } + } + else if ((tagName == nsWSDLAtoms::sInput_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + nsCOMPtr input; + + operation->GetInput(getter_AddRefs(input)); + rv = ProcessMessageBinding(childElement, input); + if (NS_FAILED(rv)) { + return rv; + } + } + else if ((tagName == nsWSDLAtoms::sOutput_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + nsCOMPtr output; + + operation->GetOutput(getter_AddRefs(output)); + rv = ProcessMessageBinding(childElement, output); + if (NS_FAILED(rv)) { + return rv; + } + } + else if ((tagName == nsWSDLAtoms::sFault_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + // XXX TO BE IMPLEMENTED + } + } + + operationInst->SetBinding(binding); + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessBindingElement(nsIDOMElement* aElement) +{ + nsresult rv = NS_OK; + + nsAutoString name; + aElement->GetAttribute(NS_LITERAL_STRING("name"), name); + + PRBool foundSOAPBinding; + nsCOMPtr binding; + nsSOAPPortBinding* bindingInst = new nsSOAPPortBinding(name); + if (!bindingInst) { + return NS_ERROR_OUT_OF_MEMORY; + } + binding = bindingInst; + bindingInst->SetAddress(mAddress); + + nsCOMPtr port; + nsAutoString typeQName, typePrefix, typeLocalName, typeNamespace; + aElement->GetAttribute(NS_LITERAL_STRING("type"), typeQName); + rv = ParseQualifiedName(aElement, + typeQName, + typePrefix, + typeLocalName, + typeNamespace); + if (NS_FAILED(rv)) { + return rv; + } + + rv = GetPortType(typeLocalName, typeNamespace, getter_AddRefs(port)); + if (NS_FAILED(rv)) { + // XXX It seem that some WSDL authors eliminate prefixes + // from qualified names in attribute values, assuming that + // the names will resolve to the targetNamespace, while + // they should technically resolve to the default namespace. + if (typePrefix.IsEmpty()) { + nsAutoString targetNamespace; + nsWSDLLoadingContext* context = GetCurrentContext(); + if (!context) { + return NS_ERROR_UNEXPECTED; + } + context->GetTargetNamespace(targetNamespace); + rv = GetPortType(typeLocalName, targetNamespace, getter_AddRefs(port)); + if (NS_FAILED(rv)) { + return rv; // Can't find a port type of the specified name + } + } + } + + nsChildElementIterator iterator(aElement); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if ((tagName == nsWSDLAtoms::sDocumentation_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + bindingInst->SetDocumentationElement(childElement); + } + else if ((tagName == nsWSDLAtoms::sBinding_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_SOAP_NAMESPACE))) { + nsAutoString style, transport; + childElement->GetAttribute(NS_LITERAL_STRING("style"), style); + childElement->GetAttribute(NS_LITERAL_STRING("transport"), transport); + + if (style.Equals(NS_LITERAL_STRING("rpc"))) { + bindingInst->SetStyle(nsISOAPPortBinding::STYLE_RPC); + } + else if (style.Equals(NS_LITERAL_STRING("document"))) { + bindingInst->SetStyle(nsISOAPPortBinding::STYLE_DOCUMENT); + } + bindingInst->SetTransport(transport); + foundSOAPBinding = PR_TRUE; + } + else if ((tagName == nsWSDLAtoms::sOperation_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE))) { + rv = ProcessOperationBinding(childElement, + port); + if (NS_FAILED(rv)) { + return rv; + } + } + } + + if (!foundSOAPBinding) { + // If we don't have a SOAP binding, we can't continue + return NS_ERROR_WSDL_BINDING_NOT_FOUND; + } + nsWSDLPort* portInst = NS_REINTERPRET_CAST(nsWSDLPort*, port.get()); + portInst->SetBinding(binding); + + mPort = port; + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessPortBinding(nsIDOMElement* aElement) +{ + nsChildElementIterator iterator(aElement); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if ((tagName == nsWSDLAtoms::sAddress_atom) && + IsElementOfNamespace(childElement, + NS_LITERAL_STRING(NS_WSDL_SOAP_NAMESPACE))) { + childElement->GetAttribute(NS_LITERAL_STRING("location"), + mAddress); + } + } + + return NS_OK; +} + +nsresult +nsWSDLLoadRequest::ProcessServiceElement(nsIDOMElement* aElement) +{ + nsresult rv; + + nsChildElementIterator iterator(aElement, + NS_LITERAL_STRING(NS_WSDL_NAMESPACE)); + nsCOMPtr childElement; + nsCOMPtr tagName; + + while (NS_SUCCEEDED(iterator.GetNextChild(getter_AddRefs(childElement), + getter_AddRefs(tagName))) && + childElement) { + if (tagName == nsWSDLAtoms::sPort_atom) { + nsAutoString name; + childElement->GetAttribute(NS_LITERAL_STRING("name"), name); + if (name.Equals(mPortName)) { + nsAutoString bindingQName, bindingPrefix; + + childElement->GetAttribute(NS_LITERAL_STRING("binding"), bindingQName); + rv = ParseQualifiedName(childElement, + bindingQName, + bindingPrefix, + mBindingName, + mBindingNamespace); + if (NS_FAILED(rv)) { + return rv; // binding of an unknown namespace + } + + rv = ProcessPortBinding(childElement); + if (NS_FAILED(rv)) { + return rv; + } + + break; + } + } + } + + return NS_OK; +} diff --git a/mozilla/extensions/xmlextras/wsdl/src/nsWSDLLoader.h b/mozilla/extensions/xmlextras/wsdl/src/nsWSDLLoader.h new file mode 100644 index 00000000000..8e04bf19fd7 --- /dev/null +++ b/mozilla/extensions/xmlextras/wsdl/src/nsWSDLLoader.h @@ -0,0 +1,211 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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. + * + * The Initial Developer of the Original Code is Netscape + * Communications. Portions created by Netscape Communications are + * Copyright (C) 2001 by Netscape Communications. All + * Rights Reserved. + * + * Contributor(s): + * Vidur Apparao (original author) + */ + +#ifndef __nsWSDLLoader_h__ +#define __nsWSDLLoader_h__ + +#include "nsIWSDLLoader.h" +#include "nsWSDLPrivate.h" + +#include "nsDOMUtils.h" + +// XPCOM Includes +#include "nsCOMPtr.h" +#include "nsSupportsArray.h" +#include "nsString.h" +#include "nsIAtom.h" +#include "nsHashtable.h" +#include "nsError.h" + +// Loading includes +#include "nsIURI.h" +#include "nsIXMLHTTPRequest.h" +#include "nsIDOMEventListener.h" + +// schema includes +#include "nsISchemaLoader.h" + +// DOM includes +#include "nsIDOMDocument.h" + +#define NS_ERROR_WSDL_LOADPENDING NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_GENERAL, 1) + +class nsWSDLAtoms { +public: + static void CreateWSDLAtoms(); + static void DestroyWSDLAtoms(); + + static nsIAtom* sDefinitions_atom; + static nsIAtom* sTypes_atom; + static nsIAtom* sMessage_atom; + static nsIAtom* sPortType_atom; + static nsIAtom* sBinding_atom; + static nsIAtom* sService_atom; + static nsIAtom* sPort_atom; + static nsIAtom* sOperation_atom; + static nsIAtom* sPart_atom; + static nsIAtom* sDocumentation_atom; + static nsIAtom* sImport_atom; + static nsIAtom* sInput_atom; + static nsIAtom* sOutput_atom; + static nsIAtom* sFault_atom; + + static nsIAtom* sBody_atom; + static nsIAtom* sHeader_atom; + static nsIAtom* sHeaderFault_atom; + static nsIAtom* sAddress_atom; +}; + +class nsWSDLLoader : public nsIWSDLLoader { +public: + nsWSDLLoader(); + virtual ~nsWSDLLoader(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIWSDLLOADER + +protected: + nsresult GetResolvedURI(const nsAReadableString& aSchemaURI, + const char* aMethod, + nsIURI** aURI); + +protected: + nsWSDLPort* mPort; +}; + + +class nsWSDLLoadingContext { +public: + nsWSDLLoadingContext(nsIDOMDocument* aDocument, + const nsAReadableString& aLocation) : + mDocument(aDocument), mChildIndex(0), mDocumentLocation(aLocation) { + } + ~nsWSDLLoadingContext() { + } + + void GetRootElement(nsIDOMElement** aElement) { + mDocument->GetDocumentElement(aElement); + } + + PRUint32 GetChildIndex() { return mChildIndex; } + void SetChildIndex(PRUint32 aChildIndex) { mChildIndex = aChildIndex; } + + void GetTargetNamespace(nsAWritableString& aNamespace) { + nsCOMPtr element; + GetRootElement(getter_AddRefs(element)); + if (element) { + element->GetAttribute(NS_LITERAL_STRING("targetNamespace"), + aNamespace); + } + else { + aNamespace.Truncate(); + } + } + + void GetDocumentLocation(nsAWritableString& aLocation) { + aLocation.Assign(mDocumentLocation); + } + +protected: + // XXX hold onto the document till issues related to dangling + // document pointers in content are fixed. After that, just + // hold onto the root element. + nsCOMPtr mDocument; + PRUint32 mChildIndex; + nsString mDocumentLocation; +}; + +class nsWSDLLoadRequest : public nsIDOMEventListener +{ +public: + nsWSDLLoadRequest(PRBool aIsSync, + nsIWSDLLoadListener* aListener, + const nsAReadableString& aPortName); + virtual ~nsWSDLLoadRequest(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIDOMEVENTLISTENER + + nsresult LoadDefinition(const nsAReadableString& aURI); + nsresult ResumeProcessing(); + nsresult ContineProcessingTillDone(); + nsresult GetPort(nsIWSDLPort** aPort); + + nsresult PushContext(nsIDOMDocument* aDocument, + const nsAReadableString& aLocation); + nsWSDLLoadingContext* GetCurrentContext(); + void PopContext(); + + nsresult GetSchemaElement(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsISchemaElement** aSchemaComponent); + nsresult GetSchemaType(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsISchemaType** aSchemaComponent); + nsresult GetMessage(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsIWSDLMessage** aMessage); + nsresult GetPortType(const nsAReadableString& aName, + const nsAReadableString& aNamespace, + nsIWSDLPort** aPort); + + nsresult ProcessImportElement(nsIDOMElement* aElement, + PRUint32 aIndex); + nsresult ProcessTypesElement(nsIDOMElement* aElement); + nsresult ProcessMessageElement(nsIDOMElement* aElement); + nsresult ProcessAbstractPartElement(nsIDOMElement* aElement, + nsWSDLMessage* aMessage); + nsresult ProcessPortTypeElement(nsIDOMElement* aElement); + nsresult ProcessAbstractOperation(nsIDOMElement* aElement, + nsWSDLPort* aPort); + nsresult ProcessOperationComponent(nsIDOMElement* aElement, + nsIWSDLMessage** aMessage); + nsresult ProcessMessageBinding(nsIDOMElement* aElement, + nsIWSDLMessage* aMessage); + nsresult ProcessOperationBinding(nsIDOMElement* aElement, + nsIWSDLPort* aPort); + nsresult ProcessBindingElement(nsIDOMElement* aElement); + nsresult ProcessPortBinding(nsIDOMElement* aElement); + nsresult ProcessServiceElement(nsIDOMElement* aElement); + +protected: + nsCOMPtr mListener; + nsCOMPtr mRequest; + nsCOMPtr mSchemaLoader; + + PRBool mIsSync; + + nsCOMPtr mPort; + nsString mPortName; + nsString mBindingName; + nsString mBindingNamespace; + nsString mAddress; + + nsVoidArray mContextStack; + + nsSupportsHashtable mTypes; + nsSupportsHashtable mMessages; + nsSupportsHashtable mPortTypes; +}; + +#endif // __nsWSDLLoader_h__ diff --git a/mozilla/extensions/xmlextras/wsdl/src/nsWSDLPrivate.h b/mozilla/extensions/xmlextras/wsdl/src/nsWSDLPrivate.h index d8d80182b71..d714715bbaf 100644 --- a/mozilla/extensions/xmlextras/wsdl/src/nsWSDLPrivate.h +++ b/mozilla/extensions/xmlextras/wsdl/src/nsWSDLPrivate.h @@ -25,138 +25,220 @@ #define __nsWSDLPrivate_h__ #include "nsIWSDL.h" -#include "nsIWSDLLoader.h" +#include "nsIWSDLSOAPBinding.h" // DOM Includes #include "nsIDOMElement.h" +// Schema includes +#include "nsISchema.h" + // XPCOM Includes #include "nsCOMPtr.h" +#include "nsVoidArray.h" #include "nsSupportsArray.h" #include "nsString.h" -class nsWSDLLoader : public nsIWSDLLoader { +#define NS_WSDL_SCHEMA_NAMESPACE "http://www.w3.org/2001/XMLSchema" +#define NS_WSDL_NAMESPACE "http://schemas.xmlsoap.org/wsdl/" +#define NS_WSDL_SOAP_NAMESPACE "http://schemas.xmlsoap.org/wsdl/soap/" + +class nsSOAPPortBinding : public nsISOAPPortBinding { public: - nsWSDLLoader(); - virtual ~nsWSDLLoader(); - + nsSOAPPortBinding(const nsAReadableString& aName); + virtual ~nsSOAPPortBinding(); + NS_DECL_ISUPPORTS - NS_DECL_NSIWSDLLOADER -}; + NS_DECL_NSIWSDLBINDING + NS_DECL_NSISOAPPORTBINDING -class nsWSDLService : public nsIWSDLService { -public: - nsWSDLService(); - virtual ~nsWSDLService(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIWSDLSERVICE - - NS_IMETHOD SetName(const nsAReadableString& aName); NS_IMETHOD SetDocumentationElement(nsIDOMElement* aElement); - NS_IMETHOD AddPort(nsIWSDLPort* aPort); + NS_IMETHOD SetAddress(const nsAReadableString& aAddress); + NS_IMETHOD SetStyle(PRUint16 aStyle); + NS_IMETHOD SetTransport(const nsAReadableString& aTransport); protected: nsString mName; + nsString mAddress; + PRUint16 mStyle; + nsString mTransport; nsCOMPtr mDocumentationElement; - nsSupportsArray mPorts; }; class nsWSDLPort : public nsIWSDLPort { public: - nsWSDLPort(); + nsWSDLPort(const nsAReadableString &aName); virtual ~nsWSDLPort(); NS_DECL_ISUPPORTS NS_DECL_NSIWSDLPORT - NS_IMETHOD SetName(const nsAReadableString& aName); NS_IMETHOD SetDocumentationElement(nsIDOMElement* aElement); - NS_IMETHOD SetBindingInfo(const nsAReadableString& aBindingName, - PRUint16 aStyle, - const nsAReadableString& aTransport); NS_IMETHOD AddOperation(nsIWSDLOperation* aOperation); + NS_IMETHOD SetBinding(nsIWSDLBinding* aBinding); protected: nsString mName; nsCOMPtr mDocumentationElement; - nsString mBindingName; - PRUint16 mStyle; - nsString mTransport; nsSupportsArray mOperations; + nsCOMPtr mBinding; +}; + +class nsSOAPOperationBinding : public nsISOAPOperationBinding { +public: + nsSOAPOperationBinding(); + virtual ~nsSOAPOperationBinding(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIWSDLBINDING + NS_DECL_NSISOAPOPERATIONBINDING + + NS_IMETHOD SetDocumentationElement(nsIDOMElement* aElement); + NS_IMETHOD SetStyle(PRUint16 aStyle); + NS_IMETHOD SetSoapAction(const nsAReadableString& aAction); + +protected: + PRUint16 mStyle; + nsString mSoapAction; + nsCOMPtr mDocumentationElement; }; class nsWSDLOperation : public nsIWSDLOperation { public: - nsWSDLOperation(); + nsWSDLOperation(const nsAReadableString &aName); virtual ~nsWSDLOperation(); NS_DECL_ISUPPORTS NS_DECL_NSIWSDLOPERATION - NS_IMETHOD SetName(const nsAReadableString& aName); NS_IMETHOD SetDocumentationElement(nsIDOMElement* aElement); - NS_IMETHOD SetBindingInfo(PRUint16 aStyle, - const nsAReadableString& aSoapAction); - NS_IMETHOD SetInputMessage(nsIWSDLMessage* aInputMessage); - NS_IMETHOD SetOutputMessage(nsIWSDLMessage* aOutputMessage); - NS_IMETHOD SetFaultMessage(nsIWSDLMessage* aFaultMessage); + NS_IMETHOD SetInput(nsIWSDLMessage* aInputMessage); + NS_IMETHOD SetOutput(nsIWSDLMessage* aOutputMessage); + NS_IMETHOD AddFault(nsIWSDLMessage* aFaultMessage); + NS_IMETHOD AddParameter(const nsAReadableString& aParameter); + NS_IMETHOD SetBinding(nsIWSDLBinding* aBinding); protected: nsString mName; nsCOMPtr mDocumentationElement; - PRUint16 mStyle; - nsString mSoapAction; nsCOMPtr mInputMessage; nsCOMPtr mOutputMessage; - nsCOMPtr mFaultMessage; + nsSupportsArray mFaultMessages; + nsStringArray mParameters; + nsCOMPtr mBinding; }; class nsWSDLMessage : public nsIWSDLMessage { public: - nsWSDLMessage(); + nsWSDLMessage(const nsAReadableString& aName); virtual ~nsWSDLMessage(); NS_DECL_ISUPPORTS NS_DECL_NSIWSDLMESSAGE - NS_IMETHOD SetName(const nsAReadableString& aName); NS_IMETHOD SetDocumentationElement(nsIDOMElement* aElement); - NS_IMETHOD SetBindingInfo(PRUint16 aLocation, PRUint16 aUse, - const nsAReadableString& aEncodingStyle, - const nsAReadableString& aNamespace); NS_IMETHOD AddPart(nsIWSDLPart* aPart); protected: nsString mName; nsCOMPtr mDocumentationElement; + nsSupportsArray mParts; +}; + +class nsSOAPPartBinding : public nsISOAPPartBinding { +public: + nsSOAPPartBinding(PRUint16 aLocation, PRUint16 aUse, + const nsAReadableString& aEncodingStyle, + const nsAReadableString& aNamespace); + virtual ~nsSOAPPartBinding(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIWSDLBINDING + NS_DECL_NSISOAPPARTBINDING + +protected: PRUint16 mLocation; PRUint16 mUse; nsString mEncodingStyle; - nsString mNamespace; - nsSupportsArray mParts; + nsString mNamespace; }; class nsWSDLPart : public nsIWSDLPart { public: - nsWSDLPart(); + nsWSDLPart(const nsAReadableString& aName); virtual ~nsWSDLPart(); NS_DECL_ISUPPORTS NS_DECL_NSIWSDLPART - NS_IMETHOD SetName(const nsAReadableString& aName); NS_IMETHOD SetTypeInfo(const nsAReadableString& aType, const nsAReadableString& aElementName, - nsIDOMElement* aSchema, - nsIDOMElement* aSchemaRoot); + nsISchemaComponent* aSchemaComponent); + NS_IMETHOD SetBinding(nsIWSDLBinding* aBinding); protected: nsString mName; nsString mType; nsString mElementName; - nsCOMPtr mSchema; - nsCOMPtr mSchemaRoot; + nsCOMPtr mSchemaComponent; + nsCOMPtr mBinding; }; + +#define NS_WSDLPORT_CID \ +{ /* c1dfb250-0c19-4339-8211-24eabc0103e5 */ \ + 0xc1dfb250, 0x0c19, 0x4339, \ + {0x82, 0x11, 0x24, 0xea, 0xbc, 0x01, 0x03, 0xe5}} + +#define NS_WSDLPORT_CONTRACTID \ +"@mozilla/xmlextras/wsdl/wsdlport;1" + +#define NS_WSDLOPERATION_CID \ +{ /* cf54bdf5-20de-45ef-b6c8-aa535007549a */ \ + 0xcf54bdf5, 0x20de, 0x45ef, \ + {0xb6, 0xc8, 0xaa, 0x53, 0x50, 0x07, 0x54, 0x9a}} + +#define NS_WSDLOPERATION_CONTRACTID \ +"@mozilla/xmlextras/wsdl/wsdloperation;1" + +#define NS_WSDLMESSAGE_CID \ +{ /* 36b26cab-3eed-4c7c-81ad-94c8b1eb9ebe */ \ + 0x36b26cab, 0x3eed, 0x4c7c, \ + {0x81, 0xad, 0x94, 0xc8, 0xb1, 0xeb, 0x9e, 0xbe}} + +#define NS_WSDLMESSAGE_CONTRACTID \ +"@mozilla/xmlextras/wsdl/wsdlmessage;1" + +#define NS_WSDLPART_CID \ +{ /* 1841ebe8-5bdc-4e79-bcf4-329785318491 */ \ + 0x1841ebe8, 0x5bdc, 0x4e79, \ + {0xbc, 0xf4, 0x32, 0x97, 0x85, 0x31, 0x84, 0x91}} + +#define NS_WSDLPART_CONTRACTID \ +"@mozilla/xmlextras/wsdl/wsdlpart;1" + +#define NS_SOAPPORTBINDING_CID \ +{ /* a9155950-e49d-4123-93b7-e263a3af2b32 */ \ + 0xa9155950, 0xe49d, 0x4123, \ + {0x93, 0xb7, 0xe2, 0x63, 0xa3, 0xaf, 0x2b, 0x32}} + +#define NS_SOAPPORTBINDING_CONTRACTID \ +"@mozilla/xmlextras/wsdl/soapportbinding;1" + +#define NS_SOAPOPERATIONBINDING_CID \ +{ /* f5230937-4af6-43fb-9766-1890896632b2 */ \ + 0xf5230937, 0x4af6, 0x43fb, \ + {0x97, 0x66, 0x18, 0x90, 0x89, 0x66, 0x32, 0xb2}} + +#define NS_SOAPOPERATIONBINDING_CONTRACTID \ +"@mozilla/xmlextras/wsdl/soapoperationbinding;1" + +#define NS_SOAPPARTBINDING_CID \ +{ /* b7698d5c-06cc-45fe-b6bc-88e32a9f970e */ \ + 0xb7698d5c, 0x06cc, 0x45fe, \ + {0xb6, 0xbc, 0x88, 0xe3, 0x2a, 0x9f, 0x97, 0x0e}} + +#define NS_SOAPPARTBINDING_CONTRACTID \ +"@mozilla/xmlextras/wsdl/soappartbinding;1" + #endif // __nsWSDLPrivate_h__