1 //----------------------------------------------------------------------
2 //
3 // PerfectJPattern: "Design patterns are good but components are better!"
4 // IAdaptingStrategy.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.api.structural.adapter;
22
23 import java.lang.reflect.Method;
24
25 import org.perfectjpattern.core.api.behavioral.strategy.IStrategy;
26
27
28 /**
29 * Abstract definition of the adapting strategy to use e.g.
30 * <ul>
31 * <li>Signature exact matching: the Adaptee and Target methods (name and
32 * parameters) must match or at least the Adaptee methods must be a subset
33 * of Target methods</li>
34 * <li>Signature types matching: the Adaptee and Target methods must
35 * match or at least the Adaptee methods must be a subset of the type
36 * signature of the Target methods</li>
37 * <li>Names mapping: The user defines dynamically the correspondence
38 * between methods in Adaptee and Target by name</li>
39 * </ul>
40 *
41 * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
42 * @version $Revision: 1.0 $Date: Jan 28, 2009 1:00:42 PM $
43 */
44 public
45 interface IAdaptingStrategy
46 extends IStrategy
47 {
48 //------------------------------------------------------------------------
49 // public
50 //------------------------------------------------------------------------
51 /**
52 * According to the definition of this strategy validates the tuple <code>
53 * Target</code>/<code>Adaptee</code>. Should the two not match an
54 * {@link NoSuchMethodError} will be thrown.
55 *
56 * @param aTargetClass Target class type
57 * @param anAdaptee Adaptee instance
58 * @param anAdapter Adapter instance
59 * @throws NoSuchMethodError
60 */
61 public void
62 validate(Class<?> aTargetClass, Object anAdaptee, Object anAdapter)
63 throws NoSuchMethodError;
64
65 //------------------------------------------------------------------------
66 /**
67 * Returns the <code>Adaptee</code> or otherwise <code>Adapter</code> method
68 * that corresponds to the given <code>Target</code> class type. If the
69 * corresponding method is not found an {@link NoSuchMethodError} will
70 * be thrown.
71 *
72 * @see #validate(Class, Object, Object)
73 *
74 * @param aTargetClass Target class type
75 * @param anAdaptee Adaptee instance
76 * @param anAdapter Adapter instance
77 * @param aTargetMethod Target method to search for in the Adaptee
78 * @return <code>Adaptee</code> method that corresponds to the given
79 * <code>Target</code> class type
80 * @throws NoSuchMethodError
81 */
82 public Method
83 resolve(Class<?> aTargetClass, Object anAdaptee, Object anAdapter,
84 Method aTargetMethod)
85 throws NoSuchMethodError;
86 }