1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.asterisk.fastagi;
18
19 import java.util.Map;
20
21 /***
22 * A MappingStrategy that is configured via a fixed set of properties.<br>
23 * This mapping strategy is most useful when used with the Spring framework.<br>
24 * Example (using Spring):
25 *
26 * <pre>
27 * <beans>
28 * <bean id="mapping"
29 * class="net.sf.asterisk.fastagi.SimpleMappingStrategy">
30 * <property name="mappings">
31 * <map>
32 * <entry>
33 * <key><value>hello.agi</value></key>
34 * <ref local="hello"/>
35 * </entry>
36 * <entry>
37 * <key><value>leastcostdial.agi</value></key>
38 * <ref local="leastCostDial"/>
39 * </entry>
40 * </map>
41 * </property>
42 * </bean>
43 *
44 * <bean id="hello"
45 * class="com.example.fastagi.HelloAGIScript"/>
46 *
47 * <bean id="leastCostDial"
48 * class="com.example.fastagi.LeastCostDialAGIScript">
49 * <property name="rates"><value>rates.txt</value></property>
50 * </bean>
51 * <beans>
52 * </pre>
53 *
54 * LeastCostDialAGIScript and HelloAGIScript must both implement the AGIScript.<br>
55 *
56 * @author srt
57 * @version $Id: SimpleMappingStrategy.java,v 1.4 2005/10/25 22:29:29 srt Exp $
58 * @since 0.2
59 */
60 public class SimpleMappingStrategy implements MappingStrategy
61 {
62 private Map mappings;
63
64 /***
65 * Set the path to AGIScript mapping.<br>
66 * Use the path (for example <code>hello.agi</code>) as key and your
67 * AGIScript (for example <code>new HelloAGIScript()</code>) as value of
68 * this map.
69 *
70 * @param mappings the path to AGIScript mapping.
71 */
72 public void setMappings(Map mappings)
73 {
74 this.mappings = mappings;
75 }
76
77 public AGIScript determineScript(AGIRequest request)
78 {
79 if (mappings == null)
80 {
81 return null;
82 }
83
84 return (AGIScript) mappings.get(request.getScript());
85 }
86 }