KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.sapia.soto.aop;
2
3 import org.sapia.soto.ConfigurationException;
4
5 import org.sapia.util.xml.confix.ObjectHandlerIF;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.List JavaDoc;
9 import java.util.Map JavaDoc;
10
11
12 /**
13  * An instance of this class encapsulates advices and advice references.
14  * The latter must correspond to existing advice definitions.
15  *
16  * @author Yanick Duchesne
17  * <dl>
18  * <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>
19  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
20  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
21  * </dl>
22  */

23 public class Group implements ObjectHandlerIF {
24   private String JavaDoc _id;
25   private List JavaDoc _defs = new ArrayList JavaDoc();
26   private List JavaDoc _refs = new ArrayList JavaDoc();
27   private List JavaDoc _advices = new ArrayList JavaDoc();
28
29   /**
30    * Constructor for Group.
31    */

32   public Group() {
33     super();
34   }
35
36   /**
37    * Sets this group's identifier.
38    *
39    * @param an identifier.
40    */

41   public void setId(String JavaDoc id) {
42     _id = id;
43   }
44
45   /**
46    * Returns this group's identifier.
47    *
48    * @param an identifier.
49    */

50   public String JavaDoc getId() {
51     return _id;
52   }
53
54   /**
55    * Internally creates an advice definition and returns it.
56    *
57    * @return an <code>AdviceDef</code>.
58    */

59   public AdviceDef createAdviceDef() {
60     AdviceDef def = new AdviceDef();
61     def.setId("null");
62     _defs.add(def);
63
64     return def;
65   }
66
67   /**
68    * Internally creates an advice definition and returns it.
69    *
70    * @return an <code>AdviceRef</code>.
71    */

72   public AdviceRef createAdviceRef() {
73     AdviceRef ref = new AdviceRef();
74     _refs.add(ref);
75
76     return ref;
77   }
78
79   /**
80    * Returns the advices that this instance encapsulates.
81    *
82    * @return a <code>List</code> of <code>Advice</code> instances.
83    */

84   public List JavaDoc getAdvices() throws ConfigurationException {
85     return _advices;
86   }
87
88   /**
89    * Adds the given advice to this instance.
90    *
91    * @param adv an <code>Advice</code>.
92    */

93   public void addAdvice(Advice adv) {
94     _advices.add(adv);
95   }
96
97   /**
98    * @see org.sapia.util.xml.confix.ObjectHandlerIF#handleObject(String, Object)
99    */

100   public void handleObject(String JavaDoc name, Object JavaDoc obj)
101     throws org.sapia.util.xml.confix.ConfigurationException {
102     if (obj instanceof Advice) {
103       _advices.add(obj);
104     } else {
105       throw new org.sapia.util.xml.confix.ConfigurationException(obj.getClass()
106                                                                     .getName() +
107         " is not an instance of " + Advice.class.getName());
108     }
109   }
110
111   void resolve(Map JavaDoc defs) throws ConfigurationException {
112     AdviceRef ref;
113     AdviceDef def;
114
115     for (int i = 0; i < _defs.size(); i++) {
116       def = (AdviceDef) _defs.get(i);
117       _advices.add(def.getInstance());
118     }
119
120     for (int i = 0; i < _refs.size(); i++) {
121       ref = (AdviceRef) _refs.get(i);
122       _advices.add(ref.resolve(defs));
123     }
124   }
125 }
126
Popular Tags