KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > TypedEventMessage


1 package org.jacorb.notification;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2003 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

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 JavaDoc;
29 import org.omg.CORBA.AnyHolder JavaDoc;
30 import org.omg.CORBA.ORB JavaDoc;
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 /**
43  * @author Alphonse Bendt
44  * @version $Id: TypedEventMessage.java,v 1.4 2005/02/13 23:56:59 alphonse.bendt Exp $
45  */

46
47 public class TypedEventMessage extends AbstractMessage
48 {
49     public static final String JavaDoc TYPE_NAME = "%TYPED";
50
51     public static final String JavaDoc OPERATION_NAME = "operation";
52
53     public static final String JavaDoc EVENT_TYPE = "event_type";
54
55     private static final ORB JavaDoc sORB = ORB.init();
56
57     private static final Any JavaDoc sUndefinedAny = sORB.create_any();
58
59     private static final EventHeader sEventHeader;
60
61     private static final String JavaDoc 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     ////////////////////////////////////////
72

73     private String JavaDoc idlInterfaceName_;
74
75     private String JavaDoc operationName_;
76
77     private Property[] parameters_;
78
79     /**
80      * used for conversion to filterable TypedEvent
81      */

82     private Property[] typedEvent_;
83
84     /**
85      * used for conversion to Any and StructuredEvent
86      */

87     private Property[] filterableHeader_;
88
89     private Any JavaDoc anyValue_;
90
91     private StructuredEvent structuredEventValue_;
92
93     ////////////////////////////////////////
94

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 JavaDoc getConstraintKey()
107     {
108         return sTypedKey;
109     }
110
111     public void setTypedEvent(String JavaDoc interfaceName, String JavaDoc 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 JavaDoc _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 JavaDoc 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 JavaDoc _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 JavaDoc headerName) throws EvaluationException
199     {
200         throw new EvaluationException();
201     }
202
203     public EvaluationResult extractVariableHeader(EvaluationContext evaluationContext,
204             ComponentName componentName, String JavaDoc 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 JavaDoc();
228     }
229
230     public boolean hasStopTime()
231     {
232         return false;
233     }
234
235     public long getStopTime()
236     {
237         throw new UnsupportedOperationException JavaDoc();
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 JavaDoc anyHolder)
261             throws UnsupportedFilterableData
262     {
263         return mappingFilter.match_typed(toTypedEvent(), anyHolder);
264     }
265 }
Popular Tags