1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2001
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 #include "nsReadableUtils.h"
40 #include "nsSOAPBlock.h"
41 #include "nsSOAPUtils.h"
42 #include "nsIServiceManager.h"
43 #include "nsISOAPAttachments.h"
44 #include "nsISOAPMessage.h"
45 #include "nsSOAPException.h"
47 nsSOAPBlock::nsSOAPBlock()
51 nsSOAPBlock::~nsSOAPBlock()
55 NS_IMPL_ISUPPORTS2(nsSOAPBlock
, nsISOAPBlock
, nsIJSNativeInitializer
)
56 NS_IMETHODIMP
nsSOAPBlock::Init(nsISOAPAttachments
* aAttachments
,
59 if (aVersion
== nsISOAPMessage::VERSION_1_1
60 || aVersion
== nsISOAPMessage::VERSION_1_2
) {
61 mAttachments
= aAttachments
;
65 return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE
,"SOAP_BAD_VERSION", "Bad version used to initialize block.");
68 /* attribute AString namespaceURI; */
69 NS_IMETHODIMP
nsSOAPBlock::GetNamespaceURI(nsAString
& aNamespaceURI
)
74 nsresult rc
= mElement
->GetNamespaceURI(temp
);
77 return mEncoding
->GetInternalSchemaURI(temp
, aNamespaceURI
);
79 return mElement
->GetNamespaceURI(aNamespaceURI
);
81 aNamespaceURI
.Assign(mNamespaceURI
);
86 NS_IMETHODIMP
nsSOAPBlock::SetNamespaceURI(const nsAString
& aNamespaceURI
)
88 nsresult rc
= SetElement(nsnull
);
91 mNamespaceURI
.Assign(aNamespaceURI
);
95 /* attribute AString name; */
96 NS_IMETHODIMP
nsSOAPBlock::GetName(nsAString
& aName
)
99 return mElement
->GetLocalName(aName
);
106 NS_IMETHODIMP
nsSOAPBlock::SetName(const nsAString
& aName
)
108 nsresult rc
= SetElement(nsnull
);
115 /* attribute nsISOAPEncoding encoding; */
116 NS_IMETHODIMP
nsSOAPBlock::GetEncoding(nsISOAPEncoding
* *aEncoding
)
118 NS_ENSURE_ARG_POINTER(aEncoding
);
119 *aEncoding
= mEncoding
;
120 NS_IF_ADDREF(*aEncoding
);
124 NS_IMETHODIMP
nsSOAPBlock::SetEncoding(nsISOAPEncoding
* aEncoding
)
126 mEncoding
= aEncoding
;
127 mComputeValue
= PR_TRUE
;
131 /* attribute nsISchemaType schemaType; */
132 NS_IMETHODIMP
nsSOAPBlock::GetSchemaType(nsISchemaType
* *aSchemaType
)
134 NS_ENSURE_ARG_POINTER(aSchemaType
);
135 *aSchemaType
= mSchemaType
;
136 NS_IF_ADDREF(*aSchemaType
);
140 NS_IMETHODIMP
nsSOAPBlock::SetSchemaType(nsISchemaType
* aSchemaType
)
142 mSchemaType
= aSchemaType
;
143 mComputeValue
= PR_TRUE
;
147 /* attribute nsIDOMElement element; */
148 NS_IMETHODIMP
nsSOAPBlock::GetElement(nsIDOMElement
* *aElement
)
150 NS_ENSURE_ARG_POINTER(aElement
);
151 *aElement
= mElement
;
152 NS_IF_ADDREF(*aElement
);
156 NS_IMETHODIMP
nsSOAPBlock::SetElement(nsIDOMElement
* aElement
)
159 mComputeValue
= PR_TRUE
;
163 /* attribute nsIVariant value; */
164 NS_IMETHODIMP
nsSOAPBlock::GetValue(nsIVariant
* *aValue
)
166 NS_ENSURE_ARG_POINTER(aValue
);
167 if (mElement
) { // Check for auto-computation
169 mComputeValue
= PR_FALSE
;
172 mEncoding
->Decode(mElement
, mSchemaType
, mAttachments
,
173 getter_AddRefs(mValue
));
175 mStatus
= SOAP_EXCEPTION(NS_ERROR_NOT_INITIALIZED
,"SOAP_NO_ENCODING","No encoding found to decode block.");
180 NS_IF_ADDREF(*aValue
);
181 return mElement
? mStatus
: NS_OK
;
184 NS_IMETHODIMP
nsSOAPBlock::SetValue(nsIVariant
* aValue
)
186 nsresult rc
= SetElement(nsnull
);
194 nsSOAPBlock::Initialize(nsISupports
* aOwner
, JSContext
* cx
,
195 JSObject
* obj
, PRUint32 argc
, jsval
* argv
)
198 // Get the arguments.
202 nsAutoString namespaceURI
;
203 nsIVariant
* s1
= nsnull
;
204 nsISupports
* s2
= nsnull
;
205 nsISupports
* s3
= nsnull
;
207 if (!JS_ConvertArguments(cx
, argc
, argv
, "/%iv %is %is %ip %ip",
209 static_cast<nsAString
*>(&name
),
210 static_cast<nsAString
*>(&namespaceURI
),
213 return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE
,"SOAP_BLOCK_INIT", "Could not interpret block initialization arguments.");
215 nsCOMPtr
<nsIVariant
> value
= dont_AddRef(s1
);
216 nsCOMPtr
<nsISupports
> schemaType
= dont_AddRef(s2
);
217 nsCOMPtr
<nsISupports
> encoding
= dont_AddRef(s3
);
219 nsresult rc
= SetValue(value
);
225 rc
= SetNamespaceURI(namespaceURI
);
229 nsCOMPtr
<nsISchemaType
> v
= do_QueryInterface(schemaType
, &rc
);
232 rc
= SetSchemaType(v
);
237 nsCOMPtr
<nsISOAPEncoding
> v
= do_QueryInterface(encoding
, &rc
);