1 53 54 106 107 package com.Yasna.forum; 108 109 123 public abstract class AuthorizationFactory { 124 125 126 129 private static String className = 130 "com.Yasna.forum.database.DbAuthorizationFactory"; 131 132 private static AuthorizationFactory factory = null; 133 134 149 public static Authorization getAuthorization(String username, 150 String password) throws UnauthorizedException 151 { 152 loadAuthorizationFactory(); 153 return factory.createAuthorization(username, password); 154 } 155 156 161 public static Authorization getAnonymousAuthorization() { 162 loadAuthorizationFactory(); 163 return factory.createAnonymousAuthorization(); 164 } 165 166 176 public abstract Authorization createAuthorization(String username, 177 String password) throws UnauthorizedException; 178 179 185 public abstract Authorization createAnonymousAuthorization(); 186 187 197 private static void loadAuthorizationFactory() { 198 if (factory == null) { 199 synchronized(className) { 201 if (factory == null) { 202 String classNameProp = PropertyManager.getProperty( 204 "AuthorizationFactory.className" 205 ); 206 if (classNameProp != null) { 207 className = classNameProp; 208 } 209 try { 210 Class c = Class.forName(className); 211 factory = (AuthorizationFactory)c.newInstance(); 212 } 213 catch (Exception e) { 214 System.err.println("Exception loading class: " + e); 215 e.printStackTrace(); 216 } 217 } 218 } 219 } 220 } 221 } 222 | Popular Tags |