View Javadoc
1 /* 2 * Copyright (c) 2003 3 * Information Desire GmbH 4 * All rights reserved. 5 */ 6 package com.infodesire.infobit; 7 8 import java.util.Properties; 9 import java.util.Collection; 10 11 import net.sf.hibernate.HibernateException; 12 import net.sf.hibernate.MappingException; 13 import net.sf.hibernate.tool.hbm2ddl.SchemaExport; 14 import net.sf.hibernate.cfg.Configuration; 15 import net.sf.hibernate.Session; 16 import net.sf.hibernate.SessionFactory; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 21 import com.infodesire.infobit.security.SecurityProvider; 22 import com.infodesire.infobit.security.DefaultSecurityProvider; 23 import com.infodesire.infobit.hibernate.SessionProvider; 24 import com.infodesire.infobit.hibernate.ThreadLocalSessionProvider; 25 26 import com.infodesire.infobit.dao.InfobitDAO; 27 import com.infodesire.infobit.dao.AclDAO; 28 import com.infodesire.infobit.data.Infobit; 29 import com.infodesire.infobit.data.Acl; 30 31 import com.infodesire.infobit.render.InfobitRenderer; 32 33 /*** 34 * infobit pool - main entry point for infobits. shall handle all infobbit 35 * operations and session management 36 * 37 * @author konstantin 38 * @created July 29, 2003 39 * @version $Revision: 1.9 $ 40 */ 41 public final class InfobitPool { 42 /*** 43 * name of property ( map entry ) holding name of given infobit pool 44 */ 45 public final static String NAME = "pool.name"; 46 /*** 47 * name of property ( map entry ) holding class name of hibernate session 48 * provider. if not specified, default one will be used ( {@see 49 * com.infodesire.infobit.hibernate.DefaultSessionProvider} ) 50 */ 51 public final static String SESSION_PROVIDER = "pool.sessionprovider"; 52 /*** 53 * name of property ( map entry ) holding class name of security provider. 54 * if not specified, default one will be used ( {@see 55 * com.infodesire.infobit.security.DefaultSecurityProvider} ) 56 */ 57 public final static String SECURITY_PROVIDER = "pool.securityprovider"; 58 59 private static Log _log = LogFactory.getLog(InfobitPool.class); 60 private String _name; 61 62 private SecurityProvider _securityProvider; 63 private SessionProvider _sessionProvider; 64 65 private InfobitManager _infobitManager = null; 66 private AclManager _aclManager = null; 67 68 private InfobitRenderer _infobitRenderer = null; 69 70 71 /*** 72 * Gets the Name attribute of the InfobitPool object 73 * 74 * @return The Name value 75 */ 76 public String getName() { 77 return _name; 78 } 79 80 81 82 /*** 83 * provide DAO for infobit manipulation. do it lazy and synchronized. 84 * 85 * @return DAO for infobit manipulation 86 */ 87 88 public synchronized InfobitManager getInfobitManager() { 89 if (_infobitManager == null) { 90 _infobitManager = new InfobitDAO(getSecurityProvider(), getSessionProvider()); 91 } 92 return _infobitManager; 93 } 94 95 96 /*** 97 * provide DAO for infobit manipulation. do it lazy and synchronized. 98 * 99 * @return The AclDAO value 100 */ 101 public synchronized AclManager getAclManager() { 102 if (_aclManager == null) { 103 _aclManager = new AclDAO(getSecurityProvider(), getSessionProvider()); 104 } 105 106 return _aclManager; 107 } 108 109 110 /*** 111 * Gets the RenderManager attribute of the InfobitPool object 112 * 113 * @return The RenderManager value 114 */ 115 public InfobitRenderer getInfobitRenderer() { 116 return null; 117 } 118 119 120 121 /*** 122 * Sets the Name attribute of the InfobitPool object 123 * 124 * @param name The new Name value 125 */ 126 public void setName(String name) { 127 _name = name; 128 } 129 130 131 /*** 132 * initialize pool off property map. set own name and construct session and 133 * security providers. necessary properties are defined by provider classes 134 * 135 * @param properties Description of Parameter 136 * @exception InfobitException Description of Exception 137 */ 138 public void init(Properties properties) throws InfobitException { 139 if (properties.containsKey(NAME)) { 140 setName(properties.getProperty(NAME)); 141 } 142 // configure security provider 143 String providerClassName = properties.getProperty(SESSION_PROVIDER); 144 Class providerClass = null; 145 if (providerClassName != null) { 146 providerClass = loadClass(providerClassName); 147 if (null == providerClass) { 148 _log.warn("did not found configured session provider class: " + providerClassName + " fallback to default"); 149 } 150 } 151 if (providerClass == null) { 152 providerClass = ThreadLocalSessionProvider.class; 153 } 154 155 try { 156 _sessionProvider = (SessionProvider) providerClass.newInstance(); 157 } catch (Exception ex) { 158 _log.fatal("exception occured while instantiating session provider", ex); 159 throw new InfobitException("exception occured while instantiating session provider", ex); 160 } 161 _sessionProvider.init(properties); 162 163 // and security provder 164 providerClassName = properties.getProperty(SECURITY_PROVIDER); 165 providerClass = null; 166 if (providerClassName != null) { 167 providerClass = loadClass(providerClassName); 168 if (null == providerClass) { 169 _log.warn("did not found configured security provider class: " + providerClassName + " fallback to default"); 170 } 171 } 172 if (providerClass == null) { 173 providerClass = DefaultSecurityProvider.class; 174 } 175 176 try { 177 _securityProvider = (SecurityProvider) providerClass.newInstance(); 178 } catch (Exception ex) { 179 _log.fatal("exception occured while instantiating session provider", ex); 180 throw new InfobitException("exception occured while instantiating session provider", ex); 181 } 182 _securityProvider.init(properties); 183 184 } 185 186 187 /*** 188 * flush given pool. close / flush active session if any 189 */ 190 public void flush() { 191 try { 192 Session sess = getSessionProvider().getSession(); 193 getSessionProvider().returnCloseSession(sess); 194 } catch (Exception ex) { 195 _log.error("error occured while flushing infobit pool", ex); 196 } 197 } 198 199 200 /*** 201 * Gets the SessionProvider attribute of the InfobitPool object 202 * 203 * @return The SessionProvider value 204 */ 205 SessionProvider getSessionProvider() { 206 return _sessionProvider; 207 } 208 209 210 /*** 211 * Gets the SecurityProvider attribute of the InfobitPool object 212 * 213 * @return The SecurityProvider value 214 */ 215 SecurityProvider getSecurityProvider() { 216 return _securityProvider; 217 } 218 219 220 /*** 221 * Sets the SessionProvider attribute of the InfobitPool object 222 * 223 * @param sessionProvider The new SessionProvider value 224 */ 225 void setSessionProvider(SessionProvider sessionProvider) { 226 _sessionProvider = sessionProvider; 227 } 228 229 230 /*** 231 * Sets the SecurityProvider attribute of the InfobitPool object 232 * 233 * @param securityProvider The new SecurityProvider value 234 */ 235 void setSecurityProvider(SecurityProvider securityProvider) { 236 _securityProvider = securityProvider; 237 } 238 239 240 /*** 241 * load class safely 242 * 243 * @param name Description of Parameter 244 * @return Description of the Returned Value 245 */ 246 private Class loadClass(String name) { 247 Class clazz = null; 248 try { 249 clazz = Thread.currentThread().getContextClassLoader().loadClass(name); 250 } catch (ClassNotFoundException e) { 251 try { 252 clazz = Class.forName(name); 253 } catch (ClassNotFoundException ee) { 254 try { 255 clazz = this.getClass().getClassLoader().loadClass(name); 256 } catch (ClassNotFoundException eee) { 257 } 258 } 259 } 260 261 return clazz; 262 } 263 }

This page was automatically generated by Maven