1 package org.sapia.gumby; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.IOException ; 6 import java.io.InputStream ; 7 8 import org.sapia.gumby.factory.GumbyObjectFactory; 9 import org.sapia.gumby.view.View; 10 import org.sapia.util.xml.confix.Dom4jProcessor; 11 12 40 public class RenderContext { 41 42 private Settings _settings; 43 private GuiEnv _env; 44 private GumbyObjectFactory _fac; 45 46 RenderContext(GumbyObjectFactory parent, GuiEnv env, Settings settings) { 47 _fac = new GumbyObjectFactory(parent, this); 48 _settings = settings; 49 _env = env; 50 } 51 52 57 public GuiEnv getEnv() { 58 return _env; 59 } 60 61 64 public Settings getSettings() { 65 return _settings; 66 } 67 68 91 public RenderContext newChildInstance() { 92 return new RenderContext(_fac, new DefaultGuiEnv(_env), new Settings( 93 _settings)); 94 } 95 96 111 public View createView(String scope) { 112 View v = new View(this); 113 _env.addScope(scope, v); 114 return v; 115 } 116 117 124 public Object render(InputStream xmlDesc) throws Exception { 125 Dom4jProcessor proc = new Dom4jProcessor(_fac); 126 return proc.process(xmlDesc); 127 } 128 129 138 public void render(Object parent, InputStream xmlDesc) throws Exception { 139 Dom4jProcessor proc = new Dom4jProcessor(_fac); 140 proc.process(parent, xmlDesc); 141 } 142 143 146 public Object render(File xmlDesc) throws Exception { 147 return render(new FileInputStream (xmlDesc)); 148 } 149 150 153 public void render(Object parent, File xmlDesc) throws Exception { 154 render(parent, new FileInputStream (xmlDesc)); 155 } 156 157 168 public void loadDefinitions(InputStream is) throws Exception { 169 if(is != null) { 170 try { 171 Dom4jProcessor proc = new Dom4jProcessor(_fac); 172 proc.process(new Object (), is); 173 } finally { 174 try { 175 is.close(); 176 } catch(IOException e) { 177 } 178 } 179 } 180 } 181 182 } 183 | Popular Tags |