/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * 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 the Initial Developer are Copyright (C) 2001
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Vidur Apparao <vidur@netscape.com> (original author)
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#include "nsISupports.idl"
#include "nsISVSchemaErrorHandler.idl"

/**
 * the original code came from mozilla/extensions/webservices/public/nsISchema.idl
 */

interface nsISVSchema;
interface nsISVSchemaType;
interface nsISVSchemaSimpleType;
interface nsISVSchemaBuiltinType;
interface nsISVSchemaListType;
interface nsISVSchemaUnionType;
interface nsISVSchemaRestrictionType;
interface nsISVSchemaComplexType;
interface nsISVSchemaParticle;
interface nsISVSchemaModelGroup;
interface nsISVSchemaAnyParticle;
interface nsISVSchemaElement;
interface nsISVSchemaAttributeComponent;
interface nsISVSchemaAttribute;
interface nsISVSchemaAttributeGroup;
interface nsISVSchemaAnyAttribute;
interface nsISVSchemaFacet;

/**
 * The collection of loaded schemas. If a schema references other
 * schemas (generally through an import), these will be included
 * in the corresponding collection.
 */
[scriptable, uuid(a3e9f1c3-8a3b-4c49-a093-74b51a333356)]
interface nsISVSchemaCollection : nsISupports {
  nsISVSchema getSchema(in AString targetNamespace);
  nsISVSchemaElement getElement(in AString name, in AString aNamespace);
  nsISVSchemaAttribute getAttribute(in AString name, in AString aNamespace);
  nsISVSchemaType getType(in AString name, in AString aNamespace);
};

[scriptable, uuid(9ed2eaf0-d2eb-430a-814e-ed2d5641b20e)]
interface nsISVSchemaComponent : nsISupports {
  readonly attribute AString targetNamespace;
  void resolve(in nsISVSchemaErrorHandler aErrorHandler);
  void clear();
};

[scriptable, uuid(47b42895-63e8-4309-b519-24d5492d26af)]
interface nsISVSchema : nsISVSchemaComponent {
  /* Is this necessary? */
  readonly attribute AString schemaNamespace;

  readonly attribute PRUint32 typeCount;
  nsISVSchemaType getTypeByIndex(in PRUint32 index);
  nsISVSchemaType getTypeByName(in AString name);

  readonly attribute PRUint32 attributeCount;
  nsISVSchemaAttribute getAttributeByIndex(in PRUint32 index);
  nsISVSchemaAttribute getAttributeByName(in AString name);

  readonly attribute PRUint32 elementCount;
  nsISVSchemaElement getElementByIndex(in PRUint32 index);
  nsISVSchemaElement getElementByName(in AString name);
  
  readonly attribute PRUint32 attributeGroupCount;
  nsISVSchemaAttributeGroup getAttributeGroupByIndex(in PRUint32 index);
  nsISVSchemaAttributeGroup getAttributeGroupByName(in AString name);

  readonly attribute PRUint32 modelGroupCount;
  nsISVSchemaModelGroup getModelGroupByIndex(in PRUint32 index);
  nsISVSchemaModelGroup getModelGroupByName(in AString name);

  readonly attribute nsISVSchemaCollection collection;
};

[scriptable, uuid(efa0b937-bc67-4da5-a02f-dbd1036d8c28)]
interface nsISVSchemaType : nsISVSchemaComponent {
  const unsigned short SCHEMA_TYPE_SIMPLE = 1;
  const unsigned short SCHEMA_TYPE_COMPLEX = 2;
  const unsigned short SCHEMA_TYPE_PLACEHOLDER = 3;

  readonly attribute AString name;
  readonly attribute unsigned short schemaType;
};

[scriptable, uuid(0cd89306-f9fe-4696-855f-a87be3dd2fe7)]
interface nsISVSchemaSimpleType : nsISVSchemaType {
  const unsigned short SIMPLE_TYPE_BUILTIN = 1;
  const unsigned short SIMPLE_TYPE_LIST = 2;
  const unsigned short SIMPLE_TYPE_UNION = 3;
  const unsigned short SIMPLE_TYPE_RESTRICTION = 4;

