View Javadoc

1   //----------------------------------------------------------------------
2   // 
3   // PerfectJPattern: "Design patterns are good but components are better!" 
4   // Decorator.java Copyright (c) 2009 Giovanni Azua Garcia
5   // bravegag@hotmail.com
6   //  
7   // This program is free software; you can redistribute it and/or
8   // modify it under the terms of the GNU General Public License
9   // as published by the Free Software Foundation; either version 3
10  // of the License, or (at your option) any later version.
11  //
12  // This program 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
15  // GNU General Public License for more details.
16  //
17  // You should have received a copy of the GNU General Public License
18  // along with this program; if not, see <http://www.gnu.org/licenses/>.
19  //
20  //----------------------------------------------------------------------
21  package org.perfectjpattern.core.structural.proxy;
22  
23  import org.perfectjpattern.core.api.structural.proxy.*;
24  import org.perfectjpattern.core.structural.*;
25  
26  
27  /**
28   * Componentized implementation of <code>IProxy</code> interface. Provides
29   * special access to the underlying Subject.<br/>
30   * 
31   * @param <C> Decorated Component type
32   * 
33   * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
34   * @version $Revision: 1.0 $ $Date: Nov 25, 2007 3:15:23 PM $
35   */
36  public abstract
37  class AbstractProxy<C>
38  extends AbstractSurrogate<C, C>
39  implements IProxy<C>
40  {
41      //------------------------------------------------------------------------
42      // public
43      //------------------------------------------------------------------------
44      /**
45       * Creates a <code>Proxy&lt;E&gt;</code> from a Component interface 
46       * type and instance.
47       * 
48       * @param anInterface The Component interface type.
49       * @param aComponent The Component instance to Decorate.
50       * @throws IllegalArgumentException 'anInterface' must not be null.
51       * @throws IllegalArgumentException 'anInterface' must be an interface type.
52       * @throws IllegalArgumentException 'aComponent' must not be null.
53       */
54      public 
55      AbstractProxy(Class<C> anInterface, C aComponent)
56      throws IllegalArgumentException
57      {
58          super(anInterface, aComponent);
59      }
60  
61      //------------------------------------------------------------------------
62      /** 
63       * {@inheritDoc}
64       */
65      public final C
66      getSubject()
67      {
68          return getComponent();
69      }
70  
71      //------------------------------------------------------------------------
72      /** 
73       * {@inheritDoc}
74       */
75      public final C
76      getRealSubject()
77      {
78          return getUnderlying();
79      }
80  }