|
||||||||||
前のクラス 次のクラス | フレームあり フレームなし | |||||||||
概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |
java.lang.Objectshohaku.configutils.ComponentFactory
public class ComponentFactory
XMLデータで定義された情報を基に、指定のスコープでコンポーネントを生成する機能を提供します。
例:
// 湖を表現するオブジェクト 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; } } //定義ファイル lake-factory.xml <component-factory> <!-- インスタンスを生成する(シングルトンで定義、一度のみ生成する) --> <components name="new"> <!-- コンストラクタ --> <component id="new.constructor" name="constructor" class="Foo" instance="singleton"> <init> <arg><string>支笏湖</string></arg> </init> </component> <!-- デフォルトコンストラクタとプロパティ --> <component id="new.property" name="property" class="Foo" instance="singleton"> <property name="name"> <string>阿寒湖</string> </property> </component> <!-- デフォルトコンストラクタとメソッド --> <component id="new.method" name="method" class="Foo" instance="singleton"> <method name="setName"> <arg><string>倶多楽湖</string></arg> </method> </component> </components> <!-- コンポーネントを参照する(プロトタイプで定義、毎回新規生成する) --> <components name="ref"> <!-- コンポーネントを参照してリストを生成します --> <component name="list" class="java.util.ArrayList" instance="prototype"> <method name="add"> <arg><ref>new.constructor</ref></arg> </method> <method name="add"> <arg><ref>new.property</ref></arg> </method> <method name="add"> <arg><ref>new.method</ref></arg> </method> </component> </components> <component-factory> グループ名とコンポーネント名を ':' で区切りコンポーネント識別子として認識されます。 ファイルの読み取りとコンポーネント取得は以下の様に為ります。 ComponentFactory factory = ComponentFactory.getFactory("lake-factory.xml"); Lake lake = (Lake) factory.getComponent("new:constructor"); List list = (List) factory.getComponent("ref:list"); System.out.println("湖名=" + lake.getName()); System.out.println("リスト=" + list.toString()); >>湖名=支笏湖 >>リスト=[支笏湖, 阿寒湖, 倶多楽湖]
メソッドの概要 | |
---|---|
java.lang.Object |
getComponent(java.lang.String componentId)
指定の識別子を持つコンポーネントを生成して返却します。 |
shohaku.ginkgo.NodeCompositeRule |
getDefaultNodeCompositeRule()
デフォルトの構成ルールを返却します。 |
static ComponentFactory |
getFactory(java.lang.String resourcePath)
定義ファイルからコンポーネントファクトリのインスタンスを生成して返却します。 |
static ComponentFactory |
getFactory(java.lang.String resourcePath,
java.lang.ClassLoader classLoader)
定義ファイルからコンポーネントファクトリのインスタンスを生成して返却します。 |
クラス java.lang.Object から継承されたメソッド |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
メソッドの詳細 |
---|
public shohaku.ginkgo.NodeCompositeRule getDefaultNodeCompositeRule()
public java.lang.Object getComponent(java.lang.String componentId) throws shohaku.core.lang.ObjectCreationException
componentId
- コンポーネント識別子
shohaku.core.lang.ObjectCreationException
- オブジェクトの生成に失敗した場合に発生しますpublic static ComponentFactory getFactory(java.lang.String resourcePath) throws shohaku.core.lang.NoSuchResourceException
resourcePath
- 定義ファイルへのパス
shohaku.core.lang.NoSuchResourceException
- 指定の定義ファイルが発見出来ない場合public static ComponentFactory getFactory(java.lang.String resourcePath, java.lang.ClassLoader classLoader) throws shohaku.core.lang.NoSuchResourceException
resourcePath
- 定義ファイルへのパスclassLoader
- 生成に使用するクラスローダ
shohaku.core.lang.NoSuchResourceException
- 指定の定義ファイルが発見出来ない場合
|
||||||||||
前のクラス 次のクラス | フレームあり フレームなし | |||||||||
概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |