01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.common;
18:
19: import javax.jbi.servicedesc.ServiceEndpoint;
20: import javax.xml.namespace.QName;
21: import javax.xml.parsers.DocumentBuilderFactory;
22:
23: import org.w3c.dom.Document;
24: import org.w3c.dom.DocumentFragment;
25: import org.w3c.dom.Element;
26: import org.w3c.dom.Text;
27:
28: public class ExternalEndpoint implements ServiceEndpoint {
29:
30: private QName eprElement;
31: private String locationUri;
32: private QName serviceName;
33: private String endpointName;
34: private QName[] interfaces = null;
35:
36: public ExternalEndpoint(QName eprElement, String locationUri,
37: QName serviceName, String epName, QName[] interfaces) {
38: this .eprElement = eprElement;
39: this .locationUri = locationUri;
40: this .endpointName = epName;
41: this .serviceName = serviceName;
42: this .interfaces = interfaces;
43: }
44:
45: public ExternalEndpoint(QName eprElement, String locationUri,
46: QName serviceName, String epName, QName interfaceName) {
47: this .eprElement = eprElement;
48: this .locationUri = locationUri;
49: this .endpointName = epName;
50: this .serviceName = serviceName;
51: if (interfaceName != null) {
52: this .interfaces = new QName[] { interfaceName };
53: }
54: }
55:
56: public DocumentFragment getAsReference(QName operationName) {
57: try {
58: DocumentBuilderFactory dbf = DocumentBuilderFactory
59: .newInstance();
60: dbf.setNamespaceAware(true);
61: Document doc = dbf.newDocumentBuilder().newDocument();
62: DocumentFragment df = doc.createDocumentFragment();
63: Element e = doc.createElementNS(eprElement
64: .getNamespaceURI(), eprElement.getLocalPart());
65: Text t = doc.createTextNode(locationUri);
66: e.appendChild(t);
67: df.appendChild(e);
68: return df;
69: } catch (Exception e) {
70: throw new RuntimeException("Could not create reference", e);
71: }
72: }
73:
74: public QName getServiceName() {
75: return serviceName;
76: }
77:
78: public String getEndpointName() {
79: return endpointName;
80: }
81:
82: public QName[] getInterfaces() {
83: return interfaces;
84: }
85:
86: }
|