1 7 package com.sun.corba.se.spi.orb ; 8 9 import java.util.Map ; 10 import java.util.Set ; 11 import java.util.Iterator ; 12 import java.util.Properties ; 13 14 import java.security.PrivilegedExceptionAction ; 15 import java.security.PrivilegedActionException ; 16 import java.security.AccessController ; 17 18 import java.lang.reflect.Field ; 19 20 import org.omg.CORBA.INTERNAL ; 21 22 import com.sun.corba.se.spi.logging.CORBALogDomains ; 23 24 import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 25 26 import com.sun.corba.se.impl.orbutil.ObjectUtility ; 27 28 public abstract class ParserImplBase { 32 private ORBUtilSystemException wrapper ; 33 34 protected abstract PropertyParser makeParser() ; 35 36 40 protected void complete() 41 { 42 } 43 44 public ParserImplBase() 45 { 46 wrapper = ORBUtilSystemException.get( 48 CORBALogDomains.ORB_LIFECYCLE ) ; 49 } 50 51 public void init( DataCollector coll ) 52 { 53 PropertyParser parser = makeParser() ; 54 coll.setParser( parser ) ; 55 Properties props = coll.getProperties() ; 56 Map map = parser.parse( props ) ; 57 setFields( map ) ; 58 } 59 60 private Field getAnyField( String name ) 61 { 62 Field result = null ; 63 64 try { 65 Class cls = this.getClass() ; 66 result = cls.getDeclaredField( name ) ; 67 while (result == null) { 68 cls = cls.getSuperclass() ; 69 if (cls == null) 70 break ; 71 72 result = cls.getDeclaredField( name ) ; 73 } 74 } catch (Exception exc) { 75 throw wrapper.fieldNotFound( exc, name ) ; 76 } 77 78 if (result == null) 79 throw wrapper.fieldNotFound( name ) ; 80 81 return result ; 82 } 83 84 protected void setFields( Map map ) 85 { 86 Set entries = map.entrySet() ; 87 Iterator iter = entries.iterator() ; 88 while (iter.hasNext()) { 89 java.util.Map.Entry entry = (java.util.Map.Entry)(iter.next()) ; 90 final String name = (String )(entry.getKey()) ; 91 final Object value = entry.getValue() ; 92 93 try { 94 AccessController.doPrivileged( 95 new PrivilegedExceptionAction () { 96 public Object run() throws IllegalAccessException , 97 IllegalArgumentException 98 { 99 Field field = getAnyField( name ) ; 100 field.setAccessible( true ) ; 101 field.set( ParserImplBase.this, value ) ; 102 return null ; 103 } 104 } 105 ) ; 106 } catch (PrivilegedActionException exc) { 107 throw wrapper.errorSettingField( exc.getCause(), name, 110 ObjectUtility.compactObjectToString(value) ) ; 111 } 112 } 113 114 complete() ; 117 } 118 } 119 | Popular Tags |