<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
><channel><title>Himmel &#187; aop</title> <atom:link href="http://lazing.ave7.net/tag/aop/feed/" rel="self" type="application/rss+xml" /><link>http://lazing.ave7.net</link> <description>时间很长；现在很短；距离很长；相遇很短</description> <lastBuildDate>Wed, 11 Jan 2012 18:03:14 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license> <item><title>Spring 2.5 AOP Schema编程小解</title><link>http://lazing.ave7.net/2008/spring-25-aop-schema-urinate-programming/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=spring-25-aop-schema-urinate-programming</link> <comments>http://lazing.ave7.net/2008/spring-25-aop-schema-urinate-programming/#comments</comments> <pubDate>Fri, 22 Feb 2008 06:41:07 +0000</pubDate> <dc:creator>某L</dc:creator> <category><![CDATA[Tech Forge]]></category> <category><![CDATA[aop]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Spring]]></category> <category><![CDATA[xml]]></category><guid isPermaLink="false">http://lazing.ave7.net/blog/?p=241</guid> <description><![CDATA[AOP是已经是蔓延了好几年的话题，不过因为没有标准化的平台以及工具的缺乏，一直没有很好的推广。这里所用的AOP实现主要是Spring对AspectJ的封装。感谢Spring的出色贡献，我们甚至都不用知道什么是AspectJ就可以使用AOP概念进行程序设计和实现了。 AOP编程模型 通常情况下，程序中有很多公共的部分，比如事务控制，比如LOG记录。他们遍布程序各处，使代码凌乱不堪难以维护。AOP是对OOP一个很好的补充。OOP很好的描述了业务模型中各个组件的交互方式，但是对于系统组件的装配与互操作，却鲜有明确的定义。 下面就是这样的一个应用场景，对于一个业务方法，比如queryUserInfo我们都需要事务控制，日志记录。 从业务方法角度看AOP 在每一次调用业务方法时，AOP框架会使用around方式调用装配给业务方法的adviser..(可能更好理解的方式是类似 beforeMethod, afterMethod&#8230;)。 从Adviser看AOP 一个Adviser可能被装配给多个业务类的多个方法，通过不同的操作模型完成相关任务。 Spring 2.5 与AOP实现 下面通过一个非常简单的例子来说明Spring中AOP的Schema配置实现方式。 在此之前，应当对Spring 2.5 的Schema机制以及AOP AspectJ编程的一般概念有所了解。 请先阅读 Aspect Oriented Programming with Spring 关于AspectJ编程的相关概念及模式，请访问AspectJ website 下面是AOP的配置spring bean xml 文件 下面是 org.ave7.ws.aop.SystemMonitor 类的实现代码 package org.ave7.ws.aop; import org.aspectj.lang.ProceedingJoinPoint; import org.apache.commons.collections.LRUMap; import org.apache.commons.lang.builder.ReflectionToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.apache.commons.lang.time.DurationFormatUtils; import org.apache.commons.lang.time.StopWatch; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class SystemMonitor { <a href="http://lazing.ave7.net/2008/spring-25-aop-schema-urinate-programming/"> read more <span class="meta-nav">&#187;</span></a><br /><div><img src="http://lazing.ave7.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br />]]></description> <content:encoded><![CDATA[<p>AOP是已经是蔓延了好几年的话题，不过因为没有标准化的平台以及工具的缺乏，一直没有很好的推广。这里所用的AOP实现主要是Spring对AspectJ的封装。感谢Spring的出色贡献，我们甚至都不用知道什么是AspectJ就可以使用AOP概念进行程序设计和实现了。</p><h4>AOP编程模型</h4><p>通常情况下，程序中有很多公共的部分，比如事务控制，比如LOG记录。他们遍布程序各处，使代码凌乱不堪难以维护。AOP是对OOP一个很好的补充。OOP很好的描述了业务模型中各个组件的交互方式，但是对于系统组件的装配与互操作，却鲜有明确的定义。</p><p>下面就是这样的一个应用场景，对于一个业务方法，比如queryUserInfo我们都需要事务控制，日志记录。</p><h5>从业务方法角度看AOP</h5><p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="258" alt="AOP  Example 1" src="http://lazing.ave7.net/" width="293" border="0"></p><p>在每一次调用业务方法时，AOP框架会使用around方式调用装配给业务方法的adviser..(可能更好理解的方式是类似 beforeMethod, afterMethod&#8230;)。</p><h5>从Adviser看AOP</h5><p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="154" alt="image" src="http://lazing.ave7.net/" width="363" border="0"></p><p>一个Adviser可能被装配给多个业务类的多个方法，通过不同的操作模型完成相关任务。</p><h4>Spring 2.5 与AOP实现</h4><p>下面通过一个非常简单的例子来说明Spring中AOP的Schema配置实现方式。</p><p>在此之前，应当对Spring 2.5 的Schema机制以及AOP AspectJ编程的一般概念有所了解。</p><p>请先阅读</p><ul><li><a href="http://static.springsource.org/spring/docs/2.5.x/reference/aop.html">Aspect Oriented Programming with Spring</a><li>关于AspectJ编程的相关概念及模式，请访问<a href="http://www.eclipse.org/aspectj/">AspectJ website</a></li></ul><p>下面是AOP的配置spring bean xml 文件</p><pre class="xml" name="code"><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="<a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a>" xsi:schemalocation="<a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a> <a href="http://www.springframework.org/schema/beans/spring-beans.xsd">http://www.springframework.org/schema/beans/spring-beans.xsd</a>
		<a href="http://www.springframework.org/schema/aop">http://www.springframework.org/schema/aop</a> <a href="http://www.springframework.org/schema/aop/spring-aop.xsd">http://www.springframework.org/schema/aop/spring-aop.xsd</a>
		<a href="http://www.springframework.org/schema/tx">http://www.springframework.org/schema/tx</a> <a href="http://www.springframework.org/schema/tx/spring-tx.xsd">http://www.springframework.org/schema/tx/spring-tx.xsd</a>" xmlns:tx="<a href="http://www.springframework.org/schema/tx">http://www.springframework.org/schema/tx</a>" xmlns:aop="<a href="http://www.springframework.org/schema/aop">http://www.springframework.org/schema/aop</a>" xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>">
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		
		<tx:attributes>
			
			<tx:method name="get*" read-only="true" />
			<tx:method name="find*" read-only="true" />
			<tx:method name="page*" read-only="true" />
			<tx:method name="load*" read-only="true" />
			<tx:method name="query*" read-only="true" />
			
			<tx:method name="*" />
		</tx:attributes>
	</tx:advice>
	
	<bean class="org.ave7.ws.aop.SystemMonitor" id="systemMonitor">
	</bean>

	<aop:config>
		<aop:pointcut id="serviceMethods" expression="execution(* org.ave7.ws.service.impl.*.*(..))" />
		<aop:advisor pointcut-ref="serviceMethods" advice-ref="txAdvice" />
		
		<aop:aspect ref="systemMonitor">
			<aop:around pointcut-ref="serviceMethods" method="profileMethod" />
		</aop:aspect>
	</aop:config>

	
	<bean class="org.ave7.ws.service.impl.UserServiceImpl" id="userService">
	</bean>

