/* -*- 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 <vidur@netscape.com> (original author)
 */

#include "nsISupports.idl"

%{ C++
#include "nsAString.h"
%} 

interface nsISchema;
interface nsISchemaType;
interface nsISchemaSimpleType;
interface nsISchemaBuiltinType;
interface nsISchemaListType;
interface nsISchemaUnionType;
interface nsISchemaRestrictionType;
interface nsISchemaComplexType;
interface nsISchemaParticle;
interface nsISchemaModelGroup;
interface nsISchemaAnyParticle;
interface nsISchemaElement;
interface nsISchemaAttributeComponent;
interface nsISchemaAttribute;
interface nsISchemaAttributeGroup;
interface nsISchemaAnyAttribute;
interface nsISchemaFacet;

/**
 * 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(427c5511-941b-48c0-9abc-8ec9ea5d964b)]
interface nsISchemaCollection : nsISupports {
  nsISchema getSchema(in AString targetNamespace);
  nsISchemaElement getElement(in AString name, in AString aNamespace);
  nsISchemaAttribute getAttribute(in AString name, in AString aNamespace);
  nsISchemaType getType(in AString name, in AString aNamespace);
};

[scriptable, uuid(3c14a020-6f4e-11d5-9b46-000064657374)]
interface nsISchemaComponent : nsISupports {
  readonly attribute AString targetNamespace;
  void resolve();
  void clear();
};

[scriptable, uuid(3c14a021-6f4e-11d5-9b46-000064657374)]
interface nsISchema : nsISchemaComponent {
  readonly attribute AString schemaNamespace;

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

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

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

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

  readonly attribute nsISchemaCollection collection;
};

[scriptable, uuid(3c14a022-6f4e-11d5-9b46-000064657374)]
interface nsISchemaType : nsISchemaComponent {
  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(3c14a023-6f4e-11d5-9b46-000064657374)]
interface nsISchemaSimpleType : nsISchemaType {
  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(3c14a024-6f4e-11d5-9b46-000064657374)]
interface nsISchemaBuiltinType : nsISchemaSimpleType {
  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(3c14a025-6f4e-11d5-9b46-000064657374)]
interface nsISchemaListType : nsISchemaSimpleType {
  readonly attribute nsISchemaSimpleType listType;
};

[scriptable, uuid(3c14a026-6f4e-11d5-9b46-000064657374)]
interface nsISchemaUnionType : nsISchemaSimpleType {
  readonly attribute PRUint32 unionTypeCount;
  nsISchemaSimpleType getUnionType(in PRUint32 index);
};

[scriptable, uuid(3c14a027-6f4e-11d5-9b46-000064657374)]
interface nsISchemaRestrictionType : nsISchemaSimpleType {
  readonly attribute nsISchemaSimpleType baseType;
  readonly attribute PRUint32 facetCount;
  nsISchemaFacet getFacet(in PRUint32 index);
};

[scriptable, uuid(3c14a028-6f4e-11d5-9b46-000064657374)]
interface nsISchemaComplexType : nsISchemaType {
  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 nsISchemaType 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 nsISchemaSimpleType simpleBaseType; 

  readonly attribute nsISchemaModelGroup modelGroup;
  
  readonly attribute PRUint32 attributeCount;
  nsISchemaAttributeComponent getAttributeByIndex(in PRUint32 index);
  nsISchemaAttributeComponent getAttributeByName(in AString name);

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

[scriptable, uuid(3c14a029-6f4e-11d5-9b46-000064657374)]
interface nsISchemaParticle : nsISchemaComponent {
  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(3c14a02a-6f4e-11d5-9b46-000064657374)]
interface nsISchemaModelGroup : nsISchemaParticle {
  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;
  nsISchemaParticle 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.
  nsISchemaElement getElementByName(in AString name);
};

[scriptable, uuid(3c14a02b-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAnyParticle : nsISchemaParticle {
  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(3c14a02c-6f4e-11d5-9b46-000064657374)]
interface nsISchemaElement : nsISchemaParticle {
  readonly attribute nsISchemaType type;

  readonly attribute AString defaultValue;
  readonly attribute AString fixedValue;

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

[scriptable, uuid(3c14a02d-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAttributeComponent : nsISchemaComponent {
  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(3c14a02e-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAttribute : nsISchemaAttributeComponent {
  const unsigned short USE_OPTIONAL = 1;
  const unsigned short USE_PROHIBITED = 2;
  const unsigned short USE_REQUIRED = 3;

  readonly attribute nsISchemaSimpleType type;
 
  readonly attribute AString defaultValue;
  readonly attribute AString fixedValue;
  readonly attribute unsigned short use;
};

[scriptable, uuid(3c14a02f-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAttributeGroup : nsISchemaAttributeComponent {
  readonly attribute PRUint32 attributeCount;
  nsISchemaAttributeComponent getAttributeByIndex(in PRUint32 index);
  nsISchemaAttributeComponent getAttributeByName(in AString name);
};

[scriptable, uuid(3c14a030-6f4e-11d5-9b46-000064657374)]
interface nsISchemaAnyAttribute : nsISchemaAttributeComponent {
  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(3c14a031-6f4e-11d5-9b46-000064657374)]
interface nsISchemaFacet : nsISchemaComponent {
  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;
};
