Coverage Report - org.wiztools.xml2spreadsheet.jxlimpl.JXLColor
 
Classes in this File Line Coverage Branch Coverage Complexity
JXLColor
84% 
100% 
0
 
 1  
 /*
 2  
  * JXLColor.java
 3  
  *
 4  
  * Created on November 17, 2006, 5:36 PM
 5  
  *
 6  
  * To change this template, choose Tools | Template Manager
 7  
  * and open the template in the editor.
 8  
  */
 9  
 
 10  
 package org.wiztools.xml2spreadsheet.jxlimpl;
 11  
 
 12  
 import java.lang.reflect.Field;
 13  
 import java.util.HashMap;
 14  
 import java.util.Map;
 15  
 import jxl.format.Colour;
 16  
 import org.wiztools.xml2spreadsheet.exception.OperationException;
 17  
 import org.wiztools.xml2spreadsheet.exception.XML2XLSFatalException;
 18  
 
 19  
 /**
 20  
  *
 21  
  * @author subhash
 22  
  */
 23  
 public class JXLColor {
 24  
     
 25  
     private static JXLColor jxlc;
 26  
     
 27  
     private Map<String, Colour> colorMap;
 28  
     
 29  
     /** Creates a new instance of JXLColor */
 30  9
     private JXLColor() {
 31  9
         colorMap = new HashMap<String, Colour>();
 32  9
         Field[] arr = Colour.class.getFields();
 33  
         try{
 34  576
             for(Field f: arr){
 35  
                 //System.out.println("=>>>>"+f.getType().getName()+" :: "+Colour.class.getName());
 36  567
                 if(f.getType().getName().equals(Colour.class.getName())){
 37  567
                     Colour color = (Colour)f.get(null);
 38  
                     //System.out.println("Putting in Map colors: "+f.getName().toLowerCase());
 39  567
                     colorMap.put(f.getName().toLowerCase(), color);
 40  
                 }
 41  
             }
 42  
         }
 43  0
         catch(IllegalAccessException iae){
 44  
             //throw new XML2XLSFatalException("Access permission for reflection need to be provided for this application to work.");
 45  0
             iae.printStackTrace();
 46  9
         }
 47  9
     }
 48  
     
 49  
     public static JXLColor getInstance(){
 50  54
         if(jxlc == null){
 51  9
             jxlc = new JXLColor();
 52  
         }
 53  54
         return jxlc;
 54  
     }
 55  
     
 56  
     public Colour getColor(String colorStr) throws OperationException{
 57  54
         colorStr = colorStr.toLowerCase();
 58  54
         Colour c = colorMap.get(colorStr);
 59  54
         if(c == null){
 60  0
             throw new OperationException("Color not found in the map: "+colorStr);
 61  
         }
 62  54
         return c;
 63  
     }
 64  
 }