1 package org.jacorb.notification; 2 3 22 23 import org.jacorb.notification.filter.ComponentName; 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.interfaces.Message; 28 import org.omg.CORBA.Any ; 29 import org.omg.CORBA.AnyHolder ; 30 import org.omg.CORBA.ORB ; 31 import org.omg.CosNotification.EventHeader; 32 import org.omg.CosNotification.EventType; 33 import org.omg.CosNotification.EventTypeHelper; 34 import org.omg.CosNotification.FixedEventHeader; 35 import org.omg.CosNotification.Property; 36 import org.omg.CosNotification.PropertySeqHelper; 37 import org.omg.CosNotification.StructuredEvent; 38 import org.omg.CosNotifyFilter.Filter; 39 import org.omg.CosNotifyFilter.MappingFilter; 40 import org.omg.CosNotifyFilter.UnsupportedFilterableData; 41 42 46 47 public class TypedEventMessage extends AbstractMessage 48 { 49 public static final String TYPE_NAME = "%TYPED"; 50 51 public static final String OPERATION_NAME = "operation"; 52 53 public static final String EVENT_TYPE = "event_type"; 54 55 private static final ORB sORB = ORB.init(); 56 57 private static final Any sUndefinedAny = sORB.create_any(); 58 59 private static final EventHeader sEventHeader; 60 61 private static final String sTypedKey = AbstractMessage.calcConstraintKey("", TYPE_NAME); 62 63 static 64 { 65 EventType _eventType = new EventType("", TYPE_NAME); 66 FixedEventHeader _fixedHeader = new FixedEventHeader(_eventType, ""); 67 Property[] _variableHeader = new Property[0]; 68 sEventHeader = new EventHeader(_fixedHeader, _variableHeader); 69 } 70 71 73 private String idlInterfaceName_; 74 75 private String operationName_; 76 77 private Property[] parameters_; 78 79 82 private Property[] typedEvent_; 83 84 87 private Property[] filterableHeader_; 88 89 private Any anyValue_; 90 91 private StructuredEvent structuredEventValue_; 92 93 95 public void reset() 96 { 97 super.reset(); 98 99 typedEvent_ = null; 100 parameters_ = null; 101 filterableHeader_ = null; 102 anyValue_ = null; 103 structuredEventValue_ = null; 104 } 105 106 public String getConstraintKey() 107 { 108 return sTypedKey; 109 } 110 111 public void setTypedEvent(String interfaceName, String operation, Property[] params) 112 { 113 idlInterfaceName_ = interfaceName; 114 115 operationName_ = operation; 116 117 parameters_ = params; 118 } 119 120 public void setTypedEvent(Property[] props) 121 { 122 parameters_ = props; 123 } 124 125 private Property[] getFilterableHeader() 126 { 127 if (filterableHeader_ == null) 128 { 129 filterableHeader_ = new Property[parameters_.length + 1]; 130 Any _operationAny = sORB.create_any(); 131 _operationAny.insert_string(operationName_); 132 filterableHeader_[0] = new Property(OPERATION_NAME, _operationAny); 133 134 for (int x = 0; x < parameters_.length; ++x) 135 { 136 filterableHeader_[1 + x] = parameters_[x]; 137 } 138 } 139 140 return filterableHeader_; 141 } 142 143 public Any toAny() 144 { 145 if (anyValue_ == null) 146 { 147 Property[] _filterableHeader = getFilterableHeader(); 148 149 anyValue_ = sORB.create_any(); 150 151 PropertySeqHelper.insert(anyValue_, _filterableHeader); 152 } 153 return anyValue_; 154 } 155 156 public StructuredEvent toStructuredEvent() 157 { 158 if (structuredEventValue_ == null) 159 { 160 structuredEventValue_ = new StructuredEvent(); 161 162 structuredEventValue_.header = sEventHeader; 163 structuredEventValue_.filterable_data = getFilterableHeader(); 164 structuredEventValue_.remainder_of_body = sUndefinedAny; 165 } 166 return structuredEventValue_; 167 } 168 169 public Property[] toTypedEvent() 170 { 171 if (typedEvent_ == null) 172 { 173 typedEvent_ = new Property[parameters_.length + 1]; 174 175 EventType _eventType = new EventType(); 176 _eventType.domain_name = idlInterfaceName_; 177 _eventType.type_name = operationName_; 178 179 Any _eventTypeAny = sORB.create_any(); 180 EventTypeHelper.insert(_eventTypeAny, _eventType); 181 182 typedEvent_[0] = new Property(EVENT_TYPE, _eventTypeAny); 183 184 for (int x = 0; x < parameters_.length; ++x) 185 { 186 typedEvent_[1 + x] = parameters_[x]; 187 } 188 } 189 return typedEvent_; 190 } 191 192 public int getType() 193 { 194 return Message.TYPE_TYPED; 195 } 196 197 public EvaluationResult extractFilterableData(EvaluationContext evaluationContext, 198 ComponentName componentName, String headerName) throws EvaluationException 199 { 200 throw new EvaluationException(); 201 } 202 203 public EvaluationResult extractVariableHeader(EvaluationContext evaluationContext, 204 ComponentName componentName, String headerName) throws EvaluationException 205 { 206 for (int x = 0; x < parameters_.length; ++x) 207 { 208 if (parameters_[x].name.equals(headerName)) 209 { 210 EvaluationResult _result = new EvaluationResult(); 211 _result.addAny(parameters_[x].value); 212 213 return _result; 214 } 215 } 216 217 throw new EvaluationException("Headername " + headerName + " does not exist"); 218 } 219 220 public boolean hasStartTime() 221 { 222 return false; 223 } 224 225 public long getStartTime() 226 { 227 throw new UnsupportedOperationException (); 228 } 229 230 public boolean hasStopTime() 231 { 232 return false; 233 } 234 235 public long getStopTime() 236 { 237 throw new UnsupportedOperationException (); 238 } 239 240 public boolean hasTimeout() 241 { 242 return false; 243 } 244 245 public long getTimeout() 246 { 247 return 0; 248 } 249 250 public int getPriority() 251 { 252 return 0; 253 } 254 255 public boolean match(Filter filter) throws UnsupportedFilterableData 256 { 257 return filter.match_typed(toTypedEvent()); 258 } 259 260 public boolean match(MappingFilter mappingFilter, AnyHolder anyHolder) 261 throws UnsupportedFilterableData 262 { 263 return mappingFilter.match_typed(toTypedEvent(), anyHolder); 264 } 265 } | Popular Tags |