1 package org.jacorb.notification; 2 3 23 24 import org.jacorb.notification.filter.ComponentName; 25 import org.jacorb.notification.filter.EvaluationContext; 26 import org.jacorb.notification.filter.EvaluationException; 27 import org.jacorb.notification.filter.EvaluationResult; 28 import org.jacorb.notification.interfaces.Message; 29 import org.omg.CORBA.Any ; 30 import org.omg.CORBA.AnyHolder ; 31 import org.omg.CORBA.TCKind ; 32 import org.omg.CosNotification.EventHeader; 33 import org.omg.CosNotification.EventType; 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 AnyMessage extends AbstractMessage 48 { 49 public static final String TYPE_NAME = "%ANY"; 50 51 public static final int DEFAULT_PRIORITY = 0; 52 53 private static final Property[] sFilterableData; 54 55 private static final EventHeader sEventHeader; 56 57 private static final String sAnyKey = 58 AbstractMessage.calcConstraintKey( "", TYPE_NAME ); 59 60 static { 61 EventType _eventType = new EventType( "", TYPE_NAME ); 62 FixedEventHeader _fixedHeader = new FixedEventHeader( _eventType, "" ); 63 Property[] _variableHeader = new Property[ 0 ]; 64 sEventHeader = new EventHeader( _fixedHeader, _variableHeader ); 65 sFilterableData = new Property[ 0 ]; 66 } 67 68 70 73 protected Any anyValue_; 74 75 78 protected StructuredEvent structuredEventValue_; 79 80 private Property[] typedEventValue_; 81 82 private boolean isTranslationPossible_ = true; 83 84 86 public synchronized void setAny( Any any ) 87 { 88 anyValue_ = any; 89 } 90 91 92 public synchronized void reset() 93 { 94 super.reset(); 95 96 anyValue_ = null; 97 structuredEventValue_ = null; 98 typedEventValue_ = null; 99 isTranslationPossible_ = true; 100 } 101 102 103 public int getType() 104 { 105 return Message.TYPE_ANY; 106 } 107 108 109 public synchronized Any toAny() 110 { 111 return anyValue_; 112 } 113 114 115 public synchronized Property[] toTypedEvent() throws NoTranslationException 116 { 117 if (!isTranslationPossible_) { 118 throw new NoTranslationException(); 119 } 120 121 if (typedEventValue_ == null) { 122 try { 123 Property[] _typedEventValue = PropertySeqHelper.extract(anyValue_); 124 125 if (!_typedEventValue[0].name.equals("operation")) { 126 throw new IllegalArgumentException (); 127 } 128 129 if (!_typedEventValue[0].value.type().kind().equals(TCKind.tk_string)) { 130 throw new IllegalArgumentException (); 131 } 132 133 typedEventValue_ = _typedEventValue; 134 } catch (Throwable e) { 135 isTranslationPossible_ = false; 136 137 throw new NoTranslationException(); 138 } 139 } 140 return typedEventValue_; 141 } 142 143 144 public synchronized StructuredEvent toStructuredEvent() 145 { 146 148 if ( structuredEventValue_ == null ) 149 { 150 structuredEventValue_ = new StructuredEvent(); 151 structuredEventValue_.header = sEventHeader; 152 structuredEventValue_.filterable_data = sFilterableData; 153 structuredEventValue_.remainder_of_body = toAny(); 154 } 155 156 return structuredEventValue_; 157 } 158 159 160 public String getConstraintKey() 161 { 162 return sAnyKey; 163 } 164 165 166 public EvaluationResult extractFilterableData( EvaluationContext context, 167 ComponentName root, 168 String v ) 169 throws EvaluationException 170 { 171 return extractValue( context, root ); 172 } 173 174 175 public EvaluationResult extractVariableHeader( EvaluationContext context, 176 ComponentName root, 177 String v ) throws EvaluationException 178 { 179 return extractValue( context, root ); 180 } 181 182 183 public boolean match( Filter filter ) throws UnsupportedFilterableData 184 { 185 return filter.match( toAny() ); 186 } 187 188 189 public int getPriority() 190 { 191 return DEFAULT_PRIORITY; 192 } 193 194 195 public boolean match( MappingFilter filter, 196 AnyHolder value ) throws UnsupportedFilterableData 197 { 198 return filter.match( toAny(), value ); 199 } 200 201 202 public boolean hasStartTime() 203 { 204 return false; 205 } 206 207 208 public long getStartTime() 209 { 210 throw new UnsupportedOperationException (); 211 } 212 213 214 public boolean hasStopTime() 215 { 216 return false; 217 } 218 219 220 public long getStopTime() 221 { 222 throw new UnsupportedOperationException (); 223 } 224 225 226 public boolean hasTimeout() 227 { 228 return false; 229 } 230 231 232 public long getTimeout() 233 { 234 throw new UnsupportedOperationException (); 235 } 236 237 238 public String toString() { 239 return toAny().toString(); 240 } 241 } 242 | Popular Tags |