01: /* Copyright 2002 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.layout;
07:
08: import java.lang.reflect.Constructor;
09:
10: import org.jasig.portal.PortalException;
11: import org.jasig.portal.UserProfile;
12: import org.jasig.portal.layout.immutable.ImmutableUserLayoutManagerWrapper;
13: import org.jasig.portal.layout.simple.SimpleUserLayoutManager;
14: import org.jasig.portal.properties.PropertiesManager;
15: import org.jasig.portal.security.IPerson;
16: import org.apache.commons.logging.Log;
17: import org.apache.commons.logging.LogFactory;
18: import org.jasig.portal.services.stats.StatsRecorderLayoutEventListener;
19:
20: /**
21: * A factory class for obtaining {@link IUserLayoutManager} implementations.
22: *
23: * @author Peter Kharchenko {@link <a href="mailto:pkharchenko@interactivebusiness.com"">pkharchenko@interactivebusiness.com"</a>}
24: * @version 1.0
25: */
26: public class UserLayoutManagerFactory {
27:
28: private static final Log LOG = LogFactory
29: .getLog(UserLayoutManagerFactory.class);
30:
31: private static Class coreUserLayoutManagerImpl = SimpleUserLayoutManager.class;
32:
33: static {
34: // Retrieve the class name of the core IUserLayoutManager implementation
35: String className = PropertiesManager
36: .getProperty(
37: "org.jasig.portal.layout.UserLayoutManagerFactory.coreImplementation",
38: null);
39: if (className == null)
40: LOG
41: .error("UserLayoutManagerFactory: org.jasig.portal.layout.UserLayoutManagerFactory.coreImplementation must be specified in portal.properties");
42: try {
43: Class newClass = Class.forName(className);
44: coreUserLayoutManagerImpl = newClass;
45: LOG
46: .info("UserLayoutManagerFactory: Layout Manager Factory successfully loaded: "
47: + className);
48: } catch (Exception e) {
49: LOG.error(
50: "UserLayoutManagerFactory: Could not instantiate "
51: + className, e);
52: }
53: }
54:
55: /**
56: * Obtain a regular user layout manager implementation
57: *
58: * @return an <code>IUserLayoutManager</code> value
59: */
60: public static IUserLayoutManager getUserLayoutManager(
61: IPerson person, UserProfile profile) throws PortalException {
62: try {
63: Class[] cArgsClasses = { IPerson.class, UserProfile.class,
64: IUserLayoutStore.class };
65: Constructor c = coreUserLayoutManagerImpl
66: .getConstructor(cArgsClasses);
67: Object[] cArgs = { person, profile,
68: UserLayoutStoreFactory.getUserLayoutStoreImpl() };
69: IUserLayoutManager ulm = (IUserLayoutManager) c
70: .newInstance(cArgs);
71: ulm
72: .addLayoutEventListener(new StatsRecorderLayoutEventListener(
73: person, profile));
74:
75: // Wrap the implementation to provide lookup by fname
76: // support which basically merges a non-persisted channel
77: // into the layout
78: IUserLayoutManager ulmWrapper = new TransientUserLayoutManagerWrapper(
79: ulm);
80: return ulmWrapper;
81: } catch (Exception e) {
82: throw new PortalException("Unable to instantiate a \""
83: + coreUserLayoutManagerImpl.getName() + "\"", e);
84: }
85: }
86:
87: /**
88: * Returns an immutable version of a user layout manager.
89: *
90: * @param man an <code>IUserLayoutManager</code> value
91: * @return an immutable <code>IUserLayoutManager</code> value
92: * @exception PortalException if an error occurs
93: */
94: public static IUserLayoutManager immutableUserLayoutManager(
95: IUserLayoutManager man) throws PortalException {
96: return new ImmutableUserLayoutManagerWrapper(man);
97: }
98: }
|