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.net.URI;
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.ExtensionDeserializer;
026 import javax.wsdl.extensions.ExtensionRegistry;
027 import javax.xml.namespace.QName;
028
029 import org.w3c.dom.Element;
030
031 import com.ibm.wsdl.util.xml.DOMUtils;
032
033 public class JbiEndpointDeserializer implements ExtensionDeserializer {
034
035 public ExtensibilityElement unmarshall(
036 Class parentType,
037 QName elementType,
038 Element el,
039 Definition def,
040 ExtensionRegistry extReg)
041 throws WSDLException {
042
043 JbiEndpoint jbiEndpoint = (JbiEndpoint) extReg.createExtension(parentType, elementType);
044
045 String role = DOMUtils.getAttribute(el, JbiExtension.ROLE);
046 if (role == null) {
047 throw new WSDLException(WSDLException.OTHER_ERROR, "Role must be specified");
048 } else if (JbiExtension.ROLE_CONSUMER.equals(role)) {
049 jbiEndpoint.setRole(Role.CONSUMER);
050 } else if (JbiExtension.ROLE_PROVIDER.equals(role)) {
051 jbiEndpoint.setRole(Role.PROVIDER);
052 } else {
053 throw new WSDLException(WSDLException.OTHER_ERROR, "Unrecognized role: " + role);
054 }
055
056 String defaultMep = DOMUtils.getAttribute(el, JbiExtension.DEFAULT_MEP);
057 if (defaultMep == null) {
058 defaultMep = JbiExtension.DEFAULT_MEP_IN_OUT;
059 }
060 if (JbiExtension.DEFAULT_MEP_IN_ONLY.equals(defaultMep) ||
061 JbiExtension.DEFAULT_MEP_ROBUST_IN_ONLY.equals(defaultMep) ||
062 JbiExtension.DEFAULT_MEP_IN_OUT.equals(defaultMep)) {
063 jbiEndpoint.setDefaultMep(URI.create(JbiExtension.WSDL2_NS + defaultMep));
064 }
065
066 QName defaultOperation = DOMUtils.getQualifiedAttributeValue(el, JbiExtension.DEFAULT_OPERATION, null, false, def);
067 if (defaultOperation != null) {
068 jbiEndpoint.setDefaultOperation(defaultOperation);
069 }
070
071 return jbiEndpoint;
072 }
073
074 }