openejb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r591858 [3/13] - in /openejb/trunk/openejb3: ./ assembly/openejb-tomcat/ assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/ container/openejb-core/ container/openejb-core/src/main/java/org/apache/openejb/ container/openejb-cor...
Date Sun, 04 Nov 2007 22:42:06 GMT
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java?rev=591858&r1=591857&r2=591858&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java Sun Nov  4 14:41:49 2007
@@ -17,12 +17,16 @@
 package org.apache.openejb.config;
 
 import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.core.webservices.WsdlResolver;
 import org.apache.openejb.jee.ApplicationClient;
+import org.apache.openejb.jee.Connector;
 import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.HandlerChains;
+import org.apache.openejb.jee.JavaWsdlMapping;
 import org.apache.openejb.jee.JaxbJavaee;
-import org.apache.openejb.jee.WebApp;
-import org.apache.openejb.jee.Connector;
 import org.apache.openejb.jee.TldTaglib;
+import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.jee.Webservices;
 import org.apache.openejb.jee.jpa.unit.JaxbPersistenceFactory;
 import org.apache.openejb.jee.jpa.unit.Persistence;
 import org.apache.openejb.jee.oejb2.EnterpriseBean;
@@ -35,26 +39,28 @@
 import org.apache.openejb.jee.oejb2.WebServiceBindingType;
 import org.apache.openejb.jee.oejb3.JaxbOpenejbJar3;
 import org.apache.openejb.jee.oejb3.OpenejbJar;
-import org.xml.sax.SAXException;
 import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
 
+import javax.wsdl.Definition;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
-import javax.xml.parsers.SAXParserFactory;
 import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
 import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
 import java.util.List;
 
-/**
- * @version $Rev$ $Date$
- */
 public class ReadDescriptors implements DynamicDeployer {
+    @SuppressWarnings({"unchecked"})
     public AppModule deploy(AppModule appModule) throws OpenEJBException {
         for (EjbModule ejbModule : appModule.getEjbModules()) {
 
@@ -343,6 +349,71 @@
             throw new OpenEJBException("Encountered unknown error parsing the ejb-jar.xml file: " + url.toExternalForm(), e);
         }
         return ejbJar;
+    }
+
+    public static Webservices readWebservices(URL url) throws OpenEJBException {
+        Webservices webservices = null;
+        try {
+            webservices = (Webservices) JaxbJavaee.unmarshal(Webservices.class, url.openStream());
+        } catch (SAXException e) {
+            throw new OpenEJBException("Cannot parse the webservices.xml file: " + url.toExternalForm(), e);
+        } catch (JAXBException e) {
+            throw new OpenEJBException("Cannot unmarshall the webservices.xml file: " + url.toExternalForm(), e);
+        } catch (IOException e) {
+            throw new OpenEJBException("Cannot read the webservices.xml file: " + url.toExternalForm(), e);
+        } catch (Exception e) {
+            throw new OpenEJBException("Encountered unknown error parsing the webservices.xml file: " + url.toExternalForm(), e);
+        }
+        return webservices;
+    }
+
+    public static HandlerChains readHandlerChains(URL url) throws OpenEJBException {
+        HandlerChains handlerChains = null;
+        try {
+            handlerChains = (HandlerChains) JaxbJavaee.unmarshal(HandlerChains.class, url.openStream());
+        } catch (SAXException e) {
+            throw new OpenEJBException("Cannot parse the webservices.xml file: " + url.toExternalForm(), e);
+        } catch (JAXBException e) {
+            throw new OpenEJBException("Cannot unmarshall the webservices.xml file: " + url.toExternalForm(), e);
+        } catch (IOException e) {
+            throw new OpenEJBException("Cannot read the webservices.xml file: " + url.toExternalForm(), e);
+        } catch (Exception e) {
+            throw new OpenEJBException("Encountered unknown error parsing the webservices.xml file: " + url.toExternalForm(), e);
+        }
+        return handlerChains;
+    }
+
+    public static JavaWsdlMapping readJaxrpcMapping(URL url) throws OpenEJBException {
+        JavaWsdlMapping wsdlMapping = null;
+        try {
+            wsdlMapping = (JavaWsdlMapping) JaxbJavaee.unmarshal(JavaWsdlMapping.class, url.openStream());
+        } catch (SAXException e) {
+            throw new OpenEJBException("Cannot parse the JaxRPC mapping file: " + url.toExternalForm(), e);
+        } catch (JAXBException e) {
+            throw new OpenEJBException("Cannot unmarshall the JaxRPC mapping file: " + url.toExternalForm(), e);
+        } catch (IOException e) {
+            throw new OpenEJBException("Cannot read the JaxRPC mapping file: " + url.toExternalForm(), e);
+        } catch (Exception e) {
+            throw new OpenEJBException("Encountered unknown error parsing the JaxRPC mapping file: " + url.toExternalForm(), e);
+        }
+        return wsdlMapping;
+    }
+
+    public static Definition readWsdl(URL url) throws OpenEJBException {
+        Definition definition = null;
+        try {
+            WSDLFactory factory = WSDLFactory.newInstance();
+            WSDLReader reader = factory.newWSDLReader();
+            reader.setFeature("javax.wsdl.verbose", true);
+            reader.setFeature("javax.wsdl.importDocuments", true);
+            WsdlResolver wsdlResolver = new WsdlResolver(new URL(url, ".").toExternalForm(), new InputSource(url.openStream()));
+            definition = reader.readWSDL(wsdlResolver);
+        } catch (IOException e) {
+            throw new OpenEJBException("Cannot read the wsdl file: " + url.toExternalForm(), e);
+        } catch (Exception e) {
+            throw new OpenEJBException("Encountered unknown error parsing the wsdl file: " + url.toExternalForm(), e);
+        }
+        return definition;
     }
 
     public static Connector readConnector(URL url) throws OpenEJBException {

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/SunConversion.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/SunConversion.java?rev=591858&r1=591857&r2=591858&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/SunConversion.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/SunConversion.java Sun Nov  4 14:41:49 2007
@@ -36,6 +36,10 @@
 import org.apache.openejb.jee.ApplicationClient;
 import org.apache.openejb.jee.JndiReference;
 import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.jee.ServiceRef;
+import org.apache.openejb.jee.PortComponentRef;
+import org.apache.openejb.jee.WebserviceDescription;
+import org.apache.openejb.jee.PortComponent;
 import org.apache.openejb.jee.jpa.Attributes;
 import org.apache.openejb.jee.jpa.Basic;
 import org.apache.openejb.jee.jpa.Column;
@@ -77,6 +81,8 @@
 import org.apache.openejb.jee.sun.MessageDestinationRef;
 import org.apache.openejb.jee.sun.ResourceRef;
 import org.apache.openejb.jee.sun.SunWebApp;
+import org.apache.openejb.jee.sun.PortInfo;
+import org.apache.openejb.jee.sun.StubProperty;
 
 //
 // Note to developer:  the best doc on what the sun-cmp-mappings element mean can be foudn here
@@ -253,6 +259,35 @@
                 }
             }
         }
