modelglue+tartanのサンプル紹介-4
さて、modelglue.xmlの一例を紹介したところで、controller<userManager>を見てみます。
controller<userManager>は、ModelGlue.Core.Controllerを拡張したものです。
冒頭に、お決まりのinit( )メソッドがありますが、一般的なmodelglueアプリケーションの場合と比較して、tartan連携モデルでは、tartanサービスの呼出し手続きをinit( )で行います。
1.一般的modelGlueアプリケーション
<cffunction name="init" returntype="usermanager" access="public" output="false">
<cfargument name="core" type="ModelGlue.ModelGlue" required="true"/>
<cfset super.init(arguments.core) />
<cfset variables.dsn = arguments.core.getConfigSetting("dsn") />
<cfset variables.dbUser = arguments.core.getConfigSetting("dbUser") />
<cfset variables.dbPass = arguments.core.getConfigSetting("dbPass") />
<cfreturn this />
</cffunction>
2.tartan連携modelGlueアプリケーション
<cffunction name="Init" access="Public" returnType="userManager" output="false" hint="I build a new SampleController">
<cfargument name="ModelGlue" type="ModelGlue.ModelGlue" required="true" />
<cfset var result = "" />
<cfset super.Init(arguments.ModelGlue) />
<!--- Load the config params for the Tartan app we're talking to --->
<cfset result = getModelGlue().getConfigBean("Tartan.xml") />
<!--- Load the Tartan proxy --->
<cfset variables.tartanProxy = createObject("component", "ModelGlue.Util.TartanProxy").init(result) />
<!--- We're going to need the catClub service universally --->
<cfset variables.clubService = getTartan().CreateService("catClub") />
<!--- append from original "init" function --->
<cfset variables.dsn = arguments.ModelGlue.getConfigSetting("dsn") />
<cfset variables.dbUser = arguments.ModelGlue.getConfigSetting("dbUser") />
<cfset variables.dbPass = arguments.ModelGlue.getConfigSetting("dbPass") />
<cfreturn this />
</cffunction>
tartan連携アプリケーションでは、以下の部分をおまじないとして追加すればいいようです。
(ただし、CreateService( ) 内のサービス名をターゲットに応じて変更してください。)
<!--- Load the config params for the Tartan app we're talking to --->
<cfset result = getModelGlue().getConfigBean("Tartan.xml") />
<!--- Load the Tartan proxy --->
<cfset variables.tartanProxy = createObject("component", "ModelGlue.Util.TartanProxy").init(result) />
<!--- We're going to need the catClub service universally --->
<cfset variables.clubService = getTartan().CreateService("catClub") />
次回は、メソッド<getMembers>について、紹介します。
コメント