来自:matrix开源技术 作者:neo译 [2003/09/27]
| ||||||||||
访问Metadata 为了用元数据,它在运行时间必须是可达的。类的元数据是通过Invocation对象可达的。为了在我们的例子使用它,TracingInterceptor必须要修改一点点。
如果我们能够为特定的实例关闭和打开,那将很酷。JBoss AOP有一个API,他绑定元数据到一个对象实例,但是让我们伪装一个实际的跟踪API是一个更好的方案。在这例子中,我们通过用一个导言,将改变POJO类的本身的定义。我们将强制POJO类去实现一个跟踪借口和提供混合类,这个混合类处理新的跟踪API。这将是跟踪借口:
Tracing接口将在混合类中实现。当一个POJO是实例时,一个混合对象混合类将绑定到POJO类。下面是实现:
绑定一个导言 好了,所以我们定义跟踪接口,并且实现这个混合类。下一步是应用导言到POJO类。像拦截器,我们必须在XML中定义一个ponitcut。让我们看一下这项什么。
运行例子3 POJO类为了显示TracingAPI怎么被访问,它已经被扩展了一点。TracingInterceptor仍然和例子2一样。
面向方面编程对于软件开发是一个强有力的新工具。为了使你的软件开发过程更加动态和流畅,用JBoss4.0,你能够实现你自己的拦截器,元数据和导言。更详细的文档参见站点www.jboss.org。 |
面向方面编程(AOP)和JBoss(二)
最新推荐文章于 2016-08-08 16:04:16 发布