1 16 package com.google.gwt.dev.shell; 17 18 import com.google.gwt.core.ext.BadPropertyValueException; 19 import com.google.gwt.core.ext.PropertyOracle; 20 import com.google.gwt.core.ext.TreeLogger; 21 import com.google.gwt.dev.cfg.Properties; 22 import com.google.gwt.dev.cfg.Property; 23 24 import java.util.HashMap ; 25 import java.util.Map ; 26 27 31 public class ModuleSpacePropertyOracle implements PropertyOracle { 32 33 private final Map prevAnswers = new HashMap (); 34 35 private final Properties props; 36 37 private final ModuleSpace space; 38 39 public ModuleSpacePropertyOracle(Properties props, ModuleSpace space) { 40 this.space = space; 41 this.props = props; 42 } 43 44 47 public String getPropertyValue(TreeLogger logger, String propertyName) 48 throws BadPropertyValueException { 49 if (propertyName == null) { 50 throw new NullPointerException ("propertyName"); 51 } 52 53 Property prop = props.find(propertyName); 54 if (prop == null) { 55 throw new BadPropertyValueException(propertyName); 58 } 59 60 if (prevAnswers.containsKey(propertyName)) { 66 return (String ) prevAnswers.get(propertyName); 67 } else { 68 String value = computePropertyValue(logger, propertyName, prop); 69 prevAnswers.put(propertyName, value); 70 return value; 71 } 72 } 73 74 81 private String computePropertyValue(TreeLogger logger, String propertyName, 82 Property prop) throws BadPropertyValueException { 83 String value; 84 value = prop.getActiveValue(); 87 88 if (value == null) { 90 try { 93 value = space.invokeNativeString("__gwt_getProperty", null, 96 new Class [] {String .class}, new Object [] {prop.getName()}); 97 } catch (Throwable e) { 98 String msg = "Error while executing the JavaScript provider for property '" 101 + propertyName + "'"; 102 logger.log(TreeLogger.ERROR, msg, e); 103 throw new BadPropertyValueException(propertyName, "<failed to compute>"); 104 } 105 } 106 107 if (prop.isKnownValue(value)) { 109 return value; 110 } else { 111 throw new BadPropertyValueException(propertyName, value); 115 } 116 } 117 } 118 | Popular Tags |