ページの先頭行へ戻る
 Apcoordinatorユーザーズガイド

11.2.3 制御の記述

実行する仕様セクションを指定する

データ仕様内のセクションの実行を制御することができます。

<?xml version="1.0" encoding="Shift_JIS" ?>
<eSpec
    xmlns=http://interstage.fujitsu.com/schemas/uji/eSpec
    xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
    xsi:schemaLocation="http://interstage.fujitsu.com/schemas/uji/eSpec
                        http://interstage.fujitsu.com/schemas/uji/espec.xsd">
  <config>
    <version>6.0</version>
  </config>
  <specification name="sampleCheck" >
    <control>
      <validate section="sect1" />
      <validate section="^nextSection" />
    </control>
    <section name="sect1" >
      ...
      <term property="#true" value="#sect2" target="^nextSection" />
    </section>
    <section name="sect2" >
      ...
    </section>
  </specification>
</eSpec>

control
実行する仕様セクションを制御する場合は、specificationタグのコンテントの先頭にcontrolタグを記述します。controlタグを記述すると、validateタグの指定に従って、仕様セクションが実行されます。controlタグを記述しない場合は、specificationタグのコンテントの全ての仕様セクションが記述順に実行されます。

validate
validateタグでは、sectionアトリビュートによって実行する仕様セクションを指定します。sectionアトリビュートでは、直接セクション名を指定する他に、内部変数が利用できます。内部変数は先頭に"^"を付加して指定し、値はtermタグで設定します。この例では、最初のvalidateタグでは直接にセクション"sect1"が指定されているため、まず仕様セクション"sect1"を実行します。仕様セクション"sect1"の中では内部変数"nextSection"に文字列"sect2"を設定していて、2個目のvalidateタグではこれを参照して、次に仕様セクション"sect2"が実行されます。

section
nameアトリビュートでセクション名を指定します。

データBeanの一部に対して仕様セクションを実行する

データBeanに階層構造がある場合には、下の階層のデータBeanに対して仕様セクションを実行することができます。

<?xml version="1.0" encoding="Shift_JIS" ?>
<eSpec
    xmlns=http://interstage.fujitsu.com/schemas/uji/eSpec
    xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
    xsi:schemaLocation="http://interstage.fujitsu.com/schemas/uji/eSpec
                        http://interstage.fujitsu.com/schemas/uji/espec.xsd">
  <config>
    <version>6.0</version>
  </config>
  <specification name="sampleCheck" >
    <control>
      <validate section="sect1" node="subBean" targetNode="subTarget" />
      <validate section="sect2" node="*detail" />
    </control>
    <section name="sect1" >
      ...
    </section>
    <section name="sect2" >
      ...
    </section>
  </specification>
</eSpec>

validate
validateタグのnodeアトリビュートは、仕様セクションの対象となるデータBeanの階層を指定します。例ではデータBeanのgetSubBean()で取得できるBeanをチェック対象、代入先データBeanのgetSubTarget()で取得できるBeanを代入先として、仕様セクション"sect1"を実行します。
nodeアトリビュートの指定の先頭に"*"を付加した場合は、そのオブジェクトの配列の各要素について、仕様セクションを実行します。例では、データBeanのgetDetail()で取得した配列の各要素に対して、仕様セクション"sect2"を実行します。

XMLデータ仕様記述からの復帰値を設定する

ESpecValidatorのvalidateメソッドの復帰値はresultアトリビュートで設定します。

      <term result="#abc" />

result
resultアトリビュートは、validateメソッドの復帰値を設定します。複数記述した場合は、最後に実行されたものが有効になります。例では、文字列"abc"が復帰値となります。

XMLデータ仕様記述をデバッグする

XMLデータ仕様記述のdebug指定により、実行状況をログに出力することができます。

<?xml version="1.0" encoding="Shift_JIS" ?>
<eSpec
    xmlns=http://interstage.fujitsu.com/schemas/uji/eSpec
    xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
    xsi:schemaLocation="http://interstage.fujitsu.com/schemas/uji/eSpec
                        http://interstage.fujitsu.com/schemas/uji/espec.xsd">
  <config>
    <version>6.0</version>
    <debug>trace</debug>
  </config>
  <specification name="sampleCheck" >
    ...
  </specification>
</eSpec>

debug
debugタグを記述した場合には、XMLデータ仕様記述の動作状況を出力します。"snap"と指定した場合は、1タグで1行のログが出力されます。"trace"と指定した場合は、プロパティ値や演算の評価状況など詳細なログが出力されます。