KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > Domain


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.aop;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.LinkedHashMap JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import org.jboss.aop.advice.AdviceStack;
31 import org.jboss.aop.advice.AspectDefinition;
32 import org.jboss.aop.advice.InterceptorFactory;
33 import org.jboss.aop.metadata.ClassMetaDataLoader;
34 import org.jboss.aop.pointcut.CFlowStack;
35 import org.jboss.aop.pointcut.DynamicCFlow;
36 import org.jboss.aop.pointcut.Pointcut;
37 import org.jboss.aop.pointcut.PointcutStats;
38 import org.jboss.aop.pointcut.Typedef;
39 import org.jboss.aop.pointcut.ast.ClassExpression;
40
41 /**
42  * Comment
43  *
44  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
45  * @version $Revision: 56777 $
46  */

47 public class Domain extends AspectManager
48 {
49    protected AspectManager parent;
50    protected boolean parentFirst;
51    protected boolean inheritsDeclarations = true;
52    protected boolean inheritsBindings = false;
53
54
55    public Domain(AspectManager manager, boolean parentFirst)
56    {
57       this.parent = manager;
58       this.parentFirst = parentFirst;
59    }
60
61
62    /**
63     * Inherits interceptor, aspect, advice stack definitions
64     *
65     * @param inheritsDeclarations
66     */

67    public void setInheritsDeclarations(boolean inheritsDeclarations)
68    {
69       this.inheritsDeclarations = inheritsDeclarations;
70    }
71
72    public void setInheritsBindings(boolean inheritBindings)
73    {
74       this.inheritsBindings = inheritBindings;
75       if (inheritsBindings)
76       {
77          parent.subscribeSubDomain(this);
78       }
79       else
80       {
81          parent.unsubscribeSubDomain(this);
82       }
83    }
84
85    
86    public void removeBindings(ArrayList JavaDoc binds)
87    {
88       super.removeBindings(binds);
89    }
90
91    public LinkedHashMap JavaDoc getBindings()
92    {
93       if (inheritsBindings)
94       {
95          if (!parentFirst)
96          {
97             // when child first, parent bindings go in first so that they can be overridden by child.
98
LinkedHashMap JavaDoc map = new LinkedHashMap JavaDoc(parent.getBindings());
99             map.putAll(this.bindings);
100             return map;
101          }
102          else
103          {
104             LinkedHashMap JavaDoc map = new LinkedHashMap JavaDoc(this.bindings);
105             map.putAll(parent.getBindings());
106             return map;
107          }
108       }
109       return super.getBindings();
110    }
111
112    public LinkedHashMap JavaDoc getPointcuts()
113    {
114       if (inheritsBindings)
115       {
116          if (!parentFirst)
117          {
118             // when child first, parent bindings go in first so that they can be overridden by child.
119
LinkedHashMap JavaDoc map = new LinkedHashMap JavaDoc(parent.getPointcuts());
120             map.putAll(this.pointcuts);
121             return map;
122          }
123          else
124          {
125             LinkedHashMap JavaDoc map = new LinkedHashMap JavaDoc(this.pointcuts);
126             map.putAll(parent.getPointcuts());
127             return map;
128          }
129       }
130       return super.getPointcuts();
131    }
132
133    public LinkedHashMap JavaDoc getPointcutInfos()
134    {
135       if (inheritsBindings)
136       {
137          if (!parentFirst)
138          {
139             // when child first, parent bindings go in first so that they can be overridden by child.
140
LinkedHashMap JavaDoc map = new LinkedHashMap JavaDoc(parent.getPointcutInfos());
141             map.putAll(this.pointcutInfos);
142             return map;
143          }
144          else
145          {
146             LinkedHashMap JavaDoc map = new LinkedHashMap JavaDoc(this.pointcutInfos);
147             map.putAll(parent.getPointcutInfos());
148             return map;
149          }
150       }
151       return super.getPointcutInfos();
152    }
153
154    public List JavaDoc getAnnotationIntroductions()
155    {
156
157       if (inheritsBindings)
158       {
159          List JavaDoc result = new ArrayList JavaDoc();
160          if (!parentFirst)
161          {
162             // when child first, parent bindings go in first so that they can be overridden by child.
163
result.addAll(parent.getAnnotationIntroductions());
164             synchronized (annotationIntroductions)
165             {
166                result = new ArrayList JavaDoc(annotationIntroductions.values());
167             }
168             return result;
169          }
170          else
171          {
172             synchronized (annotationIntroductions)
173             {
174                result = new ArrayList JavaDoc(annotationIntroductions.values());
175             }
176             result.addAll(parent.getAnnotationIntroductions());
177             return result;
178          }
179       }
180
181       return super.getAnnotationIntroductions();
182
183    }
184
185    public List JavaDoc getAnnotationOverrides()
186    {
187       if (inheritsBindings)
188       {
189          ArrayList JavaDoc list = new ArrayList JavaDoc();
190          if (!parentFirst)
191          {
192             // when child first, parent bindings go in first so that they can be overridden by child.
193
list.addAll(parent.getAnnotationOverrides());
194             synchronized (annotationOverrides)
195             {
196                list.addAll(annotationOverrides.values());
197             }
198             return list;
199          }
200          else
201          {
202             synchronized (annotationOverrides)
203             {
204                list.addAll(annotationOverrides.values());
205             }
206             list.addAll(parent.getAnnotationOverrides());
207             return list;
208          }
209       }
210       return super.getAnnotationOverrides();
211    }
212
213    public Map JavaDoc getInterfaceIntroductions()
214    {
215       if (inheritsBindings)
216       {
217          HashMap JavaDoc map = new HashMap JavaDoc();
218          if (!parentFirst)
219          {
220             // when child first, parent bindings go in first so that they can be overridden by child.
221
map.putAll(parent.getInterfaceIntroductions());
222             synchronized (interfaceIntroductions)
223             {
224                map.putAll(interfaceIntroductions);
225             }
226             return map;
227          }
228          else
229          {
230             synchronized (interfaceIntroductions)
231             {
232                map.putAll(interfaceIntroductions);
233             }
234             map.putAll(parent.getInterfaceIntroductions());
235             return map;
236          }
237       }
238       return super.getInterfaceIntroductions();
239    }
240
241    public Map JavaDoc getTypedefs()
242    {
243       if (inheritsBindings)
244       {
245          HashMap JavaDoc map = new HashMap JavaDoc();
246          if (!parentFirst)
247          {
248             // when child first, parent bindings go in first so that they can be overridden by child.
249
map.putAll(parent.getTypedefs());
250             synchronized (typedefs)
251             {
252                map.putAll(typedefs);
253             }
254             return map;
255          }
256          else
257          {
258             synchronized (typedefs)
259             {
260                map.putAll(typedefs);
261             }
262             map.putAll(parent.getTypedefs());
263             return map;
264          }
265       }
266       return super.getTypedefs();
267    }
268
269    public Map JavaDoc getInterceptorStacks()
270    {
271       if (inheritsBindings)
272       {
273          HashMap JavaDoc map = new HashMap JavaDoc();
274          if (!parentFirst)
275          {
276             // when child first, parent bindings go in first so that they can be overridden by child.
277
map.putAll(parent.getInterceptorStacks());
278             synchronized (interceptorStacks)
279             {
280                map.putAll(interceptorStacks);
281             }
282             return map;
283          }
284          else
285          {
286             synchronized (interceptorStacks)
287             {
288                map.putAll(interceptorStacks);
289             }
290             map.putAll(parent.getInterceptorStacks());
291             return map;
292          }
293       }
294       return super.getInterceptorStacks();
295    }
296
297    public Map JavaDoc getClassMetaDataLoaders()
298    {
299       if (inheritsBindings)
300       {
301          HashMap JavaDoc map = new HashMap JavaDoc();
302          if (!parentFirst)
303          {
304             // when child first, parent bindings go in first so that they can be overridden by child.
305
map.putAll(parent.getClassMetaDataLoaders());
306             synchronized (classMetaDataLoaders)
307             {
308                map.putAll(classMetaDataLoaders);
309             }
310             return map;
311          }
312          else
313          {
314             synchronized (classMetaDataLoaders)
315             {
316                map.putAll(classMetaDataLoaders);
317             }
318             map.putAll(parent.getClassMetaDataLoaders());
319             return map;
320          }
321       }
322       return super.getClassMetaDataLoaders();
323    }
324
325    public Map JavaDoc getCflowStacks()
326    {
327       if (inheritsBindings)
328       {
329          HashMap JavaDoc map = new HashMap JavaDoc();
330          if (!parentFirst)
331          {
332             // when child first, parent bindings go in first so that they can be overridden by child.
333
map.putAll(parent.getCflowStacks());
334             synchronized (cflowStacks)
335             {
336                map.putAll(cflowStacks);
337             }
338             return map;
339          }
340          else
341          {
342             synchronized (cflowStacks)
343             {
344                map.putAll(cflowStacks);
345             }
346             map.putAll(parent.getCflowStacks());
347             return map;
348          }
349       }
350       return super.getCflowStacks();
351    }
352
353    public Map JavaDoc getDynamicCFlows()
354    {
355       if (inheritsBindings)
356       {
357          HashMap JavaDoc map = new HashMap JavaDoc();
358          if (!parentFirst)
359          {
360             // when child first, parent bindings go in first so that they can be overridden by child.
361
map.putAll(parent.getDynamicCFlows());
362             synchronized (dynamicCFlows)
363             {
364                map.putAll(dynamicCFlows);
365             }
366             return map;
367          }
368          else
369          {
370             synchronized (dynamicCFlows)
371             {
372                map.putAll(dynamicCFlows);
373             }
374             map.putAll(parent.getDynamicCFlows());
375             return map;
376          }
377       }
378       return super.getDynamicCFlows();
379    }
380
381    public Map JavaDoc getPerVMAspects()
382    {
383       if (inheritsBindings)
384       {
385          HashMap JavaDoc map = new HashMap JavaDoc();
386          if (!parentFirst)
387          {
388             // when child first, parent bindings go in first so that they can be overridden by child.
389
map.putAll(parent.getPerVMAspects());
390             synchronized (perVMAspects)
391             {
392                map.putAll(perVMAspects);
393             }
394             return map;
395          }
396          else
397          {
398             synchronized (perVMAspects)
399             {
400                map.putAll(perVMAspects);
401             }
402             map.putAll(parent.getPerVMAspects());
403             return map;
404          }
405       }
406       return super.getPerVMAspects();
407    }
408
409    public LinkedHashMap JavaDoc getPrecedenceDefs()
410    {
411       if (inheritsDeclarations)
412       {
413          if (!parentFirst)
414          {
415             // when child first, parent bindings go in first so that they can be overridden by child.
416
LinkedHashMap JavaDoc map = new LinkedHashMap JavaDoc(parent.getPrecedenceDefs());
417             map.putAll(this.precedenceDefs);
418             return map;
419          }
420          else
421          {
422             LinkedHashMap JavaDoc map = new LinkedHashMap JavaDoc(this.precedenceDefs);
423             map.putAll(parent.getPrecedenceDefs());
424             return map;
425          }
426       }
427       return super.getPrecedenceDefs();
428    }
429    
430    public Map JavaDoc getClassMetaData()
431    {
432       if (inheritsBindings)
433       {
434          HashMap JavaDoc map = new HashMap JavaDoc();
435          if (!parentFirst)
436          {
437             // when child first, parent bindings go in first so that they can be overridden by child.
438
map.putAll(parent.getClassMetaData());
439             synchronized (classMetaData)
440             {
441                map.putAll(classMetaData);
442             }
443             return map;
444          }
445          else
446          {
447             synchronized (classMetaData)
448             {
449                map.putAll(classMetaData);
450             }
451             map.putAll(parent.getClassMetaData());
452             return map;
453          }
454       }
455       return super.getClassMetaData();
456    }
457
458    public InterceptorFactory getInterceptorFactory(String JavaDoc name)
459    {
460       InterceptorFactory factory = null;
461       if (parentFirst)
462       {
463          factory = parent.getInterceptorFactory(name);
464          if (factory != null) return factory;
465       }
466       factory = super.getInterceptorFactory(name);
467
468       if (factory != null) return factory;
469       return parent.getInterceptorFactory(name);
470    }
471
472    public AdviceStack getAdviceStack(String JavaDoc name)
473    {
474       AdviceStack factory = null;
475       if (parentFirst)
476       {
477          factory = parent.getAdviceStack(name);
478          if (factory != null) return factory;
479       }
480       factory = super.getAdviceStack(name);
481
482       if (factory != null) return factory;
483       return parent.getAdviceStack(name);
484    }
485
486    public Object JavaDoc getPerVMAspect(AspectDefinition def)
487    {
488       return getPerVMAspect(def.getName());
489    }
490
491    public Object JavaDoc getPerVMAspect(String JavaDoc def)
492    {
493       Object JavaDoc factory = null;
494       if (parentFirst)
495       {
496          factory = parent.getPerVMAspect(def);
497          if (factory != null) return factory;
498       }
499       factory = super.getPerVMAspect(def);
500
501       if (factory != null) return factory;
502       return parent.getPerVMAspect(def);
503    }
504
505    public AspectDefinition getAspectDefinition(String JavaDoc name)
506    {
507       AspectDefinition factory = null;
508       if (parentFirst)
509       {
510          factory = parent.getAspectDefinition(name);
511          if (factory != null) return factory;
512       }
513       factory = super.getAspectDefinition(name);
514
515       if (factory != null) return factory;
516       return parent.getAspectDefinition(name);
517    }
518
519    public Typedef getTypedef(String JavaDoc name)
520    {
521       Typedef factory = null;
522       if (parentFirst)
523       {
524          factory = parent.getTypedef(name);
525          if (factory != null) return factory;
526       }
527       factory = super.getTypedef(name);
528
529       if (factory != null) return factory;
530       return parent.getTypedef(name);
531    }
532    
533    public DomainDefinition getContainer(String JavaDoc name)
534    {
535       DomainDefinition container = null;
536       if (parentFirst)
537       {
538          container = parent.getContainer(name);
539          if (container != null) return container;
540       }
541       container = super.getContainer(name);
542       if (container != null) return container;
543       return parent.getContainer(name);
544    }
545
546
547    
548    /**
549     * Find a pointcut of with a given name
550     */

551    public Pointcut getPointcut(String JavaDoc name)
552    {
553       Pointcut pointcut = null;
554       
555       if (parentFirst)
556       {
557          pointcut = parent.getPointcut(name);
558          if (pointcut != null) return pointcut;
559       }
560       pointcut = super.getPointcut(name);
561       if (pointcut != null) return pointcut;
562       return parent.getPointcut(name);
563    }
564
565    public void attachMetaData(ClassAdvisor advisor, Class JavaDoc clazz)
566    {
567       if (inheritsBindings)
568       {
569          if (!parentFirst)
570          {
571             // when child first, parent bindings go in first so that they can be overridden by child.
572
parent.attachMetaData(advisor, clazz);
573             super.attachMetaData(advisor, clazz);
574          }
575          else
576          {
577             super.attachMetaData(advisor, clazz);
578             parent.attachMetaData(advisor, clazz);
579          }
580       }
581       else
582       {
583          super.attachMetaData(advisor, clazz);
584       }
585    }
586
587    public CFlowStack getCFlowStack(String JavaDoc name)
588    {
589       if (inheritsDeclarations)
590       {
591          if (!parentFirst)
592          {
593             CFlowStack cflow = super.getCFlowStack(name);
594             if (cflow == null)
595             {
596                cflow = parent.getCFlowStack(name);
597             }
598             return cflow;
599          }
600          else
601          {
602             CFlowStack cflow = parent.getCFlowStack(name);
603             if (cflow == null)
604             {
605                cflow = super.getCFlowStack(name);
606             }
607             return cflow;
608          }
609       }
610       else
611       {
612          return super.getCFlowStack(name);
613       }
614    }
615
616
617    public DynamicCFlow getDynamicCFlow(String JavaDoc name)
618    {
619       if (inheritsBindings)
620       {
621          if (!parentFirst)
622          {
623             DynamicCFlow cflow = super.getDynamicCFlow(name);
624             if (cflow == null)
625             {
626                cflow = parent.getDynamicCFlow(name);
627             }
628             return cflow;
629          }
630          else
631          {
632             DynamicCFlow cflow = parent.getDynamicCFlow(name);
633             if (cflow == null)
634             {
635                cflow = super.getDynamicCFlow(name);
636             }
637             return cflow;
638          }
639       }
640       else
641       {
642          return super.getDynamicCFlow(name);
643       }
644    }
645
646    public ClassMetaDataLoader findClassMetaDataLoader(String JavaDoc group)
647    {
648       if (inheritsDeclarations)
649       {
650          if (!parentFirst)
651          {
652             ClassMetaDataLoader loader = super.findClassMetaDataLoader(group);
653             if (loader == null)
654             {
655                loader = parent.findClassMetaDataLoader(group);
656             }
657             return loader;
658          }
659          else
660          {
661             ClassMetaDataLoader loader = parent.findClassMetaDataLoader(group);
662             if (loader == null)
663             {
664                loader = super.findClassMetaDataLoader(group);
665             }
666             return loader;
667          }
668       }
669       
670       return super.findClassMetaDataLoader(group);
671    }
672    
673    //////////////////////////////////////////////////////////////////////////
674
//Methods that should delegate to the top AspectManager
675

676    /** Managed by the top-level aspect manager */
677    protected Map JavaDoc getScopedClassLoaderDomains()
678    {
679       return parent.getScopedClassLoaderDomains();
680    }
681    
682    /** Managed by the top-level aspect manager */
683    protected Map JavaDoc getSubDomainsPerClass()
684    {
685       return parent.getSubDomainsPerClass();
686    }
687
688    public void addConstructionInterceptionMarker(String JavaDoc classname)
689    {
690       parent.addConstructionInterceptionMarker(classname);
691    }
692
693    public void addFieldInterceptionMarker(String JavaDoc classname)
694    {
695       parent.addFieldInterceptionMarker(classname);
696    }
697
698    public void skipReference(String JavaDoc classname)
699    {
700       parent.skipReference(classname);
701    }
702
703    public boolean shouldSkipConstruction(String JavaDoc classname)
704    {
705       return parent.shouldSkipConstruction(classname);
706    }
707
708    public boolean shouldSkipFieldAccess(String JavaDoc classname)
709    {
710       return parent.shouldSkipFieldAccess(classname);
711    }
712
713    public void skipConstruction(String JavaDoc classname)
714    {
715       parent.skipConstruction(classname);
716    }
717
718    public void skipFieldAccess(String JavaDoc classname)
719    {
720       parent.skipFieldAccess(classname);
721    }
722
723    public boolean convertReference(String JavaDoc classname)
724    {
725       return parent.convertReference(classname);
726    }
727
728    /** Only set on a per vm basis */
729    public ArrayList JavaDoc getExclude()
730    {
731       return parent.getExclude();
732    }
733
734    /** Only set on a per vm basis */
735    public ArrayList JavaDoc getInclude()
736    {
737       return parent.getInclude();
738    }
739
740    /** Only set on a per vm basis */
741    public ArrayList JavaDoc getIgnore()
742    {
743       return parent.getIgnore();
744    }
745
746    /** Only set on a per vm basis */
747    public ClassExpression[] getIgnoreExpressions()
748    {
749       return super.getIgnoreExpressions();
750    }
751    
752    public DynamicAOPStrategy getDynamicAOPStrategy()
753    {
754       return parent.getDynamicAOPStrategy();
755    }
756
757    public void setDynamicAOPStrategy(DynamicAOPStrategy strategy)
758    {
759       parent.setDynamicAOPStrategy(strategy);
760    }
761
762    protected void updatePointcutStats(Pointcut pointcut)
763    {
764       parent.updatePointcutStats(pointcut);
765    }
766
767    protected void updateStats(PointcutStats stats)
768    {
769       parent.updateStats(stats);
770    }
771
772    public boolean isExecution()
773    {
774       return parent.isExecution();
775    }
776
777    public boolean isConstruction()
778    {
779       return parent.isConstruction();
780    }
781
782    public boolean isCall()
783    {
784       return parent.isCall();
785    }
786
787    public boolean isWithin()
788    {
789       return parent.isWithin();
790    }
791
792    public boolean isWithincode()
793    {
794       return parent.isWithincode();
795    }
796
797    public boolean isGet()
798    {
799       return parent.isGet();
800    }
801
802    public boolean isSet()
803    {
804       return parent.isSet();
805    }
806
807 }
808
Popular Tags