geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r503682 [2/2] - in /geronimo/server/trunk/modules: geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/ geronimo-cxf/src/main/java/org/apache/geronimo/cxf/ geronimo-cxf/src/test/ geronimo-cxf/src/test/java/ geronimo-cxf/src/t...
Date Mon, 05 Feb 2007 13:58:44 GMT
Added: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceRefBuilder.java?view=auto&rev=503682
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceRefBuilder.java
(added)
+++ geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceRefBuilder.java
Mon Feb  5 05:58:42 2007
@@ -0,0 +1,188 @@
+/**
+ *  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.geronimo.jaxws.builder;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import javax.xml.ws.handler.Handler;
+
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.j2ee.deployment.Module;
+import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.naming.deployment.AbstractNamingBuilder;
+import org.apache.geronimo.naming.deployment.ServiceRefBuilder;
+import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefDocument;
+import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType;
+import org.apache.geronimo.xbeans.javaee.PortComponentRefType;
+import org.apache.geronimo.xbeans.javaee.ServiceRefHandlerChainType;
+import org.apache.geronimo.xbeans.javaee.ServiceRefHandlerChainsType;
+import org.apache.geronimo.xbeans.javaee.ServiceRefHandlerType;
+import org.apache.geronimo.xbeans.javaee.ServiceRefType;
+
+import org.apache.xmlbeans.QNameSet;
+import org.apache.xmlbeans.XmlObject;
+
+public abstract class JAXWSServiceRefBuilder extends AbstractNamingBuilder implements ServiceRefBuilder
{
+
+    private static final QName GER_SERVICE_REF_QNAME = 
+        GerServiceRefDocument.type.getDocumentElementName();
+
+    private static final QNameSet GER_SERVICE_REF_QNAME_SET = 
+        QNameSet.singleton(GER_SERVICE_REF_QNAME);
+
+    private final QNameSet serviceRefQNameSet;
+    
+    public JAXWSServiceRefBuilder(Environment defaultEnvironment,
+                                  String[] eeNamespaces) {
+        super(defaultEnvironment);
+        serviceRefQNameSet = buildQNameSet(eeNamespaces, "service-ref");
+    }
+
+    protected boolean willMergeEnvironment(XmlObject specDD, XmlObject plan) {
+        return specDD.selectChildren(serviceRefQNameSet).length > 0;
+    }
+
+    public void buildNaming(XmlObject specDD,
+                            XmlObject plan,
+                            Configuration localConfiguration,
+                            Configuration remoteConfiguration,
+                            Module module,
+                            Map componentContext) throws DeploymentException {       
+        List<ServiceRefType> serviceRefsUntyped = convert(specDD.selectChildren(serviceRefQNameSet),
JEE_CONVERTER, ServiceRefType.class, ServiceRefType.type);
+        XmlObject[] gerServiceRefsUntyped = plan == null ? NO_REFS : plan.selectChildren(GER_SERVICE_REF_QNAME_SET);
+        Map serviceRefMap = mapServiceRefs(gerServiceRefsUntyped);
+        
+        for (ServiceRefType serviceRef : serviceRefsUntyped) {
+            String name = getStringValue(serviceRef.getServiceRefName());            
+            GerServiceRefType serviceRefType = (GerServiceRefType) serviceRefMap.get(name);
+            
+            buildNaming(serviceRef, serviceRefType, module, componentContext);
+        }        
+    }
+
+    private Class loadClass(String className, ClassLoader cl, String classDescription) throws
DeploymentException {
+        try {
+            return cl.loadClass(className);
+        } catch (ClassNotFoundException e) {
+            throw new DeploymentException("Could not load " + classDescription + " class
" + className, e);                
+        }         
+    }
+    
+    public void buildNaming(XmlObject serviceRef, GerServiceRefType gerServiceRefType, Module
module, Map componentContext) throws DeploymentException {
+        ServiceRefType serviceRefType = 
+            (ServiceRefType)convert(serviceRef, JEE_CONVERTER, ServiceRefType.type);
+        buildNaming(serviceRefType, gerServiceRefType, module, componentContext);
+    }
+    
+    public void buildNaming(ServiceRefType serviceRef, GerServiceRefType gerServiceRef, Module
module, Map componentContext) throws DeploymentException {
+        ClassLoader cl = module.getEarContext().getClassLoader();        
+        String name = getStringValue(serviceRef.getServiceRefName());
+        
+        String serviceInterfaceName = getStringValue(serviceRef.getServiceInterface());
+        Class serviceInterfaceClass = loadClass(serviceInterfaceName, cl, "service");   
    
+        if (!Service.class.isAssignableFrom(serviceInterfaceClass)) {
+            throw new DeploymentException(serviceInterfaceName + " service class does not
extend " + Service.class.getName());
+        }
+        
+        QName serviceQName = null;
+        if (serviceRef.isSetServiceQname()) {
+            serviceQName = serviceRef.getServiceQname().getQNameValue();
+        }
+        
+        URI wsdlURI = null;
+        if (serviceRef.isSetWsdlFile()) {
+            String wsdlLocation = serviceRef.getWsdlFile().getStringValue().trim();
+            try {
+                wsdlURI = new URI(wsdlLocation);
+            } catch (URISyntaxException e) {
+                throw new DeploymentException("Could not construct WSDL URI from " + wsdlLocation,
e);
+            }
+        }
+        
+        Class serviceReferenceType = null;
+        if (serviceRef.isSetServiceRefType()) {
+            String referenceClassName = getStringValue(serviceRef.getServiceRefType()); 
          
+            serviceReferenceType = loadClass(referenceClassName, cl, "service reference");
+        }
+  
+        if (serviceRef.isSetHandlerChains()) {                   
+            ServiceRefHandlerChainsType handlerChains = serviceRef.getHandlerChains();
+            for (ServiceRefHandlerChainType handlerChain : handlerChains.getHandlerChainArray())
{               
+                for (ServiceRefHandlerType handler : handlerChain.getHandlerArray()) {
+                    String handlerClassName = getStringValue(handler.getHandlerClass());
+                    Class handlerClass = loadClass(handlerClassName, cl, "handler");
+                    if (!Handler.class.isAssignableFrom(handlerClass)) {
+                        throw new DeploymentException(handlerClassName + " handler class
does not extend " + Handler.class.getName());
+                    }
+                }
+            }
+        }
+                       
+        Map portComponentRefMap = new HashMap();
+        PortComponentRefType[] portComponentRefs = serviceRef.getPortComponentRefArray();
+        if (portComponentRefs != null) {
+            for (int j = 0; j < portComponentRefs.length; j++) {
+                PortComponentRefType portComponentRef = portComponentRefs[j];
+                String serviceEndpointInterfaceType = getStringValue(portComponentRef.getServiceEndpointInterface());
+                Class serviceEndpointClass = loadClass(serviceEndpointInterfaceType, cl,
"service endpoint");
+                // TODO: check if it is annotated?
+                String portComponentLink = getStringValue(portComponentRef.getPortComponentLink());
+                
+                portComponentRefMap.put(serviceEndpointClass, portComponentLink);
+            }
+        }
+        
+        Object ref = createService(serviceRef, gerServiceRef, module, cl,
+                                   serviceInterfaceClass, serviceQName, 
+                                   wsdlURI, serviceReferenceType, portComponentRefMap);
+        getJndiContextMap(componentContext).put(ENV + name, ref);
+    }
+
+    public abstract Object createService(ServiceRefType serviceRef, GerServiceRefType gerServiceRef,

+                                         Module module, ClassLoader cl, Class serviceInterfaceClass,

+                                         QName serviceQName, URI wsdlURI, Class serviceReferenceType,

+                                         Map portComponentRefMap) throws DeploymentException;
+       
+    private static Map mapServiceRefs(XmlObject[] refs) {
+        Map refMap = new HashMap();
+        if (refs != null) {
+            for (int i = 0; i < refs.length; i++) {
+                GerServiceRefType ref = (GerServiceRefType) refs[i].copy()
+                        .changeType(GerServiceRefType.type);
+                String serviceRefName = ref.getServiceRefName().trim();
+                refMap.put(serviceRefName, ref);
+            }
+        }
+        return refMap;
+    }
+
+    public QNameSet getSpecQNameSet() {
+        return serviceRefQNameSet;
+    }
+
+    public QNameSet getPlanQNameSet() {
+        return GER_SERVICE_REF_QNAME_SET;
+    }
+
+}

Added: geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/HandlerChainsUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/HandlerChainsUtils.java?view=auto&rev=503682
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/HandlerChainsUtils.java
(added)
+++ geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/HandlerChainsUtils.java
Mon Feb  5 05:58:42 2007
@@ -0,0 +1,46 @@
+/**
+ *  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.geronimo.jaxws;
+
+import java.io.StringReader;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+
+public class HandlerChainsUtils {
+
+    private HandlerChainsUtils() {
+    }
+
+    public static <T> T toHandlerChains(String xml, Class<T> type)
+            throws JAXBException {
+        T handlerChains = null;
+        if (xml != null) {
+            JAXBContext ctx = JAXBContext.newInstance(type);
+            Unmarshaller unmarshaller = ctx.createUnmarshaller();
+            StringReader reader = new StringReader(xml);
+            StreamSource in = new StreamSource(reader);
+            JAXBElement<T> handlerElement = unmarshaller.unmarshal(in, type);
+            handlerChains = handlerElement.getValue();
+        }
+        return handlerChains;
+    }
+
+}

Modified: geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JNDIResolver.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JNDIResolver.java?view=diff&rev=503682&r1=503681&r2=503682
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JNDIResolver.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/JNDIResolver.java
Mon Feb  5 05:58:42 2007
@@ -18,7 +18,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.geronimo.naming.java.RootContext;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -29,27 +28,14 @@
     private static final Log LOG = 
         LogFactory.getLog(JNDIResolver.class.getName());
 
-    private Context componentContext;
-
-    public JNDIResolver(Context context) {
-        this.componentContext = context;
-    }
-
     public Object resolve(String name, Class clz) throws NamingException {
-        Context oldContext = RootContext.getComponentContext();
-        try {
-            RootContext.setComponentContext(componentContext);
-
-            Context ctx = new InitialContext();
-            ctx = (Context) ctx.lookup("java:comp/env");
+        Context ctx = new InitialContext();
+        ctx = (Context) ctx.lookup("java:comp/env");
 
-            LOG.debug("Looking up '" + name + "'");
+        LOG.debug("Looking up '" + name + "'");
 
-            Object o = ctx.lookup(name);
+        Object o = ctx.lookup(name);
 
-            return clz.cast(o);
-        } finally {
-            RootContext.setComponentContext(oldContext);
-        }
+        return clz.cast(o);
     }
 }

Modified: geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/PortInfo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/PortInfo.java?view=diff&rev=503682&r1=503681&r2=503682
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/PortInfo.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/PortInfo.java
Mon Feb  5 05:58:42 2007
@@ -17,19 +17,12 @@
 package org.apache.geronimo.jaxws;
 
 import java.io.Serializable;
-import java.io.StringReader;
 import java.io.StringWriter;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
 
 public class PortInfo implements Serializable {
 
@@ -128,32 +121,15 @@
          * Since HandlerChainsType is a type, have to wrap it into some element
          */
         QName rootElement = new QName("", "root");