</beans>
</pre><p>下面是 org.ave7.ws.aop.SystemMonitor 类的实现代码</p><pre name="code" class="java">
package org.ave7.ws.aop;

import org.aspectj.lang.ProceedingJoinPoint;

import org.apache.commons.collections.LRUMap;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SystemMonitor {

    private static final LRUMap logMap = new LRUMap(100);

    // 参数call包含了被调用方法的相关信息，请参考ApectJ网站
    public Object profileMethod(ProceedingJoinPoint call) throws Throwable {
        Log log = obtainLogger(call.getTarget().getClass());
        if (log.isDebugEnabled()) {
            log.debug("call " + call.getSignature().toLongString());
            log.debug("with para: "
                    + ReflectionToStringBuilder.toString(call.getArgs(),
                            ToStringStyle.MULTI_LINE_STYLE, true));

            StopWatch watch = new StopWatch();

            watch.start();

            try {
                Object rt = call.proceed();

                log.debug("return : "
                        + ReflectionToStringBuilder.toString(rt,
                                ToStringStyle.MULTI_LINE_STYLE, true));
                return rt;
            } catch (Throwable e) {
                log.warn("exception: " + e.getMessage(), e);
                throw e;

            } finally {
                watch.stop();
                log.debug("executing time: "
                        + DurationFormatUtils.formatDuration(watch.getTime(),
                                "m:s.S"));

            }
        } else {
            return call.proceed();
        }

    }

    private Log obtainLogger(Class<?> clazz) {

        Log log = (Log) logMap.get(clazz);
        if (null == log) {
            log = LogFactory.getLog(clazz);
            logMap.put(clazz, log);
        }
        return log;
    }

}
</pre><ul><li><a href="http://lazing.ave7.net/2007/xfire-and-spring-development-of-the-use-of-web-services/" rel="bookmark" title="2007/12/29">使用XFire与Spring开发Web Services</a></li><li><a href="http://lazing.ave7.net/2007/preamble-lazingu002639s-java-guide/" rel="bookmark" title="2007/06/23">序言 &#8211; Lazing&#8217;s Java Guide</a></li><li><a href="http://lazing.ave7.net/2009/teaching-paste-how-to-write-plug-ins-maven2/" rel="bookmark" title="2009/05/26">教学贴：如何编写Maven2插件</a></li><li><a href="http://lazing.ave7.net/2009/twitter-to-see-from-the-enterprise-software-architecture-such-as-a/" rel="bookmark" title="2009/06/28">从Twitter等看企业软件架构（一）</a></li><li><a href="http://lazing.ave7.net/2008/talk-about-easymock/" rel="bookmark" title="2008/02/10">说一下EasyMock</a></li></ul><p></p><p><a href="http://www.bshare.cn/share?url=http%3A%2F%2Flazing.ave7.net%2F2008%2Fspring-25-aop-schema-urinate-programming%2F&title=Spring+2.5+AOP+Schema%E7%BC%96%E7%A8%8B%E5%B0%8F%E8%A7%A3" title="用bShare分享或收藏本文"><img src="http://static.bshare.cn/frame/images/button_custom1-zh.gif" alt="用bShare分享或收藏本文" /></a></p><br /><div><img src="http://lazing.ave7.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br /> <img src="http://lazing.ave7.net/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=241" width="1" height="1" style="display: none;" />]]></content:encoded> <wfw:commentRss>http://lazing.ave7.net/2008/spring-25-aop-schema-urinate-programming/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license> </item> <item><title>Dynamic Language and DSL</title><link>http://lazing.ave7.net/2007/dynamic-language-and-dsl/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dynamic-language-and-dsl</link> <comments>http://lazing.ave7.net/2007/dynamic-language-and-dsl/#comments</comments> <pubDate>Thu, 29 Nov 2007 12:54:40 +0000</pubDate> <dc:creator>某L</dc:creator> <category><![CDATA[Tech Forge]]></category> <category><![CDATA[aop]]></category> <category><![CDATA[dsl]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[ruby]]></category> <category><![CDATA[xml]]></category> <category><![CDATA[xsl]]></category><guid isPermaLink="false">http://lazing.ave7.net/blog/?p=199</guid> <description><![CDATA[这是一篇技术评论，呃，请自行掠过 早上拜读了Martin Fowler老人家的BLOG Groovy or Ruby ，兴致勃勃的看这个时尚的家伙对动态语言的高谈阔论。下午就在InfoQ看到了对其新书的点评——Martin Fowler unveils details of his upcoming DSL book. 两样东西放到一起很有意思。动态语言与领域语言(Domain-Specific Language)。 MF的书中是这样介绍的。 如果我们把XSLT看成是专门格式化XML的语言，那么XSLT就是XML的DSL。 那么DSL有什么用呢？ 根据MF的论述 Domain-Specific Language DSL与通用语言相区别，是为特定目的而生的语言，它并不是什么新东西，历史几乎和计算机的历史一样长。 比如Windows的批处理文件，再比如HTML（某种意义上）。处理它们的程序和普通的应用程序不一样，这些程序并不知道这些语言具体描述了什么，却知道他们到最后大概是什么样子。但我们也不能把这些应用程序归结为系统程序，毕竟，你不能用这些动态语言写成任何一个通常意义上的程序。这些语言轻巧灵活，惹人喜爱，却长期处于没人在乎的地位。几乎没有任何一个大学开设JavaScript或者BAT的课程。然而，用它们开发的程序铺天盖地，甚至有些开发者都没有意识到他们在写程序。 我们到底有多少DSL，没有人说的清楚，甚至怎么界定都没有标准。然而这种工具的确越来越受重视。大型的软件通常都有自己的工具语言，比如SAP，比如PepleSoft，比如MathLib，比如SAS，掌握这些工具通常意味着熟练应用这些语言与相关的领域知识。而由于他们之间毫无联系，同种软件之间有着高昂的替换成本。变相垄断使得DSL由最初的简化用户操作变成了对抗新来者的武器。 标准化是由混乱走向秩序的利器。工业化也是软件行业一直追求的目标。让我们看看工业界是怎么做的，他们拥有流水线，有很好的设计，生产，销售流程。我们常常抱怨软件的变化，生产没有变化吗？现在工业可以高效的适应变化，依靠的就是对领域的深切理解，对规则的灵活掌握。 对标准的无尽追寻是业界走向成熟的重要标志。不妨设想，今后的某天，所有的财务软件都有统一的口径标准，统一的数据格式处理流程。集团化，高质量的软件生产和部署使我们更加有序的获取所需的功能。然而这一切，依靠的就是对DSL领域的入侵。Ruby的流行正式反映了这种入侵，当其追逐者不断的在各种平台上实现这门语言的时候，我们也看到了传统语言正积极的调整。Java向.net学习多语言支持。.net努力的靠近开源社区的标准。 我们说GOP，说AOP，无非就是想把领域问题(Domain Problem)从应用问题里面解离，我们需要成熟的软件产品，需要的是真正模块化的组件，而不是某个既成事实。被巨头们忽悠着团团转的我们，也只能等到他们被迫合作的时候，才能轻松一点。 笔记：DSL之二 使用DSL 笔记：DSL之一 简介 Java Scripting in JDK6 Java Module and Maven 说一下EasyMock Rating: 0.0/5 (0 votes cast)<br /><div><img src="http://lazing.ave7.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br />]]></description> <content:encoded><![CDATA[<blockquote><p>这是一篇技术评论，呃，请自行掠过</p></blockquote><p>早上拜读了Martin Fowler老人家的BLOG <a href="http://martinfowler.com/bliki/GroovyOrJRuby.html">Groovy or Ruby</a> ，兴致勃勃的看这个时尚的家伙对动态语言的高谈阔论。下午就在InfoQ看到了对其新书的点评——<a href="http://www.infoq.com/news/2007/11/martin-fowler-dsl-book">Martin Fowler unveils details of his upcoming DSL book</a>. 两样东西放到一起很有意思。动态语言与领域语言(Domain-Specific Language)。</p><p>MF的书中是这样介绍的。</p><blockquote><p>如果我们把XSLT看成是专门格式化XML的语言，那么XSLT就是XML的DSL。</p></blockquote><p>那么DSL有什么用呢？</p><p>根据MF的论述 <a href="http://martinfowler.com/bliki/DomainSpecificLanguage.html">Domain-Specific Language</a></p><blockquote><p>DSL与通用语言相区别，是为特定目的而生的语言，它并不是什么新东西，历史几乎和计算机的历史一样长。</p></blockquote><p>比如Windows的批处理文件，再比如HTML（某种意义上）。处理它们的程序和普通的应用程序不一样，这些程序并不知道这些语言具体描述了什么，却知道他们到最后大概是什么样子。但我们也不能把这些应用程序归结为系统程序，毕竟，你不能用这些动态语言写成任何一个通常意义上的程序。这些语言轻巧灵活，惹人喜爱，却长期处于没人在乎的地位。几乎没有任何一个大学开设JavaScript或者BAT的课程。然而，用它们开发的程序铺天盖地，甚至有些开发者都没有意识到他们在写程序。</p><p>我们到底有多少DSL，没有人说的清楚，甚至怎么界定都没有标准。然而这种工具的确越来越受重视。大型的软件通常都有自己的工具语言，比如SAP，比如PepleSoft，比如MathLib，比如SAS，掌握这些工具通常意味着熟练应用这些语言与相关的领域知识。而由于他们之间毫无联系，同种软件之间有着高昂的替换成本。变相垄断使得DSL由最初的简化用户操作变成了对抗新来者的武器。</p><p>标准化是由混乱走向秩序的利器。工业化也是软件行业一直追求的目标。让我们看看工业界是怎么做的，他们拥有流水线，有很好的设计，生产，销售流程。我们常常抱怨软件的变化，生产没有变化吗？现在工业可以高效的适应变化，依靠的就是对领域的深切理解，对规则的灵活掌握。</p><p>对标准的无尽追寻是业界走向成熟的重要标志。不妨设想，今后的某天，所有的财务软件都有统一的口径标准，统一的数据格式处理流程。集团化，高质量的软件生产和部署使我们更加有序的获取所需的功能。然而这一切，依靠的就是对DSL领域的入侵。Ruby的流行正式反映了这种入侵，当其追逐者不断的在各种平台上实现这门语言的时候，我们也看到了传统语言正积极的调整。Java向.net学习多语言支持。.net努力的靠近开源社区的标准。</p><p>我们说GOP，说AOP，无非就是想把领域问题(Domain Problem)从应用问题里面解离，我们需要成熟的软件产品，需要的是真正模块化的组件，而不是某个既成事实。被巨头们忽悠着团团转的我们，也只能等到他们被迫合作的时候，才能轻松一点。<ul><li><a href="http://lazing.ave7.net/2011/ruby-on-rails-installation-error-one-case/" rel="bookmark" title="2011/05/09">Ruby on Rails 安装错误一例</a></li><li><a href="http://lazing.ave7.net/2007/xfire-and-spring-development-of-the-use-of-web-services/" rel="bookmark" title="2007/12/29">使用XFire与Spring开发Web Services</a></li><li><a href="http://lazing.ave7.net/2008/maven-need-to-act-as-wikipedia/" rel="bookmark" title="2008/05/23">Maven need to act as Wikipedia</a></li><li><a href="http://lazing.ave7.net/2008/jruby-note-simple-is-beautiful/" rel="bookmark" title="2008/04/25">JRuby Note: 简单就是美</a></li><li><a href="http://lazing.ave7.net/2008/java-scripting-in-jdk6/" rel="bookmark" title="2008/07/21">Java Scripting in JDK6</a></li></ul><p></p><p><a href="http://www.bshare.cn/share?url=http%3A%2F%2Flazing.ave7.net%2F2007%2Fdynamic-language-and-dsl%2F&title=Dynamic+Language+and+DSL" title="用bShare分享或收藏本文"><img src="http://static.bshare.cn/frame/images/button_custom1-zh.gif" alt="用bShare分享或收藏本文" /></a></p><br /><div><img src="http://lazing.ave7.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br /> <img src="http://lazing.ave7.net/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=199" width="1" height="1" style="display: none;" />]]></content:encoded> <wfw:commentRss>http://lazing.ave7.net/2007/dynamic-language-and-dsl/feed/</wfw:commentRss> <slash:comments>4</slash:comments> <creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license> </item> </channel> </rss>
