KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jms > JmsResolvedEndpoint


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.jms;
18
19 import javax.jbi.servicedesc.ServiceEndpoint;
20 import javax.xml.namespace.QName JavaDoc;
21
22 import org.apache.servicemix.jbi.util.DOMUtil;
23 import org.w3c.dom.DocumentFragment JavaDoc;
24 import org.w3c.dom.Element JavaDoc;
25 import org.w3c.dom.Node JavaDoc;
26 import org.w3c.dom.NodeList JavaDoc;
27
28 public class JmsResolvedEndpoint implements ServiceEndpoint {
29
30     public final static String JavaDoc EPR_URI = "urn:servicemix:jms";
31     public final static QName JavaDoc EPR_SERVICE = new QName JavaDoc(EPR_URI, "JmsComponent");
32     public final static String JavaDoc EPR_NAME = "epr";
33     
34     private DocumentFragment JavaDoc reference;
35     private String JavaDoc epName;
36     
37     public JmsResolvedEndpoint(DocumentFragment JavaDoc epr, String JavaDoc epName) {
38         this.reference = epr;
39         this.epName = epName;
40     }
41
42     public DocumentFragment JavaDoc getAsReference(QName JavaDoc operationName) {
43         return reference;
44     }
45
46     public String JavaDoc getEndpointName() {
47         return epName;
48     }
49
50     public QName JavaDoc[] getInterfaces() {
51         return null;
52     }
53
54     public QName JavaDoc getServiceName() {
55         return EPR_SERVICE;
56     }
57     
58     public static ServiceEndpoint resolveEndpoint(DocumentFragment JavaDoc epr) {
59         if (epr.getChildNodes().getLength() == 1) {
60             Node JavaDoc child = epr.getFirstChild();
61             if (child instanceof Element JavaDoc) {
62                 Element JavaDoc elem = (Element JavaDoc) child;
63                 String JavaDoc nsUri = elem.getNamespaceURI();
64                 String JavaDoc name = elem.getLocalName();
65                 // Check simple endpoints
66
if (EPR_URI.equals(nsUri) && EPR_NAME.equals(name)) {
67                     return new JmsResolvedEndpoint(epr, DOMUtil.getElementText(elem));
68                 // Check WSA endpoints
69
} else {
70                     NodeList JavaDoc nl = elem.getElementsByTagNameNS("http://www.w3.org/2005/08/addressing", "Address");
71                     if (nl.getLength() == 1) {
72                         Element JavaDoc address = (Element JavaDoc) nl.item(0);
73                         String JavaDoc uri = DOMUtil.getElementText(address);
74                         if (uri != null) {
75                             uri = uri.trim();
76                             if (uri.startsWith("jms://")) {
77                                 return new JmsResolvedEndpoint(epr, uri);
78                             }
79                         }
80                     }
81                 }
82             }
83         }
84         return null;
85     }
86     
87 }
Popular Tags