| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FactoryContainer |
|
| 2.5;2.5 |
| 1 | package org.jtheque.primary.utils.web.analyzers.generic; | |
| 2 | ||
| 3 | import org.jdom.Element; | |
| 4 | import org.jtheque.core.utils.file.XMLException; | |
| 5 | import org.jtheque.core.utils.file.XMLReader; | |
| 6 | ||
| 7 | import java.util.ArrayList; | |
| 8 | import java.util.Collection; | |
| 9 | ||
| 10 | /* | |
| 11 | * This file is part of JTheque. | |
| 12 | * | |
| 13 | * JTheque is free software: you can redistribute it and/or modify | |
| 14 | * it under the terms of the GNU General Public License as published by | |
| 15 | * the Free Software Foundation, either version 3 of the License. | |
| 16 | * | |
| 17 | * JTheque is distributed in the hope that it will be useful, | |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 | * GNU General Public License for more details. | |
| 21 | * | |
| 22 | * You should have received a copy of the GNU General Public License | |
| 23 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
| 24 | */ | |
| 25 | ||
| 26 | /** | |
| 27 | * A container for factories. | |
| 28 | * | |
| 29 | * @author Baptiste Wicht | |
| 30 | */ | |
| 31 | 0 | public final class FactoryContainer<T> { |
| 32 | 0 | private final Collection<Factory<T>> factories = new ArrayList<Factory<T>>(10); |
| 33 | ||
| 34 | /** | |
| 35 | * Add a factory to the container. | |
| 36 | * | |
| 37 | * @param factory The factory to add to the container. | |
| 38 | */ | |
| 39 | public void add(Factory<T> factory){ | |
| 40 | 0 | factories.add(factory); |
| 41 | 0 | } |
| 42 | ||
| 43 | /** | |
| 44 | * Return the factored element | |
| 45 | * | |
| 46 | * @param element The element to get the factored object from. | |
| 47 | * @param reader The reader to use. | |
| 48 | * | |
| 49 | * @return The factored object. | |
| 50 | * | |
| 51 | * @throws XMLException If an error occurs during the XML processing. | |
| 52 | */ | |
| 53 | public T getFactoredObject(Element element, XMLReader reader) throws XMLException{ | |
| 54 | 0 | for (Factory<T> factory : factories){ |
| 55 | 0 | if (factory.canFactor(element, reader)){ |
| 56 | 0 | return factory.factor(element, reader); |
| 57 | } | |
| 58 | } | |
| 59 | ||
| 60 | 0 | return null; |
| 61 | } | |
| 62 | } |