001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.servicemix.jbi.servicedesc;
018
019 import javax.jbi.servicedesc.ServiceEndpoint;
020
021 import org.w3c.dom.Document;
022 import org.w3c.dom.DocumentFragment;
023 import org.w3c.dom.Element;
024
025 import org.apache.commons.logging.Log;
026 import org.apache.commons.logging.LogFactory;
027 import org.apache.servicemix.jbi.util.DOMUtil;
028
029 public final class EndpointReferenceBuilder {
030
031 public static final String JBI_NAMESPACE = "http://java.sun.com/jbi/end-point-reference";
032 public static final String XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
033
034 private static final Log LOG = LogFactory.getLog(EndpointReferenceBuilder.class);
035
036 private EndpointReferenceBuilder() {
037 }
038
039 public static DocumentFragment getReference(ServiceEndpoint endpoint) {
040 try {
041 Document doc = DOMUtil.newDocument();
042 DocumentFragment fragment = doc.createDocumentFragment();
043 Element epr = doc.createElementNS(JBI_NAMESPACE, "jbi:end-point-reference");
044 epr.setAttributeNS(XMLNS_NAMESPACE, "xmlns:sns", endpoint.getServiceName().getNamespaceURI());
045 epr.setAttributeNS(JBI_NAMESPACE, "jbi:service-name", "sns:" + endpoint.getServiceName().getLocalPart());
046 epr.setAttributeNS(JBI_NAMESPACE, "jbi:end-point-name", endpoint.getEndpointName());
047 fragment.appendChild(epr);
048 return fragment;
049 } catch (Exception e) {
050 LOG.warn("Unable to create reference for ServiceEndpoint " + endpoint, e);
051 return null;
052 }
053 }
054
055 }