Clover Coverage Report - perfectjpattern(Aggregated)
Coverage timestamp: Sat Feb 28 2009 14:35:07 CET
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
11   123   8   2.75
8   51   0.73   4
4     2  
1    
11.5% of code in this file is excluded from these metrics.
 
  Invoker       Line # 40 11 11.5% 8 0 100% 1.0
 
  (2)
 
1    //----------------------------------------------------------------------
2    //
3    // PerfectJPattern: "Design patterns are good but components are better!"
4    // Invoker.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.behavioral.command;
22   
23    import org.apache.commons.lang.*;
24    import org.perfectjpattern.core.api.behavioral.command.*;
25   
26   
27    /**
28    * Base core implementation of <code>IInvoker</code> interface.
29    * <br/>
30    *
31    * @see IInvoker
32    *
33    * @param <P> Command Parameter context-specific.
34    * @param <R> Command Result context-specific.
35    *
36    * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
37    * @version $Revision: 1.0 $ $Date: Jun 23, 2007 2:34:57 AM $
38    */
39    public
 
40    class Invoker<P, R>
41    implements IInvoker<P, R>
42    {
43    //------------------------------------------------------------------------
44    // public
45    //------------------------------------------------------------------------
46    /**
47    * {@inheritDoc}
48    */
 
49  5 toggle public R
50    getResult()
51    throws IllegalStateException
52    {
53  5 if (theCommand == null)
54    {
55    throw new IllegalStateException("ICommand was not set.");
56    }
57   
58  4 R myResult = theCommand.getResult();
59  4 if (myResult == null)
60    {
61    throw new IllegalStateException("No result available.");
62    }
63   
64  3 return myResult;
65    }
66   
67    //------------------------------------------------------------------------
68    /**
69    * {@inheritDoc}
70    */
 
71  7 toggle public void
72    invoke()
73    throws IllegalStateException
74    {
75  7 if (theCommand == null)
76    {
77    throw new IllegalStateException("ICommand was not set.");
78    }
79   
80  6 if (theParameter != null)
81    {
82  3 theCommand.setParameter(theParameter);
83    }
84   
85  6 theCommand.execute();
86    }
87   
88    //------------------------------------------------------------------------
89    /**
90    * {@inheritDoc}
91    */
 
92  7 toggle public void
93    setCommand(ICommand<P, R> aCommand)
94    {
95  7 theCommand = aCommand;
96    }
97   
98    //------------------------------------------------------------------------
99    /**
100    * {@inheritDoc}
101    */
 
102  3 toggle public void
103    setParameter(P aParameter)
104    throws IllegalArgumentException
105    {
106  3 Validate.notNull(aParameter, "'aParameter' must not be null");
107   
108  3 theParameter = aParameter;
109    }
110   
111    //------------------------------------------------------------------------
112    // members
113    //------------------------------------------------------------------------
114    /**
115    * The <code>ICommand</code> instance.
116    */
117    private ICommand<P, R> theCommand;
118   
119    /**
120    * The <code>IParameter</code> instance.
121    */
122    private P theParameter;
123    }