1 package org.jacorb.notification.filter.etcl; 2 3 23 24 import org.jacorb.notification.filter.EvaluationContext; 25 import org.jacorb.notification.filter.EvaluationException; 26 import org.jacorb.notification.filter.EvaluationResult; 27 import org.jacorb.notification.filter.ParseException; 28 import org.jacorb.notification.filter.PropertyDoesNotExistException; 29 import org.jacorb.notification.interfaces.Message; 30 31 35 36 public class PropertyShorthandNode extends AbstractTCLNode 37 { 38 private final String value_; 39 40 private final ETCLComponentName shorthandVariableHeader_; 41 42 private final ETCLComponentName shorthandFilterableData_; 43 44 private final ETCLComponentName shorthandDefault_; 45 46 private final ETCLComponentName shorthandDefaultAny_; 47 48 50 public PropertyShorthandNode(String value) 51 { 52 try 53 { 54 value_ = value; 55 56 shorthandVariableHeader_ = (ETCLComponentName) TCLParser 57 .parse("$.header.variable_header(" + value + ")"); 58 59 shorthandVariableHeader_.acceptInOrder(new TCLCleanUp()); 60 61 shorthandFilterableData_ = (ETCLComponentName) TCLParser.parse("$.filterable_data(" 62 + value + ")"); 63 64 shorthandFilterableData_.acceptInOrder(new TCLCleanUp()); 65 66 shorthandDefault_ = (ETCLComponentName) TCLParser.parse("$." + value); 67 shorthandDefault_.acceptInOrder(new TCLCleanUp()); 68 69 shorthandDefaultAny_ = (ETCLComponentName) TCLParser.parse("$(" + value + ")"); 70 shorthandDefaultAny_.acceptInOrder(new TCLCleanUp()); 71 72 } catch (ParseException e) 73 { 74 throw new RuntimeException (); 75 } catch (VisitorException e) 76 { 77 throw new RuntimeException (); 78 } 79 } 80 81 public EvaluationResult evaluate(EvaluationContext context) 82 throws PropertyDoesNotExistException 83 { 84 Message _event = context.getCurrentMessage(); 85 EvaluationResult _res = null; 86 87 try 88 { 89 _res = _event.extractVariableHeader(context, shorthandVariableHeader_, value_); 90 91 } catch (EvaluationException e) 92 { 93 } 96 97 if (_res == null) 98 { 99 try 100 { 101 _res = _event.extractFilterableData(context, shorthandFilterableData_, value_); 102 } catch (EvaluationException e) 103 { 104 } 107 108 if (_res == null) 109 { 110 _res = extractDefaultValue(context); 111 } 112 113 if (_res == null) 114 { 115 _res = extractDefaultAnyValue(context); 116 } 117 118 if (_res == null) 119 { 120 throw new PropertyDoesNotExistException(value_); 121 } 122 } 123 124 return _res; 125 } 126 127 public EvaluationResult extractDefaultValue(EvaluationContext context) 128 { 129 try 130 { 131 return context.getCurrentMessage().extractValue(context, shorthandDefault_); 132 } catch (Exception e) 133 { 134 return null; 135 } 136 } 137 138 public EvaluationResult extractDefaultAnyValue(EvaluationContext context) 139 { 140 try 141 { 142 return context.getCurrentMessage().extractValue(context, shorthandDefaultAny_); 143 } catch (Exception e) 144 { 145 return null; 146 } 147 } 148 149 public String toString() 150 { 151 return "PropertyShorthandNode: " + value_; 152 } 153 154 public void acceptPostOrder(AbstractTCLVisitor visitor) throws VisitorException 155 { 156 if (getFirstChild() != null) 157 { 158 ((AbstractTCLNode) getFirstChild()).acceptPostOrder(visitor); 159 } 160 } 161 162 public void acceptPreOrder(AbstractTCLVisitor visitor) throws VisitorException 163 { 164 ((AbstractTCLNode) getFirstChild()).acceptPreOrder(visitor); 165 } 166 167 public void acceptInOrder(AbstractTCLVisitor visitor) throws VisitorException 168 { 169 ((AbstractTCLNode) getFirstChild()).acceptInOrder(visitor); 170 } 171 } | Popular Tags |