|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| DefaultAssignmentPolicyFactory.java | 75% | 60% | 100% | 66.7% |
|
||||||||||||||
| 1 | /** | |
| 2 | * JTRunner is free software; you can redistribute it and/or modify it under the | |
| 3 | * terms of the GNU General Public License as published by the Free Software | |
| 4 | * Foundation; either version 2, or (at your option) any later version. | |
| 5 | */ | |
| 6 | ||
| 7 | package jtr.assigner.impl; | |
| 8 | ||
| 9 | import jtr.assigner.IAssignmentPolicyFactory; | |
| 10 | import jtr.assigner.IAssignmentPolicy; | |
| 11 | import jtr.assigner.UnknownAssignmentPolicyException; | |
| 12 | import org.apache.log4j.Logger; | |
| 13 | ||
| 14 | /** | |
| 15 | * This is the default factory used for obtaining instances of | |
| 16 | * <code>IAssignmentPolicy</code>.<br> | |
| 17 | * Once an <code>IAssignmentPolicy</code> concrete instance has been obtained, | |
| 18 | * the actual <code>IParamsAssigner</code> can be instantiated. | |
| 19 | * | |
| 20 | * @author Francesco Russo (frusso@dev.java.net) | |
| 21 | * @version 4.0 | |
| 22 | * @since 1.0 | |
| 23 | */ | |
| 24 | public class DefaultAssignmentPolicyFactory implements IAssignmentPolicyFactory { | |
| 25 | /** | |
| 26 | * Return a concrete instance of the <code>IAssignmentPolicy</code> | |
| 27 | * interface. The type of the assignment policy can be one of the default | |
| 28 | * ones (CYCLIC, INDEXED). | |
| 29 | * | |
| 30 | * @param type | |
| 31 | * String A legal type definition | |
| 32 | * @throws UnknownAssignmentPolicyException | |
| 33 | * @return IAssignmentPolicy | |
| 34 | */ | |
| 35 | 12 | public IAssignmentPolicy getInstance(String type) throws UnknownAssignmentPolicyException { |
| 36 | 12 | IAssignmentPolicy policy = null; |
| 37 | 12 | if (type.equals(CYCLIC)) { |
| 38 | 4 | policy = new CyclicAssignmentPolicy(); |
| 39 | } else { | |
| 40 | 8 | if (type.equals(INDEXED)) { |
| 41 | 8 | policy = new IndexedAssignmentPolicy(); |
| 42 | } else { | |
| 43 | 0 | String msg = "Unknown IAssignmentPolicy implementation: " + type; |
| 44 | 0 | UnknownAssignmentPolicyException e = new UnknownAssignmentPolicyException(msg); |
| 45 | 0 | logger.fatal(msg, e); |
| 46 | 0 | throw e; |
| 47 | } | |
| 48 | } | |
| 49 | 12 | return policy; |
| 50 | } | |
| 51 | ||
| 52 | /** | |
| 53 | * The type for obtaining a <code>CyclicAssignmentPolicy</code>. (<code>cyclic</code>) | |
| 54 | */ | |
| 55 | public final static String CYCLIC = "cyclic"; | |
| 56 | ||
| 57 | /** | |
| 58 | * The type for obtaining an <code>IndexedAssignmentPolicy</code>. (<code>indexed</code>) | |
| 59 | */ | |
| 60 | public final static String INDEXED = "indexed"; | |
| 61 | ||
| 62 | private static Logger logger = Logger.getLogger(DefaultAssignmentPolicyFactory.class); | |
| 63 | } |
|
||||||||||