フォトアルバム

2009年7月

      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  

なかのひと

アンケート

  • Do you Like?
    アンケート
    どのColdfusion用フレームワークが好き?
    ModelGlue:Unity
    ModelGLue
    Mach-II
    FuseBox
    LiteWire
    OnTap
    ColdBox
    OnAir
    cfWheels
    CFRails

    [PR]アンログ.jp 自動車保険

373news.com

想ひ出

  • Dvc00050
    携帯で撮った写真をアルバムにしています。

サムネイル

  • CF-OOP









  • ganymean.org









  • シナプス

Google Analytics

« オープンソースCFプロジェクト | メイン | ModelGlue+TarTan or ColdSpring »

LoggingAOP with ColdSpring

今日は、ColdSpringAOPとLog4jを使ったロギングサービスについて、解説します。
Chris ScottのColdSpringAOPのチュートリアルから引用してみます。

1.最初に、LoggingServiceを定義します。javaのlog4jからloggerクラスを生成しています。

<cfcomponent name="LoggingService" output="false">

  <cffunction name="init" returntype="net.klondike.service.LoggingService" access="public" output="false">
    <cfset var category = CreateObject("java", "org.apache.log4j.Category") />
    <cfset variables.logger = category.getInstance('net.klondike') />

    <cfreturn this />
  </cffunction>
 
  <cffunction name="info" access="public" returntype="void" output="false">
    <cfargument name=message" type="string" required="true" />
    <cfif variables.logger.isInfoEnabled()>
    <cfset variables.logger.info(arguments.message) />
    </cfif>

  </cffunction>
 
</cfcomponent>

2.次に、AOPパートです。loggingBeforeAdviceを定義します。

<cfcomponent name="loggingBeforeAdvice" extends="coldspring.aop.BeforeAdvice">

  <!--- setters for dependencies --->
  <cffunction name="setLoggingService" returntype="void" access="public""false" hint="Dependency: security service"> output=
    <cfargument name="loggingService" type="net.klondike.service.LoggingService" required="true"/>
    <cfset variables.m_loggingService = arguments.loggingService />
  </cffunction>
<cffunction name="getLoggingService" returntype="net.klondike.service.LoggingService""public" output="false" hint="Dependency: security service"> access=
    <cfreturn variables.m_loggingService />
  </cffunction>
 
  <!--- before() is called by the aop framework before method invocation --->
  <cffunction name="before" access="public" returntype="any">
    <cfargument name="method" type="coldspring.aop.Method" required="true" />
    <cfargument name="args" type="struct" required="true" />
    <cfargument name="target" type="any" required="true" />
   
    <cfset var arg = '' />
    <cfset var argString = '' />
    <cfset var objName = getMetadata(arguments.target).name />
    <cfloop collection="#args#" item="arg">
      <cfif isSimpleValue(args[arg])>
        <cfif len(argString)>
          <cfset argString = argString & ', ' />
        </cfif>
        <cfset argString = argString & arg & '=' & args[arg] >
      </cfif>
    </cfloop>
        <cfset variables.m_loggingService.info("[" & objName & "] " & method.getMethodName() & "(" & argString & ") called!") />
      </cffunction>
  </cfcomponent>

3.最後に、ColdSpringのbean定義を行います。

<beans>
 
  <!—define the logging service -->
  <bean id="loggingService"
        class="net.klondike.component.LoggingService" />

 
  <!--define the loggingBeforeAdvice and set its logging service property to reference the bean above -->
  <bean id="loggingBeforeAdvice"
        class="net.klondike.aspects.loggingBeforeAdvice">

    <property name="loggingService">
      <ref bean="loggingService" />
    </property>
  </bean>
 
  <!—now define a NamedMethodPointcutAdvisor, set the advice property to the bean above, and set its mappedNames property to ‘*’ which will create a pointcut to match all methods excluding any init method -->
  <bean id="loggingAdvisor"
        class="coldspring.aop.support.NamedMethodPointcutAdvisor">

    <property name="advice">
      <ref bean="loggingBeforeAdvice" />
    </property>
    <property name="mappedNames">
      <value>*</value>
    </property>
  </bean>
 
  <!-- to create the proxy object, first create our dao as the target object -->
  <bean id="catalogDaoTarget"
        class="net.klondike.component.catalogDAO">
    <property name="dsn">
      <value>klondike</value>
    </property>
  </bean>
 
  <!-- now create a ProxyFactoryBean with the id catalogDAO, set the target to the catalogDaoTarget bean above, and give it ,the id of the NamedMethodPointcutAdvisor above in the list of interceptorNames -->
  <bean id="catalogDAO"
        class="coldspring.aop.framework.ProxyFactoryBean">
    <property name="target">
      <ref bean="catalogDaoTarget" />
    </property>
    <property name="interceptorNames">
      <list>
        <value>loggingAdvisor</value>
      </list>
    </property>
  </bean>

 
  <!--now to use the proxy DAO, we give the id of the ProxyFactoryBean to the catalog service as the reference for the property catalogDAO -->
  <bean id="catalogService"
        class="net.klondike.component.CatalogService">
    <property name="catalogDAO">
      <ref bean="catalogDAO" />
    </property>
  </bean>

</beans>

トラックバック

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

このページへのトラックバック一覧 LoggingAOP with ColdSpring:

コメント

コメントを投稿

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

ログイン

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

    パスワード:

PR情報

  • [[PR]]
  • おすすめバナー

更新ブログ

google Search

  • Google
    blog.ganymean.org
    WWW

最近のトラックバック

Google

SHINOBI

Blog powered by TypePad
Member since 04/2005