|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AllHandleStrategy | Line # 36 | 4 | 0% | 4 | 0 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (1) | |||
| Result | |||
|
1.0
|
org.perfectjpattern.core.behavioral.chainofresponsibility.TestExample.testChainOfResponsibility
org.perfectjpattern.core.behavioral.chainofresponsibility.TestExample.testChainOfResponsibility
|
1 PASS | |
| 1 | //---------------------------------------------------------------------- | |
| 2 | // | |
| 3 | // PerfectJPattern: "Design patterns are good but components are better!" | |
| 4 | // FirstNHandleStrategy.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.chainofresponsibility; | |
| 22 | ||
| 23 | import org.perfectjpattern.core.api.behavioral.chainofresponsibility.*; | |
| 24 | ||
| 25 | /** | |
| 26 | * Concrete implementation of <code>IChainStrategy</code> that allows | |
| 27 | * all <code>IHandler</code> instances in the Chain to handle the given request. | |
| 28 | * <br/><br/> | |
| 29 | * <code>AllHandleStrategy</code> is stateless, reentrant and a Singleton | |
| 30 | * therefore it may not be directly instantiated, neither it may be extended. | |
| 31 | * | |
| 32 | * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a> | |
| 33 | * @version $Revision: 1.0 $ $Date: Nov 8, 2007 9:57:12 PM $ | |
| 34 | */ | |
| 35 | public final | |
| 36 | class AllHandleStrategy | |
| 37 | implements IChainStrategy | |
| 38 | { | |
| 39 | //------------------------------------------------------------------------ | |
| 40 | // public | |
| 41 | //------------------------------------------------------------------------ | |
| 42 | /** | |
| 43 | * Returns Singleton instance of <code>AllHandleStrategy</code>. | |
| 44 | * | |
| 45 | * @return Singleton instance of <code>AllHandleStrategy</code>. | |
| 46 | */ | |
| 47 | 15 |
public static IChainStrategy |
| 48 | getInstance() | |
| 49 | { | |
| 50 | 15 | return INSTANCE; |
| 51 | } | |
| 52 | ||
| 53 | //------------------------------------------------------------------------ | |
| 54 | /** | |
| 55 | * {@inheritDoc} | |
| 56 | */ | |
| 57 | 15 |
public void |
| 58 | process(IHandler<Object> aHandler, Object aRequest) | |
| 59 | { | |
| 60 | 15 | if (aHandler.canHandle(aRequest)) |
| 61 | { | |
| 62 | 14 | aHandler.handle(aRequest); |
| 63 | } | |
| 64 | ||
| 65 | 15 | aHandler.getSuccessor().start(aRequest); |
| 66 | } | |
| 67 | ||
| 68 | //------------------------------------------------------------------------ | |
| 69 | // private | |
| 70 | //------------------------------------------------------------------------ | |
| 71 | 2 |
private |
| 72 | AllHandleStrategy() | |
| 73 | { | |
| 74 | // do nothing | |
| 75 | } | |
| 76 | ||
| 77 | //------------------------------------------------------------------------ | |
| 78 | // members | |
| 79 | //------------------------------------------------------------------------ | |
| 80 | private static final IChainStrategy INSTANCE = new AllHandleStrategy(); | |
| 81 | } | |
|
||||||||||||