  readonly attribute unsigned short simpleType;
};

[scriptable, uuid(db0a2a09-e7f3-4b02-b080-de27fb1ef4be)]
interface nsISVSchemaBuiltinType : nsISVSchemaSimpleType {
  const unsigned short BUILTIN_TYPE_ANYTYPE = 1;
  const unsigned short BUILTIN_TYPE_STRING = 2;
  const unsigned short BUILTIN_TYPE_NORMALIZED_STRING = 3;
  const unsigned short BUILTIN_TYPE_TOKEN = 4;
  const unsigned short BUILTIN_TYPE_BYTE = 5;
  const unsigned short BUILTIN_TYPE_UNSIGNEDBYTE = 6;
  const unsigned short BUILTIN_TYPE_BASE64BINARY = 7;
  const unsigned short BUILTIN_TYPE_HEXBINARY = 8;
  const unsigned short BUILTIN_TYPE_INTEGER = 9;
  const unsigned short BUILTIN_TYPE_POSITIVEINTEGER = 10;
  const unsigned short BUILTIN_TYPE_NEGATIVEINTEGER = 11;
  const unsigned short BUILTIN_TYPE_NONNEGATIVEINTEGER = 12;
  const unsigned short BUILTIN_TYPE_NONPOSITIVEINTEGER = 13;
  const unsigned short BUILTIN_TYPE_INT = 14;
  const unsigned short BUILTIN_TYPE_UNSIGNEDINT = 15;
  const unsigned short BUILTIN_TYPE_LONG = 16;
  const unsigned short BUILTIN_TYPE_UNSIGNEDLONG = 17;
  const unsigned short BUILTIN_TYPE_SHORT = 18;
  const unsigned short BUILTIN_TYPE_UNSIGNEDSHORT = 19;
  const unsigned short BUILTIN_TYPE_DECIMAL = 20;
  const unsigned short BUILTIN_TYPE_FLOAT = 21;
  const unsigned short BUILTIN_TYPE_DOUBLE = 22;
  const unsigned short BUILTIN_TYPE_BOOLEAN = 23;
  const unsigned short BUILTIN_TYPE_TIME = 24;
  const unsigned short BUILTIN_TYPE_DATETIME = 25;
  const unsigned short BUILTIN_TYPE_DURATION = 26;
  const unsigned short BUILTIN_TYPE_DATE = 27;
  const unsigned short BUILTIN_TYPE_GMONTH = 28;
  const unsigned short BUILTIN_TYPE_GYEAR = 29;
  const unsigned short BUILTIN_TYPE_GYEARMONTH = 30;
  const unsigned short BUILTIN_TYPE_GDAY = 31;
  const unsigned short BUILTIN_TYPE_GMONTHDAY = 32;
  const unsigned short BUILTIN_TYPE_NAME = 33;
  const unsigned short BUILTIN_TYPE_QNAME = 34;
  const unsigned short BUILTIN_TYPE_NCNAME = 35;
  const unsigned short BUILTIN_TYPE_ANYURI = 36;
  const unsigned short BUILTIN_TYPE_LANGUAGE = 37;
  const unsigned short BUILTIN_TYPE_ID = 38;
  const unsigned short BUILTIN_TYPE_IDREF = 39;
  const unsigned short BUILTIN_TYPE_IDREFS = 40;
  const unsigned short BUILTIN_TYPE_ENTITY = 41;
  const unsigned short BUILTIN_TYPE_ENTITIES = 42;
  const unsigned short BUILTIN_TYPE_NOTATION = 43;
  const unsigned short BUILTIN_TYPE_NMTOKEN = 44;
  const unsigned short BUILTIN_TYPE_NMTOKENS = 45;

  readonly attribute unsigned short builtinType;
};

[scriptable, uuid(14a41758-1ec5-4ad2-aa0e-b6401573189e)]
interface nsISVSchemaListType : nsISVSchemaSimpleType {
  readonly attribute nsISVSchemaSimpleType listType;
};

