View Javadoc
1 /*
2 * Advice.java
3 * Created on August 30, 2003
4 *
5 * The Blues Framework - A lightweight application framework
6 * Copyright (C) 2003 Lonnie Pryor
7 * http://blues.lonniepryor.com
8 *
9 * This library is free software; you can redistribute it and/or modify it under the
10 * terms of the GNU Lesser General Public License as published by the Free Software
11 * Foundation; either version 2.1 of the License, or (at your option) any later
12 * version.
13 *
14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
16 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License along
19 * with this library; if not, write to:
20 *
21 * The Free Software Foundation, Inc.
22 * 59 Temple Place, Suite 330
23 * Boston, MA 02111-1307 USA
24 *
25 */
26 package com.lonniepryor.blues.sys;
27
28 import com.lonniepryor.blues.aop.Pointcut;
29 import com.lonniepryor.blues.cfg.AdviceCfg;
30 import com.lonniepryor.blues.util.BeanHelper;
31
32 /***
33 * Models the abstract view of a Blues advice.
34 *
35 * @author Lonnie Pryor
36 * @version $Revision: 1.1 $
37 */
38 public final class Advice extends Component {
39 /*** The context this service is declared in. */
40 private final Context context;
41 /*** The advice configuration information. */
42 private final AdviceCfg configuration;
43 /*** The advice instance. */
44 private final Object adviceInstance;
45
46 /***
47 * Creates a new Advice object.
48 *
49 * @param context The context this service is declared in.
50 * @param configuration The advice configuration information.
51 */
52 Advice (Context context, AdviceCfg configuration) {
53 this.context = context;
54 this.configuration = configuration;
55 if (!AdviceCfg.validAdviceTypes.isSatisfiedBy(configuration.getAdviceType()))
56 throw new SystemException(
57 "Invalid advice type: " + configuration.getAdviceType().getName());
58 this.adviceInstance = BeanHelper.introspect(configuration.getAdviceType())
59 .newBeanInstance();
60 }
61
62 /***
63 * Returns the pointcut that selects this advice.
64 *
65 * @return The pointcut that selects this advice.
66 */
67 Pointcut getPointcut () {
68 return configuration.getPointcutToAdvise();
69 }
70
71 /* (non-Javadoc)
72 * @see com.lonniepryor.blues.sys.Component#getComponentInstance()
73 */
74 Object getComponentInstance () {
75 return adviceInstance;
76 }
77
78 /* (non-Javadoc)
79 * @see com.lonniepryor.blues.sys.Component#configureInstance()
80 */
81 void configureInstance () {
82 try {
83 configuration.configure(adviceInstance, context);
84 } catch (RuntimeException re) {
85 throw new SystemException(
86 "Error configuring advice of type " + configuration.getAdviceType()
87 + " in '" + context.getContextPath() + "': " + re.getMessage(), re);
88 }
89 }
90
91 /***
92 * Registers the advice instance with the supplied registry.
93 *
94 * @param registry The registry to register with.
95 */
96 void registerWith (Registry registry) {
97 registry.registerAdvice(adviceInstance);
98 }
99 }
This page was automatically generated by Maven