フォトアルバム

2011年10月

            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          

なかのひと

373news.com

google Search

  • Google
    blog.ganymean.org
    WWW

Google Analytics

« Fusebox5 RC1リリース!? | メイン | MG:Unityジェネリック・データ・メッセージ(GDMs) »

MG:Unity カスタムコンフィグレーションの追加方法

今日から数回に分けて、Model-Glue:Unity(MG2:Unity)のマニュアルのうち、Ver1.1から大きく変更・追加されたところを紹介していきます。

第一回目は、ColdSpring.xmlを利用したカスタムコンフィグレーション方法についてです。
(原文タイトル:How To Add Custom Configuration)
メールサーバの情報を、Coldspring.xmlにbean定義し、メッセージリスナー内でこれを呼び出す方法を紹介しています。

アプリケーションでは、しばしばデータソース名かメールサーバなどの何らかの構成情報を知る必要があります。 例として、アプリケーションで<cfmail>タグを使用する必要があり、ファイル中にサーバ名、ユーザ名およびパスワードを、ソースコードの外部に保存する場合を仮定しましょう。このことは、とても良い習慣です。

(1.xからのアップグレードでない)どのModel-Glue: Unityアプリケーションには、全てのアプリケーション構成情報を集中管理するためのColdSpring.xmlがあります。

このColdsping.xmlファイルは、数組の<bean>タグで構成されています。 各々のbeanは、Model-Glueアプリケーション内で問い合わせ可能なCFCを表しています。

Model-Glue:Unityには、一般的な構成の雑事に適したbean(ModelGlue.Bean.CommonBeans.SimpleConfig)があります。そのbeanは、setConfig()ファンクションを通して構造体をセット可能な単一プロパティ(のコンフィグ)を持っています。 この構造は、アプリケーション構成情報を「登録」するのに役立ちます。beanのgetConfigSetting()ファンクションに検索するプロパティ名を与えることによって、各々の設定値にアクセスできます。

これをメールサーバのシナリオに適用するために、ColdSpring.xmlに以下を加えます:

<bean id="mailConfiguration" class="ModelGlue.Bean.CommonBeans.SimpleConfig">
    <property name="config">
        <!-- In Coldspring, a "map" represents a struct -->
        <map>
            <entry key="mailserver">
                <value>mail.mydomain.com</value>
            </entry>
            <entry key="username">
                <value>smtpUsername</value>
            </entry>
            <entry key="password">
                <value>smtpPassword</value>
            </entry>
        </map>
    </property>
</bean>

このXMLベースの構成情報をColdSpring.xmlに追加した後に、この構成設定を使用するのは簡単です。以下に、<cfmail>タグで構成設定を使用する例のリスナー機能を示します:

<cffunction name="sendEmail" access="public" returnType="void" output="false">
    <cfargument name="event" type="any">

    <cfset var message = arguments.event.getValue("message") />
    <cfset var subj = arguments.event.getValue("subj") />
    <cfset var to = arguments.event.getValue("to") />

    <!--- Get mail configuration --->
    <cfset var mailCfg = getModelGlue().getBean("mailConfiguration") />

    <!--- Use the mail configuration to send mail --->

    <cfmail
        to="#to#"
        subject="#subject#"
        server="#mailCfg.getConfigSetting("mailserver")#"
        username="#mailCfg.getConfigSetting("username")#"
        password="#mailCfg.getConfigSetting("password")#"
        >
        #message#
    </cfmail>

</cffunction>

トラックバック

このページのトラックバックURL:
http://app.synapse-blog.jp/t/trackback/190195/6192915

MG:Unity カスタムコンフィグレーションの追加方法を参照しているブログ:

コメント

コメントを投稿

コメントは記事の投稿者が承認するまで表示されません。

ログイン

  • コントロールパネルへのログイン
    アカウント:

    パスワード:

更新ブログ

最近のトラックバック

Google

ブログ powered by TypePad
Member since 04/2005