1 package org.sapia.gumby; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 6 import org.sapia.gumby.factory.GumbyObjectFactory; 7 import org.sapia.util.xml.confix.Dom4jProcessor; 8 9 33 public class RenderContextFactory { 34 35 private static GumbyObjectFactory _defaults; 36 37 static { 38 if(_defaults == null) { 39 GumbyObjectFactory defaults = new GumbyObjectFactory(); 40 try { 41 loadDefaults(defaults); 42 _defaults = defaults; 43 } catch(Exception e) { 44 e.printStackTrace(); 45 } 46 } 47 } 48 49 54 public static RenderContext newInstance() { 55 return new RenderContext(_defaults, new DefaultGuiEnv(), new Settings()); 56 } 57 58 65 public static RenderContext newInstance(GuiEnv env) { 66 return new RenderContext(_defaults, env, new Settings()); 67 } 68 69 78 public static void loadDefinitions(InputStream is) throws Exception { 79 if(_defaults != null) { 80 doLoad(_defaults, is); 81 } 82 } 83 84 private static void loadDefaults(GumbyObjectFactory fac) throws Exception { 85 doLoad(fac, RenderContextFactory.class 86 .getResourceAsStream("gumby_defs.xml")); 87 } 88 89 private static void doLoad(GumbyObjectFactory fac, InputStream is) 90 throws Exception { 91 if(is != null) { 92 try { 93 Dom4jProcessor proc = new Dom4jProcessor(fac); 94 proc.process(new Object (), is); 95 } finally { 96 try { 97 is.close(); 98 } catch(IOException e) { 99 } 100 } 101 } 102 } 103 } 104 | Popular Tags |