KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > servicedesc > InternalEndpoint


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.jbi.servicedesc;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import javax.xml.namespace.QName JavaDoc;
25
26 import org.apache.servicemix.jbi.framework.ComponentNameSpace;
27 import org.w3c.dom.DocumentFragment JavaDoc;
28
29 /**
30  * Reference generated by NMR to refer to an endpoint registration
31  *
32  * @version $Revision: 426415 $
33  */

34 public class InternalEndpoint extends AbstractServiceEndpoint {
35     
36     /**
37      * Generated serial version UID
38      */

39     private static final long serialVersionUID = -2710298087712302015L;
40     
41     private String JavaDoc endpointName;
42     private QName JavaDoc serviceName;
43     private List JavaDoc interfaces = new ArrayList JavaDoc();
44     private transient Map JavaDoc remotes = new HashMap JavaDoc();
45     
46
47     /**
48      * Constructor
49      * @param componentName
50      * @param endpointName
51      * @param serviceName
52      */

53     public InternalEndpoint(ComponentNameSpace componentName, String JavaDoc endpointName, QName JavaDoc serviceName) {
54         super(componentName);
55         this.endpointName = endpointName;
56         this.serviceName = serviceName;
57     }
58     
59     /**
60      * Get a reference to this endpoint, using an endpoint reference vocabulary
61      * that is known to the provider.
62      * @param operationName the name of the operation to be performed by a
63      * consumer of the generated endpoint reference. Set to <code>null</code>
64      * if this is not applicable.
65      * @return endpoint reference as an XML fragment; <code>null</code> if the
66      * provider does not support such references.
67      */

68     public DocumentFragment JavaDoc getAsReference(QName JavaDoc operationName) {
69         return EndpointReferenceBuilder.getReference(this);
70     }
71     
72     /**
73      * Returns the name of this endpoint.
74      * @return the endpoint name.
75      */

76     public String JavaDoc getEndpointName() {
77         return endpointName;
78     }
79     
80     /**
81      * Get the qualified names of all the interfaces implemented by this
82      * service endpoint.
83      * @return array of all interfaces implemented by this service endpoint;
84      * must be non-null and non-empty.
85      */

86     public QName JavaDoc[] getInterfaces() {
87         QName JavaDoc[] result = new QName JavaDoc[interfaces.size()];
88         interfaces.toArray(result);
89         return result;
90     }
91     
92     /**
93      * Add an interface
94      * @param name
95      */

96     public void addInterface(QName JavaDoc name) {
97         interfaces.add(name);
98     }
99
100     /**
101      * Returns the service name of this endpoint.
102      * @return the qualified service name.
103      */

104     public QName JavaDoc getServiceName() {
105        return serviceName;
106     }
107     
108     /**
109      * Retrieve all remote component namespaces where this endpoint is activated
110      * @return component namespaces
111      */

112     public InternalEndpoint[] getRemoteEndpoints() {
113         InternalEndpoint[] result = new InternalEndpoint[remotes.size()];
114         remotes.values().toArray(result);
115         return result;
116     }
117     
118     public void addRemoteEndpoint(InternalEndpoint remote) {
119         remotes.put(remote.getComponentNameSpace(), remote);
120     }
121     
122     public void removeRemoteEndpoint(InternalEndpoint remote) {
123         remotes.remove(remote.getComponentNameSpace());
124     }
125     
126     /**
127      * Check if this endpoint is locally activated
128      * @return true if the endpoint has been activated locally
129      */

130     public boolean isLocal() {
131         return getComponentNameSpace() != null;
132     }
133     
134     /**
135      * Check if the endpoint is remotely activated
136      * @return true if the endpoint has been remotely activated
137      */

138     public boolean isClustered() {
139         return remotes != null && remotes.size() > 0;
140     }
141     
142     /**
143      * @param obj
144      * @return true if equal
145      */

146     public boolean equals(Object JavaDoc obj) {
147         boolean result = false;
148         if (obj != null && obj instanceof InternalEndpoint){
149             InternalEndpoint other = (InternalEndpoint)obj;
150             result = other.serviceName.equals(this.serviceName) &&
151                      other.endpointName.equals(this.endpointName);
152         }
153         return result;
154     }
155     
156    
157     /**
158      * @return has code
159      */

160     public int hashCode() {
161         return serviceName.hashCode() ^
162                endpointName.hashCode() ;
163     }
164     
165     /**
166      * @return a pretty print of this
167      */

168     public String JavaDoc toString() {
169         return "ServiceEndpoint[service=" + serviceName + ",endpoint=" + endpointName + "]";
170     }
171 }
Popular Tags