|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
BeansMappings.java | 83,3% | 77,8% | 57,1% | 74,2% |
|
1 |
/*
|
|
2 |
* Replica is published under the terms
|
|
3 |
* of the Apache Software License.
|
|
4 |
*/
|
|
5 |
package replica.command.beans;
|
|
6 |
|
|
7 |
import java.util.HashMap;
|
|
8 |
import java.util.Hashtable;
|
|
9 |
|
|
10 |
import org.springframework.context.ApplicationContext;
|
|
11 |
|
|
12 |
import replica.command.Command;
|
|
13 |
import replica.command.CommandException;
|
|
14 |
import replica.command.Mappings;
|
|
15 |
|
|
16 |
/**
|
|
17 |
* @author Pedro Costa
|
|
18 |
* @author Helder Silva
|
|
19 |
* @since 20/Jan/2004
|
|
20 |
*/
|
|
21 |
public class BeansMappings implements Mappings { |
|
22 |
|
|
23 |
|
|
24 |
// mapps from action to bean name or reference
|
|
25 |
HashMap beansMappings; |
|
26 |
|
|
27 |
// if the mapping is a bean reference take it from context.
|
|
28 |
ApplicationContext beansContext; |
|
29 |
|
|
30 |
// if the mapping is a class name create one, put in this
|
|
31 |
// table and reuse it.
|
|
32 |
Hashtable commandsByName = new Hashtable();
|
|
33 |
|
|
34 |
|
|
35 |
/**
|
|
36 |
* Default constructor;
|
|
37 |
*/
|
|
38 | 9 |
public BeansMappings() {
|
39 | 9 |
super();
|
40 |
} |
|
41 |
|
|
42 |
/* (non-Javadoc)
|
|
43 |
* @see replica.command.Mappings#getMappedClass(java.lang.String)
|
|
44 |
*/
|
|
45 | 0 |
public Class getMappedClass(String actionId) throws CommandException { |
46 | 0 |
return getNewCommand(actionId).getClass();
|
47 |
} |
|
48 |
|
|
49 |
/* (non-Javadoc)
|
|
50 |
* @see replica.command.Mappings#getNewCommand(java.lang.String)
|
|
51 |
*/
|
|
52 | 2 |
public Command getNewCommand(String actionId) throws CommandException { |
53 |
|
|
54 | 2 |
Object obj = beansMappings.get(actionId.toLowerCase()); |
55 |
|
|
56 | 2 |
String name = null;
|
57 | 2 |
if( obj instanceof String ) |
58 | 1 |
name = obj.toString(); |
59 |
|
|
60 | 2 |
if( obj == null || obj instanceof String ){ |
61 |
// not a bean reference
|
|
62 |
// look on commands table
|
|
63 | 1 |
obj = commandsByName.get( actionId ); |
64 |
|
|
65 | 1 |
if( obj == null ){ |
66 |
// not in table , create a new one and put on table
|
|
67 | 1 |
try{
|
68 | 1 |
obj = Class.forName( name ).newInstance(); |
69 |
} |
|
70 |
catch(Exception e){
|
|
71 | 0 |
throw new CommandException("Problem creating new instance of [" + name |
72 |
+ "] for action [" + actionId + "].", e); |
|
73 |
} |
|
74 | 1 |
commandsByName.put(actionId, obj); |
75 |
} |
|
76 |
} |
|
77 |
|
|
78 | 2 |
return (Command)obj;
|
79 |
} |
|
80 |
|
|
81 |
/**
|
|
82 |
* @return
|
|
83 |
*/
|
|
84 | 0 |
public ApplicationContext getBeansContext() {
|
85 | 0 |
return beansContext;
|
86 |
} |
|
87 |
|
|
88 |
/**
|
|
89 |
* @return
|
|
90 |
*/
|
|
91 | 0 |
public HashMap getBeansMappings() {
|
92 | 0 |
return beansMappings;
|
93 |
} |
|
94 |
|
|
95 |
/**
|
|
96 |
* @param context
|
|
97 |
*/
|
|
98 | 8 |
public void setBeansContext(ApplicationContext context) { |
99 | 8 |
beansContext = context; |
100 |
} |
|
101 |
|
|
102 |
/**
|
|
103 |
* @param hashtable
|
|
104 |
*/
|
|
105 | 8 |
public void setBeansMappings(HashMap hashtable) { |
106 | 8 |
beansMappings = hashtable; |
107 |
} |
|
108 |
|
|
109 |
} |
|
110 |
|
|