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 |
| public class SetPropertyRule extends BaseRule |
31 |
| { |
32 |
| private static final Log LOG = LogFactory.getLog(SetPropertyRule.class); |
33 |
| |
34 |
| private String _propertyName; |
35 |
| private String _value; |
36 |
| private Translator _smartTranslator; |
37 |
| |
38 |
426
| public void begin(SchemaProcessor processor, Element element)
|
39 |
| { |
40 |
426
| String value = RuleUtils.processText(processor, element, _value);
|
41 |
| |
42 |
426
| Object target = processor.peek();
|
43 |
| |
44 |
426
| try
|
45 |
| { |
46 |
426
| if (_smartTranslator == null)
|
47 |
158
| _smartTranslator = RuleUtils.getTranslator(processor, "smart");
|
48 |
| |
49 |
426
| Class propertyType = PropertyUtils.getPropertyType(target, _propertyName);
|
50 |
| |
51 |
426
| Object finalValue =
|
52 |
| _smartTranslator.translate( |
53 |
| processor.getContributingModule(), |
54 |
| propertyType, |
55 |
| value, |
56 |
| element.getLocation()); |
57 |
| |
58 |
426
| PropertyUtils.write(target, _propertyName, finalValue);
|
59 |
| } |
60 |
| catch (Exception ex) |
61 |
| { |
62 |
0
| ErrorHandler eh = processor.getContributingModule().getErrorHandler();
|
63 |
| |
64 |
0
| String message = RulesMessages.unableToSetProperty(_propertyName, target, ex);
|
65 |
| |
66 |
0
| eh.error(LOG, message, element.getLocation(), ex);
|
67 |
| } |
68 |
| |
69 |
| } |
70 |
| |
71 |
1717
| public void setPropertyName(String string)
|
72 |
| { |
73 |
1717
| _propertyName = string;
|
74 |
| } |
75 |
| |
76 |
1717
| public void setValue(String string)
|
77 |
| { |
78 |
1717
| _value = string;
|
79 |
| } |
80 |
| |
81 |
7
| public String getPropertyName()
|
82 |
| { |
83 |
7
| return _propertyName;
|
84 |
| } |
85 |
| |
86 |
7
| public String getValue()
|
87 |
| { |
88 |
7
| return _value;
|
89 |
| } |
90 |
| |
91 |
| } |