1 19 20 package org.netbeans.mdr.handlers; 21 22 import org.netbeans.mdr.util.DebugException; 23 import org.netbeans.mdr.util.Logger; 24 import javax.jmi.reflect.InvalidNameException; 25 import javax.jmi.reflect.RefEnum; 26 import java.lang.reflect.Field ; 27 import java.util.Hashtable ; 28 29 33 public final class EnumResolver { 34 private static final String ENUMIMPL_SUFFIX = "Enum"; 35 private static final Hashtable enumCache = new Hashtable (50); 36 37 42 public static synchronized RefEnum resolveEnum(String ifcName, String label) { 43 String enumKey = label + ":" + ifcName; 44 RefEnum en = (RefEnum) enumCache.get(enumKey); 45 46 if (en == null) { 47 try { 48 Class cl = BaseObjectHandler.resolveInterface(ifcName + ENUMIMPL_SUFFIX); 49 Field f = cl.getField(org.netbeans.mdr.handlers.gen.TagSupport.mapEnumLiteral(label)); 50 en = (RefEnum) f.get(null); 51 enumCache.put(enumKey, en); 52 } catch (NoSuchFieldException e) { 53 throw new InvalidNameException(label, "Invalid literal name '" + label + "' for enumeration " + ifcName); 54 } catch (Exception e) { 55 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e); 56 } 57 } 58 59 return en; 60 } 61 62 } 63 | Popular Tags |