Coverage report

  %line %branch
org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl.AtomicTypeConverterProviderImpl
0% 
0% 

 1  
 /*
 2  
  * Copyright 2004-2005 The Apache Software Foundation or its licensors,
 3  
  *                     as applicable.
 4  
  *
 5  
  * Licensed under the Apache License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.portals.graffito.jcr.persistence.atomictypeconverter.impl;
 18  
 
 19  
 import java.util.HashMap;
 20  
 import java.util.Iterator;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.apache.portals.graffito.jcr.exception.IncorrectAtomicTypeException;
 24  
 import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverter;
 25  
 import org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterProvider;
 26  
 
 27  
 
 28  
 /**
 29  
  * Implementation of {@link AtomicTypeConverterProvider}.
 30  
  * 
 31  
  * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
 32  
  */
 33  
 public class AtomicTypeConverterProviderImpl implements AtomicTypeConverterProvider {
 34  
     protected Map m_converters;
 35  0
     protected Map m_converterInstances = new HashMap();
 36  
     
 37  
     /**
 38  
      * No-arg constructor.
 39  
      */
 40  0
     public AtomicTypeConverterProviderImpl() {
 41  0
     }
 42  
     
 43  
     /**
 44  
      * Full constructor.
 45  
      * 
 46  
      * @param converters a map of classes and their associated <code>AtomicTypeConverter</code>
 47  
      * classes.
 48  
      */
 49  0
     public AtomicTypeConverterProviderImpl(Map converters) {
 50  0
         m_converters= converters;
 51  0
     }
 52  
     
 53  
     /**
 54  
      * Sets the associations of classes and their <code>AtomicTypeConverter</code>
 55  
      * classes.
 56  
      * 
 57  
      * @param converters <code>Map<Class, Class></code>
 58  
      */
 59  
     public void setAtomicTypeConvertors(Map converters) {
 60  0
         m_converters= converters;
 61  0
     }
 62  
     
 63  
     /**
 64  
      * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterProvider#getAtomicTypeConverter(java.lang.Class)
 65  
      */
 66  
     public AtomicTypeConverter getAtomicTypeConverter(Class clazz) {
 67  0
         AtomicTypeConverter converter= (AtomicTypeConverter) m_converterInstances.get(clazz);
 68  0
         if(null != converter) {
 69  0
             return converter;
 70  
         }
 71  0
         Class converterClass= (Class) m_converters.get(clazz);
 72  0
         if(null == converterClass) {
 73  0
             throw new IncorrectAtomicTypeException("No registered converter for class '" + clazz + "'");
 74  
         }
 75  
         
 76  
         try {
 77  0
             converter= (AtomicTypeConverter) converterClass.newInstance();
 78  0
             m_converterInstances.put(clazz, converter);
 79  
         }
 80  0
         catch(Exception ex) {
 81  0
             throw new IncorrectAtomicTypeException(
 82  
                     "Cannot create converter instance from class '" + clazz + "'", ex);
 83  
             
 84  0
         }
 85  
         
 86  0
         return converter;
 87  
     }
 88  
     
 89  
     /**
 90  
      * @see org.apache.portals.graffito.jcr.persistence.atomictypeconverter.AtomicTypeConverterProvider#getAtomicTypeConverters()
 91  
      */
 92  
     public Map getAtomicTypeConverters() {
 93  0
         Map result= new HashMap();
 94  0
         for(Iterator it= m_converters.keySet().iterator(); it.hasNext(); ) {
 95  0
             Class clazz= (Class) it.next();
 96  0
             result.put(clazz, getAtomicTypeConverter(clazz));
 97  
         }
 98  
         
 99  0
         return result;
 100  
     }
 101  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.