KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jacorb.notification;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2004 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
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 JavaDoc;
30 import org.omg.CORBA.AnyHolder JavaDoc;
31 import org.omg.CORBA.TCKind JavaDoc;
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 /**
43  * @author Alphonse Bendt
44  * @version $Id: AnyMessage.java,v 1.13 2005/02/13 23:56:59 alphonse.bendt Exp $
45  */

46
47 public class AnyMessage extends AbstractMessage
48 {
49     public static final String JavaDoc 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 JavaDoc 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     ////////////////////////////////////////
69

70     /**
71      * the wrapped value
72      */

73     protected Any JavaDoc anyValue_;
74
75     /**
76      * the wrapped Any converted to a StructuredEvent
77      */

78     protected StructuredEvent structuredEventValue_;
79
80     private Property[] typedEventValue_;
81
82     private boolean isTranslationPossible_ = true;
83
84     ////////////////////////////////////////
85

86     public synchronized void setAny( Any JavaDoc 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 JavaDoc 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 JavaDoc();
127                 }
128
129                 if (!_typedEventValue[0].value.type().kind().equals(TCKind.tk_string)) {
130                     throw new IllegalArgumentException JavaDoc();
131                 }
132
133                 typedEventValue_ = _typedEventValue;
134             } catch (Throwable JavaDoc e) {
135                 isTranslationPossible_ = false;
136
137                 throw new NoTranslationException();
138             }
139         }
140         return typedEventValue_;
141     }
142
143
144     public synchronized StructuredEvent toStructuredEvent()
145     {
146         // the conversion should only be done once !
147

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 JavaDoc getConstraintKey()
161     {
162         return sAnyKey;
163     }
164
165
166     public EvaluationResult extractFilterableData( EvaluationContext context,
167                                                    ComponentName root,
168                                                    String JavaDoc v )
169         throws EvaluationException
170     {
171         return extractValue( context, root );
172     }
173
174
175     public EvaluationResult extractVariableHeader( EvaluationContext context,
176                                                    ComponentName root,
177                                                    String JavaDoc 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 JavaDoc 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 JavaDoc();
211     }
212
213
214     public boolean hasStopTime()
215     {
216         return false;
217     }
218
219
220     public long getStopTime()
221     {
222         throw new UnsupportedOperationException JavaDoc();
223     }
224
225
226     public boolean hasTimeout()
227     {
228         return false;
229     }
230
231
232     public long getTimeout()
233     {
234         throw new UnsupportedOperationException JavaDoc();
235     }
236
237
238     public String JavaDoc toString() {
239         return toAny().toString();
240     }
241 }
242
Popular Tags