1 11 package org.eclipse.core.expressions; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.core.runtime.Assert; 17 import org.eclipse.core.runtime.CoreException; 18 19 28 public class EvaluationContext implements IEvaluationContext { 29 30 private IEvaluationContext fParent; 31 private Object fDefaultVariable; 32 private Map fVariables; 33 private IVariableResolver[] fVariableResolvers; 34 private Boolean fAllowPluginActivation; 35 36 43 public EvaluationContext(IEvaluationContext parent, Object defaultVariable) { 44 Assert.isNotNull(defaultVariable); 45 fParent= parent; 46 fDefaultVariable= defaultVariable; 47 } 48 49 60 public EvaluationContext(IEvaluationContext parent, Object defaultVariable, IVariableResolver[] resolvers) { 61 Assert.isNotNull(defaultVariable); 62 Assert.isNotNull(resolvers); 63 fParent= parent; 64 fDefaultVariable= defaultVariable; 65 fVariableResolvers= resolvers; 66 } 67 68 71 public IEvaluationContext getParent() { 72 return fParent; 73 } 74 75 78 public IEvaluationContext getRoot() { 79 if (fParent == null) 80 return this; 81 return fParent.getRoot(); 82 } 83 84 87 public Object getDefaultVariable() { 88 return fDefaultVariable; 89 } 90 91 94 public void setAllowPluginActivation(boolean value) { 95 fAllowPluginActivation= value ? Boolean.TRUE : Boolean.FALSE; 96 } 97 98 101 public boolean getAllowPluginActivation() { 102 if (fAllowPluginActivation == null) { 103 if (fParent != null) 104 return fParent.getAllowPluginActivation(); 105 return false; 106 } 107 return fAllowPluginActivation.booleanValue(); 108 } 109 110 113 public void addVariable(String name, Object value) { 114 Assert.isNotNull(name); 115 Assert.isNotNull(value); 116 if (fVariables == null) 117 fVariables= new HashMap (); 118 fVariables.put(name, value); 119 } 120 121 124 public Object removeVariable(String name) { 125 Assert.isNotNull(name); 126 if (fVariables == null) 127 return null; 128 return fVariables.remove(name); 129 } 130 131 134 public Object getVariable(String name) { 135 Assert.isNotNull(name); 136 Object result= null; 137 if (fVariables != null) { 138 result= fVariables.get(name); 139 } 140 if (result != null) 141 return result; 142 if (fParent != null) 143 return fParent.getVariable(name); 144 return null; 145 } 146 147 150 public Object resolveVariable(String name, Object [] args) throws CoreException { 151 if (fVariableResolvers != null && fVariableResolvers.length > 0) { 152 for (int i= 0; i < fVariableResolvers.length; i++) { 153 IVariableResolver resolver= fVariableResolvers[i]; 154 Object variable= resolver.resolve(name, args); 155 if (variable != null) 156 return variable; 157 } 158 } 159 if (fParent != null) 160 return fParent.resolveVariable(name, args); 161 return null; 162 } 163 } 164 | Popular Tags |