001/*
002 *  Copyright 2016 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.core.ui.script;
017
018import java.util.HashMap;
019import java.util.Map;
020
021import org.apache.avalon.framework.service.ServiceException;
022import org.apache.avalon.framework.service.ServiceManager;
023
024/**
025 * Runtime default script binding, provides default variables to the script tool, and a configuration file for the functions. 
026 */
027public class RuntimeScriptBinding extends StaticConfigurableScriptBinding
028{
029    private ServiceManager _manager;
030
031    @Override
032    public void service(ServiceManager manager) throws ServiceException
033    {
034        super.service(manager);
035
036        _manager = manager;
037    }
038    
039    @Override
040    public Map<String, Object> getVariables(ScriptExecArguments execArgs)
041    {
042        Map<String, Object> variables = new HashMap<>();
043        variables.put("__internal_ametys_serviceManager", _manager);
044        variables.put("__internal_ametys_sourceResolver", _sourceResolver);
045        variables.put("__internal_ametys_avalonContext", _context);
046        return variables;
047    }
048
049}