1 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 37 public class ReadContentRule extends BaseRule 38 { 39 private static final Log LOG = LogFactory.getLog(ReadContentRule.class); 40 41 private String _propertyName; 42 43 public void begin(SchemaProcessor processor, Element element) 44 { 45 String value = RuleUtils.processText(processor, element, element.getContent()); 46 47 try 48 { 49 Translator t = processor.getContentTranslator(); 50 51 Object target = processor.peek(); 52 53 Class propertyType = PropertyUtils.getPropertyType(target, _propertyName); 54 55 Object finalValue = 56 t.translate( 57 processor.getContributingModule(), 58 propertyType, 59 value, 60 element.getLocation()); 61 62 PropertyUtils.write(target, _propertyName, finalValue); 63 } 64 catch (Exception ex) 65 { 66 ErrorHandler eh = processor.getContributingModule().getErrorHandler(); 67 68 eh.error( 69 LOG, 70 RulesMessages.readContentFailure(processor, element, ex), 71 element.getLocation(), 72 ex); 73 } 74 75 } 76 77 public String getPropertyName() 78 { 79 return _propertyName; 80 } 81 82 public void setPropertyName(String string) 83 { 84 _propertyName = string; 85 } 86 87 } 88 | Popular Tags |