(***********************************************************************)
(*                                                                     *)
(*                                 GALAX                               *)
(*                            XML Query Engine                         *)
(*                                                                     *)
(*  Copyright 2000, Lucent Technologies.                               *)
(*  Distributed only by permission.                                    *)
(*                                                                     *)
(***********************************************************************)

(* $Id: schema.mli,v 1.15 2002/11/15 05:29:23 simeon Exp $ *)

open Xquery_ast
open Print

(*********************************************)
(* This module implements Schema compilation *)
(*********************************************)

(**********************************)
(* Schema internal representation *)
(**********************************)

type schema
type conflict

(************************************)
(* Elementary operations on schemas *)
(************************************)

(* Update an existing schema *)

val resolve_model : Namespace.nsenv -> schema -> model -> model

val insert_and_resolve_group : Namespace.nsenv -> schema -> Sym.group_symbol -> model -> unit
val insert_and_resolve_element : Namespace.nsenv -> schema -> Sym.elem_symbol -> typed_model -> unit
val insert_and_resolve_attribute : Namespace.nsenv -> schema -> Sym.attr_symbol -> typed_model -> unit

val insert_and_resolve_bulk : Namespace.nsenv -> schema -> sort_decl_list -> unit

val create_and_resolve_root : Namespace.nsenv -> schema -> Sym.uelem_symbol option -> unit

val insert_group : schema -> Sym.rgroup_symbol -> model -> unit
val insert_element : schema -> Sym.relem_symbol -> conflict ref * typed_model -> unit
val insert_attribute : schema -> Sym.rattr_symbol -> conflict ref * typed_model -> unit

val insert_bulk : schema -> (conflict ref * sort_decl) list -> unit

val create_root : schema -> Sym.relem_symbol option -> unit
val create_schema_name : schema -> sname option -> unit

(* Accesses schema information *)

val get_all_groups : schema -> Sym.rgroup_symbol list

val get_root      : schema -> Sym.relem_symbol option
val get_name      : schema -> sname option
val get_group     : schema -> Sym.rgroup_symbol -> model
val get_element   : schema -> Sym.relem_symbol  -> typed_model
val get_attribute : schema -> Sym.rattr_symbol  -> typed_model

val group_exists     : schema -> Sym.rgroup_symbol -> unit
val element_exists   : schema -> Sym.relem_symbol  -> unit
val attribute_exists : schema -> Sym.rattr_symbol  -> unit

val dereference_rgroup       : schema -> Sym.rgroup_symbol -> model
val dereference_rgroup_stats : schema -> Sym.rgroup_symbol -> (model * Sym.rgroup_symbol list)
val dereference_group        : schema -> Sym.group_symbol -> model
val dereference_model        : schema -> model -> model
val dereference_elem_attr    : schema -> model -> model

(* Test for global elements without conflicts *)

val is_unique_global_element   : schema -> Sym.relem_symbol  -> bool
val is_unique_global_attribute : schema -> Sym.rattr_symbol  -> bool

(*********************************)
(* Operation on compiled schemas *)
(*********************************)

(* Creates a new schema *)

val empty_schema : unit -> schema
val create_schema :
    Namespace.nsenv -> sname option -> Sym.uelem_symbol option -> sort_decl_list -> schema
val create_schema_with_env :
    Namespace.nsenv -> schema -> sname option -> Sym.uelem_symbol option -> sort_decl_list -> schema
val copy_schema : schema -> schema

(* Note:
     Create schema takes a schema name, a root name (group) and a list
     of sort declarations and compiles into a schema in which all
     names are resolved
   -J&B *)

(* Exports a schema *)

val dump_schema : schema -> sort_decl_list

(* Prints a schema *)

val print_schema : schema -> unit

(* Normalizes a schema *)

val compile_schema : schema -> schema

(* Model normalization *)

val compile_model : schema -> Sym.rgroup_symbol -> model -> model * (conflict ref * sort_decl) list

