summaryrefslogtreecommitdiff
path: root/qpid/dotnet/Qpid.Client/Client/AMQDestination.cs
blob: 07ce3c23548c838d97df845b3d45c7586d50aa6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */
using System;

namespace Apache.Qpid.Client
{
    public abstract class AMQDestination
    {
        protected readonly string _exchangeName;
        protected readonly string _exchangeClass;
        protected readonly string _destinationName;
        protected readonly bool _isExclusive;
        protected readonly bool _isAutoDelete;
        protected bool _isDurable;

        public bool IsDurable
        {
           
            get { return _isDurable; }
        }

        protected string _queueName;

        protected AMQDestination(String exchangeName, String exchangeClass, String destinationName, bool isExclusive,
                                 bool isAutoDelete, String queueName)
        {
            // XXX: This is ugly - OnlyRequired because of ReplyToDestination.
//            if (destinationName == null)
//            {
//                throw new ArgumentNullException("destinationName");
//            }

            // XXX: This is ugly - OnlyRequired because of SendingDestinationAdapter.
//            if (exchangeName == null)
//            {
//                throw new ArgumentNullException("exchangeName");
//            }

            // XXX: This is ugly - OnlyRequired because of SendingDestinationAdapter.
//            if (exchangeClass == null)
//            {
//                throw new ArgumentNullException("exchangeClass");
//            }

            _exchangeName = exchangeName;
            _exchangeClass = exchangeClass;
            _destinationName = destinationName;
            _isExclusive = isExclusive;
            _isAutoDelete = isAutoDelete;
            _queueName = queueName;
        }

        public string Name
        {
            get
            {
                return _destinationName;
            }
        }

        public abstract string RoutingKey
        {
            get;
        }

        public abstract string EncodedName
        {
            get;
        }

        public bool AutoDelete
        {
            get
            {
                return _isAutoDelete;
            }
        }

        public string QueueName
        {
            get
            {
                return _queueName;
            }
            set
            {
                _queueName = value;
            }
        }

        public string ExchangeName
        {
            get
            {
                return _exchangeName;
            }
        }

        public string ExchangeClass
        {
            get
            {
                return _exchangeClass;
            }
        }

        public bool IsExclusive
        {
            get
            {
                return _isExclusive;
            }
        }

        public bool IsAutoDelete
        {
            get
            {
                return _isAutoDelete;
            }
        }

        public override string ToString()
        {
            return "Destination: " + _destinationName + ", " +
                   "Queue Name: " + _queueName + ", Exchange: " + _exchangeName +
                   ", Exchange class: " + _exchangeClass + ", Exclusive: " + _isExclusive +
                   ", AutoDelete: " + _isAutoDelete; // +", Routing  Key: " + RoutingKey;
        }

        public override bool Equals(object o)
        {
            if (this == o)
            {
                return true;
            }
            if (o == null || GetType() != o.GetType())
            {
                return false;
            }

            AMQDestination that = (AMQDestination) o;

            if (!StringsNotEqualNullSafe(_destinationName, that._destinationName))
            {
                return false;
            }
            if (!StringsNotEqualNullSafe(_exchangeClass, that._exchangeClass))
            {
                return false;
            }
            if (!StringsNotEqualNullSafe(_exchangeName, that._exchangeName))
            {
                return false;
            }
            if (!StringsNotEqualNullSafe(_queueName, that._queueName))
            {
                return false;
            }
            if (_isExclusive != that._isExclusive)
            {
                return false;
            }
            if (_isAutoDelete != that._isAutoDelete)
            {
                return false;
            }
            return true;
        }

        private bool StringsNotEqualNullSafe(string one, string two)
        {
            if ((one == null && two != null) ||
                (one != null && !one.Equals(two)))
            {
                return false;
            }
            else
            {
                return true;
            }
        }
 
        public override int GetHashCode()
        {
            int result;
            if (_exchangeName == null)
            {
                result = "".GetHashCode();   
            }
            else
            {
                result = _exchangeName.GetHashCode();
            }
            if (_exchangeClass != null)
            {
                result = 29 * result + _exchangeClass.GetHashCode();                
            }
            if (_destinationName != null)
            {
                result = 29 * result + _destinationName.GetHashCode();                
            }
            if (_queueName != null)
            {
                result = 29 * result + _queueName.GetHashCode();
            }
            result = result * (_isExclusive ? 13 : 7);
            result = result * (_isAutoDelete ? 13 : 7);
            
            Console.WriteLine("FIXME HashCode for " + this + " = " + result);
            return result;
        }

        public abstract bool IsNameRequired { get; }
    }
}