/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) 1999-2006 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/
package org.olat.core.gui.control.generic.portal;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.olat.core.extensions.ExtensionManager;
import org.olat.core.extensions.OLATExtension;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.generic.portal.Portal;
import org.olat.core.gui.control.generic.portal.PortalFactory;
import org.olat.core.gui.control.generic.portal.PortalImpl;
import org.olat.core.logging.AssertException;
import org.olat.core.logging.StartupException;
import org.olat.core.logging.Tracing;
/**
* Description:<br>
* PortalImpl factory to create new portal instances. The portals are defined in
* WEB-INF/olat_extensions.xml
* <P>
* Initial Date: 08.07.2005 <br>
* @author gnaegi
*/
public class PortalFactory {
private static final PortalFactory INSTANCE = new PortalFactory();
private static Map portals = new HashMap();
/**
* Singleton
*/
private PortalFactory() {
// singleton
}
/**
* @return PortalFactory instance
*/
public static final PortalFactory getInstance() {
return INSTANCE;
}
/**
* Bean method used by spring. Adds all known portals to the portals map
* @param portalList
*/
public void setPortalList(List portalList) {
if (portalList == null)
throw new AssertException("null value for portalList not allowed.");
// check beans
ExtensionManager extMgr = ExtensionManager.getInstance();
try {
for (Iterator iter = portalList.iterator(); iter.hasNext();) {
Portal portal = (Portal) iter.next();
portals.put(portal.getName(), portal);
Tracing.logInfo("Adding portal from configuraton:: " + portal.getName(), PortalFactory.class);
if (portal instanceof OLATExtension) {
try {
extMgr.deployExtension((OLATExtension)portal);
} catch (IOException ioe) {
throw new StartupException("Error deploying bean '" + portal + "'.", ioe);
}
}
}
}
catch (ClassCastException cce) {
throw new StartupException("Configured portlet is not of type portal", cce);
}
}
/**
* Factory method to create a new portal instance with the given name
* @param portalName The portal identitfyer specified in WEB-INF/olat_extensions.xml
* @param wControl
* @param ureq
* @return PortalImpl
*/
public static PortalImpl createPortal(String portalName, WindowControl wControl, UserRequest ureq) {
// create portlet controller
PortalImpl p = (PortalImpl) portals.get(portalName);
if (p == null) {
Tracing.logWarn("Could not create portal with name::" + portalName, PortalFactory.class);
return null;
}
return p.createInstance(wControl, ureq);
}
}