Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 72450 invoked from network); 2 Feb 2007 15:51:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Feb 2007 15:51:31 -0000 Received: (qmail 19130 invoked by uid 500); 2 Feb 2007 15:51:37 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 19096 invoked by uid 500); 2 Feb 2007 15:51:37 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 19071 invoked by uid 99); 2 Feb 2007 15:51:37 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Feb 2007 07:51:37 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Feb 2007 07:51:29 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 75FD41A981A; Fri, 2 Feb 2007 07:51:09 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r502637 - in /geronimo/server/trunk/modules: geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/ geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/ Date: Fri, 02 Feb 2007 15:51:09 -0000 To: scm@geronimo.apache.org From: dims@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070202155109.75FD41A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dims Date: Fri Feb 2 07:51:07 2007 New Revision: 502637 URL: http://svn.apache.org/viewvc?view=rev&rev=502637 Log: Fix for GERONIMO-2791 - Switching ServiceRef naming builder Added: geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFServiceRefBuilder.java geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/ServiceRefBuilder.java geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/SwitchingServiceRefBuilder.java Added: geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFServiceRefBuilder.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFServiceRefBuilder.java?view=auto&rev=502637 ============================================================================== --- geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFServiceRefBuilder.java (added) +++ geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFServiceRefBuilder.java Fri Feb 2 07:51:07 2007 @@ -0,0 +1,207 @@ +/** + * 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.cxf.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 org.apache.geronimo.common.DeploymentException; +import org.apache.geronimo.gbean.GBeanInfo; +import org.apache.geronimo.gbean.GBeanInfoBuilder; +import org.apache.geronimo.j2ee.deployment.Module; +import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; +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 class CXFServiceRefBuilder 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; + private final CXFBuilder cxfBuilder; + + public CXFServiceRefBuilder(Environment defaultEnvironment, + String[] eeNamespaces, + CXFBuilder cxfBuilder) { + super(defaultEnvironment); + this.cxfBuilder = cxfBuilder; + 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 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 name, ClassLoader cl) throws DeploymentException { + try { + return cl.loadClass(name); + } catch (ClassNotFoundException e) { + throw new DeploymentException("Could not load service class " + name, 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(); + Class jaxwsServiceClass = loadClass("javax.xml.ws.Service", cl); + String name = getStringValue(serviceRef.getServiceRefName()); + String serviceInterfaceName = getStringValue(serviceRef.getServiceInterface()); + Class serviceInterfaceClass = loadClass(serviceInterfaceName, cl); + + if (!jaxwsServiceClass.isAssignableFrom(serviceInterfaceClass)) { + throw new DeploymentException(serviceInterfaceName + " class does not extend " + jaxwsServiceClass.getName()); + } + // TODO: check if service class is abstract??? + + QName serviceQName = null; + if (serviceRef.isSetServiceQname()) { + serviceQName = serviceRef.getServiceQname().getQNameValue(); + } + + URI wsdlURI = null; + if (serviceRef.isSetWsdlFile()) { + try { + wsdlURI = new URI(serviceRef.getWsdlFile().getStringValue().trim()); + } catch (URISyntaxException e) { + throw new DeploymentException("could not construct wsdl uri from " + serviceRef.getWsdlFile().getStringValue(), e); + } + } + + Class serviceReferenceType = null; + if (serviceRef.isSetServiceRefType()) { + String referenceClassName = getStringValue(serviceRef.getServiceRefType()); + serviceReferenceType = loadClass(referenceClassName, cl); + } + + // TODO: handle handler chains + if (serviceRef.isSetHandlerChains()) { + ServiceRefHandlerChainsType handlerChains = serviceRef.getHandlerChains(); + for (ServiceRefHandlerChainType handlerChain : handlerChains.getHandlerChainArray()) { + // bindings, port, service + for (ServiceRefHandlerType handler : handlerChain.getHandlerArray()) { + // handler class + } + } + } + + 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); + String portComponentLink = getStringValue(portComponentRef.getPortComponentLink()); + + portComponentRefMap.put(serviceEndpointClass, portComponentLink); + } + } + + Object ref = cxfBuilder.createService(serviceInterfaceClass, serviceReferenceType, wsdlURI, serviceQName, portComponentRefMap, serviceRef.getHandlerChains(), gerServiceRef, module, cl); + getJndiContextMap(componentContext).put(ENV + name, ref); + } + + 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; + } + + public static final GBeanInfo GBEAN_INFO; + + static { + GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic( + CXFServiceRefBuilder.class, NameFactory.MODULE_BUILDER); + infoBuilder.addInterface(ServiceRefBuilder.class); + infoBuilder.addAttribute("defaultEnvironment", Environment.class, true, + true); + infoBuilder.addAttribute("eeNamespaces", String[].class, true, true); + infoBuilder.addReference("CXFBuilder", CXFBuilder.class, + NameFactory.MODULE_BUILDER); + + infoBuilder.setConstructor(new String[] { "defaultEnvironment", + "eeNamespaces", "CXFBuilder" }); + + GBEAN_INFO = infoBuilder.getBeanInfo(); + } + + public static GBeanInfo getGBeanInfo() { + return GBEAN_INFO; + } + + +} Added: geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/ServiceRefBuilder.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/ServiceRefBuilder.java?view=auto&rev=502637 ============================================================================== --- geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/ServiceRefBuilder.java (added) +++ geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/ServiceRefBuilder.java Fri Feb 2 07:51:07 2007 @@ -0,0 +1,39 @@ +/** + * 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.naming.deployment; + +import java.util.Map; + +import org.apache.geronimo.common.DeploymentException; + +import org.apache.geronimo.j2ee.deployment.Module; + +import org.apache.geronimo.kernel.repository.Environment; + +import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType; + +import org.apache.xmlbeans.XmlObject; + +public interface ServiceRefBuilder { + void buildNaming(XmlObject serviceRef, + GerServiceRefType serviceRefType, + Module module, + Map componentContext) throws DeploymentException; + + Environment getEnvironment(); +} Added: geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/SwitchingServiceRefBuilder.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/SwitchingServiceRefBuilder.java?view=auto&rev=502637 ============================================================================== --- geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/SwitchingServiceRefBuilder.java (added) +++ geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/SwitchingServiceRefBuilder.java Fri Feb 2 07:51:07 2007 @@ -0,0 +1,214 @@ +/** + * 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.naming.deployment; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.geronimo.common.DeploymentException; +import org.apache.geronimo.deployment.service.EnvironmentBuilder; +import org.apache.geronimo.gbean.GBeanInfo; +import org.apache.geronimo.gbean.GBeanInfoBuilder; +import org.apache.geronimo.j2ee.deployment.Module; +import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; +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.xbeans.geronimo.naming.GerServiceRefDocument; +import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType; +import org.apache.geronimo.xbeans.javaee.ServiceRefType; + +import org.apache.xmlbeans.QNameSet; +import org.apache.xmlbeans.XmlObject; + +public class SwitchingServiceRefBuilder extends AbstractNamingBuilder { + + 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; + + private final Collection jaxrpcBuilders; + + private final Collection jaxwsBuilders; + + private Environment environment; + + public SwitchingServiceRefBuilder(String[] eeNamespaces, + Collection jaxrpcBuilders, + Collection jaxwsBuilders) { + super(null); + this.jaxrpcBuilders = jaxrpcBuilders; + this.jaxwsBuilders = jaxwsBuilders; + this.serviceRefQNameSet = buildQNameSet(eeNamespaces, "service-ref"); + } + + public void buildEnvironment(XmlObject specDD, + XmlObject plan, + Environment environment) + throws DeploymentException { + this.environment = environment; + } + + public void buildNaming(XmlObject specDD, + XmlObject plan, + Configuration localConfiguration, + Configuration remoteConfiguration, + Module module, + Map componentContext) throws DeploymentException { + ClassLoader cl = module.getEarContext().getClassLoader(); + Class jaxrpcClass = loadClass("javax.xml.rpc.Service", cl); + Class jaxwsClass = loadClass("javax.xml.ws.Service", cl); + + boolean mergedJAXRPCEnv = false; + boolean mergedJAXWSEnv = false; + + XmlObject[] serviceRefs = specDD.selectChildren(serviceRefQNameSet); + + XmlObject[] gerServiceRefsUntyped = plan == null ? NO_REFS : plan + .selectChildren(GER_SERVICE_REF_QNAME_SET); + Map serviceRefMap = mapServiceRefs(gerServiceRefsUntyped); + + for (XmlObject serviceRef : serviceRefs) { + ServiceRefType serviceRefType = (ServiceRefType) convert( + serviceRef, JEE_CONVERTER, ServiceRefType.type); + + String name = getStringValue(serviceRefType.getServiceRefName()); + GerServiceRefType gerServiceRefType = (GerServiceRefType) serviceRefMap + .get(name); + + String serviceInterfaceName = getStringValue(serviceRefType + .getServiceInterface()); + Class serviceInterfaceClass = loadClass(serviceInterfaceName, cl); + + if (jaxrpcClass.isAssignableFrom(serviceInterfaceClass)) { + // class jaxrpc handler + ServiceRefBuilder jaxrpcBuilder = getJAXRCPBuilder(); + jaxrpcBuilder.buildNaming(serviceRef, gerServiceRefType, + module, componentContext); + if (!mergedJAXRPCEnv) { + mergeEnvironment(jaxrpcBuilder); + mergedJAXRPCEnv = true; + } + } else if (jaxwsClass.isAssignableFrom(serviceInterfaceClass)) { + // calll jaxws handler + ServiceRefBuilder jaxwsBuilder = getJAXWSBuilder(); + jaxwsBuilder.buildNaming(serviceRef, gerServiceRefType, module, + componentContext); + if (!mergedJAXWSEnv) { + mergeEnvironment(jaxwsBuilder); + mergedJAXWSEnv = true; + } + } else { + throw new DeploymentException(serviceInterfaceName + + " does not extend " + + jaxrpcClass.getName() + " or " + + jaxwsClass.getName()); + } + } + } + + private ServiceRefBuilder getJAXWSBuilder() throws DeploymentException { + ServiceRefBuilder jaxwsBuilder = null; + if (this.jaxwsBuilders == null || this.jaxwsBuilders.isEmpty()) { + throw new DeploymentException( + "No JAX-WS ServiceRefBuilders registered"); + } else { + jaxwsBuilder = (ServiceRefBuilder) this.jaxwsBuilders.iterator() + .next(); + } + return jaxwsBuilder; + } + + private ServiceRefBuilder getJAXRCPBuilder() throws DeploymentException { + ServiceRefBuilder jaxrpcBuilder = null; + if (this.jaxrpcBuilders == null || this.jaxrpcBuilders.isEmpty()) { + throw new DeploymentException( + "No JAX-RPC ServiceRefBuilders registered"); + } else { + jaxrpcBuilder = (ServiceRefBuilder) this.jaxrpcBuilders.iterator() + .next(); + } + return jaxrpcBuilder; + } + + private void mergeEnvironment(ServiceRefBuilder builder) { + Environment env = builder.getEnvironment(); + if (env != null) { + EnvironmentBuilder.mergeEnvironments(this.environment, env); + } + } + + private Class loadClass(String name, ClassLoader cl) + throws DeploymentException { + try { + return cl.loadClass(name); + } catch (ClassNotFoundException e) { + throw new DeploymentException("Could not load service class " + + name, e); + } + } + + 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; + } + + public static final GBeanInfo GBEAN_INFO; + + static { + GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic( + SwitchingServiceRefBuilder.class, NameFactory.MODULE_BUILDER); + infoBuilder.addAttribute("eeNamespaces", String[].class, true, true); + infoBuilder.addReference("JAXRPCBuilder", ServiceRefBuilder.class, + NameFactory.MODULE_BUILDER); + infoBuilder.addReference("JAXWSBuilder", ServiceRefBuilder.class, + NameFactory.MODULE_BUILDER); + + infoBuilder.setConstructor(new String[] { "eeNamespaces", + "JAXRPCBuilder", "JAXWSBuilder" }); + + GBEAN_INFO = infoBuilder.getBeanInfo(); + } + + public static GBeanInfo getGBeanInfo() { + return GBEAN_INFO; + } +}