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.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications.
19 * Portions created by the Initial Developer are Copyright (C) 2001
20 * the Initial Developer. All Rights Reserved.
23 * Vidur Apparao <vidur@netscape.com> (original author)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsSchemaPrivate.h"
41 ////////////////////////////////////////////////////////////
43 // nsSchemaBuiltinType implementation
45 ////////////////////////////////////////////////////////////
46 nsSchemaBuiltinType::nsSchemaBuiltinType(PRUint16 aBuiltinType
)
47 : mBuiltinType(aBuiltinType
)
51 nsSchemaBuiltinType::~nsSchemaBuiltinType()
55 NS_IMPL_ISUPPORTS4_CI(nsSchemaBuiltinType
,
61 /* readonly attribute wstring targetNamespace; */
63 nsSchemaBuiltinType::GetTargetNamespace(nsAString
& aTargetNamespace
)
65 aTargetNamespace
.AssignLiteral(NS_SCHEMA_2001_NAMESPACE
);
70 /* void resolve (in nsIWebServiceErrorHandler aErrorHandler); */
72 nsSchemaBuiltinType::Resolve(nsIWebServiceErrorHandler
* aErrorHandler
)
78 NS_IMETHODIMP
nsSchemaBuiltinType::Clear()
83 /* readonly attribute wstring name; */
85 nsSchemaBuiltinType::GetName(nsAString
& aName
)
87 switch(mBuiltinType
) {
88 case BUILTIN_TYPE_ANYTYPE
:
89 aName
.AssignLiteral("anyType");
91 case BUILTIN_TYPE_STRING
:
92 aName
.AssignLiteral("string");
94 case BUILTIN_TYPE_NORMALIZED_STRING
:
95 aName
.AssignLiteral("normalizedString");
97 case BUILTIN_TYPE_TOKEN
:
98 aName
.AssignLiteral("token");
100 case BUILTIN_TYPE_BYTE
:
101 aName
.AssignLiteral("byte");
103 case BUILTIN_TYPE_UNSIGNEDBYTE
:
104 aName
.AssignLiteral("unsignedByte");
106 case BUILTIN_TYPE_BASE64BINARY
:
107 aName
.AssignLiteral("base64Binary");
109 case BUILTIN_TYPE_HEXBINARY
:
110 aName
.AssignLiteral("hexBinary");
112 case BUILTIN_TYPE_INTEGER
:
113 aName
.AssignLiteral("integer");
115 case BUILTIN_TYPE_POSITIVEINTEGER
:
116 aName
.AssignLiteral("positiveInteger");
118 case BUILTIN_TYPE_NEGATIVEINTEGER
:
119 aName
.AssignLiteral("negativeInteger");
121 case BUILTIN_TYPE_NONNEGATIVEINTEGER
:
122 aName
.AssignLiteral("nonNegativeInteger");
124 case BUILTIN_TYPE_NONPOSITIVEINTEGER
:
125 aName
.AssignLiteral("nonPositiveInteger");
127 case BUILTIN_TYPE_INT
:
128 aName
.AssignLiteral("int");
130 case BUILTIN_TYPE_UNSIGNEDINT
:
131 aName
.AssignLiteral("unsignedInt");
133 case BUILTIN_TYPE_LONG
:
134 aName
.AssignLiteral("long");
136 case BUILTIN_TYPE_UNSIGNEDLONG
:
137 aName
.AssignLiteral("unsignedLong");
139 case BUILTIN_TYPE_SHORT
:
140 aName
.AssignLiteral("short");
142 case BUILTIN_TYPE_UNSIGNEDSHORT
:
143 aName
.AssignLiteral("unsignedShort");
145 case BUILTIN_TYPE_DECIMAL
:
146 aName
.AssignLiteral("decimal");
148 case BUILTIN_TYPE_FLOAT
:
149 aName
.AssignLiteral("float");
151 case BUILTIN_TYPE_DOUBLE
:
152 aName
.AssignLiteral("double");
154 case BUILTIN_TYPE_BOOLEAN
:
155 aName
.AssignLiteral("boolean");
157 case BUILTIN_TYPE_TIME
:
158 aName
.AssignLiteral("time");
160 case BUILTIN_TYPE_DATETIME
:
161 aName
.AssignLiteral("dateTime");
163 case BUILTIN_TYPE_DURATION
:
164 aName
.AssignLiteral("duration");
166 case BUILTIN_TYPE_DATE
:
167 aName
.AssignLiteral("date");
169 case BUILTIN_TYPE_GMONTH
:
170 aName
.AssignLiteral("gMonth");
172 case BUILTIN_TYPE_GYEAR
:
173 aName
.AssignLiteral("gYear");
175 case BUILTIN_TYPE_GYEARMONTH
:
176 aName
.AssignLiteral("gYearMonth");
178 case BUILTIN_TYPE_GDAY
:
179 aName
.AssignLiteral("gDay");
181 case BUILTIN_TYPE_GMONTHDAY
:
182 aName
.AssignLiteral("gMonthDay");
184 case BUILTIN_TYPE_NAME
:
185 aName
.AssignLiteral("Name");
187 case BUILTIN_TYPE_QNAME
:
188 aName
.AssignLiteral("QName");
190 case BUILTIN_TYPE_NCNAME
:
191 aName
.AssignLiteral("NCName");
193 case BUILTIN_TYPE_ANYURI
:
194 aName
.AssignLiteral("anyURI");
196 case BUILTIN_TYPE_LANGUAGE
:
197 aName
.AssignLiteral("language");
199 case BUILTIN_TYPE_ID
:
200 aName
.AssignLiteral("ID");
202 case BUILTIN_TYPE_IDREF
:
203 aName
.AssignLiteral("IDREF");
205 case BUILTIN_TYPE_IDREFS
:
206 aName
.AssignLiteral("IDREFS");
208 case BUILTIN_TYPE_ENTITY
:
209 aName
.AssignLiteral("ENTITY");
211 case BUILTIN_TYPE_ENTITIES
:
212 aName
.AssignLiteral("ENTITIES");
214 case BUILTIN_TYPE_NOTATION
:
215 aName
.AssignLiteral("NOTATION");
217 case BUILTIN_TYPE_NMTOKEN
:
218 aName
.AssignLiteral("NMTOKEN");
220 case BUILTIN_TYPE_NMTOKENS
:
221 aName
.AssignLiteral("NMTOKENS");
224 NS_ERROR("Unknown builtin type!");
231 /* readonly attribute unsigned short schemaType; */
233 nsSchemaBuiltinType::GetSchemaType(PRUint16
*aSchemaType
)
235 NS_ENSURE_ARG_POINTER(aSchemaType
);
237 *aSchemaType
= nsISchemaType::SCHEMA_TYPE_SIMPLE
;
242 /* readonly attribute unsigned short simpleType; */
244 nsSchemaBuiltinType::GetSimpleType(PRUint16
*aSimpleType
)
246 NS_ENSURE_ARG_POINTER(aSimpleType
);
248 *aSimpleType
= nsISchemaSimpleType::SIMPLE_TYPE_BUILTIN
;
253 /* readonly attribute unsigned short builtinType; */
255 nsSchemaBuiltinType::GetBuiltinType(PRUint16
*aBuiltinType
)
257 NS_ENSURE_ARG_POINTER(aBuiltinType
);
259 *aBuiltinType
= mBuiltinType
;
264 ////////////////////////////////////////////////////////////
266 // nsSchemaListType implementation
268 ////////////////////////////////////////////////////////////
269 nsSchemaListType::nsSchemaListType(nsSchema
* aSchema
,
270 const nsAString
& aName
)
271 : nsSchemaComponentBase(aSchema
), mName(aName
)
275 nsSchemaListType::~nsSchemaListType()
279 NS_IMPL_ISUPPORTS4_CI(nsSchemaListType
,
285 /* void resolve (in nsIWebServiceErrorHandler aErrorHandler); */
287 nsSchemaListType::Resolve(nsIWebServiceErrorHandler
* aErrorHandler
)
294 mIsResolved
= PR_TRUE
;
295 if (mListType
&& mSchema
) {
296 nsCOMPtr
<nsISchemaType
> type
;
297 rv
= mSchema
->ResolveTypePlaceholder(aErrorHandler
, mListType
, getter_AddRefs(type
));
299 return NS_ERROR_FAILURE
;
301 mListType
= do_QueryInterface(type
);
303 return NS_ERROR_FAILURE
;
306 rv
= mListType
->Resolve(aErrorHandler
);
313 nsSchemaListType::Clear()
319 mIsCleared
= PR_TRUE
;
328 /* readonly attribute wstring name; */
330 nsSchemaListType::GetName(nsAString
& aName
)
337 /* readonly attribute unsigned short schemaType; */
339 nsSchemaListType::GetSchemaType(PRUint16
*aSchemaType
)
341 NS_ENSURE_ARG_POINTER(aSchemaType
);
343 *aSchemaType
= nsISchemaType::SCHEMA_TYPE_SIMPLE
;
348 /* readonly attribute unsigned short simpleType; */
350 nsSchemaListType::GetSimpleType(PRUint16
*aSimpleType
)
352 NS_ENSURE_ARG_POINTER(aSimpleType
);
354 *aSimpleType
= nsISchemaSimpleType::SIMPLE_TYPE_LIST
;
359 /* readonly attribute nsISchemaSimpleType listType; */
361 nsSchemaListType::GetListType(nsISchemaSimpleType
* *aListType
)
363 NS_ENSURE_ARG_POINTER(aListType
);
365 NS_IF_ADDREF(*aListType
= mListType
);
371 nsSchemaListType::SetListType(nsISchemaSimpleType
* aListType
)
373 mListType
= aListType
;
378 ////////////////////////////////////////////////////////////
380 // nsSchemaUnionType implementation
382 ////////////////////////////////////////////////////////////
383 nsSchemaUnionType::nsSchemaUnionType(nsSchema
* aSchema
,
384 const nsAString
& aName
)
385 : nsSchemaComponentBase(aSchema
), mName(aName
)
389 nsSchemaUnionType::~nsSchemaUnionType()
393 NS_IMPL_ISUPPORTS4_CI(nsSchemaUnionType
,
399 /* void resolve (in nsIWebServiceErrorHandler aErrorHandler); */
401 nsSchemaUnionType::Resolve(nsIWebServiceErrorHandler
* aErrorHandler
)
407 mIsResolved
= PR_TRUE
;
410 count
= mUnionTypes
.Count();
411 for (i
= 0; i
< count
; ++i
) {
412 nsCOMPtr
<nsISchemaType
> type
;
413 nsresult rv
= mSchema
->ResolveTypePlaceholder(aErrorHandler
, mUnionTypes
.ObjectAt(i
),
414 getter_AddRefs(type
));
416 return NS_ERROR_FAILURE
;
418 nsCOMPtr
<nsISchemaSimpleType
> simpleType
= do_QueryInterface(type
);
419 mUnionTypes
.ReplaceObjectAt(simpleType
, i
);
420 rv
= type
->Resolve(aErrorHandler
);
432 nsSchemaUnionType::Clear()
438 mIsCleared
= PR_TRUE
;
440 count
= mUnionTypes
.Count();
441 for (i
= 0; i
< count
; ++i
) {
442 mUnionTypes
.ObjectAt(i
)->Clear();
449 /* readonly attribute wstring name; */
451 nsSchemaUnionType::GetName(nsAString
& aName
)
458 /* readonly attribute unsigned short schemaType; */
460 nsSchemaUnionType::GetSchemaType(PRUint16
*aSchemaType
)
462 NS_ENSURE_ARG_POINTER(aSchemaType
);
464 *aSchemaType
= nsISchemaType::SCHEMA_TYPE_SIMPLE
;
469 /* readonly attribute unsigned short simpleType; */
471 nsSchemaUnionType::GetSimpleType(PRUint16
*aSimpleType
)
473 NS_ENSURE_ARG_POINTER(aSimpleType
);
475 *aSimpleType
= nsISchemaSimpleType::SIMPLE_TYPE_UNION
;
480 /* readonly attribute PRUint32 unionTypeCount; */
482 nsSchemaUnionType::GetUnionTypeCount(PRUint32
*aUnionTypeCount
)
484 NS_ENSURE_ARG_POINTER(aUnionTypeCount
);
486 *aUnionTypeCount
= mUnionTypes
.Count();
491 /* nsISchemaSimpleType getUnionType (in PRUint32 index); */
493 nsSchemaUnionType::GetUnionType(PRUint32 aIndex
, nsISchemaSimpleType
** aResult
)
495 NS_ENSURE_ARG_POINTER(aResult
);
497 if (aIndex
>= (PRUint32
)mUnionTypes
.Count()) {
498 return NS_ERROR_FAILURE
;
501 NS_ADDREF(*aResult
= mUnionTypes
.ObjectAt(aIndex
));
507 nsSchemaUnionType::AddUnionType(nsISchemaSimpleType
* aType
)
509 NS_ENSURE_ARG(aType
);
511 return mUnionTypes
.AppendObject(aType
) ? NS_OK
: NS_ERROR_OUT_OF_MEMORY
;
514 ////////////////////////////////////////////////////////////
516 // nsSchemaRestrictionType implementation
518 ////////////////////////////////////////////////////////////
519 nsSchemaRestrictionType::nsSchemaRestrictionType(nsSchema
* aSchema
,
520 const nsAString
& aName
)
521 : nsSchemaComponentBase(aSchema
), mName(aName
)
525 nsSchemaRestrictionType::~nsSchemaRestrictionType()
529 NS_IMPL_ISUPPORTS4_CI(nsSchemaRestrictionType
,
533 nsISchemaRestrictionType
)
535 /* void resolve (in nsIWebServiceErrorHandler aErrorHandler); */
537 nsSchemaRestrictionType::Resolve(nsIWebServiceErrorHandler
* aErrorHandler
)
544 mIsResolved
= PR_TRUE
;
545 if (mBaseType
&& mSchema
) {
546 nsCOMPtr
<nsISchemaType
> type
;
547 rv
= mSchema
->ResolveTypePlaceholder(aErrorHandler
, mBaseType
, getter_AddRefs(type
));
549 return NS_ERROR_FAILURE
;
551 mBaseType
= do_QueryInterface(type
);
553 return NS_ERROR_FAILURE
;
555 rv
= mBaseType
->Resolve(aErrorHandler
);
563 nsSchemaRestrictionType::Clear()
569 mIsCleared
= PR_TRUE
;
576 count
= mFacets
.Count();
577 for (i
= 0; i
< count
; ++i
) {
578 mFacets
.ObjectAt(i
)->Clear();
585 /* readonly attribute wstring name; */
587 nsSchemaRestrictionType::GetName(nsAString
& aName
)
594 /* readonly attribute unsigned short schemaType; */
596 nsSchemaRestrictionType::GetSchemaType(PRUint16
*aSchemaType
)
598 NS_ENSURE_ARG_POINTER(aSchemaType
);
600 *aSchemaType
= nsISchemaType::SCHEMA_TYPE_SIMPLE
;
605 /* readonly attribute unsigned short simpleType; */
607 nsSchemaRestrictionType::GetSimpleType(PRUint16
*aSimpleType
)
609 NS_ENSURE_ARG_POINTER(aSimpleType
);
611 *aSimpleType
= nsISchemaSimpleType::SIMPLE_TYPE_RESTRICTION
;
616 /* readonly attribute nsISchemaSimpleType baseType; */
618 nsSchemaRestrictionType::GetBaseType(nsISchemaSimpleType
* *aBaseType
)
620 NS_ENSURE_ARG_POINTER(aBaseType
);
622 NS_IF_ADDREF(*aBaseType
= mBaseType
);
627 /* readonly attribute PRUint32 facetCount; */
629 nsSchemaRestrictionType::GetFacetCount(PRUint32
*aFacetCount
)
631 NS_ENSURE_ARG_POINTER(aFacetCount
);
633 *aFacetCount
= mFacets
.Count();
638 /* nsISchemaFacet getFacet(in PRUint32 index); */
640 nsSchemaRestrictionType::GetFacet(PRUint32 aIndex
, nsISchemaFacet
** aResult
)
642 NS_ENSURE_ARG_POINTER(aResult
);
644 if (aIndex
>= (PRUint32
)mFacets
.Count()) {
645 return NS_ERROR_FAILURE
;
648 NS_ADDREF(*aResult
= mFacets
.ObjectAt(aIndex
));
654 nsSchemaRestrictionType::SetBaseType(nsISchemaSimpleType
* aBaseType
)
656 NS_ENSURE_ARG(aBaseType
);
658 mBaseType
= aBaseType
;
664 nsSchemaRestrictionType::AddFacet(nsISchemaFacet
* aFacet
)
666 NS_ENSURE_ARG(aFacet
);
668 return mFacets
.AppendObject(aFacet
) ? NS_OK
: NS_ERROR_OUT_OF_MEMORY
;
671 ////////////////////////////////////////////////////////////
673 // nsSchemaTypePlaceholder implementation
675 ////////////////////////////////////////////////////////////
676 nsSchemaTypePlaceholder::nsSchemaTypePlaceholder(nsSchema
* aSchema
,
677 const nsAString
& aName
)
678 : nsSchemaComponentBase(aSchema
), mName(aName
)
682 nsSchemaTypePlaceholder::~nsSchemaTypePlaceholder()
686 NS_IMPL_ISUPPORTS3_CI(nsSchemaTypePlaceholder
,
692 /* void resolve (in nsIWebServiceErrorHandler aErrorHandler); */
694 nsSchemaTypePlaceholder::Resolve(nsIWebServiceErrorHandler
* aErrorHandler
)
701 nsSchemaTypePlaceholder::Clear()
706 /* readonly attribute wstring name; */
708 nsSchemaTypePlaceholder::GetName(nsAString
& aName
)
715 /* readonly attribute unsigned short schemaType; */
717 nsSchemaTypePlaceholder::GetSchemaType(PRUint16
*aSchemaType
)
719 NS_ENSURE_ARG_POINTER(aSchemaType
);
721 *aSchemaType
= nsISchemaType::SCHEMA_TYPE_PLACEHOLDER
;
726 /* readonly attribute unsigned short simpleType; */
728 nsSchemaTypePlaceholder::GetSimpleType(PRUint16
*aSimpleType
)
730 return NS_ERROR_FAILURE
;
734 ////////////////////////////////////////////////////////////
736 // nsSchemaFacet implementation
738 ////////////////////////////////////////////////////////////
739 nsSchemaFacet::nsSchemaFacet(nsSchema
* aSchema
)
740 : nsSchemaComponentBase(aSchema
), mIsFixed(PR_FALSE
)
744 nsSchemaFacet::~nsSchemaFacet()
748 NS_IMPL_ISUPPORTS2_CI(nsSchemaFacet
,
752 /* void resolve (in nsIWebServiceErrorHandler aErrorHandler); */
754 nsSchemaFacet::Resolve(nsIWebServiceErrorHandler
* aErrorHandler
)
761 nsSchemaFacet::Clear()
767 nsSchemaFacet::SetFacetType(PRUint16 aFacetType
)
769 mFacetType
= aFacetType
;
775 nsSchemaFacet::SetIsFixed(PRBool aIsFixed
)
782 /* readonly attribute unsigned short facetType; */
784 nsSchemaFacet::GetFacetType(PRUint16
*aFacetType
)
786 NS_ENSURE_ARG_POINTER(aFacetType
);
788 *aFacetType
= mFacetType
;
793 /* readonly attribute AString value; */
795 nsSchemaFacet::GetValue(nsAString
& aValue
)
797 if ((mFacetType
== FACET_TYPE_TOTALDIGITS
) ||
798 (mFacetType
== FACET_TYPE_FRACTIONDIGITS
) ||
799 (mFacetType
== FACET_TYPE_WHITESPACE
) ||
800 (mFacetType
== FACET_TYPE_LENGTH
) ||
801 (mFacetType
== FACET_TYPE_MINLENGTH
) ||
802 (mFacetType
== FACET_TYPE_MAXLENGTH
)) {
803 return NS_ERROR_ILLEGAL_VALUE
;
806 aValue
.Assign(mStrValue
);
811 /* readonly attribute PRUint32 lengthValue; */
813 nsSchemaFacet::GetLengthValue(PRUint32
*aLengthValue
)
815 NS_ENSURE_ARG_POINTER(aLengthValue
);
817 if ((mFacetType
!= FACET_TYPE_LENGTH
) &&
818 (mFacetType
!= FACET_TYPE_MINLENGTH
) &&
819 (mFacetType
!= FACET_TYPE_MAXLENGTH
)) {
820 return NS_ERROR_ILLEGAL_VALUE
;
823 *aLengthValue
= mUintValue
;
828 /* readonly attribute PRUint32 digitsValue; */
830 nsSchemaFacet::GetDigitsValue(PRUint32
*aDigitsValue
)
832 NS_ENSURE_ARG_POINTER(aDigitsValue
);
834 if ((mFacetType
!= FACET_TYPE_TOTALDIGITS
) &&
835 (mFacetType
!= FACET_TYPE_FRACTIONDIGITS
)) {
836 return NS_ERROR_ILLEGAL_VALUE
;
839 *aDigitsValue
= mUintValue
;
844 /* readonly attribute unsigned short whitespaceValue; */
846 nsSchemaFacet::GetWhitespaceValue(PRUint16
*aWhitespaceValue
)
848 NS_ENSURE_ARG_POINTER(aWhitespaceValue
);
850 if (mFacetType
!= FACET_TYPE_WHITESPACE
) {
851 return NS_ERROR_ILLEGAL_VALUE
;
854 *aWhitespaceValue
= mWhitespaceValue
;
859 /* readonly attribute boolean isfixed; */
861 nsSchemaFacet::GetIsfixed(PRBool
*aIsFixed
)
863 NS_ENSURE_ARG_POINTER(aIsFixed
);
865 *aIsFixed
= mIsFixed
;
871 nsSchemaFacet::SetValue(const nsAString
& aStrValue
)
873 mStrValue
.Assign(aStrValue
);
879 nsSchemaFacet::SetUintValue(PRUint32 aUintValue
)
881 mUintValue
= aUintValue
;
887 nsSchemaFacet::SetWhitespaceValue(PRUint16 aWhitespaceValue
)
889 mWhitespaceValue
= aWhitespaceValue
;