[scriptable, uuid(38352e6c-d989-4431-85b9-f248b941ac07)]
interface nsISVSchemaUnionType : nsISVSchemaSimpleType {
  readonly attribute PRUint32 unionTypeCount;
  nsISVSchemaSimpleType getUnionType(in PRUint32 index);
};

[scriptable, uuid(0a0fedc6-656a-4162-bde9-add2462e668d)]
interface nsISVSchemaRestrictionType : nsISVSchemaSimpleType {
  readonly attribute nsISVSchemaSimpleType baseType;
  readonly attribute PRUint32 facetCount;
  nsISVSchemaFacet getFacet(in PRUint32 index);
};

[scriptable, uuid(f078e1f9-cfe2-4b77-ab70-a8abd366267f)]
interface nsISVSchemaComplexType : nsISVSchemaType {
  const unsigned short CONTENT_MODEL_EMPTY = 1;
  const unsigned short CONTENT_MODEL_SIMPLE = 2;
  const unsigned short CONTENT_MODEL_ELEMENT_ONLY = 3;
  const unsigned short CONTENT_MODEL_MIXED = 4;

  const unsigned short DERIVATION_EXTENSION_SIMPLE = 1;
  const unsigned short DERIVATION_RESTRICTION_SIMPLE = 2;
  const unsigned short DERIVATION_EXTENSION_COMPLEX = 3;
  const unsigned short DERIVATION_RESTRICTION_COMPLEX = 4;
  const unsigned short DERIVATION_SELF_CONTAINED = 5; // Restriction of ur-type

  readonly attribute unsigned short contentModel;
  readonly attribute unsigned short derivation;
  readonly attribute nsISVSchemaType baseType;

  // For complex types that are derivations of simple types or of
  // complex types that are themselves derivations of simple types
  // i.e. derivation is either DERIVATION_RESTRICTION_SIMPLE or
  // DERIVATION_EXTENSION_SIMPLE.
  readonly attribute nsISVSchemaSimpleType simpleBaseType;

  readonly attribute nsISVSchemaModelGroup modelGroup;
  
  readonly attribute PRUint32 attributeCount;
  nsISVSchemaAttributeComponent getAttributeByIndex(in PRUint32 index);
  nsISVSchemaAttributeComponent getAttributeByName(in AString name);

  readonly attribute boolean abstract;
  
  readonly attribute boolean isArray;
  readonly attribute nsISVSchemaType arrayType;
  readonly attribute PRUint32 arrayDimension;
};

[scriptable, uuid(25712c88-05cb-4e94-a1c4-3d365df32708)]
interface nsISVSchemaParticle : nsISVSchemaComponent {
  const unsigned short PARTICLE_TYPE_ELEMENT = 1;
  const unsigned short PARTICLE_TYPE_MODEL_GROUP = 2;
  const unsigned short PARTICLE_TYPE_ANY = 3;

  const PRUint32 OCCURRENCE_UNBOUNDED = 0xFFFFFFFF;

  readonly attribute AString name;
  readonly attribute unsigned short particleType;

  readonly attribute PRUint32 minOccurs;
  readonly attribute PRUint32 maxOccurs;
};

[scriptable, uuid(19d749dd-3782-4e3a-bce9-653e08c75508)]
interface nsISVSchemaModelGroup : nsISVSchemaParticle {
  const unsigned short COMPOSITOR_ALL = 1;
  const unsigned short COMPOSITOR_SEQUENCE = 2;
  const unsigned short COMPOSITOR_CHOICE = 3;

  readonly attribute unsigned short compositor;

  readonly attribute PRUint32 particleCount;
  nsISVSchemaParticle getParticle(in PRUint32 index);

  // Get named element definition for a named element that is
  // part of this model group or part of a nested model group.
  nsISVSchemaElement getElementByName(in AString name);
};

[scriptable, uuid(8369e29b-a24c-4dbc-9885-657abb0c8161)]
interface nsISVSchemaAnyParticle : nsISVSchemaParticle {
  const unsigned short PROCESS_STRICT = 1;
  const unsigned short PROCESS_SKIP = 2;
  const unsigned short PROCESS_LAX = 3;

