/*
* Copyright 2004, 2005, 2006 Odysseus Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.odysseus.calyxo.panels.control;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import de.odysseus.calyxo.base.ModuleContext;
import de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.access.AccessSupport;
import de.odysseus.calyxo.control.Dispatcher;
import de.odysseus.calyxo.control.PluginContext;
import de.odysseus.calyxo.control.Plugin;
import de.odysseus.calyxo.control.conf.ParamConfig;
import de.odysseus.calyxo.control.conf.PluginConfig;
import de.odysseus.calyxo.panels.PanelsService;
import de.odysseus.calyxo.panels.misc.PanelsAccessor;
/**
* Panels plugin.
* The plugin expects parameter <code>config</code>, a comma-separated
* list of configuration file paths.
*
* @author Christoph Beck
*/
public class PanelsPlugin implements Plugin {
private static Log log = LogFactory.getLog(PanelsPlugin.class);
private PanelsService service = new PanelsService();
private ModuleContext module;
/* (non-Javadoc)
* @see de.odysseus.calyxo.control.Plugin#init(de.odysseus.calyxo.control.conf.PluginConfig, de.odysseus.calyxo.control.PluginContext)
*/
public void init(PluginConfig config, PluginContext context) throws ConfigException {
log.trace("init() start");
module = context.getModuleContext();
ParamConfig param = config.getParamConfig("config");
if (param == null) {
throw new ConfigException("Missing parameter 'config' in " + config.toInlineString());
}
service.init(module, param.getValue());
Dispatcher dispatcher = new PanelsDispatcher(module);
context.setDispatcher("panels", dispatcher);
param = config.getParamConfig("global");
if (param != null && "true".equals(param.getValue())) {
context.setDefaultDispatcher(dispatcher);
}
AccessSupport access = AccessSupport.getInstance(module);
access.put("panels", new PanelsAccessor(module));
log.trace("init() end");
}
/* (non-Javadoc)
* @see de.odysseus.calyxo.control.Plugin#destroy()
*/
public void destroy() {
service.destroy(module);
}
}