1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.apache.commons.betwixt.digester; |
17 |
|
|
18 |
|
import java.util.Map; |
19 |
|
|
20 |
|
import org.apache.commons.betwixt.XMLBeanInfo; |
21 |
|
import org.apache.commons.logging.Log; |
22 |
|
import org.apache.commons.logging.LogFactory; |
23 |
|
import org.xml.sax.Attributes; |
24 |
|
import org.xml.sax.SAXException; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
175 |
public class ClassRule extends RuleSupport { |
32 |
|
|
33 |
175 |
private static final Log log = LogFactory.getLog(ClassRule.class); |
34 |
|
|
35 |
|
|
36 |
415 |
public ClassRule() { |
37 |
415 |
} |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
public void begin(Attributes attributes) throws SAXException { |
48 |
1519 |
String className = attributes.getValue("name"); |
49 |
1519 |
if (className == null || "".equals(className)) { |
50 |
0 |
throw new SAXException("Invalid 'class' element. " |
51 |
|
+ "Attribute 'name' is required but was not found but was not found."); |
52 |
|
} |
53 |
|
|
54 |
|
try { |
55 |
|
|
56 |
1519 |
Class beanClass = Class.forName(className); |
57 |
1519 |
XMLBeanInfo xmlBeanInfo = new XMLBeanInfo(beanClass); |
58 |
1519 |
XMLBeanInfoDigester xmlBeanInfoDigester = (XMLBeanInfoDigester) getDigester(); |
59 |
1519 |
xmlBeanInfoDigester.setBeanClass(beanClass); |
60 |
1519 |
xmlBeanInfoDigester.push(xmlBeanInfo); |
61 |
|
|
62 |
0 |
} catch (ClassNotFoundException e) { |
63 |
0 |
throw new SAXException("Invalid 'class' element. Unable to find class: " + className, e); |
64 |
|
} |
65 |
1519 |
} |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
public void end() { |
71 |
1519 |
XMLBeanInfo xmlBeanInfo = (XMLBeanInfo) getDigester().pop(); |
72 |
1519 |
MultiMappingBeanInfoDigester digester = (MultiMappingBeanInfoDigester) getDigester(); |
73 |
1519 |
Map xmlBeanInfoMapping = digester.getBeanInfoMap(); |
74 |
1519 |
xmlBeanInfoMapping.put(xmlBeanInfo.getBeanClass(), xmlBeanInfo); |
75 |
1519 |
digester.setBeanClass(null); |
76 |
1519 |
} |
77 |
|
} |
78 |
|
|