1 17 18 package org.apache.avalon.logging.impl; 19 20 import java.io.File ; 21 import java.net.URL ; 22 import org.apache.avalon.util.criteria.Parameter; 23 import org.apache.avalon.util.criteria.CriteriaException; 24 25 import org.apache.avalon.util.i18n.ResourceManager; 26 import org.apache.avalon.util.i18n.Resources; 27 28 35 public class ConfigurationParameter extends Parameter 36 { 37 41 private static final Resources REZ = 42 ResourceManager.getPackageResources( ConfigurationParameter.class ); 43 44 48 52 public ConfigurationParameter( final String key ) 53 { 54 super( key, URL .class ); 55 } 56 57 62 public Object resolve( Object value ) 63 throws CriteriaException 64 { 65 if( value == null ) 66 return null; 67 if( value instanceof URL ) 68 { 69 return value; 70 } 71 if( value instanceof String ) 72 { 73 return resolve( super.resolve( URL .class, value ) ); 74 } 75 else if( value instanceof File ) 76 { 77 File file = (File ) value; 78 if( ! file.exists() ) 79 { 80 final String error = 81 REZ.getString( 82 "parameter.configuration.fnf.error", 83 file.toString() ); 84 throw new CriteriaException( error ); 85 } 86 87 try 88 { 89 return file.toURL(); 90 } 91 catch( Throwable e ) 92 { 93 final String error = 94 REZ.getString( 95 "parameter.configuration.file.error", 96 file.toString() ); 97 throw new CriteriaException( error ); 98 } 99 } 100 else 101 { 102 final String error = 103 REZ.getString( 104 "parameter.unknown", 105 value.getClass().getName(), URL .class.getName() ); 106 throw new CriteriaException( error ); 107 } 108 } 109 } 110 | Popular Tags |