KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > aop > AdviceRef


1 package org.sapia.soto.aop;
2
3 import org.sapia.soto.ConfigurationException;
4
5 import java.util.Map JavaDoc;
6
7
8 /**
9  * An instance of this class refers to an advice - or, rather, to an advice
10  * definition.
11  *
12  * @see org.sapia.soto.aop.AdviceDef
13  *
14  * @author Yanick Duchesne
15  * <dl>
16  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
17  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
18  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
19  * </dl>
20  */

21 public class AdviceRef {
22   private String JavaDoc _id;
23
24   /**
25    * Constructor for AdviceRef.
26    */

27   public AdviceRef() {
28     super();
29   }
30
31   /**
32    * Sets the identifier of the advice to which this instance refers.
33    *
34    * @param the identifier of an advice.
35    * @see AdviceDef
36    */

37   public void setId(String JavaDoc id) {
38     _id = id;
39   }
40
41   /**
42    * Returns an <code>Advice</code> corresponding to this instance's
43    * identifier.
44    *
45    * @param defs a <code>Map</code> containing id-to<code>AdviceDef</code>
46    * mappings.
47    */

48   public Advice resolve(Map JavaDoc defs) throws ConfigurationException {
49     if (_id == null) {
50       throw new ConfigurationException(
51         "'id' attribute not set on advice reference");
52     }
53
54     AdviceDef def = (AdviceDef) defs.get(_id);
55
56     if (def == null) {
57       throw new ConfigurationException("No advice definitions matches ID: " +
58         _id);
59     }
60
61     return def.getInstance();
62   }
63 }
64
Popular Tags