1 64 65 package com.jcorporate.expresso.core.dbobj; 66 67 import org.apache.log4j.Logger; 68 69 import java.util.HashMap ; 70 71 72 78 public final class SchemaFactory { 79 HashMap createdSchemas; 80 static Logger log = Logger.getLogger(SchemaFactory.class); 81 static SchemaFactory theInstance = new SchemaFactory(); 82 private String mDataContext; 83 private int mUserID; 84 85 protected SchemaFactory() { 86 createdSchemas = new HashMap (5); 87 } 88 89 public static SchemaFactory getInstance() { 90 return theInstance; 91 } 92 93 94 public synchronized Schema getSchema(String className) { 95 Schema returnValue = (Schema) createdSchemas.get(className); 96 97 if (returnValue == null) { 98 returnValue = constructSchema(className); 99 if (returnValue != null) { 100 createdSchemas.put(className, returnValue); 101 } 102 } 103 104 return returnValue; 105 } 106 107 private Schema constructSchema(String className) { 108 try { 109 Schema result = Schema.instantiate(className); 110 result.setDataContext(getDataContext()); 111 result.setRequestingUser(getRequestingUser()); 112 return result; 113 114 } catch (java.lang.Throwable t) { 115 t.printStackTrace(); 116 log.error("Error instantiating schema: ", t); 117 return null; 118 } 119 } 120 121 private int getRequestingUser() { 122 return mUserID; 123 } 124 125 public String getDataContext() { 126 return mDataContext; 127 } 128 129 public void setDataContext(String dataContext) { 130 mDataContext = dataContext; 131 } 132 133 public void setRequestingUser(int uid) { 134 mUserID = uid; 135 } 136 } | Popular Tags |