1 17 18 package org.apache.avalon.repository.impl; 19 20 import java.util.ArrayList ; 21 import java.util.StringTokenizer ; 22 23 import org.apache.avalon.repository.Artifact; 24 25 import org.apache.avalon.util.criteria.Parameter; 26 import org.apache.avalon.util.criteria.CriteriaException; 27 28 29 36 public class ArtifactSequenceParameter extends Parameter 37 { 38 42 private final String m_delimiter; 43 44 48 54 public ArtifactSequenceParameter( 55 final String key, final String delimiter, Artifact[] defaults ) 56 { 57 super( key, Artifact[].class, defaults ); 58 m_delimiter = delimiter; 59 } 60 61 66 public Object resolve( Object value ) 67 throws CriteriaException 68 { 69 if( value == null ) return null; 70 if( value instanceof Artifact[] ) 71 { 72 return value; 73 } 74 if( value instanceof String [] ) 75 { 76 String [] specs = (String []) value; 77 Artifact[] artifacts = new Artifact[ specs.length ]; 78 for( int i=0; i<specs.length; i++ ) 79 { 80 final String spec = specs[i]; 81 artifacts[i] = Artifact.createArtifact( spec ); 82 } 83 return artifacts; 84 } 85 else if( value instanceof String ) 86 { 87 ArrayList list = new ArrayList (); 88 String s = (String ) value; 89 StringTokenizer tokenizer = 90 new StringTokenizer ( s, m_delimiter ); 91 while( tokenizer.hasMoreTokens() ) 92 { 93 final String spec = tokenizer.nextToken(); 94 Artifact artifact = Artifact.createArtifact( spec ); 95 list.add( artifact ); 96 } 97 return list.toArray( new Artifact[0] ); 98 } 99 else 100 { 101 final String error = 102 "Don't know how to transform an instance of [" 103 + value.getClass().getName() 104 + " to a Artifact[]."; 105 throw new CriteriaException( error ); 106 } 107 } 108 } 109 | Popular Tags |