Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

calculator_contract

Jean-Guilhem Rouel edited this page Feb 24, 2016 · 2 revisions

The contract between the framework Unicorn and an observer is composed of two files located on observer side :

To learn more : http://www.w3.org/QA/Tools/Unicorn/contract/

Table of Contents

observer.wadl

An xml file which has to be validated by the schema [wiki:observer-response.xsd]. This file tells to Unicorn

  • what are possible input methods of the observer (input by URI?, by text? or by file?)
  • what are possible parameters for each input method
  • what is the type of the parameters
Some examples: This contract usually has 2 main parts:
<application>
  <grammars>
    <xs:schema>   
       ...
       Part 1: Declaration of types
       ...
    </xs:schema>
  </grammars>

  <resources>
    ...
      Part 2: Declaration of possible input methods and possible parameters for each method
    ...
  </resources>
</application>

full source of observer.wadl

<?xml version="1.0"  encoding="utf-8"?>

<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://research.sun.com/wadl wadl.xsd"
      xmlns="http://research.sun.com/wadl"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:uco="http://www.w3.org/unicorn/observationresponse">
    
    <xs:schema>
      <xs:element name="tX2">
        <xs:complexType>
        <xs:choice>
          <xs:element name="0" />
          <xs:element name="1" />
         </xs:choice>
        </xs:complextype>
      </xs:element>
    </xs:schema>
  
    <resources base="http://localhost/">
      <resource uri="calculator.php">
        <method name="GET" id="CalculatorGET">
          <request>
            <query_variable name="uri" />
            <query_variable name="x2" type="tX2"/>
            <query_variable name="xn"/>
          </request>
        </method>
      </resource>
    </resources>
</application>

Explanation

  • The first part defines a complex type tX2. A tX2 type can take only two values, 0 or 1.
  • Inside <resources>..&lt;/ressources&gt;</resources> tags, we define several ressources of our observer. In our case, we have just one resource, calculator.php, based on !http://localhost/ (Full path of our observer will be !http://localhost/calculator.php).
  • Our observer have only one input method (read from an URI), so we have to define the only one entry <method>..</method>
 There are two attributes for the tag &lt;method&gt;&lt;/method&gt; : 
      • name : GET or POST.
      • id : method's key name. We'll use this id in observer.rdf.
 This input method takes 3 parameters (of which two are optional).
     * uri : path of a file which contains some simple arithmetic operations (notype define).
     * x2 : (optional) it's a complex type to multiply results by 2 (which is declared in the first part). 
     * xn : (optional) to multiply results by n.

observer.rdf

This file contains all localized information, lists of mimetypes handled by each method of the observer and information about input parameter handle by the observer. This file has an ucn:Observer element which contains :

    * A rdf:ID attribute as reference to the WADL file.
    * Zero or more ucn:name elements as the name of the observer in different language.
    * Zero or more ucn:description element to describe the observer in different language.
    * Zero or more ucn:help element, link to a help page about the observer in different language.
    * One or more ucn:inputMethod containing the exactly one ucn:Parameter itself containing One or more ucn:mimetype elements to define each mimetype handled by the method.

In our case we have just one method, CalculatorGET, which takes an uri containing text. So the mimetype will be text/plain.

&amp;lt&#59;rdf&amp;&#35;58&#59;RDF
	xmlns&amp;&#35;58&#59;rdf&amp;&#35;61&#59;&amp;quot&#59;&amp;amp&#59;rdf&amp;&#35;59&#59;&amp;&#35;35&#59;&amp;quot&#59;
	xmlns&amp;&#35;58&#59;rdfs&amp;&#35;61&#59;&amp;quot&#59;&amp;amp&#59;rdfs&amp;&#35;59&#59;&amp;&#35;35&#59;&amp;quot&#59;
	xmlns&amp;&#35;58&#59;ucn&amp;&#35;61&#59;&amp;quot&#59;&amp;amp&#59;ucn&amp;&#35;59&#59;&amp;&#35;35&#59;&amp;quot&#59;
	xmlns&amp;&#35;61&#59;&amp;quot&#59;&amp;amp&#59;ucn&amp;&#35;59&#59;&amp;&#35;35&#59;&amp;quot&#59;
	xml&amp;&#35;58&#59;base&amp;&#35;61&#59;&amp;quot&#59;&amp;amp&#59;ucn&amp;&#35;59&#59;&amp;quot&#59;
	&amp;gt&#59;

	&amp;lt&#59;ucn&amp;&#35;58&#59;Observer ucn&amp;&#35;58&#59;id&amp;&#35;61&#59;&amp;quot&#59;calculator&amp;quot&#59; ucn&amp;&#35;58&#59;reference&amp;&#35;61&#59;&amp;quot&#59;calculator&amp;quot&#59;&amp;gt&#59;
	
		&amp;lt&#59;ucn&amp;&#35;58&#59;name xml&amp;&#35;58&#59;lang&amp;&#35;61&#59;&amp;quot&#59;en&amp;quot&#59;&amp;gt&#59;Calculator&amp;lt&#59;/ucn&#58;name&amp;gt&#59;
		&amp;lt&#59;ucn&amp;&#35;58&#59;name xml&amp;&#35;58&#59;lang&amp;&#35;61&#59;&amp;quot&#59;fr&amp;quot&#59;&amp;gt&#59;Calculatrice&amp;lt&#59;/ucn&#58;name&amp;gt&#59;
		&amp;lt&#59;ucn&amp;&#35;58&#59;description xml&amp;&#35;58&#59;lang&amp;&#35;61&#59;&amp;quot&#59;en&amp;quot&#59;&amp;gt&#59;An observer who evaluates simple arithmetic operations.&amp;lt&#59;/ucn&#58;description&amp;gt&#59;
		&amp;lt&#59;ucn&amp;&#35;58&#59;description xml&amp;&#35;58&#59;lang&amp;&#35;61&#59;&amp;quot&#59;fr&amp;quot&#59;&amp;gt&#59;Un observateur qui évalue des opérations arithmétiques.&amp;lt&#59;/ucn&#58;description&amp;gt&#59;
		
		&amp;lt&#59;ucn&amp;&#35;58&#59;inputMethod&amp;gt&#59;
			&amp;lt&#59;ucn&amp;&#35;58&#59;ParameterURI ucn&amp;&#35;58&#59;methodName&amp;&#35;61&#59;&amp;quot&#59;CalculatorGET&amp;quot&#59; ucn&amp;&#35;58&#59;parameterName&amp;&#35;61&#59;&amp;quot&#59;uri&amp;quot&#59;&amp;gt&#59;
   		            &amp;lt&#59;ucn&amp;&#35;58&#59;mimetype&amp;gt&#59;text/plain&amp;lt&#59;/ucn&#58;mimetype&amp;gt&#59;
			&amp;lt&#59;/ucn&#58;parameteruri&amp;gt&#59;
		&amp;lt&#59;/ucn&#58;inputmethod&amp;gt&#59;

	&amp;lt&#59;/ucn&#58;observer&amp;gt&#59;

&amp;lt&#59;/rdf&#58;rdf&amp;gt&#59;

Use an extra layer of security with two factor authentication (2FA) when logging into google

Clone this wiki locally