<?xml version="1.0" encoding="UTF-8"?>

<!--

   This schema is used by the Omixed Server Test Harness to test
   various features of the server.

   Things to test:

   - normal links (1:1 and 1:many)

   - recursive links
   
   - multiple links from A to B

   - bidirection links: A to B and B to A

   - attribute types
   
   - validation rules

   
-->


<OmixedDatabaseSchema name="testing model" 
		      verson="1.0"
		      comment="used by the server test harness">
  
  <ItemTypeList>
    
    <!-- 
	 tests recursive linking
      -->
    
    <ItemType name="Part">
 
      <Attribute type="date" name="Manufacture Date"/>

      <Attribute type="string" name="Reference Number"/>

      <!-- a part can be composed of many other parts -->

      <!-- 
	   note the by default the recursive expansion mode is
           "forward", here we are setting it to "bidirectional" so that
	   something will be considered to be part of something else
           in a recursive fashion, e.g. if we have these items:

	    Faucet =[HasPart]=> Valve =[HasPart]=> Washer
	
	   and

            Kitchen =[Contains]=> Faucet
					     
	   then we want to be able to ask "is there a Washer in the
	   kitchen?" or "where is the washer?"

	-->
      <Link name="HasSubPart" to="Part" arity="many" options="RecursiveExpandBidirectional"/>

    </ItemType>


    <!-- 
	 tests multiple links (2 links to Person and 2 to Company)
      -->

    <ItemType name="Train">

      <Attribute type="integer" name="Number of coaches"/>

      <Link name="Operator" to="Company" arity="one"/>
      
      <Link name="Driver" to="Person" arity="one"/>

      <Link name="Passenger" to="Person" arity="many"/>

      <Link name="Component" to="Part" arity="many"/>

      <Link name="Manufacturer" to="Company" arity="one"/>

      <!-- testing unnamed links -->
      <Link to="Location" arity="one"/>

    </ItemType>


    <!-- 
	 tests bidirectional links (Person is linked to Train
	 and Train is linked to Person)
      -->

    <ItemType name="Person">
     
      <Attribute type="text" name="Address"/>

      <Attribute type="date" name="Date of Birth"/>

      <Attribute type="integer" name="Age"/>  <!-- in years to test the 'integer' type -->

      <Attribute type="number" name="Height"/>  <!-- in metres to test the 'number' type -->

      <Attribute type="url" name="Home Page"/>

      <File name="Photo" />
      
      <File name="Spreadsheet" />

      <!-- for the trainspotters, which trains has this person spotted? -->
      <Link name="Spotted" to="Train" arity="many" />

      <!-- recursive link to other Person who is a friend -->
      <Link name="Friend" to="Person" arity="many" />

      <!-- another recursive link to Person for our enemies -->
      <Link name="Enemy" to="Person" arity="many" />


    </ItemType>
     


    <ItemType name="Company">

      <Attribute type="text" name="Address"/>

      <Link name="Employee" to="Person" arity="many"/>
      
    </ItemType>

    
    <ItemType name="Location">
      
      <Attribute type="text" name="Description"/>

      <Group name="Coordinates">
	<Attribute type="string" name="Latitude"/>
	<Attribute type="string" name="Longitude"/>
	<Attribute type="string" name="Altitude"/>
      </Group>

    </ItemType>
    

    <!-- testing item types with spaces in their name -->
    <ItemType name="Home Location">
      
      <!-- testing link names with spaces in their name -->
      <Link name="Nearby Place" to="Location" arity="many"/>
      
      <Attribute type="list" name="type"> 
	<ListOption name="indoors"/>  <!-- maybe better called PermittedValue or something? -->
	<ListOption name="outdoors"/> <!-- might have optional  label=""  atribute too -->
	<ListOption name="underground"/>
      </Attribute> 

    </ItemType>
    

    <!-- testing of nested groups with re-used names -->

    <ItemType name="Process">

      <Attribute type="text" name="Description"/>
 
      <Group name="Overview">
	<Attribute type="integer" name="Run time (minutes)"/>
	<Attribute type="number" name="Cost (US dollar)"/>
      </Group>
      
      <Group name="Details">
	<Group name="Phase One">
	  <Link name="Reviewed By" to="Person" arity="many"/>
	  <Link name="Approved By" to="Person"/>
	  <Group name="Alpha Sector">
	    <File name="Photograph"/>
	    <Attribute type="string" name="In"/>
	    <Attribute type="string" name="Out"/>
	  </Group>
	  <Group name="Beta Sector">
	    <Attribute type="string" name="In"/>
	    <Attribute type="string" name="Out"/>
	  </Group>
	</Group>
	<Group name="Phase Two">
	  <Link name="Reviewed By" to="Person" arity="many"/>
	  <Link name="Approved By" to="Person"/>
	  <Group name="Alpha Sector">
	    <File name="Photograph"/>
	    <Attribute type="string" name="In"/>
	    <Attribute type="string" name="Out"/>
	  </Group>
	  <Group name="Beta Sector">
	    <Attribute type="string" name="In"/>
	    <Attribute type="string" name="Out"/>
	  </Group>
	</Group>
      </Group>
    
    </ItemType>


  </ItemTypeList>
  

  <RootItemTypeList>
    <ItemType name="Train"/>
  </RootItemTypeList>
  
  
</OmixedDatabaseSchema>
