shohaku.shoin.factory
クラス ComponentFactory

java.lang.Object
  拡張shohaku.shoin.factory.AbstractResourceSetFactory
      拡張shohaku.shoin.factory.AbstractIOResourceSetFactory
          拡張shohaku.shoin.factory.AbstractGinkgoResourceSetFactory
              拡張shohaku.shoin.factory.ComponentFactory
すべての実装インタフェース:
GinkgoResourceSetFactory, IOResourceSetFactory, ResourceKeyPrefixSupport, ResourceSetFactory

public class ComponentFactory
extends AbstractGinkgoResourceSetFactory
implements ResourceKeyPrefixSupport

XMLデータで定義された情報を基に、POJOを生成するファクトリを提供します。

例:

 // 湖を表現するオブジェクト
 public class Lake {
     private String name;
     public static Lake(String name) { this.name = name; }
     public String getName() { return name; }
     public void setName(String name) { this.name = name; }
 }

 //定義ファイル component-factory.xml
 <component-factory>

    <!-- コンポーネントの定義、グループ名="lake", シングルトン -->
    <components name="lake">
        <component id="constructorId" name="constructor" class="Lake" instance="singleton">
            <init>
                <arg><string>支笏湖</string></arg>
            </init>
        </component>
        <component id="propertyId" name="property" class="Lake" instance="singleton">
            <property name="name">
                <string>阿寒湖</string>
            </property>
        </component>
        <component id="methodId" name="method" class="Lake" instance="singleton">
            <method name="setName">
                <arg><string>倶多楽湖</string></arg>
            </method>
        </component>
    </components>

    <!-- コンポーネントを参照する、グループ名="ref",  プロトタイプ(要求ごとに新規生成する)  -->
    <components name="ref">
        <!-- コンポーネントを参照してリストを生成します -->
        <component name="list" class="java.util.ArrayList" instance="prototype">
            <method name="add">
                <arg><ref>constructorId</ref></arg>
            </method>
            <method name="add">
                <arg><ref>propertyId</ref></arg>
            </method>
            <method name="add">
                <arg><ref>methodId</ref></arg>
            </method>
        </component>
    </components>

 <component-factory>

 グループ名とコンポーネント名を ':' で区切りコンポーネント識別子として認識されます。
 一般的なファイルの読み取りとコンポーネント取得の手順は以下の様に為ります。 
 ComponentFactory factory = new ComponentFactory();
 IOResource inres = FeatureFactory.getLoader().getIOResource("component-factory.xml");
 factory.setIOResources(new IOResource[] { inres });
 
 ResourceSet resources = factory.getResourceSet();
 Lake lake = (Lake) resources.getObject("lake:constructor");
 List list = (List) resources.getObject("ref:list");
 
 System.out.println("湖名=" + lake.getName());
 System.out.println("リスト=" + list.toString());

 >>湖名=支笏湖
 >>リスト=[支笏湖, 阿寒湖, 倶多楽湖]

 


コンストラクタの概要
ComponentFactory()
          プロパティを初期値で初期化します。
 
メソッドの概要
 java.lang.String getPrefix()
          全てのリソースに対する接頭辞を返却します。
 java.lang.String[] getSourcesPrefix()
          リソース単位での接頭辞の配列を返却します。
protected  void initValues(java.util.Map lookup, shohaku.ginkgo.TagNode root, int index)
          リソースの初期化および登録します。
protected  ResourceSet newResourceSetObject(java.util.Map lookup)
          マップからリソース集合を生成して返却します。
 void setPrefix(java.lang.String prefix)
          全てのリソースに対する接頭辞を格納します。
 void setSourcesPrefix(java.lang.String[] prefixs)
          リソース単位での接頭辞の配列を格納します。
 
クラス shohaku.shoin.factory.AbstractGinkgoResourceSetFactory から継承したメソッド
findClassLoader, getClassLoader, getDefaultNodeCompositeRule, getDocumentCompositeRule, getNodeCompositeRule, getParentDocument, getParseDocument, getResourceSet, load, load, newResourceSetMap, setClassLoader, setDocumentCompositeRule, setNodeCompositeRule, setParentDocument, setParseDocument
 
クラス shohaku.shoin.factory.AbstractIOResourceSetFactory から継承したメソッド
getIOResources, setIOResources
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
インタフェース shohaku.shoin.IOResourceSetFactory から継承したメソッド
getIOResources, setIOResources
 

コンストラクタの詳細

ComponentFactory

public ComponentFactory()
プロパティを初期値で初期化します。

メソッドの詳細

newResourceSetObject

protected ResourceSet newResourceSetObject(java.util.Map lookup)
マップからリソース集合を生成して返却します。
デフォルトでは ObjectCreationProxy 用のリソース集合を生成します。

オーバーライド:
クラス AbstractGinkgoResourceSetFactory 内の newResourceSetObject
パラメータ:
lookup - リソースを格納するマップ
戻り値:
リソース集合

initValues

protected void initValues(java.util.Map lookup,
                          shohaku.ginkgo.TagNode root,
                          int index)
                   throws shohaku.ginkgo.GinkgoException
クラス AbstractGinkgoResourceSetFactory の記述:
リソースの初期化および登録します。

定義:
クラス AbstractGinkgoResourceSetFactory 内の initValues
パラメータ:
lookup - リソースを格納するマップ
root - ルートタグ
index - IOリソースのインデックス
例外:
shohaku.ginkgo.GinkgoException

getPrefix

public java.lang.String getPrefix()
インタフェース ResourceKeyPrefixSupport の記述:
全てのリソースに対する接頭辞を返却します。

定義:
インタフェース ResourceKeyPrefixSupport 内の getPrefix
戻り値:
全てのリソースに対する接頭辞

setPrefix

public void setPrefix(java.lang.String prefix)
インタフェース ResourceKeyPrefixSupport の記述:
全てのリソースに対する接頭辞を格納します。

定義:
インタフェース ResourceKeyPrefixSupport 内の setPrefix
パラメータ:
prefix - 全てのリソースに対する接頭辞

getSourcesPrefix

public java.lang.String[] getSourcesPrefix()
インタフェース ResourceKeyPrefixSupport の記述:
リソース単位での接頭辞の配列を返却します。

定義:
インタフェース ResourceKeyPrefixSupport 内の getSourcesPrefix
戻り値:
リソース単位での接頭辞の配列

setSourcesPrefix

public void setSourcesPrefix(java.lang.String[] prefixs)
インタフェース ResourceKeyPrefixSupport の記述:
リソース単位での接頭辞の配列を格納します。

定義:
インタフェース ResourceKeyPrefixSupport 内の setSourcesPrefix
パラメータ:
prefixs - リソース単位での接頭辞の配列