1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.hivemind.schema.rules; |
16 |
| |
17 |
| import org.apache.commons.logging.Log; |
18 |
| import org.apache.commons.logging.LogFactory; |
19 |
| import org.apache.hivemind.Element; |
20 |
| import org.apache.hivemind.ErrorHandler; |
21 |
| import org.apache.hivemind.schema.SchemaProcessor; |
22 |
| import org.apache.hivemind.schema.Translator; |
23 |
| import org.apache.hivemind.util.PropertyUtils; |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| public class ReadContentRule extends BaseRule |
38 |
| { |
39 |
| private static final Log LOG = LogFactory.getLog(ReadContentRule.class); |
40 |
| |
41 |
| private String _propertyName; |
42 |
| |
43 |
21
| public void begin(SchemaProcessor processor, Element element)
|
44 |
| { |
45 |
21
| String value = RuleUtils.processText(processor, element, element.getContent());
|
46 |
| |
47 |
21
| try
|
48 |
| { |
49 |
21
| Translator t = processor.getContentTranslator();
|
50 |
| |
51 |
21
| Object target = processor.peek();
|
52 |
| |
53 |
21
| Class propertyType = PropertyUtils.getPropertyType(target, _propertyName);
|
54 |
| |
55 |
21
| Object finalValue =
|
56 |
| t.translate( |
57 |
| processor.getContributingModule(), |
58 |
| propertyType, |
59 |
| value, |
60 |
| element.getLocation()); |
61 |
| |
62 |
20
| PropertyUtils.write(target, _propertyName, finalValue);
|
63 |
| } |
64 |
| catch (Exception ex) |
65 |
| { |
66 |
2
| ErrorHandler eh = processor.getContributingModule().getErrorHandler();
|
67 |
| |
68 |
2
| eh.error(
|
69 |
| LOG, |
70 |
| RulesMessages.readContentFailure(processor, element, ex), |
71 |
| element.getLocation(), |
72 |
| ex); |
73 |
| } |
74 |
| |
75 |
| } |
76 |
| |
77 |
25
| public String getPropertyName()
|
78 |
| { |
79 |
25
| return _propertyName;
|
80 |
| } |
81 |
| |
82 |
1030
| public void setPropertyName(String string)
|
83 |
| { |
84 |
1030
| _propertyName = string;
|
85 |
| } |
86 |
| |
87 |
| } |