+
+        Map<String, ServiceRef> serviceRefMap = applicationClient.getServiceRefMap();
+        for (org.apache.openejb.jee.sun.ServiceRef ref : sunApplicationClient.getServiceRef()) {
+            String refName = ref.getServiceRefName();
+            ServiceRef serviceRef = serviceRefMap.get(refName);
+            if (serviceRef != null) {
+                Map<String,PortComponentRef> ports = new TreeMap<String,PortComponentRef>();
+                for (PortComponentRef portComponentRef : serviceRef.getPortComponentRef()) {
+                    ports.put(portComponentRef.getServiceEndpointInterface(), portComponentRef);
+                }
+
+                for (PortInfo portInfo : ref.getPortInfo()) {
+                    PortComponentRef portComponentRef = ports.get(portInfo.getServiceEndpointInterface());
+                    if (portComponentRef != null) {
+                        for (StubProperty stubProperty : portInfo.getStubProperty()) {
+                            String name = stubProperty.getName();
+                            String value = stubProperty.getValue();
+                            portComponentRef.getProperties().setProperty(name, value);
+                        }
+                    }
+                }
+
+                String wsdlOverride = ref.getWsdlOverride();
+                if (wsdlOverride != null && wsdlOverride.length() > 0) {
+                    String wsdlRepoUri = processWsdlPublishLocation(wsdlOverride);
+                    serviceRef.setMappedName("wsdlrepo:" + wsdlRepoUri);
+                }
+            }
+        }
     }
 
     public void convertModule(WebModule webModule) {
@@ -322,6 +357,80 @@
                 }
             }
         }
+
+        Map<String, ServiceRef> serviceRefMap = webApp.getServiceRefMap();
+        for (org.apache.openejb.jee.sun.ServiceRef ref : sunWebApp.getServiceRef()) {
+            String refName = ref.getServiceRefName();
+            ServiceRef serviceRef = serviceRefMap.get(refName);
+            if (serviceRef != null) {
+                Map<String,PortComponentRef> ports = new TreeMap<String,PortComponentRef>();
+                for (PortComponentRef portComponentRef : serviceRef.getPortComponentRef()) {
+                    ports.put(portComponentRef.getServiceEndpointInterface(), portComponentRef);
+                }
+
+                for (PortInfo portInfo : ref.getPortInfo()) {
+                    PortComponentRef portComponentRef = ports.get(portInfo.getServiceEndpointInterface());
+                    if (portComponentRef != null) {
+                        for (StubProperty stubProperty : portInfo.getStubProperty()) {
+                            String name = stubProperty.getName();
+                            String value = stubProperty.getValue();
+                            portComponentRef.getProperties().setProperty(name, value);
+                        }
+                    }
+                }
+
+                String wsdlOverride = ref.getWsdlOverride();
+                if (wsdlOverride != null && wsdlOverride.length() > 0) {
+                    String wsdlRepoUri = processWsdlPublishLocation(wsdlOverride);
+                    serviceRef.setMappedName("wsdlrepo:" + wsdlRepoUri);
+                }
+            }
+        }
+
+        // map wsdl locations
+        if (webModule.getWebservices() != null) {
+            Map<String, WebserviceDescription> descriptions = webModule.getWebservices().getWebserviceDescriptionMap();
+            for (org.apache.openejb.jee.sun.WebserviceDescription sunDescription : sunWebApp.getWebserviceDescription()) {
+                WebserviceDescription description = descriptions.get(sunDescription.getWebserviceDescriptionName());
+                if (description == null) continue;
+
+                String location = processWsdlPublishLocation(sunDescription.getWsdlPublishLocation(), description.getWsdlFile());
+                if (location != null) {
+                    for (PortComponent portComponent : description.getPortComponent()) {
+                        portComponent.setWsdlPublishLocation(location);
+                    }
+                }
+            }
+        }
+    }
+
+
+    public static String processWsdlPublishLocation(String location) {
+        return processWsdlPublishLocation(location, null);
+    }
+
+    public static String processWsdlPublishLocation(String location, String wsdlFile) {
+        if (location == null) return null;
+
+        if (location.startsWith("file:")) {
+            // location format = file:{repository}/{location}.wsdl
+            location = location.replaceFirst("file:[^/]*/", "");
+
+            // append wsdl name without leading META-INF/wsdl or WEB-INF/wsdl or ending .wsdl
+            if (wsdlFile != null) {
+                wsdlFile = wsdlFile.replaceFirst("META-INF/wsdl/", "");
+                wsdlFile = wsdlFile.replaceFirst("WEB-INF/wsdl/", "");
+                location = location + "/" + wsdlFile;
+            }
+            location = location.replaceFirst("\\.wsdl$", "");
+        } else if (location.startsWith("http:") || location.startsWith("https:")) {
+            // location format = https://{server}:{port}/{location}?WSDL
+            location = location.replaceFirst("http[s]?://[^/]*/", "");
+            location = location.replaceFirst("\\?.*$", "");
+        }
+
+        if (location.length() == 0) location = null;
+        return location;
     }
 
     public void convertModule(EjbModule ejbModule, EntityMappings entityMappings) {
@@ -332,7 +441,7 @@
 
         // merge data from sun-ejb-jar.xml file
         SunEjbJar sunEjbJar = getSunEjbJar(ejbModule);
-        mergeEjbConfig(ejbModule.getOpenejbJar(), sunEjbJar);
+        mergeEjbConfig(ejbModule, sunEjbJar);
         mergeEntityMappings(entities, ejbModule.getModuleId(), ejbModule.getEjbJar(), ejbModule.getOpenejbJar(), sunEjbJar);
 
         // merge data from sun-cmp-mappings.xml file
@@ -344,7 +453,10 @@
         }
     }
 
-    private void mergeEjbConfig(OpenejbJar openejbJar, SunEjbJar sunEjbJar) {
+    private void mergeEjbConfig(EjbModule ejbModule, SunEjbJar sunEjbJar) {
+        EjbJar ejbJar = ejbModule.getEjbJar();
+        OpenejbJar openejbJar = ejbModule.getOpenejbJar();
+
         if (openejbJar == null) return;
         if (sunEjbJar == null) return;
         if (sunEjbJar.getEnterpriseBeans() == null) return;
@@ -420,10 +532,60 @@
                 }
             }
 
+            EnterpriseBean bean = ejbJar.getEnterpriseBeansByEjbName().get(ejb.getEjbName());
+            if (bean != null) {
+                Map<String, ServiceRef> serviceRefMap = bean.getServiceRefMap();
+                for (org.apache.openejb.jee.sun.ServiceRef ref : ejb.getServiceRef()) {
+                    String refName = ref.getServiceRefName();
+                    ServiceRef serviceRef = serviceRefMap.get(refName);
+                    if (serviceRef != null) {
+                        Map<String,PortComponentRef> ports = new TreeMap<String,PortComponentRef>();
+                        for (PortComponentRef portComponentRef : serviceRef.getPortComponentRef()) {
+                            ports.put(portComponentRef.getServiceEndpointInterface(), portComponentRef);
+                        }
+
+                        for (PortInfo portInfo : ref.getPortInfo()) {
+                            PortComponentRef portComponentRef = ports.get(portInfo.getServiceEndpointInterface());
+                            if (portComponentRef != null) {
+                                for (StubProperty stubProperty : portInfo.getStubProperty()) {
+                                    String name = stubProperty.getName();
+                                    String value = stubProperty.getValue();
+                                    portComponentRef.getProperties().setProperty(name, value);
+                                }
+                            }
+                        }
+
+                        String wsdlOverride = ref.getWsdlOverride();
+                        if (wsdlOverride != null && wsdlOverride.length() > 0) {
+                            String wsdlRepoUri = processWsdlPublishLocation(wsdlOverride);
+                            serviceRef.setMappedName("wsdlrepo:" + wsdlRepoUri);
+                        }
+                    }
+                }
+            }
+
             if (ejb.getMdbResourceAdapter() != null) {
                 // resource adapter id is the MDB container ID
                 String resourceAdapterId = ejb.getMdbResourceAdapter().getResourceAdapterMid();
                 deployment.setContainerId(resourceAdapterId);
+            }
+
+
+            // map wsdl locations
+            if (ejbModule.getWebservices() != null) {
+                Map<String, WebserviceDescription> descriptions = ejbModule.getWebservices().getWebserviceDescriptionMap();
+                for (org.apache.openejb.jee.sun.WebserviceDescription sunDescription : sunEjbJar.getEnterpriseBeans().getWebserviceDescription()) {
+                    WebserviceDescription description = descriptions.get(sunDescription.getWebserviceDescriptionName());
+                    if (description == null) continue;
+
+                    String location = processWsdlPublishLocation(sunDescription.getWsdlPublishLocation(), description.getWsdlFile());
+                    if (location != null) {
+                        for (PortComponent portComponent : description.getPortComponent()) {
+                            // this could be a problem multiple port components used at runtime
+                            portComponent.setWsdlPublishLocation(location);
+                        }
+                    }
+                }
             }
         }
     }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java?rev=591858&r1=591857&r2=591858&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java Sun Nov  4 14:41:49 2007
