1 17 18 package org.apache.avalon.util.criteria; 19 20 import java.util.ArrayList ; 21 import java.util.StringTokenizer ; 22 23 30 public class PackedParameter extends Parameter 31 { 32 36 private final String m_delimiter; 37 38 42 48 public PackedParameter( 49 final String key, final String delimiter, String [] defaults ) 50 { 51 super( key, String [].class, defaults ); 52 m_delimiter = delimiter; 53 } 54 55 60 public Object resolve( Object value ) 61 throws CriteriaException 62 { 63 if( value == null ) return null; 64 if( value instanceof String [] ) 65 { 66 return value; 67 } 68 else if( value instanceof String ) 69 { 70 ArrayList list = new ArrayList (); 71 String s = (String ) value; 72 StringTokenizer tokenizer = 73 new StringTokenizer ( s, m_delimiter ); 74 while( tokenizer.hasMoreTokens() ) 75 { 76 list.add( tokenizer.nextToken() ); 77 } 78 return list.toArray( new String [0] ); 79 } 80 else 81 { 82 final String error = 83 "Don't know how to transform an instance of [" 84 + value.getClass().getName() 85 + " to a String[]."; 86 throw new CriteriaException( error ); 87 } 88 } 89 } 90 | Popular Tags |