1 package org.sapia.magnet.domain.system; 2 3 import java.util.Collection ; 6 import java.util.Iterator ; 7 import java.util.Map ; 8 import java.util.TreeMap ; 9 10 11 import org.sapia.magnet.render.AbstractRenderable; 14 import org.sapia.magnet.render.MagnetContext; 15 import org.sapia.magnet.render.RenderingException; 16 17 18 29 public class Environment extends AbstractRenderable { 30 31 35 36 private String _theId; 37 38 39 private String _theParent; 40 41 42 private Map _theVariables; 43 44 48 51 public Environment() { 52 _theVariables = new TreeMap (); 53 } 54 55 59 64 public String getId() { 65 return _theId; 66 } 67 68 73 public String getParent() { 74 return _theParent; 75 } 76 77 83 public Collection getVariables() { 84 return _theVariables.values(); 85 } 86 87 91 96 public void setId(String anId) { 97 _theId = anId; 98 } 99 100 105 public void setParent(String aParent) { 106 _theParent = aParent; 107 } 108 109 114 public void addVariable(Variable aVariable) { 115 _theVariables.put(aVariable.getName(), aVariable); 116 } 117 118 123 public void removeVariable(Variable aVariable) { 124 _theVariables.remove(aVariable.getName()); 125 } 126 127 130 public void clearVariables() { 131 _theVariables.clear(); 132 } 133 134 138 144 public void render(MagnetContext aContext) throws RenderingException { 145 try { 147 _theId = resolveValue(aContext, _theId); 148 _theParent = resolveValue(aContext, _theParent); 149 } catch (RenderingException re) { 150 StringBuffer aBuffer = new StringBuffer (); 151 aBuffer.append("Unable to resolve the attribute of the environment '"). 152 append(_theId).append("'"); 153 154 throw new RenderingException(aBuffer.toString(), re); 155 } 156 157 Variable aVariable = null; 159 try { 160 for (Iterator it = _theVariables.values().iterator(); it.hasNext(); ) { 161 aVariable = (Variable) it.next(); 162 aVariable.render(aContext); 163 } 164 } catch (RenderingException re) { 165 StringBuffer aBuffer = new StringBuffer ("Unable to render the variable"); 166 if (aVariable != null) { 167 aBuffer.append(" '").append(aVariable.getName()).append("'"); 168 } 169 aBuffer.append(" of the environment '").append(_theId).append("'"); 170 171 throw new RenderingException(aBuffer.toString(), re); 172 } 173 } 174 175 180 public String toString() { 181 StringBuffer aBuffer = new StringBuffer (super.toString()); 182 aBuffer.append("[id=").append(_theId). 183 append(" parent=").append(_theParent). 184 append(" variables=").append(_theVariables). 185 append("]"); 186 187 return aBuffer.toString(); 188 } 189 } 190 | Popular Tags |