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.decorator;
22  
23  import org.perfectjpattern.core.api.structural.decorator.IDecorator;
24  import org.perfectjpattern.core.structural.*;
25  
26  
27  /**
28   * Abstract reusable implementation of {@link IDecorator}.
29   * <br/>
30   * 
31   * @param <C> <code>Component</code> element type. Interface type 
32   *        being decorated. 
33   * @param <D> <code>Decorator</code> element type. This type covers the 
34   *        following two use-cases: 
35   *        <ul>
36   *        <li>If the Decorator does not offer added functionality then 
37   *        this type is the same as &lt;C&gt;</li>
38   *        <li>Otherwise &lt;D&gt; will be a subclass of &lt;C&gt; that 
39   *        is, it will comply to &lt;C&gt; and offer extra functionality</li>
40   *        </ul>
41   * 
42   * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
43   * @version $Revision: 1.0 $ $Date: Nov 25, 2007 3:15:23 PM $
44   */
45  public abstract
46  class AbstractDecorator<C, D extends C>
47  extends AbstractSurrogate<D, C>
48  implements IDecorator<C, D>
49  {
50      //------------------------------------------------------------------------
51      // public
52      //------------------------------------------------------------------------
53      /**
54       * Constructs a Decorator from the class type of the Decorator <code>
55       * Class&lt;D&gt;</code> and the Component &lt;C&gt; instance to decorate.
56       * <br/></br>
57       * Depending on whether the user wants to add functionality to &lt;C&gt; 
58       * or not, the type &lt;D&gt; will be a subtype of &lt;C&gt; or be the same 
59       * respectively.
60       * <br/><br/>
61       * @param aDecoratorType Class type of the <code>Decorator</code> interface
62       * @param aComponent The Component instance to Decorate
63       * @throws IllegalArgumentException 'anInterface' must not be null
64       * @throws IllegalArgumentException 'anInterface' must be an interface type
65       * @throws IllegalArgumentException 'aComponent' must not be null
66       */
67      public 
68      AbstractDecorator(Class<D> aDecoratorType, C aComponent)
69      {
70          super(aDecoratorType, aComponent);
71      }
72      
73      //------------------------------------------------------------------------
74      /** 
75       * {@inheritDoc}
76       */
77      public final C
78      getDecorated()
79      {
80          return super.getUnderlying();
81      }
82  }