/* * Copyright 2004-2006 Stefan Reuter * * 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 org.asteriskjava.fastagi; import java.util.Map; /** * A MappingStrategy that is configured via a fixed set of properties.<p> * This mapping strategy is most useful when used with the Spring framework.<p> * Example (using Spring): * * <pre> * <beans> * <bean id="mapping" * class="org.asteriskjava.fastagi.SimpleMappingStrategy"> * <property name="mappings"> * <map> * <entry> * <key><value>hello.agi</value></key> * <ref local="hello"/> * </entry> * <entry> * <key><value>leastcostdial.agi</value></key> * <ref local="leastCostDial"/> * </entry> * </map> * </property> * </bean> * * <bean id="hello" * class="com.example.fastagi.HelloAgiScript"/> * * <bean id="leastCostDial" * class="com.example.fastagi.LeastCostDialAgiScript"> * <property name="rates"><value>rates.txt</value></property> * </bean> * <beans> * </pre> * * LeastCostDialAgiScript and HelloAgiScript must both implement the AgiScript.<p> * * @author srt * @version $Id: SimpleMappingStrategy.java 938 2007-12-31 03:23:38Z srt $ * @since 0.2 */ public class SimpleMappingStrategy implements MappingStrategy { private Map<String, AgiScript> mappings; /** * Set the "path to AgiScript" mapping.<p> * Use the path (for example <code>hello.agi</code>) as key and your * AgiScript (for example <code>new HelloAgiScript()</code>) as value of * this map. * * @param mappings the path to AgiScript mapping. */ public void setMappings(Map<String, AgiScript> mappings) { this.mappings = mappings; } public AgiScript determineScript(AgiRequest request) { if (mappings == null) { return null; } return mappings.get(request.getScript()); } }