  readonly attribute unsigned short process;
  readonly attribute AString namespace;
};

[scriptable, uuid(7aab361f-8412-4fad-ba13-2af7c39b54d9)]
interface nsISVSchemaElement : nsISVSchemaParticle {
  readonly attribute nsISVSchemaType type;

  readonly attribute AString defaultValue;
  readonly attribute AString fixedValue;

  readonly attribute boolean nillable;
  readonly attribute boolean abstract;
};

[scriptable, uuid(a9e4bf57-fb60-4f00-8807-e20757b85f2e)]
interface nsISVSchemaAttributeComponent : nsISVSchemaComponent {
  const unsigned short COMPONENT_TYPE_ATTRIBUTE = 1;
  const unsigned short COMPONENT_TYPE_GROUP = 2;
  const unsigned short COMPONENT_TYPE_ANY = 3;
  
  readonly attribute AString name;
  readonly attribute unsigned short componentType;
};

[scriptable, uuid(241528b5-d85c-4625-8f42-12458ac3df21)]
interface nsISVSchemaAttribute : nsISVSchemaAttributeComponent {
  const unsigned short USE_OPTIONAL = 1;
  const unsigned short USE_PROHIBITED = 2;
  const unsigned short USE_REQUIRED = 3;

  readonly attribute nsISVSchemaSimpleType type;
 
  readonly attribute AString defaultValue;
  readonly attribute AString fixedValue;
  readonly attribute unsigned short use;

  readonly attribute AString qualifiedNamespace;
};

[scriptable, uuid(3279223d-4059-43af-a290-bb6fe401618f)]
interface nsISVSchemaAttributeGroup : nsISVSchemaAttributeComponent {
  readonly attribute PRUint32 attributeCount;
  nsISVSchemaAttributeComponent getAttributeByIndex(in PRUint32 index);
  nsISVSchemaAttributeComponent getAttributeByName(in AString name);
};

[scriptable, uuid(1969d64c-29e8-4fa1-a4aa-0edb6ac12948)]
interface nsISVSchemaAnyAttribute : nsISVSchemaAttributeComponent {
  const unsigned short PROCESS_STRICT = 1;
  const unsigned short PROCESS_SKIP = 2;
  const unsigned short PROCESS_LAX = 3;

  readonly attribute unsigned short process;
  readonly attribute AString namespace;
};

[scriptable, uuid(74a513b7-7519-4296-ad7a-878f5d616ee3)]
interface nsISVSchemaFacet : nsISVSchemaComponent {
  const unsigned short FACET_TYPE_LENGTH = 1;
  const unsigned short FACET_TYPE_MINLENGTH = 2;
  const unsigned short FACET_TYPE_MAXLENGTH = 3;
  const unsigned short FACET_TYPE_PATTERN = 4;
  const unsigned short FACET_TYPE_ENUMERATION = 5;
  const unsigned short FACET_TYPE_WHITESPACE = 6;
  const unsigned short FACET_TYPE_MAXINCLUSIVE = 7;
  const unsigned short FACET_TYPE_MININCLUSIVE = 8;
  const unsigned short FACET_TYPE_MAXEXCLUSIVE = 9;
  const unsigned short FACET_TYPE_MINEXCLUSIVE = 10;
  const unsigned short FACET_TYPE_TOTALDIGITS = 11;
  const unsigned short FACET_TYPE_FRACTIONDIGITS = 12;
  
  const unsigned short WHITESPACE_PRESERVE = 1;
  const unsigned short WHITESPACE_REPLACE = 1;
  const unsigned short WHITESPACE_COLLAPSE = 1;
  

  readonly attribute unsigned short facetType;
  readonly attribute AString value;
  readonly attribute PRUint32 lengthValue; // For length, minLength & maxLength
  readonly attribute PRUint32 digitsValue; // For totalDigits & fractionDigits
  readonly attribute unsigned short whitespaceValue; // For whitespace only
  readonly attribute boolean isfixed;
};
