1 7 8 package com.sun.corba.se.impl.orb ; 9 10 import org.omg.CORBA.INITIALIZE ; 11 12 import java.util.Properties ; 13 import java.util.List ; 14 import java.util.LinkedList ; 15 import java.util.Iterator ; 16 17 import java.lang.reflect.Array ; 18 19 import com.sun.corba.se.spi.orb.Operation ; 20 import com.sun.corba.se.spi.orb.StringPair ; 21 import com.sun.corba.se.spi.logging.CORBALogDomains ; 22 23 import com.sun.corba.se.impl.orbutil.ObjectUtility ; 24 import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 25 26 public class PrefixParserAction extends ParserActionBase { 27 private Class componentType ; 28 private ORBUtilSystemException wrapper ; 29 30 public PrefixParserAction( String propertyName, 31 Operation operation, String fieldName, Class componentType ) 32 { 33 super( propertyName, true, operation, fieldName ) ; 34 this.componentType = componentType ; 35 this.wrapper = ORBUtilSystemException.get( 36 CORBALogDomains.ORB_LIFECYCLE ) ; 37 } 38 39 45 public Object apply( Properties props ) 46 { 47 String prefix = getPropertyName() ; 48 int prefixLength = prefix.length() ; 49 if (prefix.charAt( prefixLength - 1 ) != '.') { 50 prefix += '.' ; 51 prefixLength++ ; 52 } 53 54 List matches = new LinkedList () ; 55 56 Iterator iter = props.keySet().iterator() ; 58 while (iter.hasNext()) { 59 String key = (String )(iter.next()) ; 60 if (key.startsWith( prefix )) { 61 String suffix = key.substring( prefixLength ) ; 62 String value = props.getProperty( key ) ; 63 StringPair data = new StringPair( suffix, value ) ; 64 Object result = getOperation().operate( data ) ; 65 matches.add( result ) ; 66 } 67 } 68 69 int size = matches.size() ; 70 if (size > 0) { 71 Object result = null ; 76 try { 77 result = Array.newInstance( componentType, size ) ; 78 } catch (Throwable thr) { 79 throw wrapper.couldNotCreateArray( thr, 80 getPropertyName(), componentType, 81 new Integer ( size ) ) ; 82 } 83 84 Iterator iter2 = matches.iterator() ; 85 int ctr = 0 ; 86 while (iter2.hasNext()) { 87 Object obj = iter2.next() ; 88 89 try { 90 Array.set( result, ctr, obj ) ; 91 } catch (Throwable thr) { 92 throw wrapper.couldNotSetArray( thr, 93 getPropertyName(), new Integer (ctr), 94 componentType, new Integer (size), 95 ObjectUtility.compactObjectToString( obj )) ; 96 } 97 ctr++ ; 98 } 99 100 return result ; 101 } else 102 return null ; 103 } 104 } 105 | Popular Tags |