1 17 package org.apache.servicemix.jbi.container; 18 19 import org.apache.servicemix.jbi.framework.ComponentNameSpace; 20 import org.apache.servicemix.jbi.framework.Registry; 21 import org.apache.servicemix.jbi.messaging.ExchangePacket; 22 import org.apache.servicemix.jbi.messaging.MessageExchangeImpl; 23 import org.apache.servicemix.jbi.resolver.SubscriptionFilter; 24 import org.apache.servicemix.jbi.servicedesc.InternalEndpoint; 25 26 import javax.jbi.servicedesc.ServiceEndpoint; 27 import javax.xml.namespace.QName ; 28 29 import java.io.Serializable ; 30 31 38 public class SubscriptionSpec implements Serializable { 39 40 43 private static final long serialVersionUID = 8458586342841647313L; 44 45 private QName service; 46 private QName interfaceName; 47 private QName operation; 48 private String endpoint; 49 private transient SubscriptionFilter filter; 50 private ComponentNameSpace name; 51 52 public String getEndpoint() { 53 return endpoint; 54 } 55 56 public void setEndpoint(String endpoint) { 57 this.endpoint = endpoint; 58 } 59 60 public SubscriptionFilter getFilter() { 61 return filter; 62 } 63 64 public void setFilter(SubscriptionFilter filter) { 65 this.filter = filter; 66 } 67 68 public QName getInterfaceName() { 69 return interfaceName; 70 } 71 72 public void setInterfaceName(QName interfaceName) { 73 this.interfaceName = interfaceName; 74 } 75 76 public QName getOperation() { 77 return operation; 78 } 79 80 public void setOperation(QName operation) { 81 this.operation = operation; 82 } 83 84 public QName getService() { 85 return service; 86 } 87 88 public void setService(QName service) { 89 this.service = service; 90 } 91 92 95 public ComponentNameSpace getName() { 96 return name; 97 } 98 99 105 public void setName(ComponentNameSpace name) { 106 this.name = name; 107 } 108 109 116 public boolean matches(Registry registry, MessageExchangeImpl exchange) { 117 boolean result = false; 118 119 ExchangePacket packet = exchange.getPacket(); 120 ComponentNameSpace sourceId = packet.getSourceId(); 121 if (sourceId != null) { 122 if (service != null) { 124 ServiceEndpoint[] ses = registry.getEndpointsForService(service); 125 if (ses != null) { 126 for (int i = 0; i < ses.length; i++) { 127 InternalEndpoint se = (InternalEndpoint) ses[i]; 128 if (se.getComponentNameSpace() != null && se.getComponentNameSpace().equals(sourceId)) { 129 result = true; 130 break; 131 } 132 } 133 } 134 } 135 if (result && interfaceName != null) { 136 ServiceEndpoint[] ses = registry.getEndpointsForInterface(interfaceName); 137 if (ses != null) { 138 result = false; 139 for (int i = 0; i < ses.length; i++) { 140 InternalEndpoint se = (InternalEndpoint) ses[i]; 141 if (se.getComponentNameSpace() != null && se.getComponentNameSpace().equals(sourceId)) { 142 result = true; 143 break; 144 } 145 } 146 } 147 } 148 } 149 150 if (service == null && interfaceName == null) { 152 result = true; 153 } 154 if (result && filter != null) { 155 result = filter.matches(exchange); 156 } 157 return result; 158 } 159 160 163 public boolean equals(Object obj) { 164 boolean result = false; 165 if (obj instanceof SubscriptionSpec) { 166 SubscriptionSpec other = (SubscriptionSpec) obj; 167 result = (name == null && other.name == null || name.equals(other.name)) 168 && (service == null && other.service == null) 169 || (service != null && other.service != null && service.equals(other.service)) 170 && (interfaceName == null && other.interfaceName == null) 171 || (interfaceName != null && other.interfaceName != null && interfaceName 172 .equals(other.interfaceName)) && (endpoint == null && other.endpoint == null) 173 || (endpoint != null && other.endpoint != null && endpoint.equals(other.endpoint)); 174 175 } 176 return result; 177 } 178 179 182 public int hashCode() { 183 return (name != null ? name.hashCode() : 0) 184 ^ (service != null ? service.hashCode() : (interfaceName != null ? interfaceName.hashCode() : super 185 .hashCode())); 186 } 187 188 } 189 | Popular Tags |