@@ -18,6 +18,7 @@
 
 import org.apache.openejb.jee.WebApp;
 import org.apache.openejb.jee.TldTaglib;
+import org.apache.openejb.jee.Webservices;
 
 import java.util.Map;
 import java.util.HashMap;
@@ -30,11 +31,12 @@
 /**
  * @version $Rev$ $Date$
  */
-public class WebModule implements DeploymentModule {
+public class WebModule implements WsModule {
     private final ValidationContext validation;
     private final Map<String,Object> altDDs = new HashMap<String,Object>();
 
     private WebApp webApp;
+    private Webservices webservices;
     private String host;
     private String contextRoot;
     private ClassLoader classLoader;
@@ -94,6 +96,15 @@
     public void setWebApp(WebApp webApp) {
         this.webApp = webApp;
     }
+
+    public Webservices getWebservices() {
+        return webservices;
+    }
+
+    public void setWebservices(Webservices webservices) {
+        this.webservices = webservices;
+    }
+
     public ClassLoader getClassLoader() {
         return classLoader;
     }

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsDeployer.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsDeployer.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsDeployer.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,287 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.config;
+
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.core.webservices.JaxWsUtils;
+import org.apache.openejb.jee.EnterpriseBean;
+import org.apache.openejb.jee.JndiConsumer;
+import org.apache.openejb.jee.PortComponent;
+import org.apache.openejb.jee.ServiceImplBean;
+import org.apache.openejb.jee.ServiceRef;
+import org.apache.openejb.jee.Servlet;
+import org.apache.openejb.jee.ServletMapping;
+import org.apache.openejb.jee.SessionBean;
+import org.apache.openejb.jee.SessionType;
+import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.jee.WebserviceDescription;
+import org.apache.openejb.jee.Webservices;
+import org.apache.openejb.util.LogCategory;
+import org.apache.openejb.util.Logger;
+
+import javax.xml.namespace.QName;
+import javax.wsdl.Definition;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Set;
+
+public class WsDeployer implements DynamicDeployer {
+    public static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP, WsDeployer.class.getPackage().getName());
+
+    public AppModule deploy(AppModule appModule) throws OpenEJBException {
+        // process all webservice port
+        for (EjbModule ejbModule : appModule.getEjbModules()) {
+            processPorts(ejbModule);
+        }
+        for (WebModule webModule : appModule.getWebModules()) {
+            processPorts(webModule);
+        }
+
+        // Resolve service-refs
+        for (EjbModule ejbModule : appModule.getEjbModules()) {
+            for (EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
+                resolveServiceRefs(enterpriseBean, ejbModule.getJarLocation());
+            }
+        }
+        for (WebModule webModule : appModule.getWebModules()) {
+            resolveServiceRefs(webModule.getWebApp(), webModule.getJarLocation());
+        }
+        for (ClientModule clientModule : appModule.getClientModules()) {
+            resolveServiceRefs(clientModule.getApplicationClient(), clientModule.getJarLocation());
+        }
+
+        return appModule;
+    }
+
+    private void resolveServiceRefs(JndiConsumer jndiConsumer, String baseLocation) {
+        URL baseURL;
+        try {
+            File file = new File(baseLocation);
+            if (file.exists()) {
+                baseURL = file.toURL();
+                if (file.isFile()) {
+                    baseURL = new URL("jar", null, baseURL.toExternalForm() + "!/");
+                }
+            } else {
+                baseURL = new URL(baseLocation);
+            }
+        } catch (MalformedURLException e) {
+            logger.error("Invalid module location " + baseLocation);
+            return;
+        }
+
+        Map<URL,Definition> wsdlFiles = new HashMap<URL,Definition>();
+        for (ServiceRef serviceRef : jndiConsumer.getServiceRef()) {
+            if (serviceRef.getServiceQname() == null && serviceRef.getWsdlFile() != null) {
+                // parse the wsdl and get the serviceQname
+                try {
+                    String wsdlFile = serviceRef.getWsdlFile();
+                    URL wsdlUrl = new URL(baseURL, wsdlFile);
+                    Definition definition = wsdlFiles.get(wsdlUrl);
+                    if (definition == null) {
+                        definition = ReadDescriptors.readWsdl(wsdlUrl);
+                        wsdlFiles.put(wsdlUrl, definition);
+                    }
+
+                    Set serviceQNames = definition.getServices().keySet();
+                    if (serviceQNames.size() == 1) {
+                        QName serviceQName = (QName) serviceQNames.iterator().next();
+                        serviceRef.setServiceQname(serviceQName.toString());
+                    } else if (serviceQNames.isEmpty()) {
+                        logger.error("The service-ref " + serviceRef.getName() + " must define service-qname because the wsdl-file " + serviceRef.getWsdlFile() + " does not constain any service definitions ");
+                    } else {
+                        logger.error("The service-ref " + serviceRef.getName() + " must define service-qname because the wsdl-file " + serviceRef.getWsdlFile() + " constain more then one service definitions " + serviceQNames);
+                    }
+                } catch(Exception e) {
+                    logger.error("Unable to read wsdl file " + serviceRef.getWsdlFile());
+                }
+            }
+        }
+    }
+
+    private void processPorts(WebModule webModule) throws OpenEJBException {
+        // map existing webservice port declarations by servlet link
+        Webservices webservices = webModule.getWebservices();
+        Map<String, PortComponent> portMap = new TreeMap<String, PortComponent>();
+        if (webservices != null) {
+            for (WebserviceDescription webserviceDescription : webservices.getWebserviceDescription()) {
+                for (PortComponent portComponent : webserviceDescription.getPortComponent()) {
+                    ServiceImplBean serviceImplBean = portComponent.getServiceImplBean();
+                    if (serviceImplBean != null && serviceImplBean.getServletLink() != null) {
+                        portMap.put(serviceImplBean.getServletLink(), portComponent);
+                    }
+                }
+            }
+        }
+
+        // map existing servlet-mapping declarations
+        WebApp webApp = webModule.getWebApp();
+        Map<String, ServletMapping> servletMappings = new TreeMap<String, ServletMapping>();
+        for (ServletMapping servletMapping : webApp.getServletMapping()) {
+            servletMappings.put(servletMapping.getServletName(), servletMapping);
+        }
+
+        // add port declarations for webservices
+        WebserviceDescription webserviceDescription = null;
+        for (Servlet servlet : webApp.getServlet()) {
+            String className = servlet.getServletClass();
+
+            try {
+                Class<?> clazz = webModule.getClassLoader().loadClass(className);
+                if (JaxWsUtils.isWebService(clazz)) {
+                    // add servlet mapping if not already declared
+                    ServletMapping servletMapping = servletMappings.get(servlet.getServletName());
+                    if (servletMapping == null) {
+                        servletMapping = new ServletMapping();
+                        servletMapping.setServletName(servlet.getServletName());
+
+                        String location = "/" + JaxWsUtils.getServiceName(clazz);
+                        servletMapping.getUrlPattern().add(location);
+                        webApp.getServletMapping().add(servletMapping);
+                    }
+
+                    // define port if not already declared
+                    PortComponent portComponent = portMap.get(clazz.getName());
+                    if (portComponent == null) {
+                        // create port
+                        portComponent = new PortComponent();
+                        ServiceImplBean serviceImplBean = new ServiceImplBean();
+                        serviceImplBean.setServletLink(className);
+                        portComponent.setServiceImplBean(serviceImplBean);
+
+                        // add port declaration
+                        if (webservices == null) {
+                            webservices = new Webservices();
+                            webModule.setWebservices(webservices);
+                        }
+                        if (webserviceDescription == null) {
+                            webserviceDescription = new WebserviceDescription();
+                            webserviceDescription.setWebserviceDescriptionName(JaxWsUtils.getServiceName(clazz));
+                            webservices.getWebserviceDescription().add(webserviceDescription);
+                        }
+                        webserviceDescription.getPortComponent().add(portComponent);
+                    }
+
+                    // set port values from annotations if not already set
+                    if (portComponent.getServiceEndpointInterface() == null) {
+                        portComponent.setServiceEndpointInterface(JaxWsUtils.getServiceInterface(clazz));
+                    }
+                    if (portComponent.getPortComponentName() == null) {
+                        portComponent.setPortComponentName(JaxWsUtils.getName(clazz));
+                    }
+                    if (portComponent.getWsdlPort() == null) {
+                        portComponent.setWsdlPort(JaxWsUtils.getPortQName(clazz));
+                    }
+                    if (portComponent.getWsdlService() == null) {
+                        portComponent.setWsdlService(JaxWsUtils.getServiceQName(clazz));
+                    }
+                    if (webserviceDescription.getWsdlFile() == null) {
+                        webserviceDescription.setWsdlFile(JaxWsUtils.getServiceWsdlLocation(clazz, webModule.getClassLoader()));
+                    }
+                }
+            } catch (Exception e) {
+                throw new OpenEJBException("Unable to load servlet class: " + className, e);
+            }
+        }
+    }
+
+    private void processPorts(EjbModule ejbModule) throws OpenEJBException {
+        // map existing webservice port declarations by servlet link
+        Webservices webservices = ejbModule.getWebservices();
+        Map<String, PortComponent> portMap = new TreeMap<String, PortComponent>();
+        if (webservices != null) {
+            for (WebserviceDescription webserviceDescription : webservices.getWebserviceDescription()) {
+                for (PortComponent portComponent : webserviceDescription.getPortComponent()) {
+                    ServiceImplBean serviceImplBean = portComponent.getServiceImplBean();
+                    if (serviceImplBean != null && serviceImplBean.getEjbLink() != null) {
+                        portMap.put(serviceImplBean.getEjbLink(), portComponent);
+                    }
+                }
+            }
+        }
+
+        WebserviceDescription webserviceDescription = null;
+        for (EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
+            // skip if this is not a webservices endpoint
+            if (!(enterpriseBean instanceof SessionBean)) continue;
+            SessionBean sessionBean = (SessionBean) enterpriseBean;
+            if (sessionBean.getSessionType() != SessionType.STATELESS) continue;
+            if (sessionBean.getServiceEndpoint() == null) continue;
+
+            Class<?> ejbClass = null;
+            try {
+                ejbClass = ejbModule.getClassLoader().loadClass(sessionBean.getEjbClass());
+            } catch (ClassNotFoundException e) {
+                throw new OpenEJBException("Unable to load ejb class: " + sessionBean.getEjbClass(), e);
+            }
+
+            // create webservices dd if not defined
+            if (webservices == null) {
+                webservices = new Webservices();
+                ejbModule.setWebservices(webservices);
+            }
+            if (webserviceDescription == null) {
+                webserviceDescription = new WebserviceDescription();
+                if (JaxWsUtils.isWebService(ejbClass)) {
+                    webserviceDescription.setWebserviceDescriptionName(JaxWsUtils.getServiceName(ejbClass));
+                } else {
+                    // todo create webserviceDescription name using some sort of jaxrpc data 
+                }
+                webservices.getWebserviceDescription().add(webserviceDescription);
+            }
+
+            // add a port component if we don't alrady have one
+            PortComponent portComponent = portMap.get(sessionBean.getEjbName());
+            if (portComponent == null) {
+                portComponent = new PortComponent();
+                webserviceDescription.getPortComponent().add(portComponent);
+
+                ServiceImplBean serviceImplBean = new ServiceImplBean();
+                serviceImplBean.setEjbLink(sessionBean.getEjbName());
+                portComponent.setServiceImplBean(serviceImplBean);
+            }
+
+            // set service endpoint interface
+            if (portComponent.getServiceEndpointInterface() == null) {
+                portComponent.setServiceEndpointInterface(sessionBean.getServiceEndpoint());
+            }
+
+            // default location is /@WebService.serviceName/@WebService.name
+            if (JaxWsUtils.isWebService(ejbClass)) {
+                if (portComponent.getPortComponentName() == null) {
+                    portComponent.setPortComponentName(JaxWsUtils.getName(ejbClass));
+                }
+                if (portComponent.getWsdlPort() == null) {
+                    portComponent.setWsdlPort(JaxWsUtils.getPortQName(ejbClass));
+                }
+                if (portComponent.getWsdlService() == null) {
+                    portComponent.setWsdlService(JaxWsUtils.getServiceQName(ejbClass));
+                }
+                if (webserviceDescription.getWsdlFile() == null) {
+                    webserviceDescription.setWsdlFile(JaxWsUtils.getServiceWsdlLocation(ejbClass, ejbModule.getClassLoader()));
+                }
+            } else {
+                // todo location JAX-RPC services comes from wsdl file
+            }
+        }
+    }
+}

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsModule.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsModule.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsModule.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsModule.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,26 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.config;
+
+import org.apache.openejb.jee.Webservices;
+
+public interface WsModule extends DeploymentModule {
+    Webservices getWebservices();
+
+    void setWebservices(Webservices webservices);
+}

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreContainerSystem.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreContainerSystem.java?rev=591858&r1=591857&r2=591858&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreContainerSystem.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreContainerSystem.java Sun Nov  4 14:41:49 2007
@@ -16,20 +16,21 @@
  */
 package org.apache.openejb.core;
 
-import java.util.HashMap;
-
 import org.apache.openejb.Container;
 import org.apache.openejb.DeploymentInfo;
-import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.core.ivm.naming.IvmContext;
+import org.apache.openejb.loader.SystemInstance;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * @org.apache.xbean.XBean element="containerSystem"
  */
 public class CoreContainerSystem implements org.apache.openejb.spi.ContainerSystem {
-
-    HashMap deployments = new HashMap();
-    HashMap containers = new HashMap();
+    Map<Object, DeploymentInfo> deployments = new ConcurrentHashMap<Object, DeploymentInfo>();
+    Map<Object, Container> containers = new ConcurrentHashMap<Object, Container>();
+    Map<String, WebDeploymentInfo> webDeployments = new ConcurrentHashMap<String, WebDeploymentInfo>();
     IvmContext jndiRootContext = null;
 
     public CoreContainerSystem() {
@@ -54,19 +55,27 @@
     }
 
     public DeploymentInfo getDeploymentInfo(Object id) {
-        return (DeploymentInfo) deployments.get(id);
+        return deployments.get(id);
     }
 
     public DeploymentInfo [] deployments() {
-        return (DeploymentInfo []) deployments.values().toArray(new DeploymentInfo [deployments.size()]);
+        return deployments.values().toArray(new DeploymentInfo [deployments.size()]);
+    }
+
+    public void addDeployment(DeploymentInfo deployment) {
+        this.deployments.put(deployment.getDeploymentID(), deployment);
+    }
+
+    public void removeDeploymentInfo(DeploymentInfo info){
+        this.deployments.remove(info.getDeploymentID());
     }
 
     public Container getContainer(Object id) {
-        return (Container) containers.get(id);
+        return containers.get(id);
     }
 
     public Container [] containers() {
-        return (Container []) containers.values().toArray(new Container [containers.size()]);
+        return containers.values().toArray(new Container [containers.size()]);
     }
 
     public void addContainer(Object id, Container c) {
@@ -77,16 +86,21 @@
         containers.remove(id);
     }
 
-    public void addDeployment(DeploymentInfo deployment) {
-
-        this.deployments.put(deployment.getDeploymentID(), deployment);
+    public WebDeploymentInfo getWebDeploymentInfo(String id) {
+        return webDeployments.get(id);
+    }
 
+    public WebDeploymentInfo [] WebDeployments() {
+        return webDeployments.values().toArray(new WebDeploymentInfo [webDeployments.size()]);
     }
 
-    public void removeDeploymentInfo(DeploymentInfo info){
-        this.deployments.remove(info.getDeploymentID());
+    public void addWebDeployment(WebDeploymentInfo webDeployment) {
+        this.webDeployments.put(webDeployment.getId(), webDeployment);
     }
 
+    public void removeWebDeploymentInfo(WebDeploymentInfo info){
+        this.webDeployments.remove(info.getId());
+    }
 
     public javax.naming.Context getJNDIContext() {
         return jndiRootContext;

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreWebDeploymentInfo.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreWebDeploymentInfo.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreWebDeploymentInfo.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreWebDeploymentInfo.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,59 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.core;
+
+import org.apache.openejb.Injection;
+
+import javax.naming.Context;
+import java.util.Collection;
+import java.util.ArrayList;
+
+public class CoreWebDeploymentInfo implements WebDeploymentInfo {
+    private String id;
+    private ClassLoader classLoader;
+    private final Collection<Injection> injections = new ArrayList<Injection>();
+    private Context jndiEnc;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public ClassLoader getClassLoader() {
+        return classLoader;
+    }
+
+    public void setClassLoader(ClassLoader classLoader) {
+        this.classLoader = classLoader;
+    }
+
+    public Collection<Injection> getInjections() {
+        return injections;
+    }
+
+    public Context getJndiEnc() {
+        return jndiEnc;
+    }
+
+    public void setJndiEnc(Context jndiEnc) {
+        this.jndiEnc = jndiEnc;
+    }
+}

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/WebDeploymentInfo.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/WebDeploymentInfo.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/WebDeploymentInfo.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/WebDeploymentInfo.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,33 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.core;
+
+import org.apache.openejb.Injection;
+
+import javax.naming.Context;
+import java.util.Collection;
+
+public interface WebDeploymentInfo {
+    String getId();
+
+    ClassLoader getClassLoader();
+
+    Collection<Injection> getInjections();
+
+    Context getJndiEnc();
+}

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxRReference.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxRReference.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxRReference.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxRReference.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,31 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.core.ivm.naming;
+
+import javax.xml.registry.ConnectionFactory;
+import javax.xml.registry.JAXRException;
+
+public class JaxRReference extends Reference {
+    public Object getObject() throws javax.naming.NamingException {
+        try {
+            return ConnectionFactory.newInstance();
+        } catch (JAXRException e) {
+            throw new NamingException("Error creating JaxR ConnectionFactory", e);
+        }
+    }
+}
\ No newline at end of file

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxRpcServiceReference.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxRpcServiceReference.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxRpcServiceReference.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxRpcServiceReference.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,110 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.core.ivm.naming;
+
+import org.apache.openejb.util.Logger;
+import org.apache.openejb.util.LogCategory;
+
+import javax.naming.NamingException;
+import javax.xml.namespace.QName;
+import javax.xml.rpc.ServiceFactory;
+import javax.xml.rpc.Service;
+import javax.xml.rpc.ServiceException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+
+// todo deal with handlers
+public class JaxRpcServiceReference extends Reference {
+    private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB, JaxRpcServiceReference.class);
+
+    private String serviceClassName;
+    private ClassLoader classLoader;
+    private URI wsdlURI;
+    private QName serviceQName;
+    private String referenceClassName;
+
+    public JaxRpcServiceReference(QName serviceQName, URI wsdlURI, String referenceClassName, String serviceClassName, ClassLoader classLoader) {
+        this.classLoader = classLoader;
+        this.serviceQName = serviceQName;
+        this.wsdlURI = wsdlURI;
+        this.referenceClassName = referenceClassName;
+        this.serviceClassName = serviceClassName;
+    }
+
+    public Object getObject() throws NamingException {
+        Class<? extends Service> serviceClass = loadClass(serviceClassName).asSubclass(Service.class);
+        Class<?> referenceClass = getReferenceClass();
+
+        if (referenceClass != null && Service.class.isAssignableFrom(referenceClass)) {
+            serviceClass = referenceClass.asSubclass(Service.class);
+        }
+
+        try {
+            Service instance;
+            if (Service.class.equals(serviceClass)) {
+                instance = ServiceFactory.newInstance().createService(getWsdlURL(), serviceQName);
+            } else {
+                try {
+                    instance = serviceClass.getConstructor(URL.class, QName.class).newInstance(getWsdlURL(), serviceQName);
+                } catch (Throwable e) {
+                    throw (NamingException) new NamingException("Could not instantiate jax-ws service class " + serviceClass.getName()).initCause(e);
+                }
+            }
+
+            if (referenceClass != null && !Service.class.isAssignableFrom(referenceClass)) {
+                // do port lookup
+                return instance.getPort(referenceClass);
+            } else {
+                // return service
+                return instance;
+            }
+        } catch (ServiceException e) {
+            throw (NamingException) new NamingException("Error creating service proxy").initCause(e);
+        }
+    }
+
+    private Class getReferenceClass() throws NamingException {
+        if (referenceClassName == null) return null;
+        return loadClass(referenceClassName);
+    }
+
+    private Class<?> loadClass(String name) throws NamingException {
+        try {
+            return classLoader.loadClass(name);
+        } catch (ClassNotFoundException e) {
+            NamingException exception = new NamingException("Count not load class " + name);
+            exception.initCause(e);
+            throw exception;
+        }
+    }
+
+    private URL getWsdlURL() {
+        if (wsdlURI == null) return null;
+
+        try {
+            return new URL(wsdlURI.toString());
+        } catch (MalformedURLException e) {
+            URL wsdlURL = classLoader.getResource(this.wsdlURI.toString());
+            if (wsdlURL == null) {
+                logger.warning("Error obtaining WSDL: " + this.wsdlURI, e);
+            }
+            return wsdlURL;
+        }
+    }
+}

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxWsServiceReference.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxWsServiceReference.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxWsServiceReference.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/JaxWsServiceReference.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,128 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.core.ivm.naming;
+
+import org.apache.openejb.core.webservices.HandlerResolverImpl;
+import org.apache.openejb.core.webservices.HandlerChainData;
+import org.apache.openejb.core.webservices.PortRefData;
+import org.apache.openejb.core.webservices.WsdlRepo;
+import org.apache.openejb.core.webservices.ProviderWrapper;
+import org.apache.openejb.core.webservices.ServiceRefData;
+import org.apache.openejb.Injection;
+import org.apache.openejb.loader.SystemInstance;
+
+import javax.naming.NamingException;
+import javax.naming.InitialContext;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import javax.xml.ws.handler.HandlerResolver;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.util.List;
+import java.util.ArrayList;
+
+public class JaxWsServiceReference extends Reference {
+    private final Class<? extends Service> serviceClass;
+    private final Class<?> referenceClass;
+    private final URL wsdlUrl;
+    private final QName serviceQName;
+    private final List<HandlerChainData> handlerChains = new ArrayList<HandlerChainData>();
+    private final List<Injection> injections;
+    private WsdlRepo wsdlRepo;
+    private final List<PortRefData> portRefs = new ArrayList<PortRefData>();
+    private String wsdlRepoUri;
+
+    public JaxWsServiceReference(Class<? extends Service> serviceClass, Class<?> referenceClass, URL wsdlUrl, QName serviceQName, String wsdlRepoUri, List<PortRefData> portRefs, List<HandlerChainData> handlerChains, List<Injection> injections) {
+        if (portRefs != null) {
+            this.portRefs.addAll(portRefs);
+        }
+        this.serviceClass = serviceClass;
+        this.referenceClass = referenceClass;
+        this.wsdlUrl = wsdlUrl;
+        this.serviceQName = serviceQName;
+        this.wsdlRepoUri = wsdlRepoUri;
+        if (handlerChains != null) {
+            this.handlerChains.addAll(handlerChains);
+        }
+        this.injections = injections;
+    }
+
+    public Object getObject() throws javax.naming.NamingException {
+        URL wsdlUrl = getWsdlUrl();
+
+        ProviderWrapper.beforeCreate(portRefs);
+        Service instance;
+        try {
+            instance = null;
+            if (Service.class.equals(serviceClass)) {
+                instance = Service.create(wsdlUrl, serviceQName);
+            } else {
+                try {
+                    instance = serviceClass.getConstructor(URL.class, QName.class).newInstance(wsdlUrl, serviceQName);
+                } catch (Throwable e) {
+                    throw (NamingException) new NamingException("Could not instantiate jax-ws service class " + serviceClass.getName()).initCause(e);
+                }
+            }
+        } finally {
+            ProviderWrapper.afterCreate();
+        }
+
+        if (!handlerChains.isEmpty()) {
+            HandlerResolver handlerResolver = new HandlerResolverImpl(handlerChains, injections, new InitialContext());
+            instance.setHandlerResolver(handlerResolver);
+        }
+
+        Object port;
+        if (referenceClass != null && !Service.class.isAssignableFrom(referenceClass)) {
+            // do port lookup
+            port = instance.getPort(referenceClass);
+        } else {
+            // return service
+            port = instance;
+        }
+
+        // register the service data so it can be fetched when the service is passed over the EJBd protocol
+        ServiceRefData serviceRefData = new ServiceRefData(serviceClass, referenceClass, wsdlUrl, serviceQName, null, handlerChains, portRefs);
+        ServiceRefData.putServiceRefData(port, serviceRefData);
+
+        return port;
+    }
+
+    private URL getWsdlUrl() {
+        WsdlRepo wsdlRepo = getWsdlRepo();
+        if (wsdlRepo != null) {
+            String wsdlLocation = wsdlRepo.getWsdl(wsdlRepoUri, serviceQName, referenceClass.getName());
+            if (wsdlLocation != null) {
+                try {
+                    URL wsdlUrl = new URL(wsdlLocation);
+                    return wsdlUrl;
+                } catch (MalformedURLException e) {
+                }
+            }
+        }
+
+        return wsdlUrl;
+    }
+
+    private WsdlRepo getWsdlRepo() {
+        if (wsdlRepo == null) {
+            wsdlRepo = SystemInstance.get().getComponent(WsdlRepo.class);
+        }
+        return wsdlRepo;
+    }
+}

Copied: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/EjbWsContext.java (from r585401, openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/EjbWebServiceContext.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/EjbWsContext.java?p2=openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/EjbWsContext.java&p1=openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/EjbWebServiceContext.java&r1=585401&r2=591858&rev=591858&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/EjbWebServiceContext.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/EjbWsContext.java Sun Nov  4 14:41:49 2007
@@ -24,14 +24,10 @@
 
 import org.apache.openejb.core.ThreadContext;
 
-/**
- * @version $Rev$ $Date$
- */
-public class EjbWebServiceContext implements WebServiceContext {
-
+public class EjbWsContext implements WebServiceContext {
     private SessionContext context;
     
-    public EjbWebServiceContext(SessionContext context) {
+    public EjbWsContext(SessionContext context) {
         this.context = context;
     }
     
@@ -51,5 +47,4 @@
     public boolean isUserInRole(String roleName) {
         return this.context.isCallerInRole(roleName);
     }
-
 }

Propchange: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/EjbWsContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/EjbWsContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/EjbWsContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java?rev=591858&r1=591857&r2=591858&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java Sun Nov  4 14:41:49 2007
@@ -128,7 +128,7 @@
                     try {
                         wsContext = (WebServiceContext) ctx.lookup("java:comp/WebServiceContext");
                     } catch (NamingException e) {
-                        wsContext = new EjbWebServiceContext(sessionContext);
+                        wsContext = new EjbWsContext(sessionContext);
                         ctx.bind("java:comp/WebServiceContext", wsContext);
                     }
                 }

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerChainData.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerChainData.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerChainData.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerChainData.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,51 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.core.webservices;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class HandlerChainData {
+    private final String serviceNamePattern;
+    private final String portNamePattern;
+    private final List<String> protocolBindings = new ArrayList<String>();
+    private final List<HandlerData> handlers = new ArrayList<HandlerData>();
+
+    public HandlerChainData(String serviceNamePattern, String portNamePattern, List<String> protocolBindings, List<HandlerData> handlers) {
+        this.serviceNamePattern = serviceNamePattern;
+        this.portNamePattern = portNamePattern;
+        this.protocolBindings.addAll(protocolBindings);
+        this.handlers.addAll(handlers);
+    }
+
+    public String getServiceNamePattern() {
+        return serviceNamePattern;
+    }
+
+    public String getPortNamePattern() {
+        return portNamePattern;
+    }
+
+    public List<String> getProtocolBindings() {
+        return protocolBindings;
+    }
+
+    public List<HandlerData> getHandlers() {
+        return handlers;
+    }
+}

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerData.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerData.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerData.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerData.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,62 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.core.webservices;
+
+import javax.xml.namespace.QName;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+public class HandlerData {
+    private final Class<?> handlerClass;
+    private final Properties initParams = new Properties();
+    private final List<QName> soapHeaders = new ArrayList<QName>();
+    private final List<String> soapRoles = new ArrayList<String>();
+    private final List<Method> postConstruct = new ArrayList<Method>();
+    private final List<Method> preDestroy = new ArrayList<Method>();
+
+    public HandlerData(Class<?> handlerClass) {
+        if (handlerClass == null) throw new NullPointerException("handlerClass is null");
+        this.handlerClass = handlerClass;
+    }
+
+    public Properties getInitParams() {
+        return initParams;
+    }
+
+    public List<QName> getSoapHeaders() {
+        return soapHeaders;
+    }
+
+    public List<String> getSoapRoles() {
+        return soapRoles;
+    }
+
+    public Class<?> getHandlerClass() {
+        return handlerClass;
+    }
+
+    public List<Method> getPostConstruct() {
+        return postConstruct;
+    }
+
+    public List<Method> getPreDestroy() {
+        return preDestroy;
+    }
+}

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerResolverImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerResolverImpl.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerResolverImpl.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/HandlerResolverImpl.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,185 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.core.webservices;
+
+import org.apache.openejb.Injection;
+import org.apache.openejb.InjectionProcessor;
+
+import javax.naming.Context;
+import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.HandlerResolver;
+import javax.xml.ws.handler.LogicalHandler;
+import javax.xml.ws.handler.PortInfo;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+public class HandlerResolverImpl implements HandlerResolver {
+    private final List<HandlerChainData> handlerChains;
+    private final List<Injection> injections;
+    private final Context context;
+    private final List<InjectionProcessor<Handler>> handlerInstances = new ArrayList<InjectionProcessor<Handler>>();
+
+    public HandlerResolverImpl(List<HandlerChainData> handlerChains, List<Injection> injections, Context context) {
+        this.handlerChains = handlerChains;
+        this.injections = injections;
+        this.context = context;
+    }
+
+    public void destroyHandlers() {
+        List<InjectionProcessor<Handler>> handlerInstances = new ArrayList<InjectionProcessor<Handler>>(this.handlerInstances);
+        this.handlerInstances.clear();
+        for (InjectionProcessor<Handler> handlerInstance : handlerInstances) {
+            handlerInstance.preDestroy();
+        }
+    }
+
+    public List<Handler> getHandlerChain(javax.xml.ws.handler.PortInfo portInfo) {
+        List<Handler> chain = new ArrayList<Handler>();
+        for (HandlerChainData handlerChain : handlerChains) {
+            List<Handler> handlers = buildHandlers(portInfo, handlerChain);
+            handlers = sortHandlers(handlers);
+            chain.addAll(handlers);
+        }
+        chain = sortHandlers(chain);
+        return chain;
+    }
+
+    private List<Handler> buildHandlers(javax.xml.ws.handler.PortInfo portInfo, HandlerChainData handlerChain) {
+        if (!matchServiceName(portInfo, handlerChain.getServiceNamePattern()) ||
+                !matchPortName(portInfo, handlerChain.getPortNamePattern()) ||
+                !matchBinding(portInfo, handlerChain.getProtocolBindings())) {
+            return Collections.emptyList();
+        }
+
+        List<Handler> handlers = new ArrayList<Handler>(handlerChain.getHandlers().size());
+        for (HandlerData handler : handlerChain.getHandlers()) {
+            try {
+                Class<? extends Handler> handlerClass = handler.getHandlerClass().asSubclass(Handler.class);
+                InjectionProcessor<Handler> processor = new InjectionProcessor<Handler>(handlerClass,
+                        injections,
+                        handler.getPostConstruct(),
+                        handler.getPreDestroy(),
+                        context);
+                processor.createInstance();
+                processor.postConstruct();
+                Handler handlerInstance = processor.getInstance();
+
+                handlers.add(handlerInstance);
+                handlerInstances.add(processor);
+            } catch (Exception e) {
+                throw new WebServiceException("Failed to instantiate handler", e);
+            }
+        }
+        return handlers;
+    }
+
+    private boolean matchServiceName(PortInfo info, String namePattern) {
+        return match((info == null ? null : info.getServiceName()), namePattern);
+    }
+
+    private boolean matchPortName(PortInfo info, String namePattern) {
+        return match((info == null ? null : info.getPortName()), namePattern);
+    }
+
+    private boolean matchBinding(PortInfo info, List bindings) {
+        return match((info == null ? null : info.getBindingID()), bindings);
+    }
+
+    private boolean match(String binding, List bindings) {
+        if (binding == null) {
+            return (bindings == null || bindings.isEmpty());
+        } else {
+            if (bindings == null || bindings.isEmpty()) {
+                return true;
+            } else {
+                String actualBindingURI = JaxWsUtils.getBindingURI(binding);
+                Iterator iter = bindings.iterator();
+                while (iter.hasNext()) {
+                    String bindingToken = (String) iter.next();
+                    String bindingURI = JaxWsUtils.getBindingURI(bindingToken);
+                    if (actualBindingURI.equals(bindingURI)) {
+                        return true;
+                    }
+                }
+                return false;
+            }
+        }
+    }
+
+    /**
+     * Performs basic localName matching, namespaces are not checked!
+     */
+    private boolean match(QName name, String namePattern) {
+        if (name == null) {
+            return (namePattern == null || namePattern.equals("*"));
+        } else {
+            if (namePattern == null) {
+                return true;
+            } else {
+                String localNamePattern;
+
+                // get the local name from pattern
+                int pos = namePattern.indexOf(':');
+                localNamePattern = (pos == -1) ? namePattern : namePattern
+                        .substring(pos + 1);
+                localNamePattern = localNamePattern.trim();
+
+                if (localNamePattern.equals("*")) {
+                    // matches anything
+                    return true;
+                } else if (localNamePattern.endsWith("*")) {
+                    // match start
+                    localNamePattern = localNamePattern.substring(0, localNamePattern.length() - 1);
+                    return name.getLocalPart().startsWith(localNamePattern);
+                } else {
+                    // match exact
+                    return name.getLocalPart().equals(localNamePattern);
+                }
+            }
+        }
+    }
+
+    /**
+     * sorts the handlers into correct order. All of the logical handlers first
+     * followed by the protocol handlers
+     *
+     * @param handlers
+     * @return sorted list of handlers
+     */
+    private List<Handler> sortHandlers(List<Handler> handlers) {
+        List<LogicalHandler> logicalHandlers = new ArrayList<LogicalHandler>();
+        List<Handler> protocolHandlers = new ArrayList<Handler>();
+
+        for (Handler handler : handlers) {
+            if (handler instanceof LogicalHandler) {
+                logicalHandlers.add((LogicalHandler) handler);
+            } else {
+                protocolHandlers.add(handler);
+            }
+        }
+
+        List<Handler> sortedHandlers = new ArrayList<Handler>();
+        sortedHandlers.addAll(logicalHandlers);
+        sortedHandlers.addAll(protocolHandlers);
+        return sortedHandlers;
+    }
+}

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/JaxWsUtils.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/JaxWsUtils.java?rev=591858&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/JaxWsUtils.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/JaxWsUtils.java Sun Nov  4 14:41:49 2007
@@ -0,0 +1,288 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.core.webservices;
+
+import javax.jws.WebService;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingType;
+import javax.xml.ws.WebServiceClient;
+import javax.xml.ws.WebServiceProvider;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+public class JaxWsUtils {
+
+    private static final Map<String, String> BINDING_MAP = new HashMap<String, String>();
+
+    static {
+        BINDING_MAP.put("##SOAP11_HTTP", "http://schemas.xmlsoap.org/wsdl/soap/http");
+        BINDING_MAP.put("##SOAP12_HTTP", "http://www.w3.org/2003/05/soap/bindings/HTTP/");
+        BINDING_MAP.put("##SOAP11_HTTP_MTOM", "http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true");
+        BINDING_MAP.put("##SOAP12_HTTP_MTOM", "http://www.w3.org/2003/05/soap/bindings/HTTP/?mtom=true");
+        BINDING_MAP.put("##XML_HTTP", "http://www.w3.org/2004/08/wsdl/http");
+    }
+
+    private JaxWsUtils() {
+    }
+
+    public static QName getPortType(Class<?> seiClass) {
+        WebService webService = seiClass.getAnnotation(WebService.class);
+        if (webService != null) {
+            String localName = webService.name();
+            if (localName == null || localName.length() == 0) {
+                localName = seiClass.getName();
+            }
+            String namespace = webService.targetNamespace();
+            return new QName(getNamespace(seiClass, namespace), localName);
+        }
+        return null;
+    }
+
+    public static String getBindingURI(String token) {
+        if (token != null) {
+            if (token.startsWith("##")) {
+                String uri = BINDING_MAP.get(token);
+                if (uri == null) {
+                    throw new IllegalArgumentException("Unsupported binding token: " + token);
+                }
+                return uri;
+            }
+            return token;
+        }
+        return BINDING_MAP.get("##SOAP11_HTTP");
+    }
+
+    public static boolean isWebService(Class clazz) {
+        return ((clazz.isAnnotationPresent(WebService.class) || clazz.isAnnotationPresent(WebServiceProvider.class)) && isProperWebService(clazz));
+    }
+
+    private static boolean isProperWebService(Class clazz) {
+        int modifiers = clazz.getModifiers();
+        return (Modifier.isPublic(modifiers) && !Modifier.isFinal(modifiers) && !Modifier.isAbstract(modifiers));
+    }
+
+    public static String getServiceName(Class clazz) {
+        return getServiceQName(clazz).getLocalPart();
+    }
+
+    private static String getServiceName(Class clazz, String name) {
+        if (name == null || name.trim().length() == 0) {
+            return clazz.getSimpleName() + "Service";
+        } else {
+            return name.trim();
+        }
+    }
+
+    private static String getPortName(Class clazz, String name, String portName) {
+        if (portName == null || portName.trim().length() == 0) {
+            if (name == null || name.trim().length() == 0) {
+                return clazz.getSimpleName() + "Port";
+            } else {
+                return name + "Port";
+            }
+        } else {
+            return portName.trim();
+        }
+    }
+
+    private static String getNamespace(Class clazz, String namespace) {
+        if (namespace == null || namespace.trim().length() == 0) {
+            Package pkg = clazz.getPackage();
+            if (pkg == null) {
+                return null;
+            } else {
+                return getNamespace(pkg.getName());
+            }
+        } else {
+            return namespace.trim();
+        }
+    }
+
+    private static String getNamespace(String packageName) {
+        if (packageName == null || packageName.length() == 0) {
+            return null;
+        }
+        StringTokenizer tokenizer = new StringTokenizer(packageName, ".");
+        String[] tokens;
+        if (tokenizer.countTokens() == 0) {
+            tokens = new String[0];
+        } else {
+            tokens = new String[tokenizer.countTokens()];
+            for (int i = tokenizer.countTokens() - 1; i >= 0; i--) {
+                tokens[i] = tokenizer.nextToken();
+            }
+        }
+        StringBuffer namespace = new StringBuffer("http://");
+        String dot = "";
+        for (int i = 0; i < tokens.length; i++) {
+            if (i == 1) {
+                dot = ".";
+            }
+            namespace.append(dot).append(tokens[i]);
+        }
+        namespace.append('/');
+        return namespace.toString();
+    }
+
+    private static QName getServiceQName(Class clazz, String namespace, String name) {
+        return new QName(getNamespace(clazz, namespace), getServiceName(clazz, name));
+    }
+
+    public static QName getServiceQName(Class<?> clazz) {
+        WebService webService = clazz.getAnnotation(WebService.class);
+        if (webService != null) {
+            return getServiceQName(clazz, webService.targetNamespace(), webService.serviceName());
+        }
+        WebServiceProvider webServiceProvider = clazz.getAnnotation(WebServiceProvider.class);
+        if (webServiceProvider != null) {
+            return getServiceQName(clazz, webServiceProvider.targetNamespace(), webServiceProvider.serviceName());
+        }
+        WebServiceClient webServiceClient = clazz.getAnnotation(WebServiceClient.class);
+        if (webServiceClient != null) {
+            return getServiceQName(clazz, webServiceClient.targetNamespace(), webServiceClient.name());
+        }
+        throw new IllegalArgumentException("The " + clazz.getName() + " is not annotated");
+    }
+
+    private static QName getPortQName(Class<?> clazz, String namespace, String name, String portName) {
+        return new QName(getNamespace(clazz, namespace), getPortName(clazz, name, portName));
+    }
+
+    public static QName getPortQName(Class<?> clazz) {
+        WebService webService = clazz.getAnnotation(WebService.class);
+        if (webService != null) {
+            return getPortQName(clazz, webService.targetNamespace(), webService.name(), webService.portName());
+        }
+
+        WebServiceProvider webServiceProvider = clazz.getAnnotation(WebServiceProvider.class);
+        if (webServiceProvider != null) {
+            return getPortQName(clazz, webServiceProvider.targetNamespace(), null, webServiceProvider.portName());
+        }
+
+        throw new IllegalArgumentException("The " + clazz.getName() + " is not annotated");
+    }
+
+    public static String getName(Class<?> clazz) {
+        WebService webService = clazz.getAnnotation(WebService.class);
+        if (webService != null) {
+            String sei = webService.endpointInterface();
+            if (sei != null && sei.trim().length() != 0) {
+                try {
+                    Class seiClass = clazz.getClassLoader().loadClass(sei.trim());
+                    return getNameFromInterface(seiClass);
+                } catch (ClassNotFoundException e) {
+                    throw new RuntimeException("Unable to load SEI class: " + sei, e);
+                }
+            }
+            return getName(clazz, webService.name());
+        }
+
+        WebServiceProvider webServiceProvider = clazz.getAnnotation(WebServiceProvider.class);
+        if (webServiceProvider != null) {
+            return clazz.getSimpleName();
+        }
+
+        throw new IllegalArgumentException("The " + clazz.getName() + " is not annotated");
+    }
+
+    private static String getNameFromInterface(Class<?> intf) {
+        WebService webService = intf.getAnnotation(WebService.class);
+        if (webService != null) {
+            return getName(intf, webService.name());
+        }
+        throw new IllegalArgumentException("The " + intf.getName() + " is not annotated");
+    }
+
+    private static String getName(Class clazz, String name) {
+        if (name != null) {
+            name = name.trim();
+            if (name.length() > 0) {
+                return name;
+            }
+        }
+        return clazz.getSimpleName();
+    }
+
+    private static String getWsdlLocation(Class<?> clazz) {
+        WebService webService = clazz.getAnnotation(WebService.class);
+        if (webService != null) {
+            String wsdlLocation = webService.wsdlLocation().trim();
+            if (wsdlLocation.length() == 0) wsdlLocation = null;
+            return wsdlLocation;
+        }
+
+        WebServiceClient webServiceClient = clazz.getAnnotation(WebServiceClient.class);
+        if (webServiceClient != null) {
+            String wsdlLocation = webServiceClient.wsdlLocation().trim();
+            if (wsdlLocation.length() == 0) wsdlLocation = null;
+            return wsdlLocation;
+        }
+
+        WebServiceProvider webServiceProvider = clazz.getAnnotation(WebServiceProvider.class);
+        if (webServiceProvider != null) {
+            String wsdlLocation = webServiceProvider.wsdlLocation().trim();
+            if (wsdlLocation.length() == 0) wsdlLocation = null;
+            return wsdlLocation;
+        }
+
+        return null;
+    }
+
+    public static String getServiceInterface(Class<?> clazz) {
+        WebService webService = clazz.getAnnotation(WebService.class);
+        if (webService != null && webService.endpointInterface() != null) {
+            String endpointInterface = webService.endpointInterface().trim();
+            if (endpointInterface.length() == 0) endpointInterface = null;
+            return endpointInterface;
+        }
+
+        return null;
+    }
+
+    public static String getServiceWsdlLocation(Class<?> clazz, ClassLoader loader) {
+        String wsdlLocation = getWsdlLocation(clazz);
+        if (wsdlLocation != null && !wsdlLocation.equals("")) {
+            return wsdlLocation;
+        }
+
+        String serviceInterfaceClassName = getServiceInterface(clazz);
+        if (serviceInterfaceClassName != null && !serviceInterfaceClassName.equals("")) {
+            try {
+                Class serviceInterfaceClass = loader.loadClass(serviceInterfaceClassName);
+                return getWsdlLocation(serviceInterfaceClass);
+            } catch (Exception e) {
+            }
+        }
+        return null;
+    }
+
+    public static boolean containsWsdlLocation(Class<?> clazz, ClassLoader loader) {
+        String wsdlLocSEIFromAnnotation = getServiceWsdlLocation(clazz, loader);
+        return wsdlLocSEIFromAnnotation != null && !wsdlLocSEIFromAnnotation.equals("");
+    }
+
+    public static String getBindingUriFromAnn(Class<?> clazz) {
+        BindingType bindingType = clazz.getAnnotation(BindingType.class);
+        if (bindingType != null) {
+            return bindingType.value();
+        }
+        return null;
+    }
+}



Mime
View raw message