You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2008/05/30 17:21:39 UTC
svn commit: r661757 - in /cxf/trunk:
common/common/src/main/java/org/apache/cxf/configuration/spring/
rt/core/src/main/java/org/apache/cxf/bus/spring/
rt/core/src/main/resources/META-INF/cxf/
rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/...
Author: dkulp
Date: Fri May 30 08:21:39 2008
New Revision: 661757
URL: http://svn.apache.org/viewvc?rev=661757&view=rev
Log:
[CXF-1619] Patch from Ian Roberts applied. Major thanks!
Added:
cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/BusWiringType.java (with props)
cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java (with props)
Modified:
cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java
cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java
cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java
cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java
cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineFactoryBeanDefinitionParser.java
cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/spring/RMManagerBeanDefinitionParser.java
cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/rmmanager.xml
Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java?rev=661757&r1=661756&r2=661757&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java Fri May 30 08:21:39 2008
@@ -20,6 +20,7 @@
import java.util.Map;
import java.util.StringTokenizer;
+import java.util.logging.Logger;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
@@ -33,6 +34,7 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.CacheMap;
import org.apache.cxf.helpers.DOMUtils;
import org.springframework.beans.factory.BeanDefinitionStoreException;
@@ -46,14 +48,19 @@
public abstract class AbstractBeanDefinitionParser
extends org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser {
+ public static final String WIRE_BUS_ATTRIBUTE = AbstractBeanDefinitionParser.class.getName() + ".wireBus";
+
private static Map<String, JAXBContext> packageContextCache = new CacheMap<String, JAXBContext>();
+
+ private static final Logger LOG = LogUtils.getL7dLogger(AbstractBeanDefinitionParser.class);
+
private Class beanClass;
@Override
protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
boolean setBus = parseAttributes(element, ctx, bean);
- if (!setBus && ctx.getRegistry().containsBeanDefinition("cxf") && hasBusProperty()) {
- wireBus(bean, "cxf");
+ if (!setBus && hasBusProperty()) {
+ addBusWiringAttribute(bean, BusWiringType.PROPERTY);
}
parseChildElements(element, ctx, bean);
}
@@ -219,8 +226,9 @@
return first;
}
- protected void wireBus(BeanDefinitionBuilder bean, String busId) {
- bean.addPropertyReference("bus", busId);
+ protected void addBusWiringAttribute(BeanDefinitionBuilder bean, BusWiringType type) {
+ LOG.fine("Adding " + WIRE_BUS_ATTRIBUTE + " attribute " + type + " to bean " + bean);
+ bean.getRawBeanDefinition().setAttribute(WIRE_BUS_ATTRIBUTE, type);
}
protected void mapElementToJaxbProperty(Element parent,
Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java?rev=661757&r1=661756&r2=661757&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java Fri May 30 08:21:39 2008
@@ -62,8 +62,8 @@
}
}
- if (!setBus && ctx.getRegistry().containsBeanDefinition("cxf")) {
- wireBus(factoryBean, "cxf");
+ if (!setBus) {
+ addBusWiringAttribute(factoryBean, BusWiringType.PROPERTY);
}
NodeList children = element.getChildNodes();
Added: cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/BusWiringType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/BusWiringType.java?rev=661757&view=auto
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/BusWiringType.java (added)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/BusWiringType.java Fri May 30 08:21:39 2008
@@ -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.cxf.configuration.spring;
+
+/**
+ * Enumeration for the ways in which the CXF bus can be wired into a Spring
+ * bean.
+ *
+ * @author Ian Roberts
+ */
+public enum BusWiringType {
+ /**
+ * Wire the bus into the <code>bus</code> property of the target bean.
+ */
+ PROPERTY,
+
+ /**
+ * Wire the bus into the first indexed constructor argument of the target
+ * bean.
+ */
+ CONSTRUCTOR
+}
Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/BusWiringType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/BusWiringType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java?rev=661757&view=auto
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java (added)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java Fri May 30 08:21:39 2008
@@ -0,0 +1,101 @@
+/**
+ * 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.cxf.bus.spring;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser;
+import org.apache.cxf.configuration.spring.BusWiringType;
+import org.apache.cxf.helpers.CastUtils;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.config.ConstructorArgumentValues;
+import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
+
+/**
+ * BeanFactoryPostProcessor that looks for any bean definitions that have the
+ * {@link AbstractBeanDefinitionParser#WIRE_BUS_ATTRIBUTE} attribute set. If the attribute has the value
+ * {@link BusWiringType#PROPERTY} then it attaches their "bus" property to the bean called "cxf". If the
+ * attribute has the value {@link BusWiringType#CONSTRUCTOR} then it shifts any existing indexed constructor
+ * arguments one place to the right and adds a reference to "cxf" as the first constructor argument. This
+ * processor is intended to operate on beans defined via Spring namespace support which require a reference to
+ * the CXF bus.
+ *
+ * @author Ian Roberts
+ */
+public class BusWiringBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
+
+ private static final Logger LOG = LogUtils.getL7dLogger(BusWiringBeanFactoryPostProcessor.class);
+
+ public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException {
+ if (factory.containsBeanDefinition(Bus.DEFAULT_BUS_ID)) {
+ for (String beanName : factory.getBeanDefinitionNames()) {
+ LOG.fine("Checking bean " + beanName);
+ BeanDefinition beanDefinition = factory.getBeanDefinition(beanName);
+ if (BusWiringType.PROPERTY == beanDefinition
+ .getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_ATTRIBUTE)) {
+ LOG.fine("Found " + AbstractBeanDefinitionParser.WIRE_BUS_ATTRIBUTE + " attribute "
+ + BusWiringType.PROPERTY + " on bean " + beanName);
+ beanDefinition.getPropertyValues()
+ .addPropertyValue("bus", new RuntimeBeanReference(Bus.DEFAULT_BUS_ID));
+ } else if (BusWiringType.CONSTRUCTOR == beanDefinition
+ .getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_ATTRIBUTE)) {
+ LOG.fine("Found " + AbstractBeanDefinitionParser.WIRE_BUS_ATTRIBUTE + " attribute "
+ + BusWiringType.CONSTRUCTOR + " on bean " + beanName);
+ ConstructorArgumentValues constructorArgs = beanDefinition.getConstructorArgumentValues();
+ insertConstructorArg(constructorArgs, new RuntimeBeanReference(Bus.DEFAULT_BUS_ID));
+ }
+ }
+ }
+ }
+
+ /**
+ * Insert the given value as the first constructor argument in the given set. To do this, we clear the
+ * argument set, then re-insert all its generic arguments, then re-insert all its indexed arguments with
+ * their indices incremented by 1, and finally set the first indexed argument (at index 0) to the given
+ * value.
+ *
+ * @param constructorArgs the argument definition to modify.
+ * @param valueToInsert the value to insert as the first argument.
+ */
+ private void insertConstructorArg(ConstructorArgumentValues constructorArgs, Object valueToInsert) {
+ List<ValueHolder> genericArgs = new ArrayList<ValueHolder>(CastUtils
+ .<ValueHolder> cast(constructorArgs.getGenericArgumentValues()));
+ Map<Integer, ValueHolder> indexedArgs = new HashMap<Integer, ValueHolder>(CastUtils
+ .<Integer, ValueHolder> cast(constructorArgs.getIndexedArgumentValues()));
+
+ constructorArgs.clear();
+ for (ValueHolder genericValue : genericArgs) {
+ constructorArgs.addGenericArgumentValue(genericValue);
+ }
+ for (Map.Entry<Integer, ValueHolder> entry : indexedArgs.entrySet()) {
+ constructorArgs.addIndexedArgumentValue(entry.getKey() + 1, entry.getValue());
+ }
+ constructorArgs.addIndexedArgumentValue(0, valueToInsert);
+ }
+}
Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml?rev=661757&r1=661756&r2=661757&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml (original)
+++ cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml Fri May 30 08:21:39 2008
@@ -24,6 +24,7 @@
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl"/>
+ <bean id="org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor" class="org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor"/>
<bean id="org.apache.cxf.bus.spring.Jsr250BeanPostProcessor" class="org.apache.cxf.bus.spring.Jsr250BeanPostProcessor"/>
<bean id="org.apache.cxf.bus.spring.BusExtensionPostProcessor" class="org.apache.cxf.bus.spring.BusExtensionPostProcessor"/>
Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java?rev=661757&r1=661756&r2=661757&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java (original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java Fri May 30 08:21:39 2008
@@ -29,10 +29,10 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.apache.cxf.Bus;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser;
+import org.apache.cxf.configuration.spring.BusWiringType;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.FatalBeanException;
import org.springframework.beans.factory.BeanDefinitionStoreException;
@@ -61,13 +61,9 @@
NamedNodeMap atts = element.getAttributes();
String bus = element.getAttribute("bus");
if (StringUtils.isEmpty(bus)) {
- if (ctx.getRegistry().containsBeanDefinition(Bus.DEFAULT_BUS_ID)) {
- bean.addConstructorArgReference(Bus.DEFAULT_BUS_ID);
- }
+ addBusWiringAttribute(bean, BusWiringType.CONSTRUCTOR);
} else {
- if (ctx.getRegistry().containsBeanDefinition(bus)) {
- bean.addConstructorArgReference(bus);
- }
+ bean.addConstructorArgReference(bus);
}
for (int i = 0; i < atts.getLength(); i++) {
Attr node = (Attr) atts.item(i);
Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java?rev=661757&r1=661756&r2=661757&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java (original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineBeanDefinitionParser.java Fri May 30 08:21:39 2008
@@ -30,6 +30,7 @@
import org.apache.cxf.configuration.jsse.spring.TLSServerParametersConfig;
import org.apache.cxf.configuration.security.TLSServerParametersType;
import org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser;
+import org.apache.cxf.configuration.spring.BusWiringType;
import org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine;
import org.apache.cxf.transport.http_jetty.ThreadingParameters;
import org.apache.cxf.transports.http_jetty.configuration.TLSServerParametersIdentifiedType;
@@ -114,7 +115,12 @@
throw new RuntimeException("Could not process configuration.", e);
}
- bean.addPropertyValue("bus", busValue.getValue());
+ // if the containing bean is having the bus wired up by the post processor then we should too
+ if (ctx.getContainingBeanDefinition().getAttribute(WIRE_BUS_ATTRIBUTE) == BusWiringType.PROPERTY) {
+ addBusWiringAttribute(bean, BusWiringType.PROPERTY);
+ } else {
+ bean.addPropertyValue("bus", busValue.getValue());
+ }
bean.setLazyInit(false);
Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineFactoryBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineFactoryBeanDefinitionParser.java?rev=661757&r1=661756&r2=661757&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineFactoryBeanDefinitionParser.java (original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/spring/JettyHTTPServerEngineFactoryBeanDefinitionParser.java Fri May 30 08:21:39 2008
@@ -33,6 +33,7 @@
import org.apache.cxf.configuration.jsse.TLSServerParameters;
import org.apache.cxf.configuration.jsse.spring.TLSServerParametersConfig;
import org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser;
+import org.apache.cxf.configuration.spring.BusWiringType;
import org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory;
import org.apache.cxf.transport.http_jetty.ThreadingParameters;
@@ -73,9 +74,7 @@
if (StringUtils.isEmpty(bus)) {
- if (ctx.getRegistry().containsBeanDefinition("cxf")) {
- bean.addPropertyReference("bus", "cxf");
- }
+ addBusWiringAttribute(bean, BusWiringType.PROPERTY);
} else {
bean.addPropertyReference("bus", bus);
}
Modified: cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/spring/RMManagerBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/spring/RMManagerBeanDefinitionParser.java?rev=661757&r1=661756&r2=661757&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/spring/RMManagerBeanDefinitionParser.java (original)
+++ cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/spring/RMManagerBeanDefinitionParser.java Fri May 30 08:21:39 2008
@@ -24,6 +24,7 @@
import org.w3c.dom.Element;
import org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser;
+import org.apache.cxf.configuration.spring.BusWiringType;
import org.apache.cxf.ws.rm.RMManager;
import org.apache.cxf.ws.rm.policy.RMAssertion;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -50,8 +51,8 @@
ctx.getDelegate().parsePropertyElements(element, bean.getBeanDefinition());
String bus = element.getAttribute("bus");
- if (bus == null || "".equals(bus) && ctx.getRegistry().containsBeanDefinition("cxf")) {
- bean.addPropertyReference("bus", "cxf");
+ if (bus == null || "".equals(bus)) {
+ addBusWiringAttribute(bean, BusWiringType.PROPERTY);
} else {
bean.addPropertyReference("bus", bus);
}
Modified: cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/rmmanager.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/rmmanager.xml?rev=661757&r1=661756&r2=661757&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/rmmanager.xml (original)
+++ cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/rmmanager.xml Fri May 30 08:21:39 2008
@@ -27,6 +27,7 @@
<property name="bus" ref="cxf"/>
</bean>
<bean class="org.apache.cxf.bus.spring.Jsr250BeanPostProcessor"/>
+ <bean class="org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor"/>
<import resource="../../../../../META-INF/cxf/cxf-extension-rm.xml"/>
</beans>