1 17 18 package javax.el; 19 20 import java.beans.FeatureDescriptor ; 21 import java.util.ArrayList ; 22 import java.util.Enumeration ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.MissingResourceException ; 26 import java.util.ResourceBundle ; 27 28 public class ResourceBundleELResolver extends ELResolver { 29 30 public ResourceBundleELResolver() { 31 super(); 32 } 33 34 public Object getValue(ELContext context, Object base, Object property) 35 throws NullPointerException , PropertyNotFoundException, ELException { 36 if (context == null) { 37 throw new NullPointerException (); 38 } 39 40 if (base instanceof ResourceBundle ) { 41 context.setPropertyResolved(true); 42 43 if (property != null) { 44 try { 45 return ((ResourceBundle ) base).getObject(property 46 .toString()); 47 } catch (MissingResourceException mre) { 48 return "???" + property.toString() + "???"; 49 } 50 } 51 } 52 53 return null; 54 } 55 56 public Class <?> getType(ELContext context, Object base, Object property) 57 throws NullPointerException , PropertyNotFoundException, ELException { 58 if (context == null) { 59 throw new NullPointerException (); 60 } 61 62 if (base instanceof ResourceBundle ) { 63 context.setPropertyResolved(true); 64 } 65 66 return null; 67 } 68 69 public void setValue(ELContext context, Object base, Object property, 70 Object value) throws NullPointerException , 71 PropertyNotFoundException, PropertyNotWritableException, 72 ELException { 73 if (context == null) { 74 throw new NullPointerException (); 75 } 76 77 if (base instanceof ResourceBundle ) { 78 context.setPropertyResolved(true); 79 throw new PropertyNotWritableException(message(context, 80 "resolverNotWriteable", new Object [] { base.getClass() 81 .getName() })); 82 } 83 } 84 85 public boolean isReadOnly(ELContext context, Object base, Object property) 86 throws NullPointerException , PropertyNotFoundException, ELException { 87 if (context == null) { 88 throw new NullPointerException (); 89 } 90 91 if (base instanceof ResourceBundle ) { 92 context.setPropertyResolved(true); 93 } 94 95 return true; 96 } 97 98 public Iterator <FeatureDescriptor > getFeatureDescriptors(ELContext context, Object base) { 99 if (base instanceof ResourceBundle ) { 100 List <FeatureDescriptor > feats = new ArrayList <FeatureDescriptor >(); 101 Enumeration e = ((ResourceBundle ) base).getKeys(); 102 FeatureDescriptor feat; 103 String key; 104 while (e.hasMoreElements()) { 105 key = (String ) e.nextElement(); 106 feat = new FeatureDescriptor (); 107 feat.setDisplayName(key); 108 feat.setExpert(false); 109 feat.setHidden(false); 110 feat.setName(key); 111 feat.setPreferred(true); 112 feat.setValue(RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE); 113 feat.setValue(TYPE, String .class); 114 feats.add(feat); 115 } 116 return feats.iterator(); 117 } 118 return null; 119 } 120 121 public Class <?> getCommonPropertyType(ELContext context, Object base) { 122 if (base instanceof ResourceBundle ) { 123 return String .class; 124 } 125 return null; 126 } 127 128 } 129 | Popular Tags |