001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.assembler.classic;
018:
019: import org.apache.openejb.core.webservices.HandlerChainData;
020: import org.apache.openejb.core.webservices.HandlerData;
021: import org.apache.openejb.core.webservices.PortData;
022: import org.apache.openejb.OpenEJBException;
023: import org.apache.openejb.Injection;
024:
025: import javax.xml.namespace.QName;
026: import java.util.List;
027: import java.util.ArrayList;
028: import java.util.Collection;
029: import java.net.URL;
030: import java.net.MalformedURLException;
031:
032: public class WsBuilder {
033: public static PortData toPortData(PortInfo port,
034: Collection<Injection> injections, URL baseUrl,
035: ClassLoader classLoader) throws OpenEJBException {
036: PortData portData = new PortData();
037: portData.setPortId(port.portId);
038: if (port.serviceName != null && port.serviceName.length() != 0) {
039: portData.setServiceName(QName.valueOf(port.serviceName));
040: }
041: if (port.portName != null && port.portName.length() != 0) {
042: portData.setPortName(QName.valueOf(port.portName));
043: }
044: portData.setWsdlUrl(getWsdlURL(port.wsdlFile, baseUrl,
045: classLoader));
046: portData.getHandlerChains().addAll(
047: toHandlerChainData(port.handlerChains, classLoader));
048: portData.getInjections().addAll(injections);
049: portData.setMtomEnabled(port.mtomEnabled);
050: portData.setBindingID(port.binding);
051: portData.setWsdlPort(port.wsdlPort);
052: portData.setWsdlService(port.wsdlService);
053: portData.setLocation(port.location);
054: return portData;
055: }
056:
057: public static List<HandlerChainData> toHandlerChainData(
058: List<HandlerChainInfo> chains, ClassLoader classLoader)
059: throws OpenEJBException {
060: List<HandlerChainData> handlerChains = new ArrayList<HandlerChainData>();
061: for (HandlerChainInfo handlerChain : chains) {
062: List<HandlerData> handlers = new ArrayList<HandlerData>();
063: for (HandlerInfo handler : handlerChain.handlers) {
064: try {
065: Class<?> handlerClass = classLoader
066: .loadClass(handler.handlerClass);
067: HandlerData handlerData = new HandlerData(
068: handlerClass);
069: handlerData.getInitParams().putAll(
070: handler.initParams);
071: handlerData.getSoapHeaders().addAll(
072: handler.soapHeaders);
073: handlerData.getSoapRoles()
074: .addAll(handler.soapRoles);
075: handlers.add(handlerData);
076: } catch (ClassNotFoundException e) {
077: throw new OpenEJBException(
078: "Could not load handler class "
079: + handler.handlerClass);
080: }
081: }
082:
083: HandlerChainData handlerChainData = new HandlerChainData(
084: handlerChain.serviceNamePattern,
085: handlerChain.portNamePattern,
086: handlerChain.protocolBindings, handlers);
087: handlerChains.add(handlerChainData);
088:
089: }
090: return handlerChains;
091: }
092:
093: public static URL getWsdlURL(String wsdlFile, URL baseUrl,
094: ClassLoader classLoader) {
095: URL wsdlURL = null;
096: if (wsdlFile != null && wsdlFile.length() > 0) {
097: try {
098: wsdlURL = new URL(wsdlFile);
099: } catch (MalformedURLException e) {
100: // Not a URL, try as a resource
101: wsdlURL = classLoader.getResource(wsdlFile);
102:
103: if (wsdlURL == null && baseUrl != null) {
104: // Cannot get it as a resource, try with
105: // configurationBaseUrl
106: try {
107: wsdlURL = new URL(baseUrl, wsdlFile);
108: } catch (MalformedURLException ee) {
109: // ignore
110: }
111: }
112: }
113: }
114: return wsdlURL;
115: }
116: }
|