-        JAXBElement element = new JAXBElement(rootElement,
-                type, handlerChain);
+        JAXBElement element = 
+            new JAXBElement(rootElement, type, handlerChain);
         m.marshal(element, writer);
 
         this.handlersAsXML = writer.toString();
     }
 
-    public Object getHandlers(Class type) throws Exception {
-        if (this.handlersAsXML == null) {
-            return null;
-        }
-
-        InputSource is = new InputSource(new StringReader(this.handlersAsXML));
-
-        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-        dbf.setNamespaceAware(true);
-        DocumentBuilder db = dbf.newDocumentBuilder();
-        Document doc = db.parse(is);
-
-        JAXBContext ctx = JAXBContext.newInstance(type);
-        Unmarshaller unmarshaller = ctx.createUnmarshaller();
-
-        JAXBElement handlerElement = unmarshaller.unmarshal(
-                doc.getDocumentElement(), type);
-
-        return handlerElement.getValue();
+    public <T>T getHandlers(Class<T> type) throws Exception {
+        return HandlerChainsUtils.toHandlerChains(this.handlersAsXML, type);
     }
 
     public QName getWsdlPort() {

Added: geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/ServerJNDIResolver.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/ServerJNDIResolver.java?view=auto&rev=503682
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/ServerJNDIResolver.java
(added)
+++ geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/ServerJNDIResolver.java
Mon Feb  5 05:58:42 2007
@@ -0,0 +1,41 @@
+/**
+ *  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.geronimo.jaxws;
+
+import org.apache.geronimo.naming.java.RootContext;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+public class ServerJNDIResolver extends JNDIResolver {
+
+    private Context componentContext;
+
+    public ServerJNDIResolver(Context context) {
+        this.componentContext = context;
+    }
+
+    public Object resolve(String name, Class clz) throws NamingException {
+        Context oldContext = RootContext.getComponentContext();
+        try {
+            RootContext.setComponentContext(componentContext);
+            return super.resolve(name, clz);
+        } finally {
+            RootContext.setComponentContext(oldContext);
+        }
+    }
+}



Mime
View raw message