KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jacorb.notification;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-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 import org.jacorb.notification.filter.EventTypeIdentifier;
24 import org.omg.CosNotification.EventType;
25
26 /**
27  * @author Alphonse Bendt
28  * @version $Id: EventTypeWrapper.java,v 1.1 2005/02/13 23:56:59 alphonse.bendt Exp $
29  */

30
31 public class EventTypeWrapper implements EventTypeIdentifier, Comparable JavaDoc
32 {
33     private final EventType eventType_;
34     private final String JavaDoc constraintKey_;
35     
36     public static final EventType EVENT_TYPE_ALL = new EventType("", "%ALL");
37     
38     public static final EventType[] EMPTY_EVENT_TYPE_ARRAY = new EventType[0];
39     
40     public EventTypeWrapper(EventType eventType)
41     {
42         eventType_ = eventType;
43         
44         constraintKey_ =
45             AbstractMessage.calcConstraintKey( eventType.domain_name, eventType.type_name );
46     }
47
48     public EventType getEventType()
49     {
50         return eventType_;
51     }
52     
53     public String JavaDoc toString()
54     {
55         return toString(eventType_);
56     }
57     
58     public boolean equals(Object JavaDoc other)
59     {
60         try {
61             return equals(eventType_, ((EventTypeWrapper)other).eventType_);
62         } catch (ClassCastException JavaDoc e)
63         {
64             return super.equals(other);
65         }
66     }
67     
68     public int hashCode()
69     {
70         return toString().hashCode();
71     }
72     
73     public int compareTo(Object JavaDoc o)
74     {
75         try
76         {
77             EventTypeWrapper _other = (EventTypeWrapper) o;
78
79             int _compare = eventType_.domain_name
80                     .compareTo(_other.eventType_.domain_name);
81
82             if (_compare == 0)
83             {
84                 _compare = eventType_.type_name
85                         .compareTo(_other.eventType_.type_name);
86             }
87
88             return _compare;
89
90         } catch (ClassCastException JavaDoc e)
91         {
92             throw new IllegalArgumentException JavaDoc();
93         }
94     }
95     
96     ////////////////////////////////////////
97

98     public static String JavaDoc toString(EventType et)
99     {
100         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
101         appendEventTypeToBuffer(et, buffer);
102         return buffer.toString();
103     }
104
105     private static void appendEventTypeToBuffer(EventType et, StringBuffer JavaDoc buffer)
106     {
107         buffer.append(et.domain_name);
108         buffer.append("/");
109         buffer.append(et.type_name);
110     }
111
112     public static String JavaDoc toString(EventType[] ets)
113     {
114         StringBuffer JavaDoc b = new StringBuffer JavaDoc("[");
115
116         for (int x = 0; x < ets.length; ++x)
117         {
118             appendEventTypeToBuffer(ets[x], b);
119
120             if (x < ets.length - 1)
121             {
122                 b.append(", ");
123             }
124         }
125
126         b.append("]");
127
128         return b.toString();
129     }
130
131     public static boolean equals(EventType left, EventType right)
132     {
133         return left.domain_name.equals(right.domain_name) && left.type_name.equals(right.type_name);
134     }
135     
136     public String JavaDoc getConstraintKey()
137     {
138         return constraintKey_;
139     }
140 }
Popular Tags