Coverage Report - net.sourceforge.jeuclid.converter.FreeHepInternalDetector
 
Classes in this File Line Coverage Branch Coverage Complexity
FreeHepInternalDetector
57%
22/38
100%
6/6
4,333
 
 1  
 /*
 2  
  * Copyright 2007 - 2007 JEuclid, http://jeuclid.sf.net
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 /* $Id: FreeHepInternalDetector.java,v 88b901bf20fb 2008/06/07 14:12:27 maxberger $ */
 18  
 
 19  
 package net.sourceforge.jeuclid.converter;
 20  
 
 21  
 import java.lang.reflect.InvocationTargetException;
 22  
 import java.util.HashMap;
 23  
 import java.util.Map;
 24  
 
 25  
 import net.sourceforge.jeuclid.elements.support.ClassLoaderSupport;
 26  
 
 27  
 import org.apache.commons.logging.Log;
 28  
 import org.apache.commons.logging.LogFactory;
 29  
 import org.freehep.util.export.ExportFileType;
 30  
 
 31  
 /**
 32  
  * actual detector for FreeHEP graphics formats. Depends on the presence of
 33  
  * FreeHEP, hence the "internal".
 34  
  * 
 35  
  * @version $Revision: 88b901bf20fb $
 36  
  */
 37  
 public final class FreeHepInternalDetector {
 38  
 
 39  
     /**
 40  
      * Logger for this class
 41  
      */
 42  209
     private static final Log LOGGER = LogFactory
 43  
             .getLog(FreeHepInternalDetector.class);
 44  
 
 45  209
     private static final Map<String, String> PLUGINS_CLASSES = new HashMap<String, String>();
 46  
 
 47  0
     private FreeHepInternalDetector() {
 48  
         // Empty on purpose
 49  0
     }
 50  
 
 51  
     /**
 52  
      * Actual detection and registration routine.
 53  
      * 
 54  
      * @param registry
 55  
      *            ConverterRegistry to use
 56  
      */
 57  
     public static void actuallyDetectConversionPlugins(
 58  
             final ConverterRegistry registry) {
 59  
 
 60  209
         for (final Map.Entry<String, String> e : FreeHepInternalDetector.PLUGINS_CLASSES
 61  
                 .entrySet()) {
 62  
 
 63  
             try {
 64  1254
                 final Class<?> infoClass = ClassLoaderSupport.getInstance()
 65  
                         .loadClass(e.getKey());
 66  1254
                 final ExportFileType fileType = (ExportFileType) infoClass
 67  
                         .getConstructor().newInstance();
 68  
 
 69  1254
                 final Class<?> graphicsClass = ClassLoaderSupport.getInstance()
 70  
                         .loadClass(e.getValue());
 71  1254
                 FreeHepInternalDetector.actuallyRegister(registry, fileType,
 72  
                         graphicsClass);
 73  0
             } catch (final NoSuchMethodException ex) {
 74  0
                 FreeHepInternalDetector.LOGGER.debug(ex);
 75  0
             } catch (final ClassNotFoundException ex) {
 76  0
                 FreeHepInternalDetector.LOGGER.debug(ex);
 77  0
             } catch (final IllegalArgumentException ex) {
 78  0
                 FreeHepInternalDetector.LOGGER.debug(ex);
 79  0
             } catch (final SecurityException ex) {
 80  0
                 FreeHepInternalDetector.LOGGER.debug(ex);
 81  0
             } catch (final InstantiationException ex) {
 82  0
                 FreeHepInternalDetector.LOGGER.debug(ex);
 83  0
             } catch (final IllegalAccessException ex) {
 84  0
                 FreeHepInternalDetector.LOGGER.debug(ex);
 85  0
             } catch (final InvocationTargetException ex) {
 86  0
                 FreeHepInternalDetector.LOGGER.debug(ex);
 87  2508
             }
 88  
         }
 89  209
     }
 90  
 
 91  
     private static void actuallyRegister(final ConverterRegistry registry,
 92  
             final ExportFileType fileType, final Class<?> graphicsClass)
 93  
             throws NoSuchMethodException {
 94  1254
         final ConverterPlugin freeHepConverter = new FreeHepConverter(
 95  
                 graphicsClass);
 96  2717
         for (final String mimeType : fileType.getMIMETypes()) {
 97  3135
             for (final String suffix : fileType.getExtensions()) {
 98  1672
                 registry.registerMimeTypeAndSuffix(mimeType, suffix, false);
 99  
             }
 100  1463
             registry.registerConverter(mimeType, freeHepConverter, false);
 101  
         }
 102  1254
     }
 103  
 
 104  
     static {
 105  209
         FreeHepInternalDetector.PLUGINS_CLASSES.put(
 106  
                 "org.freehep.graphicsio.emf.EMFExportFileType",
 107  
                 "org.freehep.graphicsio.emf.EMFGraphics2D");
 108  209
         FreeHepInternalDetector.PLUGINS_CLASSES.put(
 109  
                 "org.freehep.graphicsio.gif.GIFExportFileType",
 110  
                 "org.freehep.graphicsio.gif.GIFGraphics2D");
 111  209
         FreeHepInternalDetector.PLUGINS_CLASSES.put(
 112  
                 "org.freehep.graphicsio.pdf.PDFExportFileType",
 113  
                 "org.freehep.graphicsio.pdf.PDFGraphics2D");
 114  209
         FreeHepInternalDetector.PLUGINS_CLASSES.put(
 115  
                 "org.freehep.graphicsio.ps.PSExportFileType",
 116  
                 "org.freehep.graphicsio.ps.PSGraphics2D");
 117  209
         FreeHepInternalDetector.PLUGINS_CLASSES.put(
 118  
                 "org.freehep.graphicsio.svg.SVGExportFileType",
 119  
                 "org.freehep.graphicsio.svg.SVGGraphics2D");
 120  209
         FreeHepInternalDetector.PLUGINS_CLASSES.put(
 121  
                 "org.freehep.graphicsio.swf.SWFExportFileType",
 122  
                 "org.freehep.graphicsio.swf.SWFGraphics2D");
 123  209
     }
 124  
 }