KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.ref.WeakReference JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Arrays JavaDoc;
27
28 import org.jboss.aop.advice.Interceptor;
29 import org.jboss.aop.joinpoint.Joinpoint;
30
31 public abstract class JoinPointInfo
32 {
33    private Interceptor[] interceptors;
34
35    private ArrayList JavaDoc interceptorChain = new ArrayList JavaDoc();
36    
37    private WeakReference JavaDoc advisor;
38    
39    protected volatile Joinpoint joinpoint;
40    
41    protected WeakReference JavaDoc clazz;
42
43    protected JoinPointInfo()
44    {
45       this.clazz = new WeakReference JavaDoc(null);
46    }
47    
48    protected JoinPointInfo(Advisor advisor, Class JavaDoc clazz)
49    {
50       setAdvisor(advisor);
51       this.clazz = new WeakReference JavaDoc(clazz);
52    }
53    
54    /*
55     * For copying
56     */

57    protected JoinPointInfo(JoinPointInfo other)
58    {
59       this.advisor = other.advisor;
60       if (other.interceptors != null)
61       {
62          this.interceptors = new Interceptor[other.interceptors.length];
63          System.arraycopy(other.interceptors, 0, this.interceptors, 0, other.interceptors.length);
64       }
65       if (other.interceptorChain != null)this.interceptorChain = (ArrayList JavaDoc)interceptorChain.clone();
66    }
67
68    protected void clear()
69    {
70       interceptorChain.clear();
71       interceptors = null;
72    }
73    
74    public Advisor getAdvisor()
75    {
76       if (advisor == null)
77       {
78          return null;
79       }
80       return (Advisor)advisor.get();
81    }
82
83    public Class JavaDoc getClazz()
84    {
85       return (Class JavaDoc)clazz.get();
86    }
87    
88    public void setAdvisor(Advisor advisor)
89    {
90       this.advisor = new WeakReference JavaDoc(advisor);
91    }
92
93    public boolean hasAdvices()
94    {
95       return (interceptors != null && interceptors.length > 0) /*|| (factories != null && factories.length > 0)*/;
96    }
97    
98    public boolean equalChains(JoinPointInfo other)
99    {
100       if (this.interceptors == null && other.interceptors == null) return true;
101       if (!(this.interceptors != null && other.interceptors != null))return false;
102       if (this.interceptors.length != other.interceptors.length) return false;
103       
104       for (int i = 0 ; i < this.interceptors.length ; i++)
105       {
106          if(!this.interceptors[i].equals(other.interceptors[i])) return false;
107       }
108
109       return true;
110    }
111    
112    public Joinpoint getJoinpoint()
113    {
114       if (joinpoint == null)
115       {
116          joinpoint = internalGetJoinpoint();
117       }
118       return joinpoint;
119    }
120    
121    public ArrayList JavaDoc getInterceptorChain() {
122       return interceptorChain;
123    }
124
125    public void setInterceptorChain(ArrayList JavaDoc interceptorChain) {
126       this.interceptorChain = interceptorChain;
127    }
128
129    public Interceptor[] getInterceptors() {
130       return interceptors;
131    }
132
133    public void setInterceptors(Interceptor[] interceptors) {
134       this.interceptors = interceptors;
135    }
136
137    protected abstract Joinpoint internalGetJoinpoint();
138    public abstract JoinPointInfo copy();
139 }
140
Popular Tags