001/*
002 *  Copyright 2010 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.workflow;
017
018import java.net.URL;
019import java.util.Collections;
020import java.util.Map;
021
022import com.opensymphony.workflow.FactoryException;
023import com.opensymphony.workflow.StoreException;
024import com.opensymphony.workflow.config.Configuration;
025import com.opensymphony.workflow.loader.WorkflowDescriptor;
026import com.opensymphony.workflow.loader.WorkflowFactory;
027import com.opensymphony.workflow.spi.WorkflowStore;
028import com.opensymphony.workflow.util.DefaultVariableResolver;
029import com.opensymphony.workflow.util.VariableResolver;
030
031/**
032 * Really simple OSWorkflow configuration, allowing to setup the WorkflowFactory and the WorkflowStore outside this class.
033 */
034public class SimpleConfiguration implements Configuration
035{
036    private WorkflowFactory _factory;
037
038    private WorkflowStore _store;
039
040    /**
041     * Constructor.
042     * @param factory the WorkflowFactory to manipulate workflow descriptors
043     * @param store the WorkflowStore for persisting data
044     */
045    public SimpleConfiguration(WorkflowFactory factory, WorkflowStore store)
046    {
047        _factory = factory;
048        _store = store;
049    }
050
051    public String getPersistence()
052    {
053        return _store.getClass().getName();
054    }
055
056    public Map getPersistenceArgs()
057    {
058        return Collections.EMPTY_MAP;
059    }
060
061    public VariableResolver getVariableResolver()
062    {
063        return new DefaultVariableResolver();
064    }
065
066    public WorkflowDescriptor getWorkflow(String name) throws FactoryException
067    {
068        return _factory.getWorkflow(name);
069    }
070
071    public String[] getWorkflowNames() throws FactoryException
072    {
073        return _factory.getWorkflowNames();
074    }
075
076    public WorkflowStore getWorkflowStore() throws StoreException
077    {
078        return _store;
079    }
080
081    public boolean isInitialized()
082    {
083        return true;
084    }
085
086    public boolean isModifiable(String name)
087    {
088        return _factory.isModifiable(name);
089    }
090
091    public void load(URL url) throws FactoryException
092    {
093        // empty method
094    }
095
096    public boolean removeWorkflow(String workflow) throws FactoryException
097    {
098        return _factory.removeWorkflow(workflow);
099    }
100
101    public boolean saveWorkflow(String name, WorkflowDescriptor descriptor, boolean replace) throws FactoryException
102    {
103        return _factory.saveWorkflow(name, descriptor, replace);
104    }
105
106}