1 7 package com.sun.corba.se.spi.orb ; 8 9 import java.util.Map ; 10 import java.util.AbstractMap ; 11 import java.util.Set ; 12 import java.util.AbstractSet ; 13 import java.util.Iterator ; 14 import java.util.Properties ; 15 16 import java.lang.reflect.Field ; 17 18 import org.omg.CORBA.INTERNAL ; 19 20 public abstract class ParserImplTableBase extends ParserImplBase { 24 private final ParserData[] entries ; 25 26 public ParserImplTableBase( ParserData[] entries ) 27 { 28 this.entries = entries ; 29 setDefaultValues() ; 30 } 31 32 protected PropertyParser makeParser() 33 { 34 PropertyParser result = new PropertyParser() ; 35 for (int ctr=0; ctr<entries.length; ctr++ ) { 36 ParserData entry = entries[ctr] ; 37 entry.addToParser( result ) ; 38 } 39 40 return result ; 41 } 42 43 private static final class MapEntry implements Map.Entry { 44 private Object key ; 45 private Object value ; 46 47 public MapEntry( Object key ) 48 { 49 this.key = key ; 50 } 51 52 public Object getKey() 53 { 54 return key ; 55 } 56 57 public Object getValue() 58 { 59 return value ; 60 } 61 62 public Object setValue( Object value ) 63 { 64 Object result = this.value ; 65 this.value = value ; 66 return result ; 67 } 68 69 public boolean equals( Object obj ) 70 { 71 if (!(obj instanceof MapEntry)) 72 return false ; 73 74 MapEntry other = (MapEntry)obj ; 75 76 return (key.equals( other.key )) && 77 (value.equals( other.value )) ; 78 } 79 80 public int hashCode() 81 { 82 return key.hashCode() ^ value.hashCode() ; 83 } 84 } 85 86 private static class FieldMap extends AbstractMap { 94 private final ParserData[] entries ; 95 private final boolean useDefault ; 96 97 public FieldMap( ParserData[] entries, boolean useDefault ) 98 { 99 this.entries = entries ; 100 this.useDefault = useDefault ; 101 } 102 103 public Set entrySet() 104 { 105 return new AbstractSet () 106 { 107 public Iterator iterator() 108 { 109 return new Iterator () { 110 int ctr = 0 ; 112 113 public boolean hasNext() 114 { 115 return ctr < entries.length ; 116 } 117 118 public Object next() 119 { 120 ParserData pd = entries[ctr++] ; 121 Map.Entry result = new MapEntry( pd.getFieldName() ) ; 122 if (useDefault) 123 result.setValue( pd.getDefaultValue() ) ; 124 else 125 result.setValue( pd.getTestValue() ) ; 126 return result ; 127 } 128 129 public void remove() 130 { 131 throw new UnsupportedOperationException () ; 132 } 133 } ; 134 } 135 136 public int size() 137 { 138 return entries.length ; 139 } 140 } ; 141 } 142 } ; 143 144 protected void setDefaultValues() 145 { 146 Map map = new FieldMap( entries, true ) ; 147 setFields( map ) ; 148 } 149 150 public void setTestValues() 151 { 152 Map map = new FieldMap( entries, false ) ; 153 setFields( map ) ; 154 } 155 } 156 | Popular Tags |