01: /*
02: * BEGIN_HEADER - DO NOT EDIT
03: *
04: * The contents of this file are subject to the terms
05: * of the Common Development and Distribution License
06: * (the "License"). You may not use this file except
07: * in compliance with the License.
08: *
09: * You can obtain a copy of the license at
10: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
11: * See the License for the specific language governing
12: * permissions and limitations under the License.
13: *
14: * When distributing Covered Code, include this CDDL
15: * HEADER in each file and include the License file at
16: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
17: * If applicable add the following below this CDDL HEADER,
18: * with the fields enclosed by brackets "[]" replaced with
19: * your own identifying information: Portions Copyright
20: * [year] [name of copyright owner]
21: */
22:
23: /*
24: * @(#)EndpointReference.java
25: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
26: *
27: * END_HEADER - DO NOT EDIT
28: */
29: package com.sun.jbi.messaging;
30:
31: import com.sun.jbi.messaging.util.XMLUtil;
32:
33: import org.w3c.dom.Document;
34: import org.w3c.dom.DocumentFragment;
35: import org.w3c.dom.Element;
36:
37: import javax.jbi.servicedesc.ServiceEndpoint;
38:
39: /** XML representation of an internal service endpoint.
40: * @author Sun Microsystems, Inc.
41: */
42: public class EndpointReference {
43: public static final String NS_URI_JBI = "http://java.sun.com/xml/ns/jbi";
44: public static final String NS_PFIX_JBI = "jbi";
45: public static final String NS_PFIX_SERVICE = "s";
46: public static final String ELE_END_POINT_REFERENCE = "end-point-reference";
47: public static final String ATTR_SERVICE_NAME = "service-name";
48: public static final String ATTR_ENDPOINT_NAME = "end-point-name";
49:
50: public static DocumentFragment asReference(ServiceEndpoint endpoint)
51: throws javax.jbi.messaging.MessagingException {
52: Document doc;
53: DocumentFragment frag;
54: Element ele;
55:
56: doc = XMLUtil.getInstance().newDocument();
57:
58: ele = doc.createElementNS(NS_URI_JBI, qname(NS_PFIX_JBI,
59: ELE_END_POINT_REFERENCE));
60: ele.setAttribute("xmlns:" + NS_PFIX_JBI, NS_URI_JBI);
61: ele.setAttribute("xmlns:" + NS_PFIX_SERVICE, endpoint
62: .getServiceName().getNamespaceURI());
63: ele.setAttributeNS(NS_URI_JBI, qname(NS_PFIX_JBI,
64: ATTR_SERVICE_NAME), qname(NS_PFIX_SERVICE, endpoint
65: .getServiceName().getLocalPart()));
66: ele.setAttributeNS(NS_URI_JBI, qname(NS_PFIX_JBI,
67: ATTR_ENDPOINT_NAME), endpoint.getEndpointName());
68:
69: doc.appendChild(ele);
70:
71: frag = doc.createDocumentFragment();
72: frag.appendChild(doc.getDocumentElement());
73:
74: return frag;
75: }
76:
77: private static String qname(String prefix, String value) {
78: return prefix + ":" + value;
79: }
80: }
|