Back to index

lightning-sunbird  0.9+nobinonly
nsSchemaSimpleTypes.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Vidur Apparao <vidur@netscape.com> (original author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsSchemaPrivate.h"
00040 
00042 //
00043 // nsSchemaBuiltinType implementation
00044 //
00046 nsSchemaBuiltinType::nsSchemaBuiltinType(PRUint16 aBuiltinType)
00047   : mBuiltinType(aBuiltinType)
00048 {
00049 }
00050 
00051 nsSchemaBuiltinType::~nsSchemaBuiltinType()
00052 {
00053 }
00054 
00055 NS_IMPL_ISUPPORTS4_CI(nsSchemaBuiltinType, 
00056                       nsISchemaComponent,
00057                       nsISchemaType,
00058                       nsISchemaSimpleType,
00059                       nsISchemaBuiltinType)
00060 
00061 /* readonly attribute wstring targetNamespace; */
00062 NS_IMETHODIMP
00063 nsSchemaBuiltinType::GetTargetNamespace(nsAString& aTargetNamespace)
00064 {
00065   aTargetNamespace.AssignLiteral(NS_SCHEMA_2001_NAMESPACE);
00066   
00067   return NS_OK;
00068 }
00069 
00070 /* void resolve (in nsIWebServiceErrorHandler aErrorHandler); */
00071 NS_IMETHODIMP
00072 nsSchemaBuiltinType::Resolve(nsIWebServiceErrorHandler* aErrorHandler)
00073 {
00074   return NS_OK;
00075 }
00076 
00077 /* void clear (); */
00078 NS_IMETHODIMP nsSchemaBuiltinType::Clear()
00079 {
00080   return NS_OK;
00081 }
00082 
00083 /* readonly attribute wstring name; */
00084 NS_IMETHODIMP
00085 nsSchemaBuiltinType::GetName(nsAString& aName)
00086 {
00087   switch(mBuiltinType) {
00088     case BUILTIN_TYPE_ANYTYPE:
00089       aName.AssignLiteral("anyType");
00090       break;
00091     case BUILTIN_TYPE_STRING:
00092       aName.AssignLiteral("string");
00093       break;
00094     case BUILTIN_TYPE_NORMALIZED_STRING:
00095       aName.AssignLiteral("normalizedString");
00096       break;
00097     case BUILTIN_TYPE_TOKEN:
00098       aName.AssignLiteral("token");
00099       break;
00100     case BUILTIN_TYPE_BYTE:
00101       aName.AssignLiteral("byte");
00102       break;
00103     case BUILTIN_TYPE_UNSIGNEDBYTE:
00104       aName.AssignLiteral("unsignedByte");
00105       break;
00106     case BUILTIN_TYPE_BASE64BINARY:
00107       aName.AssignLiteral("base64Binary");
00108       break;
00109     case BUILTIN_TYPE_HEXBINARY:
00110       aName.AssignLiteral("hexBinary");
00111       break;
00112     case BUILTIN_TYPE_INTEGER:
00113       aName.AssignLiteral("integer");
00114       break;
00115     case BUILTIN_TYPE_POSITIVEINTEGER:
00116       aName.AssignLiteral("positiveInteger");
00117       break;
00118     case BUILTIN_TYPE_NEGATIVEINTEGER:
00119       aName.AssignLiteral("negativeInteger");
00120       break;
00121     case BUILTIN_TYPE_NONNEGATIVEINTEGER:
00122       aName.AssignLiteral("nonNegativeInteger");
00123       break;
00124     case BUILTIN_TYPE_NONPOSITIVEINTEGER:
00125       aName.AssignLiteral("nonPositiveInteger");
00126       break;
00127     case BUILTIN_TYPE_INT:
00128       aName.AssignLiteral("int");
00129       break;
00130     case BUILTIN_TYPE_UNSIGNEDINT:
00131       aName.AssignLiteral("unsignedInt");
00132       break;
00133     case BUILTIN_TYPE_LONG:
00134       aName.AssignLiteral("long");
00135       break;
00136     case BUILTIN_TYPE_UNSIGNEDLONG:
00137       aName.AssignLiteral("unsignedLong");
00138       break;
00139     case BUILTIN_TYPE_SHORT:
00140       aName.AssignLiteral("short");
00141       break;
00142     case BUILTIN_TYPE_UNSIGNEDSHORT:
00143       aName.AssignLiteral("unsignedShort");
00144       break;
00145     case BUILTIN_TYPE_DECIMAL:
00146       aName.AssignLiteral("decimal");
00147       break;
00148     case BUILTIN_TYPE_FLOAT:
00149       aName.AssignLiteral("float");
00150       break;
00151     case BUILTIN_TYPE_DOUBLE:
00152       aName.AssignLiteral("double");
00153       break;
00154     case BUILTIN_TYPE_BOOLEAN:
00155       aName.AssignLiteral("boolean");
00156       break;
00157     case BUILTIN_TYPE_TIME:
00158       aName.AssignLiteral("time");
00159       break;
00160     case BUILTIN_TYPE_DATETIME:
00161       aName.AssignLiteral("dateTime");
00162       break;
00163     case BUILTIN_TYPE_DURATION:
00164       aName.AssignLiteral("duration");
00165       break;
00166     case BUILTIN_TYPE_DATE:
00167       aName.AssignLiteral("date");
00168       break;
00169     case BUILTIN_TYPE_GMONTH:
00170       aName.AssignLiteral("gMonth");
00171       break;
00172     case BUILTIN_TYPE_GYEAR:
00173       aName.AssignLiteral("gYear");
00174       break;
00175     case BUILTIN_TYPE_GYEARMONTH:
00176       aName.AssignLiteral("gYearMonth");
00177       break;
00178     case BUILTIN_TYPE_GDAY:
00179       aName.AssignLiteral("gDay");
00180       break;
00181     case BUILTIN_TYPE_GMONTHDAY:
00182       aName.AssignLiteral("gMonthDay");
00183       break;
00184     case BUILTIN_TYPE_NAME:
00185       aName.AssignLiteral("Name");
00186       break;
00187     case BUILTIN_TYPE_QNAME:
00188       aName.AssignLiteral("QName");
00189       break;
00190     case BUILTIN_TYPE_NCNAME:
00191       aName.AssignLiteral("NCName");
00192       break;
00193     case BUILTIN_TYPE_ANYURI:
00194       aName.AssignLiteral("anyURI");
00195       break;
00196     case BUILTIN_TYPE_LANGUAGE:
00197       aName.AssignLiteral("language");
00198       break;
00199     case BUILTIN_TYPE_ID:
00200       aName.AssignLiteral("ID");
00201       break;
00202     case BUILTIN_TYPE_IDREF:
00203       aName.AssignLiteral("IDREF");
00204       break;
00205     case BUILTIN_TYPE_IDREFS:
00206       aName.AssignLiteral("IDREFS");
00207       break;
00208     case BUILTIN_TYPE_ENTITY:
00209       aName.AssignLiteral("ENTITY");
00210       break;
00211     case BUILTIN_TYPE_ENTITIES:
00212       aName.AssignLiteral("ENTITIES");
00213       break;
00214     case BUILTIN_TYPE_NOTATION:
00215       aName.AssignLiteral("NOTATION");
00216       break;
00217     case BUILTIN_TYPE_NMTOKEN:
00218       aName.AssignLiteral("NMTOKEN");
00219       break;
00220     case BUILTIN_TYPE_NMTOKENS:
00221       aName.AssignLiteral("NMTOKENS");
00222       break;
00223     default:
00224       NS_ERROR("Unknown builtin type!");
00225       aName.Truncate();
00226   }
00227 
00228   return NS_OK;
00229 }
00230 
00231 /* readonly attribute unsigned short schemaType; */
00232 NS_IMETHODIMP
00233 nsSchemaBuiltinType::GetSchemaType(PRUint16 *aSchemaType)
00234 {
00235   NS_ENSURE_ARG_POINTER(aSchemaType);
00236 
00237   *aSchemaType = nsISchemaType::SCHEMA_TYPE_SIMPLE;
00238 
00239   return NS_OK;
00240 }
00241 
00242 /* readonly attribute unsigned short simpleType; */
00243 NS_IMETHODIMP
00244 nsSchemaBuiltinType::GetSimpleType(PRUint16 *aSimpleType)
00245 {
00246   NS_ENSURE_ARG_POINTER(aSimpleType);
00247 
00248   *aSimpleType = nsISchemaSimpleType::SIMPLE_TYPE_BUILTIN;
00249 
00250   return NS_OK;
00251 }
00252 
00253 /* readonly attribute unsigned short builtinType; */
00254 NS_IMETHODIMP
00255 nsSchemaBuiltinType::GetBuiltinType(PRUint16 *aBuiltinType)
00256 {
00257   NS_ENSURE_ARG_POINTER(aBuiltinType);
00258   
00259   *aBuiltinType = mBuiltinType;
00260 
00261   return NS_OK;
00262 }
00263 
00265 //
00266 // nsSchemaListType implementation
00267 //
00269 nsSchemaListType::nsSchemaListType(nsSchema* aSchema, 
00270                                    const nsAString& aName)
00271   : nsSchemaComponentBase(aSchema), mName(aName)
00272 {
00273 }
00274 
00275 nsSchemaListType::~nsSchemaListType()
00276 {
00277 }
00278 
00279 NS_IMPL_ISUPPORTS4_CI(nsSchemaListType, 
00280                       nsISchemaComponent,
00281                       nsISchemaType,
00282                       nsISchemaSimpleType,
00283                       nsISchemaListType)
00284 
00285 /* void resolve (in nsIWebServiceErrorHandler aErrorHandler); */
00286 NS_IMETHODIMP
00287 nsSchemaListType::Resolve(nsIWebServiceErrorHandler* aErrorHandler)
00288 {
00289   if (mIsResolved) {
00290     return NS_OK;
00291   }
00292 
00293   nsresult rv = NS_OK;
00294   mIsResolved = PR_TRUE;
00295   if (mListType && mSchema) {
00296     nsCOMPtr<nsISchemaType> type;
00297     rv = mSchema->ResolveTypePlaceholder(aErrorHandler, mListType, getter_AddRefs(type));
00298     if (NS_FAILED(rv)) {
00299       return NS_ERROR_FAILURE;
00300     }
00301     mListType = do_QueryInterface(type);
00302     if (!mListType) {
00303       return NS_ERROR_FAILURE;
00304     }
00305   }
00306   rv = mListType->Resolve(aErrorHandler);
00307 
00308   return rv;
00309 }
00310 
00311 /* void clear (); */
00312 NS_IMETHODIMP
00313 nsSchemaListType::Clear()
00314 {
00315   if (mIsCleared) {
00316     return NS_OK;
00317   }
00318 
00319   mIsCleared = PR_TRUE;
00320   if (mListType) {
00321     mListType->Clear();
00322     mListType = nsnull;
00323   }
00324 
00325   return NS_OK;
00326 }
00327 
00328 /* readonly attribute wstring name; */
00329 NS_IMETHODIMP
00330 nsSchemaListType::GetName(nsAString& aName)
00331 {
00332   aName.Assign(mName);
00333   
00334   return NS_OK;
00335 }
00336 
00337 /* readonly attribute unsigned short schemaType; */
00338 NS_IMETHODIMP
00339 nsSchemaListType::GetSchemaType(PRUint16 *aSchemaType)
00340 {
00341   NS_ENSURE_ARG_POINTER(aSchemaType);
00342 
00343   *aSchemaType = nsISchemaType::SCHEMA_TYPE_SIMPLE;
00344 
00345   return NS_OK;
00346 }
00347 
00348 /* readonly attribute unsigned short simpleType; */
00349 NS_IMETHODIMP
00350 nsSchemaListType::GetSimpleType(PRUint16 *aSimpleType)
00351 {
00352   NS_ENSURE_ARG_POINTER(aSimpleType);
00353 
00354   *aSimpleType = nsISchemaSimpleType::SIMPLE_TYPE_LIST;
00355 
00356   return NS_OK;
00357 }
00358 
00359 /* readonly attribute nsISchemaSimpleType listType; */
00360 NS_IMETHODIMP
00361 nsSchemaListType::GetListType(nsISchemaSimpleType * *aListType)
00362 {
00363   NS_ENSURE_ARG_POINTER(aListType);
00364 
00365   NS_IF_ADDREF(*aListType = mListType);
00366 
00367   return NS_OK;
00368 }
00369 
00370 NS_IMETHODIMP
00371 nsSchemaListType::SetListType(nsISchemaSimpleType* aListType)
00372 {
00373   mListType = aListType;
00374 
00375   return NS_OK;
00376 }
00377 
00379 //
00380 // nsSchemaUnionType implementation
00381 //
00383 nsSchemaUnionType::nsSchemaUnionType(nsSchema* aSchema, 
00384                                      const nsAString& aName)
00385   : nsSchemaComponentBase(aSchema), mName(aName)
00386 {
00387 }
00388 
00389 nsSchemaUnionType::~nsSchemaUnionType()
00390 {
00391 }
00392 
00393 NS_IMPL_ISUPPORTS4_CI(nsSchemaUnionType, 
00394                       nsISchemaComponent,
00395                       nsISchemaType,
00396                       nsISchemaSimpleType,
00397                       nsISchemaUnionType)
00398 
00399 /* void resolve (in nsIWebServiceErrorHandler aErrorHandler); */
00400 NS_IMETHODIMP
00401 nsSchemaUnionType::Resolve(nsIWebServiceErrorHandler* aErrorHandler)
00402 {
00403   if (mIsResolved) {
00404     return NS_OK;
00405   }
00406 
00407   mIsResolved = PR_TRUE;
00408   if (mSchema) {
00409     PRUint32 i, count;
00410     count = mUnionTypes.Count();
00411     for (i = 0; i < count; ++i) {
00412       nsCOMPtr<nsISchemaType> type;
00413       nsresult rv = mSchema->ResolveTypePlaceholder(aErrorHandler, mUnionTypes.ObjectAt(i),
00414                                                     getter_AddRefs(type));
00415       if (NS_FAILED(rv)) {
00416         return NS_ERROR_FAILURE;
00417       }
00418       nsCOMPtr<nsISchemaSimpleType> simpleType = do_QueryInterface(type);
00419       mUnionTypes.ReplaceObjectAt(simpleType, i);
00420       rv = type->Resolve(aErrorHandler);
00421       if (NS_FAILED(rv)) {
00422         return rv;
00423       }
00424     }
00425   }
00426 
00427   return NS_OK;
00428 }
00429 
00430 /* void clear (); */
00431 NS_IMETHODIMP
00432 nsSchemaUnionType::Clear()
00433 {
00434   if (mIsCleared) {
00435     return NS_OK;
00436   }
00437 
00438   mIsCleared = PR_TRUE;
00439   PRUint32 i, count;
00440   count = mUnionTypes.Count();
00441   for (i = 0; i < count; ++i) {
00442     mUnionTypes.ObjectAt(i)->Clear();
00443   }
00444   mUnionTypes.Clear();
00445 
00446   return NS_OK;
00447 }
00448 
00449 /* readonly attribute wstring name; */
00450 NS_IMETHODIMP
00451 nsSchemaUnionType::GetName(nsAString& aName)
00452 {
00453   aName.Assign(mName);
00454   
00455   return NS_OK;
00456 }
00457 
00458 /* readonly attribute unsigned short schemaType; */
00459 NS_IMETHODIMP
00460 nsSchemaUnionType::GetSchemaType(PRUint16 *aSchemaType)
00461 {
00462   NS_ENSURE_ARG_POINTER(aSchemaType);
00463 
00464   *aSchemaType = nsISchemaType::SCHEMA_TYPE_SIMPLE;
00465 
00466   return NS_OK;
00467 }
00468 
00469 /* readonly attribute unsigned short simpleType; */
00470 NS_IMETHODIMP
00471 nsSchemaUnionType::GetSimpleType(PRUint16 *aSimpleType)
00472 {
00473   NS_ENSURE_ARG_POINTER(aSimpleType);
00474 
00475   *aSimpleType = nsISchemaSimpleType::SIMPLE_TYPE_UNION;
00476 
00477   return NS_OK;
00478 }
00479 
00480 /* readonly attribute PRUint32 unionTypeCount; */
00481 NS_IMETHODIMP
00482 nsSchemaUnionType::GetUnionTypeCount(PRUint32 *aUnionTypeCount)
00483 {
00484   NS_ENSURE_ARG_POINTER(aUnionTypeCount);
00485 
00486   *aUnionTypeCount = mUnionTypes.Count();
00487 
00488   return NS_OK;
00489 }
00490 
00491 /* nsISchemaSimpleType getUnionType (in PRUint32 index); */
00492 NS_IMETHODIMP
00493 nsSchemaUnionType::GetUnionType(PRUint32 aIndex, nsISchemaSimpleType** aResult)
00494 {
00495   NS_ENSURE_ARG_POINTER(aResult);
00496 
00497   if (aIndex >= (PRUint32)mUnionTypes.Count()) {
00498     return NS_ERROR_FAILURE;
00499   }
00500 
00501   NS_ADDREF(*aResult = mUnionTypes.ObjectAt(aIndex));
00502 
00503   return NS_OK;
00504 }
00505 
00506 NS_IMETHODIMP
00507 nsSchemaUnionType::AddUnionType(nsISchemaSimpleType* aType)
00508 {
00509   NS_ENSURE_ARG(aType);
00510 
00511   return mUnionTypes.AppendObject(aType) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00512 }
00513 
00515 //
00516 // nsSchemaRestrictionType implementation
00517 //
00519 nsSchemaRestrictionType::nsSchemaRestrictionType(nsSchema* aSchema, 
00520                                                  const nsAString& aName)
00521   : nsSchemaComponentBase(aSchema), mName(aName)
00522 {
00523 }
00524 
00525 nsSchemaRestrictionType::~nsSchemaRestrictionType()
00526 {
00527 }
00528 
00529 NS_IMPL_ISUPPORTS4_CI(nsSchemaRestrictionType, 
00530                       nsISchemaComponent,
00531                       nsISchemaType,
00532                       nsISchemaSimpleType,
00533                       nsISchemaRestrictionType)
00534 
00535 /* void resolve (in nsIWebServiceErrorHandler aErrorHandler); */
00536 NS_IMETHODIMP
00537 nsSchemaRestrictionType::Resolve(nsIWebServiceErrorHandler* aErrorHandler)
00538 {
00539   if (mIsResolved) {
00540     return NS_OK;
00541   }
00542 
00543   nsresult rv = NS_OK;
00544   mIsResolved = PR_TRUE;
00545   if (mBaseType && mSchema) {
00546     nsCOMPtr<nsISchemaType> type;
00547     rv = mSchema->ResolveTypePlaceholder(aErrorHandler, mBaseType, getter_AddRefs(type));
00548     if (NS_FAILED(rv)) {
00549       return NS_ERROR_FAILURE;
00550     }
00551     mBaseType = do_QueryInterface(type);
00552     if (!mBaseType) {
00553       return NS_ERROR_FAILURE;
00554     }
00555     rv = mBaseType->Resolve(aErrorHandler);
00556   }
00557 
00558   return rv;
00559 }
00560 
00561 /* void clear (); */
00562 NS_IMETHODIMP
00563 nsSchemaRestrictionType::Clear()
00564 {
00565   if (mIsCleared) {
00566     return NS_OK;
00567   }
00568 
00569   mIsCleared = PR_TRUE;
00570   if (mBaseType) {
00571     mBaseType->Clear();
00572     mBaseType = nsnull;
00573   }
00574 
00575   PRUint32 i, count;
00576   count = mFacets.Count();
00577   for (i = 0; i < count; ++i) {
00578     mFacets.ObjectAt(i)->Clear();
00579   }
00580   mFacets.Clear();
00581 
00582   return NS_OK;
00583 }
00584 
00585 /* readonly attribute wstring name; */
00586 NS_IMETHODIMP
00587 nsSchemaRestrictionType::GetName(nsAString& aName)
00588 {
00589   aName.Assign(mName);
00590   
00591   return NS_OK;
00592 }
00593 
00594 /* readonly attribute unsigned short schemaType; */
00595 NS_IMETHODIMP
00596 nsSchemaRestrictionType::GetSchemaType(PRUint16 *aSchemaType)
00597 {
00598   NS_ENSURE_ARG_POINTER(aSchemaType);
00599 
00600   *aSchemaType = nsISchemaType::SCHEMA_TYPE_SIMPLE;
00601 
00602   return NS_OK;
00603 }
00604 
00605 /* readonly attribute unsigned short simpleType; */
00606 NS_IMETHODIMP
00607 nsSchemaRestrictionType::GetSimpleType(PRUint16 *aSimpleType)
00608 {
00609   NS_ENSURE_ARG_POINTER(aSimpleType);
00610 
00611   *aSimpleType = nsISchemaSimpleType::SIMPLE_TYPE_RESTRICTION;
00612 
00613   return NS_OK;
00614 }
00615 
00616 /* readonly attribute nsISchemaSimpleType baseType; */
00617 NS_IMETHODIMP
00618 nsSchemaRestrictionType::GetBaseType(nsISchemaSimpleType * *aBaseType)
00619 {
00620   NS_ENSURE_ARG_POINTER(aBaseType);
00621 
00622   NS_IF_ADDREF(*aBaseType = mBaseType);
00623 
00624   return NS_OK;
00625 }
00626 
00627 /* readonly attribute PRUint32 facetCount; */
00628 NS_IMETHODIMP
00629 nsSchemaRestrictionType::GetFacetCount(PRUint32 *aFacetCount)
00630 {
00631   NS_ENSURE_ARG_POINTER(aFacetCount);
00632 
00633   *aFacetCount = mFacets.Count();
00634 
00635   return NS_OK;
00636 }
00637 
00638 /* nsISchemaFacet getFacet(in PRUint32 index); */
00639 NS_IMETHODIMP
00640 nsSchemaRestrictionType::GetFacet(PRUint32 aIndex, nsISchemaFacet** aResult)
00641 {
00642   NS_ENSURE_ARG_POINTER(aResult);
00643 
00644   if (aIndex >= (PRUint32)mFacets.Count()) {
00645     return NS_ERROR_FAILURE;
00646   }
00647 
00648   NS_ADDREF(*aResult = mFacets.ObjectAt(aIndex));
00649 
00650   return NS_OK;
00651 }
00652 
00653 NS_IMETHODIMP
00654 nsSchemaRestrictionType::SetBaseType(nsISchemaSimpleType* aBaseType)
00655 {
00656   NS_ENSURE_ARG(aBaseType);
00657 
00658   mBaseType = aBaseType;
00659 
00660   return NS_OK;
00661 }
00662 
00663 NS_IMETHODIMP
00664 nsSchemaRestrictionType::AddFacet(nsISchemaFacet* aFacet)
00665 {
00666   NS_ENSURE_ARG(aFacet);
00667 
00668   return mFacets.AppendObject(aFacet) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00669 }
00670 
00672 //
00673 // nsSchemaTypePlaceholder implementation
00674 //
00676 nsSchemaTypePlaceholder::nsSchemaTypePlaceholder(nsSchema* aSchema,
00677                                                  const nsAString& aName)
00678   : nsSchemaComponentBase(aSchema), mName(aName)
00679 {
00680 }
00681 
00682 nsSchemaTypePlaceholder::~nsSchemaTypePlaceholder()
00683 {
00684 }
00685 
00686 NS_IMPL_ISUPPORTS3_CI(nsSchemaTypePlaceholder, 
00687                       nsISchemaComponent,
00688                       nsISchemaType,
00689                       nsISchemaSimpleType)
00690 
00691 
00692 /* void resolve (in nsIWebServiceErrorHandler aErrorHandler); */
00693 NS_IMETHODIMP
00694 nsSchemaTypePlaceholder::Resolve(nsIWebServiceErrorHandler* aErrorHandler)
00695 {
00696   return NS_OK;
00697 }
00698 
00699 /* void clear (); */
00700 NS_IMETHODIMP
00701 nsSchemaTypePlaceholder::Clear()
00702 {
00703   return NS_OK;
00704 }
00705 
00706 /* readonly attribute wstring name; */
00707 NS_IMETHODIMP
00708 nsSchemaTypePlaceholder::GetName(nsAString& aName)
00709 {
00710   aName.Assign(mName);
00711   
00712   return NS_OK;
00713 }
00714 
00715 /* readonly attribute unsigned short schemaType; */
00716 NS_IMETHODIMP
00717 nsSchemaTypePlaceholder::GetSchemaType(PRUint16 *aSchemaType)
00718 {
00719   NS_ENSURE_ARG_POINTER(aSchemaType);
00720 
00721   *aSchemaType = nsISchemaType::SCHEMA_TYPE_PLACEHOLDER;
00722 
00723   return NS_OK;
00724 }
00725 
00726 /* readonly attribute unsigned short simpleType; */
00727 NS_IMETHODIMP
00728 nsSchemaTypePlaceholder::GetSimpleType(PRUint16 *aSimpleType)
00729 {
00730   return NS_ERROR_FAILURE;
00731 }
00732 
00733 
00735 //
00736 // nsSchemaFacet implementation
00737 //
00739 nsSchemaFacet::nsSchemaFacet(nsSchema* aSchema)
00740   : nsSchemaComponentBase(aSchema), mIsFixed(PR_FALSE)
00741 {
00742 }
00743 
00744 nsSchemaFacet::~nsSchemaFacet()
00745 {
00746 }
00747 
00748 NS_IMPL_ISUPPORTS2_CI(nsSchemaFacet,
00749                       nsISchemaComponent,
00750                       nsISchemaFacet)
00751 
00752 /* void resolve (in nsIWebServiceErrorHandler aErrorHandler); */
00753 NS_IMETHODIMP
00754 nsSchemaFacet::Resolve(nsIWebServiceErrorHandler* aErrorHandler)
00755 {
00756   return NS_OK;
00757 }
00758 
00759 /* void clear (); */
00760 NS_IMETHODIMP
00761 nsSchemaFacet::Clear()
00762 {
00763   return NS_OK;
00764 }
00765 
00766 NS_IMETHODIMP
00767 nsSchemaFacet::SetFacetType(PRUint16 aFacetType)
00768 {
00769   mFacetType = aFacetType;
00770 
00771   return NS_OK;
00772 }
00773 
00774 NS_IMETHODIMP
00775 nsSchemaFacet::SetIsFixed(PRBool aIsFixed) 
00776 {
00777   mIsFixed = aIsFixed;
00778 
00779   return NS_OK;
00780 }
00781 
00782 /* readonly attribute unsigned short facetType; */
00783 NS_IMETHODIMP
00784 nsSchemaFacet::GetFacetType(PRUint16 *aFacetType)
00785 {
00786   NS_ENSURE_ARG_POINTER(aFacetType);
00787 
00788   *aFacetType = mFacetType;
00789   
00790   return NS_OK;
00791 }
00792 
00793 /* readonly attribute AString value; */
00794 NS_IMETHODIMP
00795 nsSchemaFacet::GetValue(nsAString & aValue)
00796 {
00797   if ((mFacetType == FACET_TYPE_TOTALDIGITS) ||
00798       (mFacetType == FACET_TYPE_FRACTIONDIGITS) ||
00799       (mFacetType == FACET_TYPE_WHITESPACE) ||
00800       (mFacetType == FACET_TYPE_LENGTH) ||
00801       (mFacetType == FACET_TYPE_MINLENGTH) ||
00802       (mFacetType == FACET_TYPE_MAXLENGTH)) {
00803     return NS_ERROR_ILLEGAL_VALUE;
00804   }
00805 
00806   aValue.Assign(mStrValue);
00807 
00808   return NS_OK;
00809 }
00810 
00811 /* readonly attribute PRUint32 lengthValue; */
00812 NS_IMETHODIMP
00813 nsSchemaFacet::GetLengthValue(PRUint32 *aLengthValue)
00814 {
00815   NS_ENSURE_ARG_POINTER(aLengthValue);
00816 
00817   if ((mFacetType != FACET_TYPE_LENGTH) &&
00818       (mFacetType != FACET_TYPE_MINLENGTH) &&
00819       (mFacetType != FACET_TYPE_MAXLENGTH)) {
00820     return NS_ERROR_ILLEGAL_VALUE;
00821   }
00822 
00823   *aLengthValue = mUintValue;
00824 
00825   return NS_OK;
00826 }
00827 
00828 /* readonly attribute PRUint32 digitsValue; */
00829 NS_IMETHODIMP
00830 nsSchemaFacet::GetDigitsValue(PRUint32 *aDigitsValue)
00831 {
00832   NS_ENSURE_ARG_POINTER(aDigitsValue);
00833 
00834   if ((mFacetType != FACET_TYPE_TOTALDIGITS) &&
00835       (mFacetType != FACET_TYPE_FRACTIONDIGITS)) {
00836     return NS_ERROR_ILLEGAL_VALUE;
00837   }
00838 
00839   *aDigitsValue = mUintValue;
00840 
00841   return NS_OK;
00842 }
00843 
00844 /* readonly attribute unsigned short whitespaceValue; */
00845 NS_IMETHODIMP
00846 nsSchemaFacet::GetWhitespaceValue(PRUint16 *aWhitespaceValue)
00847 {
00848   NS_ENSURE_ARG_POINTER(aWhitespaceValue);
00849 
00850   if (mFacetType != FACET_TYPE_WHITESPACE) {
00851     return NS_ERROR_ILLEGAL_VALUE;
00852   }
00853 
00854   *aWhitespaceValue = mWhitespaceValue;
00855 
00856   return NS_OK;
00857 }
00858 
00859 /* readonly attribute boolean isfixed; */
00860 NS_IMETHODIMP
00861 nsSchemaFacet::GetIsfixed(PRBool *aIsFixed)
00862 {
00863   NS_ENSURE_ARG_POINTER(aIsFixed);
00864   
00865   *aIsFixed = mIsFixed;
00866 
00867   return NS_OK;
00868 }
00869 
00870 NS_IMETHODIMP
00871 nsSchemaFacet::SetValue(const nsAString& aStrValue)
00872 {
00873   mStrValue.Assign(aStrValue);
00874 
00875   return NS_OK;
00876 }
00877 
00878 NS_IMETHODIMP
00879 nsSchemaFacet::SetUintValue(PRUint32 aUintValue)
00880 {
00881   mUintValue = aUintValue;
00882 
00883   return NS_OK;
00884 }
00885 
00886 NS_IMETHODIMP
00887 nsSchemaFacet::SetWhitespaceValue(PRUint16 aWhitespaceValue)
00888 {
00889   mWhitespaceValue = aWhitespaceValue;
00890 
00891   return NS_OK;
00892 }