KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > proxy > container > AOPProxyFactoryMixin


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.proxy.container;
23
24 import java.lang.ref.WeakReference JavaDoc;
25
26 public class AOPProxyFactoryMixin
27 {
28    private String JavaDoc construction;
29    private WeakReference JavaDoc mixinClassRef;
30    private WeakReference JavaDoc[] interfaceClassRefs;
31    private int hashcode;
32
33    public AOPProxyFactoryMixin(Class JavaDoc mixin, Class JavaDoc[] interfaces)
34    {
35       mixinClassRef = new WeakReference JavaDoc(mixin);
36       interfaceClassRefs = ContainerCacheUtil.getSortedWeakReferenceForInterfaces(interfaces);
37    }
38
39    public AOPProxyFactoryMixin(Class JavaDoc mixin, Class JavaDoc[] interfaces, String JavaDoc parameters)
40    {
41       this(mixin, interfaces);
42       StringBuffer JavaDoc construction = new StringBuffer JavaDoc(" new ");
43       construction.append(mixin.getName());
44       
45       if (!parameters.startsWith("("))
46       {
47          construction.append("(");
48       }
49       
50       construction.append(parameters);
51       
52       if (!parameters.endsWith(")"))
53       {
54          construction.append(")");
55       }
56       this.construction = construction.toString();
57    }
58
59    public String JavaDoc getConstruction()
60    {
61       return construction;
62    }
63
64
65    public Class JavaDoc[] getInterfaces()
66    {
67       if (interfaceClassRefs != null)
68       {
69          Class JavaDoc[] interfaces = new Class JavaDoc[interfaceClassRefs.length];
70          for (int i = 0 ; i < interfaces.length ; i++)
71          {
72             interfaces[i] = (Class JavaDoc)interfaceClassRefs[i].get();
73          }
74          return interfaces;
75       }
76       return null;
77    }
78
79    public Class JavaDoc getMixin()
80    {
81       return (Class JavaDoc)mixinClassRef.get();
82    }
83
84    public boolean equals(Object JavaDoc obj)
85    {
86       if (this == obj)
87       {
88          return true;
89       }
90       
91       if (!(obj instanceof AOPProxyFactoryMixin))
92       {
93          return false;
94       }
95       
96       AOPProxyFactoryMixin other = (AOPProxyFactoryMixin)obj;
97       
98       if (!compareConstruction(other))
99       {
100          return false;
101       }
102       if (!ContainerCacheUtil.compareClassRefs(this.mixinClassRef, other.mixinClassRef))
103       {
104          return false;
105       }
106       if (!ContainerCacheUtil.compareInterfaceRefs(this.interfaceClassRefs, other.interfaceClassRefs))
107       {
108          return false;
109       }
110       return true;
111    }
112
113    public int hashCode()
114    {
115       if (hashcode == 0)
116       {
117          
118          Class JavaDoc clazz = (Class JavaDoc)mixinClassRef.get();
119          StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
120          
121          if (clazz != null)
122          {
123             sb.append(clazz.getName());
124          }
125          
126          if (interfaceClassRefs != null)
127          {
128             for (int i = 0 ; i < interfaceClassRefs.length ; i++)
129             {
130                sb.append(";");
131                sb.append(((Class JavaDoc)interfaceClassRefs[i].get()).getName());
132             }
133          }
134          hashcode = sb.toString().hashCode();
135          if (construction != null)
136          {
137             hashcode += construction.hashCode();
138          }
139       }
140       
141       return hashcode;
142    }
143
144    public String JavaDoc toString()
145    {
146       return super.toString();
147    }
148    
149    private boolean compareConstruction(AOPProxyFactoryMixin other)
150    {
151       if (this.construction == null && other.construction != null)
152       {
153          return false;
154       }
155       if (this.construction != null && other.construction == null)
156       {
157          return false;
158       }
159       if (this.construction != null)
160       {
161          if (!this.construction.equals(other.construction))
162          {
163             return false;
164          }
165       }
166       return true;
167    }
168 }
Popular Tags