Coverage report

  %line %branch
tsukuba_bunko.peko.resource.TypeMapping
0% 
0% 

 1  
 /*
 2  
  * "Peko" Visual Novel System
 3  
  *
 4  
  * All Rights Reserved.
 5  
  * Copyright (c) 1999-2003 Tsukuba Bunko.
 6  
  *
 7  
  * $Id: TypeMapping.java,v 1.1 2005/07/11 12:49:19 ppoi Exp $
 8  
  */
 9  
 package tsukuba_bunko.peko.resource;
 10  
 
 11  
 import	java.io.InputStream;
 12  
 import	java.io.IOException;
 13  
 
 14  
 import	java.util.Properties;
 15  
 
 16  
 import	tsukuba_bunko.peko.InitializationError;
 17  
 import	tsukuba_bunko.peko.Logger;
 18  
 
 19  
 import	tsukuba_bunko.resource.DeserializerMapping;
 20  
 import	tsukuba_bunko.resource.ResourceDeserializer;
 21  
 
 22  
 
 23  
 /**
 24  
  * リソース ID と データ型のマッピングを管理します。
 25  
  * @author	$Author: ppoi $
 26  
  * @version	$Revision: 1.1 $
 27  
  */
 28  
 public class TypeMapping	{
 29  
 
 30  
 	/**
 31  
 	 * 唯一のインスタンス
 32  
 	 */
 33  0
 	private static TypeMapping	_instance = null;
 34  
 
 35  
 
 36  
 	/**
 37  
 	 * リソース ID - データ型マップ
 38  
 	 */
 39  0
 	private Properties	_typeMapping = null;
 40  
 
 41  
 	/**
 42  
 	 * DeserializerMapping
 43  
 	 */
 44  0
 	private DeserializerMapping	_deserializerMapping = null;
 45  
 
 46  
 
 47  
 	/**
 48  
 	 * <code>TypeMapping</code> のインスタンスを作成します。
 49  
 	 */
 50  
 	protected TypeMapping()
 51  
 	{
 52  0
 		super();
 53  0
 	}
 54  
 
 55  
 
 56  
 	/**
 57  
 	 * 指定されたリソースのデータ型名を取得します。
 58  
 	 * @param	resourceID	リソース ID
 59  
 	 * @return	データ型名
 60  
 	 */
 61  
 	public String getDataType( String resourceID )
 62  
 	{
 63  0
 		return _typeMapping.getProperty( resourceID );
 64  
 	}
 65  
 
 66  
 	/**
 67  
 	 * 指定されたリソースをデシリアライズする ResourceDeserializer を取得します。
 68  
 	 * @param	resourceID	リソース ID
 69  
 	 * @return	ResourceDeserializer
 70  
 	 */
 71  
 	public ResourceDeserializer getResourceDeserializer( String resourceID )
 72  
 	{
 73  0
 		String	type = _typeMapping.getProperty( resourceID );
 74  0
 		if( type != null )	{
 75  0
 			return _deserializerMapping.getResourceDeserializer( type );
 76  
 		}
 77  
 		else	{
 78  0
 			return null;
 79  
 		}
 80  
 	}
 81  
 
 82  
 	/**
 83  
 	 * DeserializerMapping を取得します。
 84  
 	 * @return	DeserializerMapping
 85  
 	 */
 86  
 	public DeserializerMapping getDeserializerMapping()
 87  
 	{
 88  0
 		return _deserializerMapping;
 89  
 	}
 90  
 
 91  
 	/**
 92  
 	 * <cpde>TypeMapping</code> を初期化します。
 93  
 	 * @throws	InitializationError	初期化に失敗した場合
 94  
 	 */
 95  
 	protected void initialize()
 96  
 	{
 97  0
 		ClassLoader	cl = getClass().getClassLoader();
 98  0
 		InputStream	is = cl.getResourceAsStream( "resources.def" );
 99  0
 		if( is == null )	{
 100  0
 			throw new InitializationError( "resources.def not found." );
 101  
 		}
 102  
 
 103  0
 		Properties	props = new Properties();
 104  
 		try	{
 105  0
 			props.load( is );
 106  
 		}
 107  0
 		catch( IOException ioe )	{
 108  0
 			Logger.fatal( "[resource] fail to initialize TypeMapping.", ioe );
 109  0
 			throw new InitializationError( "fail to initialize TypeMapping.", ioe );
 110  
 		}
 111  
 		finally	{
 112  0
 			try	{
 113  0
 				is.close();
 114  
 			}
 115  0
 			catch( IOException ioe )	{
 116  0
 				Logger.fatal( "[resource] fail to initialize TypeMapping.", ioe );
 117  0
 			}
 118  0
 		}
 119  0
 		_typeMapping = props;
 120  
 
 121  0
 		_deserializerMapping = DeserializerMapping.newInstance( "tsukuba_bunko.peko.resource.mapping" );
 122  0
 	}
 123  
 
 124  
 
 125  
 
 126  
 	/**
 127  
 	 * 唯一の <code>TypeMapping</code> のインスタンスを取得します。
 128  
 	 * @return	唯一の <code>TypeMapping</code> のインスタンス
 129  
 	 * @throws	InitializationError	初期化に失敗した場合
 130  
 	 */
 131  
 	public static TypeMapping getInstance()
 132  
 	{
 133  0
 		if( _instance == null )	{
 134  0
 			synchronized( TypeMapping.class )	{
 135  0
 				if( _instance == null )	{
 136  0
 					_instance = new TypeMapping();
 137  0
 					_instance.initialize();
 138  
 				}
 139  0
 			}
 140  
 		}
 141  0
 		return _instance;
 142  
 	}
 143  
 }

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