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.common.wsdl1;
018    
019    import java.io.PrintWriter;
020    
021    import javax.jbi.messaging.MessageExchange.Role;
022    import javax.wsdl.Definition;
023    import javax.wsdl.WSDLException;
024    import javax.wsdl.extensions.ExtensibilityElement;
025    import javax.wsdl.extensions.ExtensionRegistry;
026    import javax.wsdl.extensions.ExtensionSerializer;
027    import javax.xml.namespace.QName;
028    
029    import com.ibm.wsdl.util.xml.DOMUtils;
030    
031    public class JbiEndpointSerializer implements ExtensionSerializer {
032    
033        public void marshall(Class parentType, 
034                             QName elementType, 
035                             ExtensibilityElement extension, 
036                             PrintWriter pw, 
037                             Definition def, 
038                             ExtensionRegistry extReg) throws WSDLException {
039    
040            JbiEndpoint endpoint = (JbiEndpoint) extension;
041            if (endpoint != null) {
042                String tagName = DOMUtils.getQualifiedValue(JbiExtension.NS_URI_JBI, JbiExtension.ELEM_ENDPOINT, def);
043                pw.print("    <" + tagName);
044                DOMUtils.printAttribute(
045                                JbiExtension.ROLE,
046                                endpoint.getRole() == Role.CONSUMER ? JbiExtension.ROLE_CONSUMER : JbiExtension.ROLE_PROVIDER,
047                                pw);
048                if (endpoint.getDefaultMep() != null) {
049                    DOMUtils.printAttribute(
050                                    JbiExtension.DEFAULT_MEP,
051                                    endpoint.getDefaultMep().toString(),
052                                    pw);
053                }
054                if (endpoint.getDefaultOperation() != null) {
055                    DOMUtils.printQualifiedAttribute(
056                                    JbiExtension.DEFAULT_OPERATION, 
057                                    endpoint.getDefaultOperation(), 
058                                    def, 
059                                    pw);
060                }
061                pw.print("/>");
062            }
063        }
064    
065    }