KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.jboss.aop.Advisor;
25 import org.jboss.aop.InstanceAdvisor;
26 import org.jboss.aop.metadata.SimpleMetaData;
27
28 /**
29  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
30  * @version $Revision: 43258 $
31  */

32 public class ProxyTemplate implements Delegate, AspectManaged
33 {
34
35    public ProxyTemplate()
36    {
37    }
38
39    private Advisor classAdvisor;
40    private InstanceAdvisor instanceAdvisor;
41    protected volatile Advisor currentAdvisor;
42    
43    private Object JavaDoc delegate;
44    private Object JavaDoc[] mixins; // Do not remove this
45
private SimpleMetaData metadata;
46
47
48    public Object JavaDoc getDelegate()
49    {
50       return delegate;
51    }
52
53    public void setDelegate(Object JavaDoc delegate)
54    {
55       this.delegate = delegate;
56    }
57
58    public Advisor getAdvisor()
59    {
60       return currentAdvisor;
61    }
62
63    public void setAdvisor(Advisor advisor)
64    {
65       this.classAdvisor = advisor;
66       this.currentAdvisor = classAdvisor;
67    }
68
69    public void setMetadata(SimpleMetaData metadata)
70    {
71       this.metadata = metadata;
72    }
73
74    public void setInstanceAdvisor(InstanceAdvisor ia)
75    {
76       synchronized (this)
77       {
78          if (this.instanceAdvisor != null)
79          {
80             throw new RuntimeException JavaDoc("InstanceAdvisor already set");
81          }
82          
83          if (!(ia instanceof org.jboss.aop.proxy.container.InstanceProxyContainer))
84          {
85             throw new RuntimeException JavaDoc("Wrong type for instance advisor: " + instanceAdvisor);
86          }
87          this.instanceAdvisor = ia;
88          
89          currentAdvisor = (org.jboss.aop.proxy.container.InstanceProxyContainer)ia;
90       }
91    }
92
93    public InstanceAdvisor getInstanceAdvisor()
94    {
95       synchronized(this)
96       {
97          if (instanceAdvisor == null)
98          {
99             org.jboss.aop.proxy.container.InstanceProxyContainer ipc = ((org.jboss.aop.proxy.container.ClassProxyContainer)currentAdvisor).createInstanceProxyContainer();
100             setInstanceAdvisor(ipc);
101          }
102       }
103       return instanceAdvisor;
104    }
105    
106 }
107
Popular Tags