1 23 24 package org.dbforms.config; 25 26 import javax.servlet.ServletContext ; 27 28 29 30 36 public class DbFormsConfigRegistry { 37 38 private static DbFormsConfigRegistry instance = null; 39 40 41 private ServletContext servletContext = null; 42 43 46 protected DbFormsConfigRegistry() { 47 } 48 49 54 public static synchronized DbFormsConfigRegistry instance() { 55 if (instance == null) { 56 instance = new DbFormsConfigRegistry(); 57 } 58 59 return instance; 60 } 61 62 63 68 public void setServletContext(ServletContext servletContext) { 69 this.servletContext = servletContext; 70 } 71 72 73 80 public DbFormsConfig lookup() throws Exception { 81 return lookup(DbFormsConfig.CONFIG); 82 } 83 84 85 91 public void register(DbFormsConfig config) { 92 register(DbFormsConfig.CONFIG, config); 93 } 94 95 96 106 private DbFormsConfig lookup(String name) throws Exception { 107 DbFormsConfig config = null; 108 109 if (servletContext != null) { 110 config = (DbFormsConfig) servletContext.getAttribute(name); 111 } else { 112 throw new Exception ("cannot lookup a config object with the name [" 113 + name + "]"); 114 } 115 116 return config; 117 } 118 119 120 126 private void register(String name, 127 DbFormsConfig config) { 128 if (servletContext != null) { 129 servletContext.setAttribute(name, config); 130 } 131 } 132 } 133 | Popular Tags |