|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DynamicDelegator | Line # 47 | 9 | 0% | 3 | 0 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
(3) | |||
Result | |||
1.0
|
org.perfectjpattern.core.extras.delegate.TestDelegator.testDynamicDelegator org.perfectjpattern.core.extras.delegate.TestDelegator.testDynamicDelegator | 1 PASS | |
0.5833333
|
org.perfectjpattern.core.behavioral.observer.TestExample.testObserver org.perfectjpattern.core.behavioral.observer.TestExample.testObserver | 1 PASS | |
0.5833333
|
org.perfectjpattern.core.behavioral.observer.TestProxyObserver.testObserverPOJO org.perfectjpattern.core.behavioral.observer.TestProxyObserver.testObserverPOJO | 1 PASS | |
1 | //---------------------------------------------------------------------- | |
2 | // | |
3 | // PerfectJPattern: "Design patterns are good but components are better!" | |
4 | // DynamicDelegator.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.extras.delegate; | |
22 | ||
23 | import org.apache.commons.lang.*; | |
24 | import org.perfectjpattern.core.api.extras.delegate.*; | |
25 | ||
26 | ||
27 | /** | |
28 | * Implementation of <code>IDelegator</code> interface for creating | |
29 | * Delegate instances based on the dynamic </code>IDelegate</code> | |
30 | * type. <code>DynamicDelegator</code> should be used in cases where | |
31 | * there is no known interface definition for the targeted method. | |
32 | * <br/><br/> | |
33 | * <b>Notes</b>: Base source code implemented by Steve Lewis and Wilhelm | |
34 | * Fitzpatrick and adapted to fit PerfectJPattern componentization | |
35 | * criteria and code conventions. | |
36 | * | |
37 | * @see IDelegate | |
38 | * | |
39 | * @author <a href="mailto:smlewis@lordjoe.com">Steve Lewis</a> | |
40 | * @author <a href="mailto:wilhelmf@agileinformatics.com">Wilhelm | |
41 | * Fitzpatrick</a> | |
42 | * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a> | |
43 | * @version $Revision: 1.0 $ $Date: Jun 25, 2007 7:07:18 AM $ | |
44 | */ | |
45 | @SuppressWarnings("unchecked") | |
46 | public final | |
47 | class DynamicDelegator | |
48 | extends AbstractDelegator<IDelegate> | |
49 | { | |
50 | //------------------------------------------------------------------------ | |
51 | // public | |
52 | //------------------------------------------------------------------------ | |
53 | /** | |
54 | * Construct a <code>DynamicDelegator</code> by specifying the target | |
55 | * method signature. The method signature is defined by the types of the | |
56 | * parameters and return. | |
57 | * | |
58 | * @param aReturnClass Return type for the targeted method. | |
59 | * @param aParameters Array of method parameter types. | |
60 | */ | |
61 | 5 | public DynamicDelegator(Class aReturnClass, Class... aParameters) |
62 | { | |
63 | 5 | super(aReturnClass, aParameters); |
64 | } | |
65 | ||
66 | //------------------------------------------------------------------------ | |
67 | /** | |
68 | * {@inheritDoc} | |
69 | */ | |
70 | 2 | public IDelegate |
71 | build(Class aTarget, String aMethodName) | |
72 | throws IllegalArgumentException, UnsupportedOperationException | |
73 | { | |
74 | 2 | Validate.notNull(aTarget, "'aTarget' must not be null"); |
75 | 2 | Validate.notNull(aMethodName, "'aMethodName' must not be null"); |
76 | ||
77 | 2 | DelegateProxy myDelegate = new DelegateProxy(null, aTarget, aMethodName, |
78 | this); | |
79 | ||
80 | 2 | return myDelegate; |
81 | } | |
82 | ||
83 | //------------------------------------------------------------------------ | |
84 | /** | |
85 | * {@inheritDoc} | |
86 | */ | |
87 | 5 | public IDelegate |
88 | build(Object aTarget, String aMethodName) | |
89 | throws IllegalArgumentException, UnsupportedOperationException | |
90 | { | |
91 | 5 | Validate.notNull(aTarget, "'aTarget' must not be null"); |
92 | 5 | Validate.notNull(aMethodName, "'aMethodName' must not be null"); |
93 | ||
94 | 5 | DelegateProxy myDelegate = new DelegateProxy(aTarget, aTarget. |
95 | getClass(), aMethodName, this); | |
96 | ||
97 | 5 | return myDelegate; |
98 | } | |
99 | } |
|