KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > core > AspectComponent


1 /*
2   Copyright (C) 2001-2004 Renaud Pawlak <renaud@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.core;
20
21 import java.io.FileNotFoundException JavaDoc;
22 import java.io.Serializable JavaDoc;
23 import java.lang.reflect.InvocationTargetException JavaDoc;
24 import java.lang.reflect.Method JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.util.Set JavaDoc;
32 import java.util.Vector JavaDoc;
33 import org.apache.log4j.Logger;
34 import org.objectweb.jac.core.rtti.*;
35 import org.objectweb.jac.util.WeakHashSet;
36 import org.objectweb.jac.util.WrappedThrowableException;
37
38 /**
39  * This class is the root class for the aspect components defined by a
40  * Jac application programmers.
41  *
42  * <p>When programming a new aspect, the programmer must extends this
43  * class and define new pointcuts to link a set of base method
44  * invocation to a wrapping method. If necessary, the programmer can
45  * also redefine the methods of the interface
46  * <code>BaseProgramListener</code> to be able to react on several
47  * events happenning in the base programm such as object
48  * (de)serialization, object instantiation, object naming, object
49  * cloning, or wrappers execution.
50  *
51  * @author <a HREF="mailto:pawlak@cnam.fr">Renaud Pawlak</a>
52  *
53  * @see Pointcut */

