<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (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.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<!--
  Binding for the Swan form-model editor.

  @version $Id: model_binding.xml 449149 2006-09-23 03:58:05Z crossley $
-->

<fb:context
  xmlns:fb="http://apache.org/cocoon/forms/1.0#binding"
  xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
  path="/fd:form"
  lenient="true">

  <fb:new id="items-class"/>

  <fb:class id="action-class">
    <fb:case id="action" path=".">
      <fb:insert-node><fd:action/>
</fb:insert-node>
      <fb:group id="action" path="fd:action">
        <fb:group id="stuff" path=".">
          <fb:value id="id" path="@id"/>
          <fb:new id="label-class"/>
        </fb:group>
      </fb:group>
    </fb:case>
  </fb:class>

  <fb:class id="aggregatefield-class">
    <fb:case id="aggregatefield" path=".">
      <fb:insert-node><fd:aggregatefield/>
</fb:insert-node>
      <fb:group id="aggregatefield" path="fd:aggregatefield">
        <fb:group id="stuff" path=".">
          <fb:value id="id" path="@id"/>
          <fb:new id="label-class"/>
          <!-- TODO: required -->
          <fb:insert-node>
  <fd:widgets/>
  </fb:insert-node>
        </fb:group>
        <fb:new id="items-class"/>
      </fb:group>
    </fb:case>
  </fb:class>

  <fb:class id="booleanfield-class">
    <fb:case id="booleanfield" path=".">
      <fb:insert-node><fd:booleanfield/>
</fb:insert-node>
      <fb:group id="booleanfield" path="fd:booleanfield">
        <fb:group id="stuff" path=".">
          <fb:value id="id" path="@id"/>
          <fb:new id="label-class"/>
        </fb:group>
      </fb:group>
    </fb:case>
  </fb:class>

  <fb:class id="class-class">
    <fb:case id="class" path=".">
      <fb:insert-node><fd:class/>
</fb:insert-node>
      <fb:group id="class" path="fd:class" direction="load">
        <fb:group id="stuff" path=".">
          <fb:value id="id" path="@id"/>
          <fb:insert-node>
  <fd:widgets/>
  </fb:insert-node>
        </fb:group>
        <fb:new id="items-class"/>
      </fb:group>
    </fb:case>
  </fb:class>

  <fb:class id="field-class">
    <fb:case id="field" path=".">
      <fb:insert-node><fd:field/>
</fb:insert-node>
      <fb:group id="field" path="fd:field">
        <fb:group id="stuff" path=".">
          <fb:value id="id" path="@id"/>
          <fb:new id="label-class"/>
          <fb:value id="required" path="@required">
            <fd:convertor datatype="boolean"/>
          </fb:value>
        </fb:group>
      </fb:group>
    </fb:case>
  </fb:class>

  <fb:class id="group-class">
    <fb:case id="group" path=".">
      <fb:insert-node><fd:group/>
</fb:insert-node>
      <fb:group id="group" path="fd:group">
        <fb:group id="stuff" path=".">
          <fb:value id="id" path="@id"/>
          <fb:new id="label-class"/>
          <fb:insert-node>
  <fd:widgets/>
  </fb:insert-node>
        </fb:group>
        <fb:new id="items-class"/>
      </fb:group>
    </fb:case>
  </fb:class>

  <fb:class id="new-class">
    <fb:case id="new" path=".">
      <fb:insert-node><fd:new/>
</fb:insert-node>
      <fb:group id="new" path="fd:new">
        <fb:group id="stuff" path=".">
          <fb:value id="id" path="@id"/>
        </fb:group>
      </fb:group>
    </fb:case>
  </fb:class>

  <fb:class id="output-class">
    <fb:case id="output" path=".">
      <fb:insert-node><fd:output/>
</fb:insert-node>
      <fb:group id="output" path="fd:output">
        <fb:group id="stuff" path=".">
          <fb:value id="id" path="@id"/>
          <fb:new id="label-class"/>
        </fb:group>
      </fb:group>
    </fb:case>
  </fb:class>

  <fb:class id="repeater-class">
    <fb:case id="repeater" path=".">
      <fb:insert-node><fd:repeater/>
</fb:insert-node>
      <fb:group id="repeater" path="fd:repeater">
        <fb:group id="stuff" path=".">
          <fb:value id="id" path="@id"/>
          <fb:new id="label-class"/>
          <fb:value id="initial-size" path="@initial-size">
            <fd:convertor datatype="long"/>
          </fb:value>
          <fb:insert-node>
  <fd:widgets/>
  </fb:insert-node>
        </fb:group>
        <fb:new id="items-class"/>
      </fb:group>
    </fb:case>
  </fb:class>

  <fb:class id="row-action-class">
    <fb:case id="row-action" path=".">
      <fb:insert-node><fd:row-action/>
</fb:insert-node>
      <fb:group id="row-action" path="fd:row-action">
        <fb:group id="stuff" path=".">
          <fb:value id="id" path="@id"/>
          <fb:new id="label-class"/>
        </fb:group>
      </fb:group>
    </fb:case>
  </fb:class>

  <fb:class id="struct-class">
    <fb:case id="struct" path=".">
      <fb:insert-node><fd:struct/>
</fb:insert-node>
      <fb:group id="struct" path="fd:struct">
        <fb:group id="stuff" path=".">
          <fb:value id="id" path="@id"/>
          <fb:new id="label-class"/>
          <fb:insert-node>
  <fd:widgets/>
  </fb:insert-node>
        </fb:group>
        <fb:new id="items-class"/>
      </fb:group>
    </fb:case>
  </fb:class>

  <fb:class id="submit-class">
    <fb:case id="submit" path=".">
      <fb:insert-node><fd:submit/>
</fb:insert-node>
      <fb:group id="submit" path="fd:submit">
        <fb:group id="stuff" path=".">
          <fb:value id="id" path="@id"/>
          <fb:new id="label-class"/>
        </fb:group>
      </fb:group>
    </fb:case>
  </fb:class>

  <fb:class id="union-class">
    <fb:case id="union" path=".">
      <fb:insert-node><fd:union/>
</fb:insert-node>
      <fb:group id="union" path="fd:union">
        <fb:group id="stuff" path=".">
          <fb:value id="id" path="@id"/>
          <fb:new id="label-class"/>
          <fb:insert-node>
  <fd:widgets/>
  </fb:insert-node>
        </fb:group>
        <fb:new id="items-class"/>
      </fb:group>
    </fb:case>
  </fb:class>

  <fb:class id="view-selector-class">
    <fb:javascript id="view-selector" path="." direction="load">
      <fb:load-form>
        widget.value = "view";
      </fb:load-form>
    </fb:javascript>
  </fb:class>

  <fb:class id="items-class">
    <fb:temp-repeater id="items"
      parent-path="fd:widgets"
      row-path="*" row-path-insert="."
      virtual-rows="true">
      <fb:on-bind><fb:new id="item-row-class"/></fb:on-bind>
    </fb:temp-repeater>
  </fb:class>

  <fb:class id="item-row-class">
    <fb:javascript id="type-selector" path="." direction="load">
      <fb:load-form>
        widget.value = jxpathPointer.getNode().getFirstChild().getLocalName();
      </fb:load-form>
    </fb:javascript>
    <fb:union id="union" path=".">
      <fb:new id="action-class"/>
      <fb:new id="aggregatefield-class"/>
      <fb:new id="booleanfield-class"/>
      <fb:new id="class-class"/>
      <fb:new id="field-class"/>
      <fb:new id="group-class"/>
      <fb:new id="new-class"/>
      <fb:new id="output-class"/>
      <fb:new id="repeater-class"/>
      <fb:new id="row-action-class"/>
      <fb:new id="struct-class"/>
      <fb:new id="submit-class"/>
      <fb:new id="union-class"/>
    </fb:union>
    <!--
    The view-selector binding must happen last,
    so that all the widgets will exist that the 
    view-selector's on-value-changed handler needs.
    -->
    <fb:new id="view-selector-class"/>
  </fb:class>

  <fb:class id="label-class">
    <fb:value id="label" path="fd:label"/>
  </fb:class>

</fb:context>
