| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ConverterFactory |
|
| 1.6;1.6 |
| 1 | /** | |
| 2 | * Distribution License: | |
| 3 | * JSword is free software; you can redistribute it and/or modify it under | |
| 4 | * the terms of the GNU Lesser General Public License, version 2.1 or later | |
| 5 | * as published by the Free Software Foundation. This program is distributed | |
| 6 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even | |
| 7 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 8 | * See the GNU Lesser General Public License for more details. | |
| 9 | * | |
| 10 | * The License is available on the internet at: | |
| 11 | * http://www.gnu.org/copyleft/lgpl.html | |
| 12 | * or by writing to: | |
| 13 | * Free Software Foundation, Inc. | |
| 14 | * 59 Temple Place - Suite 330 | |
| 15 | * Boston, MA 02111-1307, USA | |
| 16 | * | |
| 17 | * © CrossWire Bible Society, 2005 - 2016 | |
| 18 | * | |
| 19 | */ | |
| 20 | package org.crosswire.jsword.util; | |
| 21 | ||
| 22 | import java.util.Map; | |
| 23 | ||
| 24 | import org.crosswire.common.util.PluginUtil; | |
| 25 | import org.crosswire.common.xml.Converter; | |
| 26 | import org.crosswire.jsword.JSOtherMsg; | |
| 27 | ||
| 28 | /** | |
| 29 | * A factory for Converters. | |
| 30 | * | |
| 31 | * @see gnu.lgpl.License The GNU Lesser General Public License for details. | |
| 32 | * @author Joe Walker | |
| 33 | * @see org.crosswire.common.xml.Converter | |
| 34 | */ | |
| 35 | 0 | public final class ConverterFactory { |
| 36 | /** | |
| 37 | * Prevent instantiation | |
| 38 | */ | |
| 39 | 0 | private ConverterFactory() { |
| 40 | 0 | } |
| 41 | ||
| 42 | /** | |
| 43 | * Generate a converter for the current converter name | |
| 44 | * @return the plugin converter | |
| 45 | */ | |
| 46 | public static Converter getConverter() { | |
| 47 | try { | |
| 48 | 0 | Class<Converter> clazz = PluginUtil.getImplementorsMap(Converter.class).get(name); |
| 49 | 0 | assert clazz != null : JSOtherMsg.lookupText("No converter called: {0}", name); |
| 50 | 0 | return clazz.newInstance(); |
| 51 | 0 | } catch (InstantiationException e) { |
| 52 | 0 | assert false : e; |
| 53 | 0 | } catch (IllegalAccessException e) { |
| 54 | 0 | assert false : e; |
| 55 | 0 | } |
| 56 | 0 | return null; |
| 57 | } | |
| 58 | ||
| 59 | /** | |
| 60 | * Get a map of the known converters, by looking up the answers in Project | |
| 61 | * | |
| 62 | * @return the map of known converters | |
| 63 | */ | |
| 64 | public static Map<String, Class<Converter>> getKnownConverters() { | |
| 65 | 0 | return PluginUtil.getImplementorsMap(Converter.class); |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * For config to set the currently preferred converter implementation | |
| 70 | * | |
| 71 | * @param name | |
| 72 | */ | |
| 73 | public static void setCurrentConverterName(String name) { | |
| 74 | 0 | ConverterFactory.name = name; |
| 75 | 0 | } |
| 76 | ||
| 77 | /** | |
| 78 | * For config to read the currently preferred converter implementation | |
| 79 | * | |
| 80 | * @return the current plugin converter | |
| 81 | */ | |
| 82 | public static String getCurrentConverterName() { | |
| 83 | 0 | return name; |
| 84 | } | |
| 85 | ||
| 86 | /** | |
| 87 | * Current default converter implementation | |
| 88 | */ | |
| 89 | 0 | private static String name = "Configurable"; |
| 90 | } |