54
55 public class AspectComponent
56     implements Serializable JavaDoc, BaseProgramListener
57 {
58     static Logger logger = Logger.getLogger("aspects");
59     static Logger loggerConf = Logger.getLogger("aspects.config");
60     static Logger loggerWrap = Logger.getLogger("wrappers");
61     static Logger loggerWuni = Logger.getLogger("wuni");
62     static Logger loggerPerf = Logger.getLogger("perf");
63
64     protected static final boolean SHARED = false;
65     protected static final boolean NOT_SHARED = true;
66
67     protected static final ClassRepository cr = ClassRepository.get();
68
69     /**
70      * Returns true if the method is defined in the aspect component
71      * class.
72      *
73      * @param methodName the method to test
74      * @return true if aspect component method */

75
76     public static boolean defines(String JavaDoc methodName) {
77         if (ClassRepository.getDirectMethodAccess(AspectComponent.class,
78                                                   methodName )[0] != null)
79             return true;
80         return false;
81     }
82
83     /**
84      * A common configuration method that defines a timer and its
85      * callback.
86      *
87      * <p>The method <code>mi</code> is invoked every
88      * <code>period</code> ms. The method is defined in the aspect
89      * component.
90      *
91      * @param period the timer's period (in ms)
92      * @param callback the method that is called every period
93      * @param args the arguments the callback is called with */

94
95     public void defineTimer(final long period, final MethodItem callback,
96                             final Object JavaDoc[] args) {
97         final AspectComponent ac=this;
98         new Thread JavaDoc() {
99                 public void run() {
100                     while(true) {
101                         try {
102                             sleep(period);
103                         } catch(Exception JavaDoc e) {
104                             e.printStackTrace();
105                         }
106                         callback.invoke(ac,args);
107                     }
108                 }
109             }.start();
110     }
111
112     /**
113      * Tell if the aspect component is already woven to the base
114      * program.<br>
115      *
116      * @see #weave() */

117
118     // public boolean woven = false;
119

120     /**
121      * Memorize how many calls have been performed on
122      * <code>start_weaving_type.start_weaving_method</code>. The
123      * weaving will start when this number reaches
124      * <code>start_weaving_count</code>.<br>
125      *
126      * @see #weave() */

127
128     public int firstCall = -1;
129
130     /**
131      * The type where the weaving has to start.
132      *
133      * @see #weave() */

134    
135     public Class JavaDoc startWeavingType;
136
137     /**
138      * The method where the weaving has to start.<br>
139      *
140      * @see #weave()
141      */

142     public String JavaDoc startWeavingMethod;
143
144     /**
145      * The number of calls of
146      * <code>startWeavingType.startWeavingMethod</code> where the
147      * weaving has to start.<br>
148      *
149      * @see #weave()
150      */

151     public int startWeavingCount;
152
153     /**
154      * The number of instance of <code>startWeavingType</code> where
155      * the weaving has to start.<br>
156      *
157      * @see #weave()
158      */

159     public int startWeavingCCount;
160
161     /**
162      * The wrappers handled by this aspect component.<br>
163      *
164      * @see #getWrappers()
165      * @see #addWrapper(Wrapper)
166      */

167     protected transient WeakHashSet wrappers;
168
169     /**
170      * Tells if this aspect component is a system listener one so that
171      * it can receive events from the org.objectweb.jac.core objects.
172      */

173     protected boolean systemListener = false;
174
175     /**
176      * Sets this aspect component to be a system or non-system
177      * listener.
178      *
179      * @param systemListener if true, the component can receive events
180      * from the JAC core objects (e.g. whenUsingNewInstance) ; if
181      * false, these events are filtered
182      */

183     public void setSystemListener(boolean systemListener) {
184         this.systemListener = systemListener;
185     }
186
187     /**
188      * Tells if this aspect component is a system listener.
189      *
190      * @return true if system listener
191      * @see #setSystemListener(boolean)
192      */

193     public boolean isSystemListener() {
194         return systemListener;
195     }
196
197     /**
198      * The default constructor of the aspect component. By default,
199      * there is no start weaving type or method so that the
200      * <code>weave()</code> is called as the aspect component is
201      * registering to the aspect component manager<br>.
202      *
203      * @see #weave()
204      * @see ACManager#register(String,Object)
205      */

206     public AspectComponent() {
207         logger.debug("New AC: "+this);
208         wrappers = new WeakHashSet();
209         firstCall = -1;
210         startWeavingType = null;
211         startWeavingMethod = null;
212         startWeavingCount = 0;
213         startWeavingCCount = 0;
214         init();
215         // Collaboration.get().setCurAC(ACManager.get().getName(this));
216
}
217
218     /**
219      * Initializes the aspect component so that its state is resetted
220      * to the default state.<br>
221      */

222     public void init() {
223         //woven = false;
224
loggerWrap.debug("clearing wrappers (was "+wrappers+")");
225         wrappers.clear();
226     }
227
228     protected String JavaDoc application=null;
229
230     /**
231      * Gets the application that declares this aspect component.
232      *
233      * @return the application's name
234      * @see Application
235      * @see ApplicationRepository
236      */

237     public String JavaDoc getApplication() {
238         return application;
239     }
240
241     /**
242      * Gets the application that declares this aspect component.
243      *
244      * <p>This method is invoked by the system and should not be
245      * directly used.
246      *
247      * @param application the application's name
248      * @see Application
249      * @see ApplicationRepository */

250
251     public void setApplication(String JavaDoc application) {
252         this.application = application;
253     }
254
255     /**
256      * Returns the wrappers handled by this aspect component. When you
257      * have a reference on a wrapper, you can also know which aspect
258      * component is currently handling it by using
259      * <code>Wrapper.getAspectComponent()</code>.<br>
260      *
261      * @return a vector containing the handdled wrappers
262      * @see #addWrapper(Wrapper)
263      * @see Wrapper#getAspectComponent() */

264    
265     public Collection JavaDoc getWrappers() {
266         return wrappers;
267     }
268    
269     /**
270      * Add a wrapper to the wrappers handled by this aspect
271      * component.
272      *
273      * <p>The programmer should not call this method explicitly unless
274      * s/he really hnows what s/he is doing. In fact, this method is
275      * automatically upcalled when the aspect component wraps a base
276      * program object (see <code>Wrappee.wrap()</code>).<br>
277      *
278      * @param wrapper the wrapper to add to the handdled wrappers
279      * @see #getWrappers()
280      * @see Wrapping#wrap(Wrappee,Wrapper,AbstractMethodItem)
281      */

282
283     public void addWrapper(Wrapper wrapper) {
284         wrappers.add(wrapper);
285     }
286
287     /**
288      * The programmer should define this method to wrap all the
289      * currently instantiated Jac objects so that it plugs a given
290      * aspect. Since the objects might allready be wrapped by other
291      * weavers, the programmer should be careful that it does not wrap
292      * the same object with the same wrapper several times. This can
293      * be done in the weave function by using the
294      * <code>Wrappee.isExtendedBy()</code> method. When a new AC is
295      * registered the weave method is automatically called. In the
296      * jac.prop file, the time when it is called can be parametrized
297      * with the org.objectweb.jac.startWeavingPlaces property.
298      *
299      * <p>This method is only called once. For the objects that are
300      * created after the weaving, the programmer must define the
301      * <code>whenUsingNewInstance</code> method to wrap them.
302      *
303      * <p>The default implementation of the weave method is the
304      * following. In most of the case, it will work if the
305      * <code>whenUsingNewInstance()</code> is correctly defined (thus,
306      * the programer do not have to redefine the weave method).
307      *
308      * <ul><pre>
309      * for (int i=0; i < JacObject.objectCount(); i++) {
310      * simulateUsingNewInstance ( (Wrappee)JacObject.getObject(i) );
311      * }
312      * </pre></ul>
313      *
314      * <b>IMPORTANT NOTE</b>: this method is not deprecated but the
315      * programmer should not overload it since it is much cleaner to
316      * define the <code>whenUsingNewInstance()</code> to implement the
317      * weaving.<br>
318      *
319      * @see #whenUsingNewInstance(Interaction)
320      * @see #simulateUsingNewInstance(Wrappee)
321      * @see Wrapping#isExtendedBy(Wrappee,ClassItem,Class)
322      */

323
324     public void weave() {
325         Iterator JavaDoc it = ObjectRepository.getMemoryObjects().iterator();
326         while (it.hasNext()) {
327             simulateUsingNewInstance((Wrappee)it.next());
328         }
329     }
330
331     /**
332      * This method is called when a new instance (that has not been
333      * wrapped by the aspect component yet) is used by a peer
334      * object.
335      *
336      * <p>By default, this method check out all the pointcuts that have
337      * been defined within this aspect component and accordingly wraps
338      * the wrappee.
339      *
340      * <p>However, for performance or flexibility reasons, the
341      * programmer can also define it from scratch so that the aspects
342      * can dynamically apply while the base program creates new base
343      * objects. The aspect component is notified only once for each new
344      * instance.
345      *
346      * <p>Here is a typical implementation of this method for a
347      * many-to-one wrappees-wrapper relationship:
348      *
349      * <ul><pre>
350      * public class MyAC extends AspectComponent {
351      * public MyWrapper myWrapper = null;
352      * public void whenUsingNewInstance() {
353      * // creates the sole instance of MyWrapper
354      * if ( myWrapper == null ) myWrapper = new MyWrapper();
355      * // make sure we do not wrap an object several times
356      * // (this is usually not useful!!)
357      * if ( wrappee().isExtendedBy( MyWrapper.class ) ) return;
358      * // Do not wrap system or aspect objects
359      * if ( wrappee().getClass().getName().startsWith( "org.objectweb.jac.core." ) ||
360      * wrappee().getClass().getName().startsWith( "org.objectweb.jac.aspects." ) )
361      * return;
362      * // wrap it...
363      * wrappee().wrapAll( myWrapper, "myWrappingMethod" );
364      * }
365      * }
366      * </pre></ul>
367      *
368      * <p>The same but with one-to-one wrappees-wrappers
369      * relationship:
370      *
371      * <ul><pre>
372      * public class MyAC extends AspectComponent {
373      * public void whenUsingNewInstance() {
374      * // make sure we do not wrap an object several times
375      * // (this is usually not useful!!)
376      * if ( wrappee().isExtendedBy( MyWrapper.class ) ) return;
377      * // Do not wrap system or aspect objects
378      * if ( wrappee().getClass().getName().startsWith( "org.objectweb.jac.core." ) ||
379      * wrappee().getClass().getName().startsWith( "org.objectweb.jac.aspects." ) )
380      * return;
381      * // one wrapper for each new instance
382      * MyWrapper myWrapper = new MyWrapper();
383      * // wrap it...
384      * wrappee().wrapAll( myWrapper, "myWrappingMethod" );
385      * }
386      * }
387      * </pre></ul>
388      *
389      * <b>NOTE</b>: this method is not upcalled until the aspect component
390      * is woven.<br>
391      *
392      * @see #weave()
393      */

394     public void whenUsingNewInstance(Interaction interaction) {
395         //if(treatedInstances.contains(wrappee())) return;
396
//treatedInstances.add(wrappee());
397
ClassItem cli = interaction.getClassItem();
398         //Log.trace("wuni",this+": "+method());
399
AbstractMethodItem method = interaction.method;
400
401         loggerWuni.debug("whenUsingNewInstance("+interaction+"); pointcuts: "+pointcuts.size());
402         int i = 0;
403         Iterator JavaDoc it = pointcuts.iterator();
404         while (it.hasNext()) {
405             loggerWuni.debug(" pointcut "+i++);
406             ((Pointcut)it.next()).applyTo(interaction.wrappee, cli);
407         }
408     }
409
410     public void whenUsingNewClass(ClassItem cli) {
411         Iterator JavaDoc it = pointcuts.iterator();
412         int i = 0;
413         loggerWuni.debug(this+".whenUsingNewClass"+cli);
414         while (it.hasNext()) {
415             ((Pointcut)it.next()).applyTo(null, cli);
416         }
417     }
418
419     /**
420      * This method simulates an instance first use so that the system
421      * upcalls <code>whenUsingNewInstance()</code> with a fake
422      * collaboration point (<code>method()</code> is null and
423      * <code>args</code> is null too).
424      *
425      * @param wrappee the wrappe on which the call is simulated.
426      * @see #whenUsingNewInstance(Interaction) */

427
428     protected void simulateUsingNewInstance(Wrappee wrappee) {
429         /** simulates a new interaction */
430         // Log.trace("core","simulateUsingNewInstance "+this);
431
Collaboration collab = Collaboration.get();
432         //collab.newInteraction();
433
whenUsingNewInstance(new Interaction(null,wrappee,null,null));
434         /** end of simulated interaction */
435         //collab.endOfInteraction();
436
}
437
438     /**
439      * This method is called when a new instance is created.
440      *
441      * <p>Since the instance is not initialized yet, the aspect
442      * component must not wrap it at this stage. To wrap a new
443      * instance, the aspect component must use the
444      * <code>whenUsingNewInstance()</code> method. This method is not
445      * upcalled when the instantiation is remotly performed (from a
446      * deployer site), see the <code>whenRemoteInstantiation()</code>
447      * method.<br>
448      *
449      * @param newInstance the newly created instance
450      * @see #whenUsingNewInstance(Interaction)
451      * @see #whenRemoteInstantiation(Wrappee,String) */

452
453     //public void whenNewInstance( Wrappee newInstance ) {}
454

455     /**
456      * This method is upcalled when a new object is instanciated from a
457      * remote site.
458      *
459      * <p>The name that is passed is the name of the remote
460      * reference that has been used to create the object. Typically, it
461      * is the name that will be used by the naming aspect to name the
462      * new object.
463      *
464      * @param newInstance the instance that have been created by a
465      * remote host
466      * @param name the name of the new instance
467      * @see org.objectweb.jac.aspects.naming.NamingAC#whenRemoteInstantiation(Wrappee,String)
468      */

469     public void whenRemoteInstantiation(Wrappee newInstance,
470                                         String JavaDoc name) {}
471
472     /**
473      * This method unwraps all the instances that have been wrapped by
474      * the aspect component.
475      *
476      * <p>This is done in a generic way that is not very efficient. To
477      * optimize this process, the user may overload the
478      * <code>unweave()</code> method to change its default
479      * behavior.<br>
480      *
481      * @see #unweave()
482      */

483     protected final void unwrapAll() {
484         loggerWrap.debug("unwrap all");
485         loggerWrap.debug(wrappers.size()+" wrappers: " + wrappers);
486         Iterator JavaDoc it = ObjectRepository.getMemoryObjects().iterator();
487         while (it.hasNext()) {
488             Object JavaDoc o = it.next();
489             if (o instanceof Wrappee) {
490                 Wrappee wrappee = (Wrappee)o;
491                 ClassItem wrappeeClass = cr.getClass(wrappee);
492                 loggerWrap.debug("testing wrappee " + wrappee);
493                 Wrapping.unwrap(wrappee,wrappeeClass,wrappers);
494                 Wrapping.unwrap(null,wrappeeClass,wrappers);
495             }
496         }
497         wrappers.clear();
498     }
499
500     /**
501      * The programmer should overload this method to unwrap all the
502      * currently wrapped Jac objects so that it unplugs a given aspect.
503      *
504      * <p>By default, calls the <code>unwrapAll</code> method but the
505      * programmer can implement the unveaving process in a more
506      * efficient way.<br>
507      *
508      * @see #unwrapAll() */

509
510     public void unweave() {
511         logger.info("--- unweaving "+this+" ---");
512         long start = System.currentTimeMillis();
513         unwrapAll();
514         pointcuts.clear();
515         loggerPerf.info("unweaved "+this+" in "+(System.currentTimeMillis()-start)+"ms");
516     }
517
518     /**
519      * This method is automatically called when a Jac Object is
520      * cloned. */

521
522     public void whenClone(Wrappee cloned, Wrappee clone) {}
523
524     /**
525      * This method is called when a JAC object is serialized and can
526      * parametrize the serialization by filling the <code>finalObject</code>
527      * parameter.
528      *
529      * <p><b>IMPORTANT</b>: this method is upcalled only if the
530      * serialization is done with a
531      * <code>JacObjectOutputStream</code>. To ensure the correct use of
532      * this class, only use <code>JacObject.serialize()</code> to
533      * serialize an object.</p>
534      *
535      * @param orgObject the object being serialized
536      * @param finalObject the corresponding serialized structure
537      * @return the object being serialized (usually orgObject, but not
538      * necessarily).
539      * @see SerializedJacObject
540      * @see JacObjectOutputStream */

541
542     public Wrappee whenSerialized(Wrappee orgObject,
543                                   SerializedJacObject finalObject) {
544         return orgObject;
545     }
546
547     /**
548      * This method is called when a base object is deserialized and can
549      * parametrize the deserialization by reading the
550      * SerializedJacObject instance to get some extra infos on the
551      * aspects.
552      *
553      * <p><b>IMPORTANT</b>: this method is upcalled only if the
554      * deserialization is done with a
555      * <code>JacObjectInputStream</code>. To ensure the correct use of
556      * this class, only use <code>JacObject.deserialize()</code> to
557      * deserialize an object.
558      *
559      * @param orgObject the corresponding serialized structure
560      * @param finalObject the object being deserialized
561      * @return the object being deserialized (usually finalObject but
562      * not necessarily)
563      * @see SerializedJacObject
564      * @see JacObjectInputStream */

565
566     public Wrappee whenDeserialized(SerializedJacObject orgObject,
567                                     Wrappee finalObject) {
568         return finalObject;
569     }
570
571
572     public void onExit() {}
573
574     /**
575      * This method is called when a wrapper is going to be applied to a
576      * wrappee.
577      *
578      * <p>By overloading this method, the aspect component can skip the
579      * wrapper, for instance if the current collaboration shows that
580      * the wrapper has allready been applied.<br>
581      *
582      * <p>If the method returns true, then the wrapper is run, else it
583      * is skipped. Default: return true.<br>
584      *
585      * @param wrapper the wrapper that is going to be runned
586      * @param wrappingMethod the name of the may-be runned wrapping
587      * method
588      * @return a boolean that tells if the wrapper has to be runned
589      * (true) or not (false)
590      * @see Wrappee
591      * @see Wrapping#wrap(Wrappee,Wrapper,AbstractMethodItem)
592      * @see Wrapper
593      * @see Wrapper#proceed(Invocation)
594      */

595     public boolean beforeRunningWrapper(Wrapper wrapper,
596                                         String JavaDoc wrappingMethod) {
597         return true;
598     }
599    
600     /**
601      * This method is called after the application of the
602      * wrapper.
603      *
604      * <p>Typically, the aspect component can set an attribute to
605      * the collaboration that indicates that the wrapper has been
606      * applied (and that can be used by the beforeRunningWrapper
607      * method).
608      *
609      * @param wrapper the wrapper that has just been runned
610      * @param wrappingMethod the name of the runned wrapping method
611      * @see Wrappee
612      * @see Wrapping#wrap(Wrappee,Wrapper,AbstractMethodItem)
613      * @see Wrapper
614      * @see Wrapper#proceed(Invocation)
615      */

616     public void afterRunningWrapper(Wrapper wrapper,
617                                     String JavaDoc wrappingMethod) {}
618
619     /**
620      * This method is called after a new wrapper wraps a wrappee.
621      */

622
623     public void afterWrap(Wrappee wrappee, Wrapper wrapper,
624                           String JavaDoc[] wrapping_methods,
625                           String JavaDoc[][] wrapped_methods) {}
626    
627     /**
628      * This method is called when a program gets a set of object from
629      * the object repository.
630      *
631      * <p>At this step, the aspect can change the returned list so that
632      * the program will see the right set of objects (for instance a
633      * security aspect may filter this set so that the user will not
634      * see the objects s/he is not allowed to see or a persistance
635      * aspect may force the load of a set of objects from the storage
636      * and add them to the list).
637      *
638      * @param objects the returned list (can be modified)
639      * @param cl the class that was used by the program to filter its
640      * instances (can be null for all the objects)
641      * @see ObjectRepository */

642
643     public void whenGetObjects(Collection JavaDoc objects, ClassItem cl) {}
644
645     public String JavaDoc whenNameObject(Object JavaDoc object,String JavaDoc name) {
646         return name;
647     }
648
649     public void getNameCounters(Map JavaDoc counters) {
650     }
651
652     public void updateNameCounters(Map JavaDoc counters) {
653     }
654
655     /**
656      * This method is upcalled by JAC when an object was seeked into
657      * the name repository and was not found.
658      *
659      * <p>The reason of this miss can be multiple. For instance, the
660      * persistence aspect may have not already load the object from the
661      * storage, or the distribution aspect may need to bind to a remote
662      * object. Thus, this method allows the aspects to resolve the
663      * object.
664      *
665      * <p>By default, this method does nothing.
666      *
667      * <p>The final choosen name is a contextual attribute called
668      * FOUND_OBJECT.
669      *
670      * @param name the name of the object
671      * @see BaseProgramListener#FOUND_OBJECT
672      */

673    
674     public void whenObjectMiss(String JavaDoc name) {}
675
676     public void whenDeleted(Wrappee object) {}
677
678     public void whenFree(Wrappee object) {}
679
680     public void afterApplicationStarted() {}
681
682     public void whenCloseDisplay(Display display) {}
683
684     public void whenTopologyChanged() {}
685
686     /**
687      * Called when the aspect's configuration is reloaded
688      */

689     public void whenReload() {}
690     public void beforeReload() {}
691
692     /**
693      * This method should be defined by the programmer when specific
694      * actions are needed once the aspect component has be
695      * configured. */

696
697     public void whenConfigured() {}
698
699     /**
700      * To overload in order to perform some treatements before the
701      * configuration. */

702     public void beforeConfiguration() throws Exception JavaDoc {
703     }
704
705     public String JavaDoc getName() {
706         return ACManager.getACM().getName(this);
707     }
708
709     /**
710      * This method is upcalled by the system when the aspect is
711      * actually registered in the AC manager.
712      *
713      * <p>Here it does nothing. */

714     public void doRegister() {
715     }
716
717     /**
718      * This method is upcalled by the system when the aspect is
719      * actually registered in the AC manager.
720      *
721      * <p>Here it does nothing. */

722     public void doUnregister() {
723     }
724
725     /** Store the pointcuts. */
726     Vector JavaDoc pointcuts = new Vector JavaDoc();
727
728     /**
729      * Defines and adds a new method pointcut.
730      *
731      * <p>For more details on how to use pointcuts, see the
732      * <code>MethodPointcut</code> class.
733      *
734      * @param wrappeeExpr the wrappee definition that matches the names
735      * as defined by the naming aspect
736      * @param wrappeeClassExpr the wrappee class expression (matches
737      * the fully qualified class name)
738      * @param wrappeeMethodExpr the wrappee method expression (matches
739      * the full method name as defined by the rtti)
740      * @param wrappingClassName the name of the wrapper class
741      * @param one2one true if each new wrapped instance corresponds to
742      * one different wrapper
743      * @see MethodPointcut
744      */

745     public Pointcut pointcut(String JavaDoc wrappeeExpr,
746                              String JavaDoc wrappeeClassExpr,
747                              String JavaDoc wrappeeMethodExpr,
748                              String JavaDoc wrappingClassName,
749                              String JavaDoc exceptionHandler,
750                              boolean one2one) {
751
752         MethodPointcut pc = new MethodPointcut( this,
753                                                 wrappeeExpr,
754                                                 wrappeeClassExpr,
755                                                 wrappeeMethodExpr,
756                                                 null,
757                                                 wrappingClassName,
758                                                 null,
759                                                 null,
760                                                 "ALL",
761                                                 exceptionHandler,
762                                                 one2one );
763         pointcuts.add(pc);
764         return pc;
765     }
766
767     /**
768      * Defines and adds a new method pointcut.
769      *
770      * <p>For more details on how to use pointcuts, see the
771      * <code>MethodPointcut</code> class.
772      *
773      * @param wrappeeExpr the wrappee definition that matches the names
774      * as defined by the naming aspect
775      * @param wrappeeClassExpr the wrappee class expression (matches
776      * the fully qualified class name)
777      * @param wrappeeMethodExpr the wrappee method expression (matches
778      * the full method name as defined by the rtti)
779      * @param wrappingClassName the name of the wrapper class
780      * @param initParameters the initialization parameters of the
781      * wrapper (passed to the wrappers constructor that matches the
782      * parameters types)
783      * @param one2One true if each new wrapped instance corresponds to
784      * one different wrapper
785      * @see MethodPointcut
786      */

787     public Pointcut pointcut(String JavaDoc wrappeeExpr,
788                              String JavaDoc wrappeeClassExpr,
789                              String JavaDoc wrappeeMethodExpr,
790                              String JavaDoc wrappingClassName,
791                              Object JavaDoc[] initParameters,
792                              String JavaDoc exceptionHandler,
793                              boolean one2One) {
794
795         MethodPointcut pc = new MethodPointcut( this,
796                                                 wrappeeExpr,
797                                                 wrappeeClassExpr,
798                                                 wrappeeMethodExpr,
799                                                 null,
800                                                 wrappingClassName,
801                                                 null,
802                                                 initParameters,
803                                                 "ALL",
804                                                 exceptionHandler,
805                                                 one2One );
806         pointcuts.add(pc);
807         return pc;
808     }
809
810     /**
811      * Defines and adds a new localized method pointcut.
812      *
813      * <p>For more details on how to use pointcuts, see the
814      * <code>MethodPointcut</code> class.
815      *
816      * @param wrappeeExpr the wrappee definition that matches the names
817      * as defined by the naming aspect
818      * @param wrappeeClassExpr the wrappee class expression (matches
819      * the fully qualified class name)
820      * @param wrappeeMethodExpr the wrappee method expression (matches
821      * the full method name as defined by the rtti)
822      * @param wrappingClassName the name of the wrapper class
823      * @param hostExpr a regular expression that macthes the hosts
824      * where the pointcut has to be applied (if null or empty string,
825      * default is ".*" which means that the pointcut will be applied on
826      * all the hosts)
827      * @param one2One true if each new wrapped instance corresponds to
828      * one different wrapper
829      * @see MethodPointcut */

830
831     public Pointcut pointcut(String JavaDoc wrappeeExpr,
832                              String JavaDoc wrappeeClassExpr,
833                              String JavaDoc wrappeeMethodExpr,
834                              String JavaDoc wrappingClassName,
835                              String JavaDoc hostExpr,
836                              String JavaDoc exceptionHandler,
837                              boolean one2One) {
838
839         MethodPointcut pc = new MethodPointcut(this,
840                                                wrappeeExpr,
841                                                wrappeeClassExpr,
842                                                wrappeeMethodExpr,
843                                                null,
844                                                wrappingClassName,
845                                                null,
846                                                null,
847                                                hostExpr,
848                                                exceptionHandler,
849                                                one2One);
850         pointcuts.add(pc);
851         return pc;
852     }
853
854     /**
855      * Defines and adds a new localized method pointcut.
856      *
857      * <p>For more details on how to use pointcuts, see the
858      * <code>MethodPointcut</code> class.
859      *
860      * @param wrappeeExpr the wrappee definition that matches the names
861      * as defined by the naming aspect
862      * @param wrappeeClassExpr the wrappee class expression (matches
863      * the fully qualified class name)
864      * @param wrappeeMethodExpr the wrappee method expression (matches
865      * the full method name as defined by the rtti)
866      * @param wrappingClassName the name of the wrapper class
867      * @param initParameters the initialization parameters of the
868      * wrapper (passed to the wrappers constructor that matches the
869      * parameters types)
870      * @param hostExpr a regular expression that macthes the hosts
871      * where the pointcut has to be applied (if null or empty string,
872      * default is ".*" which means that the pointcut will be applied on
873      * all the hosts)
874      * @param one2One true if each new wrapped instance corresponds to
875      * one different wrapper
876      * @see MethodPointcut
877      */

878     public Pointcut pointcut(String JavaDoc wrappeeExpr,
879                              String JavaDoc wrappeeClassExpr,
880                              String JavaDoc wrappeeMethodExpr,
881                              String JavaDoc wrappingClassName,
882                              Object JavaDoc[] initParameters,
883                              String JavaDoc hostExpr,
884                              String JavaDoc exceptionHandler,
885                              boolean one2One) {
886       
887         MethodPointcut pc = new MethodPointcut(this,
888                                                wrappeeExpr,
889                                                wrappeeClassExpr,
890                                                wrappeeMethodExpr,
891                                                null,
892                                                wrappingClassName,
893                                                null,
894                                                initParameters,
895                                                hostExpr,
896                                                exceptionHandler,
897                                                one2One);
898         pointcuts.add(pc);
899         return pc;
900     }
901
902     /**
903      * Defines and adds a new method pointcut.
904      *
905      * <p>For more details on how to use pointcuts, see the
906      * <code>MethodPointcut</code> class.
907      *
908      * @param wrappeeExpr the wrappee definition that matches the names
909      * as defined by the naming aspect
910      * @param wrappeeClassExpr the wrappee class expression (matches
911      * the fully qualified class name)
912      * @param wrappeeMethodExpr the wrappee method expression (matches
913      * the full method name as defined by the rtti)
914      * @param wrapper the wrapper that contains the wrapping method,
915      * cannot be null
916      *
917      * @see MethodPointcut
918      */

919     public Pointcut pointcut(String JavaDoc wrappeeExpr,
920                              String JavaDoc wrappeeClassExpr,
921                              String JavaDoc wrappeeMethodExpr,
922                              Wrapper wrapper,
923                              String JavaDoc exceptionHandler) {
924
925         MethodPointcut pc = new MethodPointcut(this,
926                                                wrappeeExpr,
927                                                wrappeeClassExpr,
928                                                wrappeeMethodExpr,
929                                                wrapper,
930                                                wrapper.getClass().getName(),
931                                                null,
932                                                null,
933                                                "ALL",
934                                                exceptionHandler,
935                                                false);
936         pointcuts.add(pc);
937         return pc;
938     }
939
940     /**
941      * Defines and adds a new localized method pointcut.
942      *
943      * <p>For more details on how to use pointcuts, see the
944      * <code>MethodPointcut</code> class.
945      *
946      * @param wrappeeExpr the wrappee definition that matches the names
947      * as defined by the naming aspect
948      * @param wrappeeClassExpr the wrappee class expression (matches
949      * the fully qualified class name)
950      * @param wrappeeMethodExpr the wrappee method expression (matches
951      * the full method name as defined by the rtti)
952      * @param wrapper the wrapper that contains the wrapping method,
953      * cannot be null
954      * @param hostExpr a regular expression that macthes the hosts
955      * where the pointcut has to be applied (if null or empty string,
956      * default is ".*" which means that the pointcut will be applied on
957      * all the hosts)
958      *
959      * @see MethodPointcut
960      */

961     public Pointcut pointcut(String JavaDoc wrappeeExpr,
962                              String JavaDoc wrappeeClassExpr,
963                              String JavaDoc wrappeeMethodExpr,
964                              Wrapper wrapper,
965                              String JavaDoc hostExpr,
966                              String JavaDoc exceptionHandler) {
967
968         MethodPointcut pc = new MethodPointcut(this,
969                                                wrappeeExpr,
970                                                wrappeeClassExpr,
971                                                wrappeeMethodExpr,
972                                                wrapper,
973                                                wrapper.getClass().getName(),
974                                                null,
975                                                null,
976                                                hostExpr,
977                                                exceptionHandler,
978                                                false);
979         pointcuts.add(pc);
980         return pc;
981     }
982
983     /**
984      * Defines and adds a new pointcut that upcalls an aspect method
985      * when the matching object is created.
986      *
987      * <p>For more details on how to use pointcuts, see the
988      * <code>MethodPointcut</code> class.
989      *
990      * @param wrappeeExpr the wrappee definition that matches the names
991      * as defined by the naming aspect
992      * @param wrappeeClassExpr the wrappee class expression (matches
993      * the fully qualified class name)
994      * @param methodName a method of the aspect component to call
995      * @param methodArgs the arguments of this methods when called
996      * @see MethodPointcut */

997
998     public Pointcut pointcut(String JavaDoc wrappeeExpr,
999                              String JavaDoc wrappeeClassExpr,
1000                             String JavaDoc methodName,
1001                             Object JavaDoc[] methodArgs,
1002                             String JavaDoc exceptionHandler) {
1003
1004        MethodPointcut pc = new MethodPointcut(this,
1005                                               wrappeeExpr,
1006                                               wrappeeClassExpr,
1007                                               null,
1008                                               null,
1009                                               null,
1010                                               methodName,
1011                                               methodArgs,
1012                                               "ALL",
1013                                               exceptionHandler,
1014                                               false);
1015        pointcuts.add(pc);
1016        return pc;
1017    }
1018
1019    /**
1020     * Defines and adds a new localized pointcut that upcalls an aspect
1021     * method when the matching object is created.
1022     *
1023     * <p>For more details on how to use pointcuts, see the
1024     * <code>MethodPointcut</code> class.</p>
1025     *
1026     * @param wrappeeExpr the wrappee definition that matches the names
1027     * as defined by the naming aspect
1028     * @param wrappeeClassExpr the wrappee class expression (matches
1029     * the fully qualified class name)
1030     * @param methodName a method of the aspect component to call
1031     * @param methodArgs the arguments of this methods when called
1032     * @see MethodPointcut */

1033
1034    public Pointcut pointcut(String JavaDoc wrappeeExpr,
1035                             String JavaDoc wrappeeClassExpr,
1036                             String JavaDoc methodName,
1037                             Object JavaDoc[] methodArgs,
1038                             String JavaDoc hostExpr,
1039                             String JavaDoc exceptionHandler) {
1040
1041        MethodPointcut pc = new MethodPointcut(this,
1042                                               wrappeeExpr,
1043                                               wrappeeClassExpr,
1044                                               null,
1045                                               null,
1046                                               null,
1047                                               methodName,
1048                                               methodArgs,
1049                                               hostExpr,
1050                                               exceptionHandler,
1051                                               false);
1052        pointcuts.add(pc);
1053        return pc;
1054    }
1055 
1056    /**
1057     * Generic config method to set an attribute on a class
1058     * @param cli the class to set an attribute on
1059     * @param name name of the attribute
1060     * @param value string value of the attribute
1061     */

1062    public void setAttribute(ClassItem cli, String JavaDoc name, String JavaDoc value) {
1063        cli.setAttribute(name,value);
1064    }
1065
1066    /**
1067     * Generic config method to set an attribute on a class
1068     * @param field the field to set an attribute on
1069     * @param name name of the attribute
1070     * @param value string value of the attribute
1071     */

1072    public void setAttribute(FieldItem field, String JavaDoc name, String JavaDoc value) {
1073        field.setAttribute(name,value);
1074    }
1075
1076
1077    /**
1078     * Generic config method to set an attribute on a method
1079     * @param method the method to set an attribute on
1080     * @param name name of the attribute
1081     * @param value string value of the attribute
1082     */

1083    public void setAttribute(AbstractMethodItem method,
1084                             String JavaDoc name, String JavaDoc value) {
1085        method.setAttribute(name,value);
1086    }
1087
1088    // following methods implement the CollaborationParticipant interface
1089

1090    public final void attrdef(String JavaDoc name, Object JavaDoc value) {
1091        Collaboration.get().addAttribute( name, value );
1092    }
1093
1094    public final Object JavaDoc attr( String JavaDoc name ) {
1095        return Collaboration.get().getAttribute( name );
1096    }
1097
1098    /** Block keywords which can be used instead of "block" */
1099    protected String JavaDoc[] blockKeywords = new String JavaDoc[0];
1100
1101    public Set JavaDoc getBlockKeywords() {
1102        return new HashSet JavaDoc(Arrays.asList(blockKeywords));
1103    }
1104
1105    /** Returns defaults configuration files that must be loaded before
1106        the user's configuration */

1107    public String JavaDoc[] getDefaultConfigs() {
1108        return new String JavaDoc[0];
1109    }
1110
1111    /**
1112     * Returns all the configuration methods of the aspect
1113     * @return Collection of MethodItem
1114     */

1115    public Collection JavaDoc getConfigurationMethods() {
1116        Vector JavaDoc result = new Vector JavaDoc();
1117        Iterator JavaDoc ms = cr.getClass(getClass()).getAllMethods().iterator();
1118
1119        while(ms.hasNext()){
1120            MethodItem methodItem=(MethodItem)ms.next();
1121            if (isConfigurationMethod(methodItem.getActualMethod())){
1122                result.add(methodItem);
1123            }
1124        }
1125        return result;
1126    }
1127
1128    /**
1129     * Returns all the name of the configuration methods of the aspect
1130     * @return Collection of String
1131     */

1132    public Collection JavaDoc getConfigurationMethodsName() {
1133        Vector JavaDoc result = new Vector JavaDoc();
1134        Method JavaDoc[] ms = getClass().getMethods();
1135        for(int i=0;i<ms.length;i++) {
1136            if (isConfigurationMethod(ms[i])) {
1137                result.add(ms[i].getName());
1138            }
1139        }
1140        return result;
1141    }
1142
1143
1144    /**
1145     * Returns all the configuration methods of the aspect whose first
1146     * parameter is compatible with a given type.
1147     * @param firstParamType the type the first parameter must be compatible with
1148     * @return a collection of MethodItem with at least one parameter,
1149     * and whose first parameter can be of type firstParamType or a
1150     * subclass of firstParamType */

1151    public List JavaDoc getConfigurationMethodsName(Class JavaDoc firstParamType) {
1152        Vector JavaDoc result = new Vector JavaDoc();
1153        Iterator JavaDoc ms = cr.getClass(getClass())
1154            .getAllMethods().iterator();
1155        // We use hash set to remove duplicate entries quickly
1156
HashSet JavaDoc names = new HashSet JavaDoc();
1157
1158        while (ms.hasNext()) {
1159            MethodItem methodItem = (MethodItem)ms.next();
1160            if (isConfigurationMethod(methodItem.getActualMethod())) {
1161                Class JavaDoc[] paramTypes = methodItem.getParameterTypes();
1162                if (paramTypes.length>0 &&
1163                    (paramTypes[0].isAssignableFrom(firstParamType) ||
1164                     firstParamType.isAssignableFrom(paramTypes[0])) &&
1165                    !names.contains(methodItem.getName())) {
1166                    result.add(methodItem.getName());
1167                    names.add(methodItem.getName());
1168                }
1169            }
1170        }
1171        return result;
1172    }
1173
1174
1175    /**
1176     * Tells wether a method is configuration method of this aspect
1177     * @param method
1178     * @return true if the method was a configuration method.
1179     */

1180    public boolean isConfigurationMethod(Method JavaDoc method) {
1181        Class JavaDoc cl = method.getDeclaringClass();
1182        if (AspectComponent.class.isAssignableFrom(cl)) {
1183            Class JavaDoc[] interfs=cl.getInterfaces();
1184            for(int i=0;i<interfs.length;i++) {
1185                if (!interfs[i].getName().endsWith("Conf"))
1186                    continue;
1187                Method JavaDoc[] ms = interfs[i].getMethods();
1188                for(int j=0; j<ms.length; j++) {
1189                    if (ms[j].getName().equals(method.getName())) {
1190                        return true;
1191                    }
1192                }
1193            }
1194        }
1195        return false;
1196    }
1197
1198    protected ConfigMethod currentConfigMethod;
1199    protected Imports currentImports;
1200
1201    /**
1202     * Configures this aspect component with a given configuration file.
1203     *
1204     * @param name name of the aspect component (informative)
1205     * @param filePath path to a resource of file containing the configuration
1206     */

1207    public void configure(String JavaDoc name, String JavaDoc filePath) {
1208        long start = System.currentTimeMillis();
1209        if (filePath == null) {
1210            return;
1211        }
1212        loggerConf.info("configuring aspect " + name + " with file "+filePath);
1213        List JavaDoc configMethods = null;
1214        try {
1215            // Naming.PARSER_NAME ("parserimpl#0") is the only
1216
// instance of ACParser, if we are on the master site, it
1217
// is automatically instantiated by the binding aspect, if
1218
// not, the binding aspect creates a stub for
1219
// parserimpl#0@mastersite
1220
Parser acp = (Parser)NameRepository.get().getObject(Naming.PARSER_NAME);
1221            configMethods = acp.parse(filePath,this.getClass().getName(),
1222                                      this.getBlockKeywords());
1223        } catch (FileNotFoundException JavaDoc e) {
1224            logger.warn("cannot find config file "+filePath+" for "+name+
1225                        "("+e+"), using serialized infos.");
1226        } catch (Exception JavaDoc e) {
1227            logger.error("configure "+name+","+filePath,e);
1228            return;
1229        }
1230        if (configMethods==null)
1231            return;
1232        currentImports = new Imports();
1233        for (int i=0; i<configMethods.size(); i++) {
1234            MethodItem method = null;
1235            Object JavaDoc statement = configMethods.get(i);
1236            if (statement instanceof ImportStatement) {
1237                ImportStatement imp = (ImportStatement)statement;
1238                currentImports.add(imp.getExpr());
1239                continue;
1240            }
1241            ConfigMethod cm = (ConfigMethod)statement;
1242            currentConfigMethod = cm;
1243            if (cm==null) {
1244                loggerConf.warn("skipping error");
1245                continue;
1246            }
1247            try {
1248                loggerConf.debug(
1249                    "invoking configuration method '"+cm.getMethod()+
1250                    "' on "+this.getClass()+" with "+Arrays.asList(cm.getArgs()));
1251                if (cm.getMethod().equals(""))
1252                    continue;
1253                MethodItem[] methodItems =
1254                    cr.getClass(this.getClass()).
1255                    getMethods(cm.getMethod());
1256                if (methodItems==null || methodItems.length==0) {
1257                    loggerConf.warn("No such configuration method "+cm.getMethod()+
1258                                    " in AC "+this.getClass());
1259                }
1260                loggerConf.debug(
1261                    "matching methods : "+Arrays.asList(methodItems));
1262
1263                Object JavaDoc[] paramValues = null;
1264                //determine which method to call based on number of parameters
1265
// Warning, ClassItem+String can become a MemberItem
1266
Vector JavaDoc exceptions = new Vector JavaDoc();
1267                for(int j=0; j<methodItems.length && method==null; j++) {
1268                    paramValues = cm.getArgs();
1269                    //If the ConfigMethod has the same number of param as MethodItem
1270
if (methodItems[j].getParameterTypes().length==paramValues.length) {
1271                        method = methodItems[j];
1272                        loggerConf.debug("selecting method "+method);
1273
1274                        // Try to convert the parameters
1275
// if it fails, try the next method
1276
paramValues = cm.getArgs();
1277                        try {
1278                            Class JavaDoc[] paramTypes = method.getParameterTypes();
1279                            for(int k=0; k<paramTypes.length; k++) {
1280                                paramValues[k] =
1281                                    ACConfiguration.convertValue(
1282                                        paramValues[k],
1283                                        paramTypes[k],
1284                                        currentImports);
1285                            }
1286                            break;
1287                        } catch(Exception JavaDoc e) {
1288                            exceptions.add(e);
1289                            method = null;
1290                        }
1291                    }
1292                    //If method==null try to translate MemberItem parameters
1293
//into ClassItem+String
1294
if (method==null &&
1295                        (methodItems[j].getParameterCount()>0)) {
1296                        for (int p=0; p<methodItems[j].getParameterCount(); p++) {
1297                            if ((MemberItem.class.isAssignableFrom(
1298                                methodItems[j].getParameterTypes()[p]))
1299                                && (methodItems[j].getParameterTypes().length
1300                                    == paramValues.length-1))
1301                            {
1302                                method = methodItems[j];
1303                                loggerConf.debug(
1304                                    "selecting method "+method+
1305                                    " with MemberItem=ClassItem+String for param #"+p);
1306                                paramValues = cm.getArgs();
1307                                Object JavaDoc paramValuesTranslated[] = new Object JavaDoc[paramValues.length-1];
1308                                try {
1309                                    Class JavaDoc[] paramTypes = method.getParameterTypes();
1310                                    ClassItem classItem =
1311                                        (ClassItem)ACConfiguration.convertValue(
1312                                            paramValues[p],
1313                                            ClassItem.class,
1314                                            currentImports);
1315                                    paramValuesTranslated[p] =
1316                                        classItem.getMember(
1317                                            (String JavaDoc)ACConfiguration.convertValue(
1318                                                paramValues[p+1],
1319                                                String JavaDoc.class,
1320                                                currentImports));
1321                                    if (!paramTypes[p].isAssignableFrom(
1322                                            paramValuesTranslated[p].getClass()))
1323                                    {
1324                                        throw new Exception JavaDoc(
1325                                            "Error translating parameter: "+
1326                                            paramValuesTranslated[0].getClass().getName()+
1327                                            " can't be assigned to "+paramTypes[p].getName());
1328                                    }
1329                                    for(int k=p+1; k<paramTypes.length; k++){
1330                                        paramValuesTranslated[k] =
1331                                            ACConfiguration.convertValue(
1332                                                paramValues[k+1],
1333                                                paramTypes[k],
1334                                                currentImports);
1335                                    }
1336
1337                                    for(int k=0; k<p; k++){
1338                                        paramValuesTranslated[k] =
1339                                            ACConfiguration.convertValue(
1340                                                paramValues[k],
1341                                                paramTypes[k],
1342                                                currentImports);
1343                                    }
1344                                    paramValues = paramValuesTranslated;
1345                                    loggerConf.debug("Parameter transformation successful");
1346                                    break;
1347                                } catch (Exception JavaDoc e) {
1348                                    loggerConf.debug("Exception in parameter transformation: "+e);
1349                                    exceptions.add(e);
1350                                    method = null;
1351                                }
1352                            }
1353                        }
1354                    }
1355               
1356                }
1357                if (method == null) {
1358                    if (exceptions.isEmpty()) {
1359                        throw new Exception JavaDoc("Wrong number of parameters for method "+
1360                                            cm.getMethod());
1361                    } else {
1362                        throw (Exception JavaDoc)exceptions.get(0);
1363                        //new Exception(exceptions.toString());
1364
}
1365                }
1366            
1367                loggerConf.debug(
1368                    filePath+": line "+cm.getLineNumber() +
1369                    ", invoke configuration method '" +
1370                    (method!=null?method.toString():cm.getMethod()) +
1371                    "' on " + this.getClass() +
1372                    " with " + Arrays.asList(cm.getArgs()));
1373                method.invoke(this,paramValues);
1374
1375            } catch (InvocationTargetException JavaDoc e) {
1376                Throwable JavaDoc target = e.getTargetException();
1377                loggerConf.warn(cm.getLineNumber() +
1378                                ", failed to invoke configuration method '"+
1379                                (method!=null?method.getFullName():cm.getMethod())+
1380                                "' on "+this.getClass() + " with "+
1381                                Arrays.asList(cm.getArgs()),target);
1382                loggerConf.info("Stack trace follows",e);
1383            } catch (Throwable JavaDoc e) {
1384                if (e instanceof WrappedThrowableException)
1385                    e = ((WrappedThrowableException)e).getWrappedThrowable();
1386                loggerConf.warn(cm.getLineNumber() +
1387                                ", failed to invoke configuration method '"+
1388                                (method!=null?method.getFullName():cm.getMethod())+
1389                                "' on "+this.getClass()+
1390                                " with "+Arrays.asList(cm.getArgs())+" : "+e);
1391                loggerConf.info("Stack trace follows",e);
1392            } finally {
1393                currentConfigMethod = null;
1394            }
1395        }
1396        loggerPerf.debug(
1397            "aspect configuration file "+filePath+" read in "+
1398            (System.currentTimeMillis()-start)+"ms");
1399    }
1400
1401    public void beforeWrappeeInit(Wrappee wrappee) {};
1402
1403    public void afterWrappeeInit(Wrappee wrappee) {};
1404
1405    /**
1406     * Issue a warning containing the file, line number and
1407     * configuration method name (if available)
1408     *
1409     * @param message the warning message to print
1410     * @see #error(String)
1411     */

1412    protected void warning(String JavaDoc message) {
1413        if (currentConfigMethod!=null)
1414            loggerConf.warn(
1415                currentConfigMethod.getLineNumber()+":"+
1416                currentConfigMethod.getMethod()+": "+message);
1417        else
1418            loggerConf.warn(message);
1419    }
1420
1421    /**
1422     * Issue an error containing the file, line number and
1423     * configuration method name (if available)
1424     *
1425     * @param message the warning message to print
1426     * @see #warning(String)
1427     */

1428    protected void error(String JavaDoc message) {
1429        if (currentConfigMethod!=null)
1430            loggerConf.error(
1431                currentConfigMethod.getLineNumber()+":"+
1432                currentConfigMethod.getMethod()+": "+message);
1433        else
1434            logger.error(message);
1435    }
1436
1437    /**
1438     * Returns a named aspect component in the same application
1439     */

1440    protected AspectComponent getAC(String JavaDoc name) {
1441        return ACManager.getACM().getACFromFullName(application+"."+name);
1442    }
1443}
1444
Popular Tags