001: package org.jacorb.notification;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1999-2004 Gerald Brose
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: import org.jacorb.notification.filter.ComponentName;
025: import org.jacorb.notification.filter.EvaluationContext;
026: import org.jacorb.notification.filter.EvaluationException;
027: import org.jacorb.notification.filter.EvaluationResult;
028: import org.jacorb.notification.interfaces.Message;
029: import org.omg.CORBA.Any;
030: import org.omg.CORBA.AnyHolder;
031: import org.omg.CORBA.TCKind;
032: import org.omg.CosNotification.EventHeader;
033: import org.omg.CosNotification.EventType;
034: import org.omg.CosNotification.FixedEventHeader;
035: import org.omg.CosNotification.Property;
036: import org.omg.CosNotification.PropertySeqHelper;
037: import org.omg.CosNotification.StructuredEvent;
038: import org.omg.CosNotifyFilter.Filter;
039: import org.omg.CosNotifyFilter.MappingFilter;
040: import org.omg.CosNotifyFilter.UnsupportedFilterableData;
041:
042: /**
043: * @author Alphonse Bendt
044: * @version $Id: AnyMessage.java,v 1.16 2005/11/11 19:35:01 alphonse.bendt Exp $
045: */
046:
047: public class AnyMessage extends AbstractMessage {
048: public static final String TYPE_NAME = "%ANY";
049:
050: public static final int DEFAULT_PRIORITY = 0;
051:
052: private static final Property[] sFilterableData;
053:
054: private static final EventHeader sEventHeader;
055:
056: private static final String sAnyKey = AbstractMessage
057: .calcConstraintKey("", TYPE_NAME);
058:
059: static {
060: EventType _eventType = new EventType("", TYPE_NAME);
061: FixedEventHeader _fixedHeader = new FixedEventHeader(
062: _eventType, "");
063: Property[] _variableHeader = new Property[0];
064: sEventHeader = new EventHeader(_fixedHeader, _variableHeader);
065: sFilterableData = new Property[0];
066: }
067:
068: ////////////////////////////////////////
069:
070: /**
071: * the wrapped value
072: */
073: protected Any anyValue_;
074:
075: /**
076: * the wrapped Any converted to a StructuredEvent
077: */
078: protected StructuredEvent structuredEventValue_;
079:
080: private Property[] typedEventValue_;
081:
082: private NoTranslationException translationException_ = null;
083:
084: ////////////////////////////////////////
085:
086: public synchronized void setAny(Any any) {
087: anyValue_ = any;
088: }
089:
090: public void doReset() {
091: anyValue_ = null;
092: structuredEventValue_ = null;
093: typedEventValue_ = null;
094: translationException_ = null;
095: }
096:
097: public int getType() {
098: return Message.TYPE_ANY;
099: }
100:
101: public synchronized Any toAny() {
102: return anyValue_;
103: }
104:
105: public synchronized Property[] toTypedEvent()
106: throws NoTranslationException {
107: if (translationException_ != null) {
108: throw translationException_;
109: }
110:
111: if (typedEventValue_ == null) {
112: try {
113: Property[] _typedEventValue = PropertySeqHelper
114: .extract(anyValue_);
115:
116: if (!_typedEventValue[0].name.equals("operation")) {
117: throw new IllegalArgumentException();
118: }
119:
120: if (!_typedEventValue[0].value.type().kind().equals(
121: TCKind.tk_string)) {
122: throw new IllegalArgumentException();
123: }
124:
125: typedEventValue_ = _typedEventValue;
126: } catch (Exception e) {
127: translationException_ = new NoTranslationException(e);
128:
129: throw translationException_;
130: }
131: }
132: return typedEventValue_;
133: }
134:
135: public synchronized StructuredEvent toStructuredEvent() {
136: // the conversion should only be done once !
137:
138: if (structuredEventValue_ == null) {
139: structuredEventValue_ = new StructuredEvent();
140: structuredEventValue_.header = sEventHeader;
141: structuredEventValue_.filterable_data = sFilterableData;
142: structuredEventValue_.remainder_of_body = toAny();
143: }
144:
145: return structuredEventValue_;
146: }
147:
148: public String getConstraintKey() {
149: return sAnyKey;
150: }
151:
152: public EvaluationResult extractFilterableData(
153: EvaluationContext context, ComponentName root, String v)
154: throws EvaluationException {
155: return extractValue(context, root);
156: }
157:
158: public EvaluationResult extractVariableHeader(
159: EvaluationContext context, ComponentName root, String v)
160: throws EvaluationException {
161: return extractValue(context, root);
162: }
163:
164: public boolean match(Filter filter)
165: throws UnsupportedFilterableData {
166: return filter.match(toAny());
167: }
168:
169: public int getPriority() {
170: return DEFAULT_PRIORITY;
171: }
172:
173: public boolean match(MappingFilter filter, AnyHolder value)
174: throws UnsupportedFilterableData {
175: return filter.match(toAny(), value);
176: }
177:
178: public boolean hasStartTime() {
179: return false;
180: }
181:
182: public long getStartTime() {
183: throw new UnsupportedOperationException();
184: }
185:
186: public boolean hasStopTime() {
187: return false;
188: }
189:
190: public long getStopTime() {
191: throw new UnsupportedOperationException();
192: }
193:
194: public boolean hasTimeout() {
195: return false;
196: }
197:
198: public long getTimeout() {
199: throw new UnsupportedOperationException();
200: }
201:
202: public String toString() {
203: return toAny().toString();
204: }
205: }
|