001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.servicemix.jbi.container;
018:
019: import java.io.Serializable;
020:
021: import javax.jbi.servicedesc.ServiceEndpoint;
022: import javax.xml.namespace.QName;
023:
024: import org.apache.servicemix.jbi.framework.ComponentNameSpace;
025: import org.apache.servicemix.jbi.framework.Registry;
026: import org.apache.servicemix.jbi.messaging.ExchangePacket;
027: import org.apache.servicemix.jbi.messaging.MessageExchangeImpl;
028: import org.apache.servicemix.jbi.resolver.SubscriptionFilter;
029: import org.apache.servicemix.jbi.servicedesc.InternalEndpoint;
030:
031: /**
032: * Represents a subscription to a JBI endpoint.
033: *
034: * @org.apache.xbean.XBean element="subscriptionSpec"
035: *
036: * @version $Revision: 564374 $
037: */
038: public class SubscriptionSpec implements Serializable {
039:
040: /**
041: * Generated serial version UID
042: */
043: private static final long serialVersionUID = 8458586342841647313L;
044:
045: private QName service;
046: private QName interfaceName;
047: private QName operation;
048: private String endpoint;
049: private transient SubscriptionFilter filter;
050: private ComponentNameSpace name;
051:
052: public String getEndpoint() {
053: return endpoint;
054: }
055:
056: public void setEndpoint(String endpoint) {
057: this .endpoint = endpoint;
058: }
059:
060: public SubscriptionFilter getFilter() {
061: return filter;
062: }
063:
064: public void setFilter(SubscriptionFilter filter) {
065: this .filter = filter;
066: }
067:
068: public QName getInterfaceName() {
069: return interfaceName;
070: }
071:
072: public void setInterfaceName(QName interfaceName) {
073: this .interfaceName = interfaceName;
074: }
075:
076: public QName getOperation() {
077: return operation;
078: }
079:
080: public void setOperation(QName operation) {
081: this .operation = operation;
082: }
083:
084: public QName getService() {
085: return service;
086: }
087:
088: public void setService(QName service) {
089: this .service = service;
090: }
091:
092: /**
093: * @return Returns the name.
094: */
095: public ComponentNameSpace getName() {
096: return name;
097: }
098:
099: /**
100: * @org.apache.xbean.XBean hide="true"
101: *
102: * @param name
103: * The name to set.
104: */
105: public void setName(ComponentNameSpace name) {
106: this .name = name;
107: }
108:
109: /**
110: * Returns true if this subscription matches the given message exchange
111: *
112: * @param exchange
113: * the exchange to be matched
114: * @return true if this subscription matches the exchange
115: */
116: public boolean matches(Registry registry,
117: MessageExchangeImpl exchange) {
118: boolean result = false;
119:
120: ExchangePacket packet = exchange.getPacket();
121: ComponentNameSpace sourceId = packet.getSourceId();
122: if (sourceId != null) {
123: // get the list of services
124: if (service != null) {
125: ServiceEndpoint[] ses = registry
126: .getEndpointsForService(service);
127: if (ses != null) {
128: for (int i = 0; i < ses.length; i++) {
129: InternalEndpoint se = (InternalEndpoint) ses[i];
130: if (se.getComponentNameSpace() != null
131: && se.getComponentNameSpace().equals(
132: sourceId)) {
133: result = true;
134: break;
135: }
136: }
137: }
138: }
139: if (result && interfaceName != null) {
140: ServiceEndpoint[] ses = registry
141: .getEndpointsForInterface(interfaceName);
142: if (ses != null) {
143: result = false;
144: for (int i = 0; i < ses.length; i++) {
145: InternalEndpoint se = (InternalEndpoint) ses[i];
146: if (se.getComponentNameSpace() != null
147: && se.getComponentNameSpace().equals(
148: sourceId)) {
149: result = true;
150: break;
151: }
152: }
153: }
154: }
155: }
156:
157: // allow a match all subscription
158: if (service == null && interfaceName == null) {
159: result = true;
160: }
161: if (result && filter != null) {
162: result = filter.matches(exchange);
163: }
164: return result;
165: }
166:
167: /**
168: * @see java.lang.Object#equals(java.lang.Object)
169: */
170: public boolean equals(Object obj) {
171: boolean result = false;
172: if (obj instanceof SubscriptionSpec) {
173: SubscriptionSpec other = (SubscriptionSpec) obj;
174: result = (name == null && other.name == null || name
175: .equals(other.name))
176: && (service == null && other.service == null)
177: || (service != null && other.service != null && service
178: .equals(other.service))
179: && (interfaceName == null && other.interfaceName == null)
180: || (interfaceName != null
181: && other.interfaceName != null && interfaceName
182: .equals(other.interfaceName))
183: && (endpoint == null && other.endpoint == null)
184: || (endpoint != null && other.endpoint != null && endpoint
185: .equals(other.endpoint));
186:
187: }
188: return result;
189: }
190:
191: /**
192: * @see java.lang.Object#hashCode()
193: */
194: public int hashCode() {
195: return (name != null ? name.hashCode() : 0)
196: ^ (service != null ? service.hashCode()
197: : (interfaceName != null ? interfaceName
198: .hashCode() : super.hashCode()));
199: }
200:
201: }
|