Author: dandiep
Date: Tue Jun 26 14:50:27 2007
New Revision: 550965
URL: http://svn.apache.org/viewvc?view=rev&rev=550965
Log:
Add a BusDefinitionParser to allow Features to be applied to the Bus.
Refactor the BeanDefinitionParser to include a FactoryBeanDefinitionParser
which makes it much easier to create beans which have properties applied to
a factory.
Added:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java
(with props)
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java
(with props)
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/NamespaceHandler.java
(with props)
incubator/cxf/trunk/rt/core/src/main/resources/META-INF/spring.schemas
(with props)
incubator/cxf/trunk/rt/core/src/main/resources/schemas/bus.xsd (with
props)
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java
(with props)
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/bus.xml
(with props)
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java
incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
incubator/cxf/trunk/rt/core/src/main/resources/META-INF/spring.handlers
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/JaxWsProxyFactoryBeanDefinitionParser.java
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/spring/ClientProxyFactoryBeanDefinitionParser.java
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/spring/ServerFactoryBeanDefinitionParser.java
incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java
Added:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java?view=auto&rev=550965
==============================================================================
---
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java
(added)
+++
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java
Tue Jun 26 14:50:27 2007
@@ -0,0 +1,325 @@
+/**
+ * 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;
+
+import java.util.StringTokenizer;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.BeanDefinitionHolder;
+import org.springframework.beans.factory.support.AbstractBeanDefinition;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.util.StringUtils;
+
+public abstract class AbstractBeanDefinitionParser
+ extends
org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser {
+
+ private Class beanClass;
+
+ @Override
+ protected void doParse(Element element, ParserContext ctx,
BeanDefinitionBuilder bean) {
+ NamedNodeMap atts = element.getAttributes();
+ boolean setBus = false;
+ for (int i = 0; i < atts.getLength(); i++) {
+ Attr node = (Attr) atts.item(i);
+ String val = node.getValue();
+ String name = node.getLocalName();
+
+ if ("createdFromAPI".equals(name)) {
+ bean.setAbstract(true);
+ } else if ("abstract".equals(name)) {
+ bean.setAbstract(true);
+ } else if (!"id".equals(name) && !"name".equals(name)) {
+ if ("bus".equals(name)) {
+ setBus = true;
+ }
+ mapAttribute(bean, element, name, val);
+ }
+ }
+
+ if (!setBus && ctx.getRegistry().containsBeanDefinition("cxf") &&
hasBusProperty()) {
+ wireBus(bean, "cxf");
+ }
+
+ NodeList children = element.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node n = children.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE) {
+ String name = n.getLocalName();
+
+ mapElement(ctx, bean, (Element) n, name);
+ }
+ }
+ }
+
+ public Class getBeanClass() {
+ return beanClass;
+ }
+
+ public void setBeanClass(Class beanClass) {
+ this.beanClass = beanClass;
+ }
+
+ @Override
+ protected Class getBeanClass(Element e) {
+ return beanClass;
+ }
+
+ protected void mapAttribute(BeanDefinitionBuilder bean, Element e, String
name, String val) {
+ mapAttribute(bean, name, val);
+ }
+
+ protected void mapAttribute(BeanDefinitionBuilder bean, String name,
String val) {
+ mapToProperty(bean, name, val);
+ }
+
+ protected void mapElement(ParserContext ctx, BeanDefinitionBuilder bean,
Element e, String name) {
+ }
+
+ @Override
+ protected String resolveId(Element elem, AbstractBeanDefinition
definition,
+ ParserContext ctx) throws
BeanDefinitionStoreException {
+
+ // REVISIT: use getAttributeNS instead
+
+ String id = getIdOrName(elem);
+ String createdFromAPI =
elem.getAttribute(BeanConstants.CREATED_FROM_API_ATTR);
+
+ if (null == id || "".equals(id)) {
+ return super.resolveId(elem, definition, ctx);
+ }
+
+ if (createdFromAPI != null &&
"true".equals(createdFromAPI.toLowerCase())) {
+ return id + getSuffix();
+ }
+ return id;
+ }
+
+ protected boolean hasBusProperty() {
+ return false;
+ }
+
+ protected String getSuffix() {
+ return "";
+ }
+
+ protected void setFirstChildAsProperty(Element element, ParserContext ctx,
+ BeanDefinitionBuilder bean, String
propertyName) {
+ String id = getAndRegisterFirstChild(element, ctx, bean, propertyName);
+ bean.addPropertyReference(propertyName, id);
+
+ }
+
+ protected String getAndRegisterFirstChild(Element element, ParserContext
ctx,
+ BeanDefinitionBuilder bean,
String propertyName) {
+ Element first = getFirstChild(element);
+
+ if (first == null) {
+ throw new IllegalStateException(propertyName + " property must
have child elements!");
+ }
+
+ // Seems odd that we have to do the registration, I wonder if there is
a better way
+ String id;
+ BeanDefinition child;
+ if
(first.getNamespaceURI().equals(BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI))
{
+ String name = first.getLocalName();
+ if ("ref".equals(name)) {
+ id = first.getAttribute("bean");
+ if (id == null) {
+ throw new IllegalStateException("<ref> elements must have
a \"bean\" attribute!");
+ }
+ return id;
+ } else if ("bean".equals(name)) {
+ BeanDefinitionHolder bdh =
ctx.getDelegate().parseBeanDefinitionElement(first);
+ child = bdh.getBeanDefinition();
+ id = bdh.getBeanName();
+ } else {
+ throw new UnsupportedOperationException("Elements with the
name " + name
+ + " are not currently "
+ + "supported as sub
elements of "
+ +
element.getLocalName());
+ }
+
+ } else {
+ child = ctx.getDelegate().parseCustomElement(first,
bean.getBeanDefinition());
+ id = child.toString();
+ }
+
+ ctx.getRegistry().registerBeanDefinition(id, child);
+ return id;
+ }
+
+ protected Element getFirstChild(Element element) {
+ Element first = null;
+ NodeList children = element.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node n = children.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE) {
+ first = (Element) n;
+ }
+ }
+ return first;
+ }
+
+ protected void wireBus(BeanDefinitionBuilder bean, String busId) {
+ bean.addPropertyReference("bus", busId);
+ }
+
+ protected void mapElementToJaxbProperty(Element parent,
+ BeanDefinitionBuilder bean,
+ QName name,
+ String propertyName) {
+ mapElementToJaxbProperty(parent, bean, name, propertyName, null);
+ }
+
+ protected void mapElementToJaxbProperty(Element parent,
+ BeanDefinitionBuilder bean,
+ QName name,
+ String propertyName,
+ Class<?> c) {
+ Node data = null;
+ NodeList nl = parent.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node n = nl.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE &&
name.getLocalPart().equals(n.getLocalName())
+ && name.getNamespaceURI().equals(n.getNamespaceURI())) {
+ data = n;
+ break;
+ }
+ }
+
+ if (data == null) {
+ return;
+ }
+
+ JAXBContext context = null;
+ Object obj = null;
+ try {
+ String pkg = getJaxbPackage();
+ if (null != c) {
+ pkg = c.getPackage().getName();
+ }
+ context = JAXBContext.newInstance(pkg,
getClass().getClassLoader());
+ Unmarshaller u = context.createUnmarshaller();
+ if (c != null) {
+ obj = u.unmarshal(data, c);
+ } else {
+ obj = u.unmarshal(data);
+ }
+
+ if (obj instanceof JAXBElement<?>) {
+ JAXBElement<?> el = (JAXBElement<?>)obj;
+ obj = el.getValue();
+
+ }
+ } catch (JAXBException e) {
+ throw new RuntimeException("Could not parse configuration.", e);
+ }
+
+ if (obj != null) {
+ bean.addPropertyValue(propertyName, obj);
+ }
+ }
+
+ protected String getJaxbPackage() {
+ return "";
+ }
+
+ protected void mapToProperty(BeanDefinitionBuilder bean, String
propertyName, String val) {
+ if (ID_ATTRIBUTE.equals(propertyName)) {
+ return;
+ }
+
+ if (StringUtils.hasText(val)) {
+ if (val.startsWith("#")) {
+ bean.addPropertyReference(propertyName, val.substring(1));
+ } else {
+ bean.addPropertyValue(propertyName, val);
+ }
+ }
+ }
+
+ protected boolean isAttribute(String pre, String name) {
+ return !"xmlns".equals(name) && (pre == null || !pre.equals("xmlns"))
+ && !"abstract".equals(name) && !"lazy-init".equals(name) &&
!"id".equals(name);
+ }
+
+ protected QName parseQName(Element element, String t) {
+ String ns = null;
+ String pre = null;
+ String local = null;
+
+ if (t.startsWith("{")) {
+ int i = t.indexOf('}');
+ if (i == -1) {
+ throw new RuntimeException("Namespace bracket '{' must having
a closing bracket '}'.");
+ }
+
+ ns = t.substring(1, i);
+ t = t.substring(i + 1);
+ }
+
+ int colIdx = t.indexOf(':');
+ if (colIdx == -1) {
+ local = t;
+ pre = "";
+
+ ns = DOMUtils.getNamespace(element, "");
+ } else {
+ pre = t.substring(0, colIdx);
+ local = t.substring(colIdx + 1);
+
+ ns = DOMUtils.getNamespace(element, pre);
+ }
+
+ return new QName(ns, local, pre);
+ }
+
+ protected String getIdOrName(Element elem) {
+ String id =
elem.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE);
+
+ if (null == id || "".equals(id)) {
+ String names = elem.getAttribute(BeanConstants.NAME_ATTR);
+ if (null != names) {
+ StringTokenizer st =
+ new StringTokenizer(names,
BeanDefinitionParserDelegate.BEAN_NAME_DELIMITERS);
+ if (st.countTokens() > 0) {
+ id = st.nextToken();
+ }
+ }
+ }
+ return id;
+ }
+
+}
Added:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java?view=auto&rev=550965
==============================================================================
---
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java
(added)
+++
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java
Tue Jun 26 14:50:27 2007
@@ -0,0 +1,97 @@
+/**
+ * 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;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.xml.ParserContext;
+
+/**
+ * This class makes it easy to create two simultaneous beans - a factory bean
and the bean
+ * that the factory produces.
+ */
+public abstract class AbstractFactoryBeanDefinitionParser extends
AbstractBeanDefinitionParser {
+
+ @Override
+ protected void doParse(Element element, ParserContext ctx,
BeanDefinitionBuilder bean) {
+ BeanDefinitionBuilder factoryBean =
BeanDefinitionBuilder.rootBeanDefinition(getFactoryClass());
+
+ NamedNodeMap atts = element.getAttributes();
+ boolean createdFromAPI = false;
+ boolean setBus = false;
+ for (int i = 0; i < atts.getLength(); i++) {
+ Attr node = (Attr) atts.item(i);
+ String val = node.getValue();
+ String pre = node.getPrefix();
+ String name = node.getLocalName();
+
+ if ("createdFromAPI".equals(name)) {
+ factoryBean.setAbstract(true);
+ bean.setAbstract(true);
+ createdFromAPI = true;
+ } else if ("abstract".equals(name)) {
+ factoryBean.setAbstract(true);
+ bean.setAbstract(true);
+ } else if (!"id".equals(name) && !"name".equals(name) &&
isAttribute(pre, name)) {
+ if ("bus".equals(name)) {
+ setBus = true;
+ }
+ mapAttribute(factoryBean, element, name, val);
+ }
+ }
+
+ if (!setBus && ctx.getRegistry().containsBeanDefinition("cxf")) {
+ wireBus(factoryBean, "cxf");
+ }
+
+ NodeList children = element.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node n = children.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE) {
+ String name = n.getLocalName();
+
+ mapElement(ctx, factoryBean, (Element) n, name);
+ }
+ }
+
+ String id = getIdOrName(element);
+ if (createdFromAPI) {
+ id = id + getSuffix();
+ }
+
+ String factoryId = id + getFactoryIdSuffix();
+
+ ctx.getRegistry().registerBeanDefinition(factoryId,
factoryBean.getBeanDefinition());
+ bean.getBeanDefinition().setAttribute("id", id);
+ bean.setFactoryBean(factoryId, "create");
+ }
+
+ protected abstract Class getFactoryClass();
+
+ /**
+ * @return The Spring ID of the factory bean.
+ */
+ protected abstract String getFactoryIdSuffix();
+}
Propchange:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java
------------------------------------------------------------------------------
svn:executable = *
Propchange:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java?view=diff&rev=550965&r1=550964&r2=550965
==============================================================================
---
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java
(original)
+++
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBusImpl.java
Tue Jun 26 14:50:27 2007
@@ -19,12 +19,14 @@
package org.apache.cxf.bus;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.buslifecycle.BusLifeCycleManager;
+import org.apache.cxf.feature.AbstractFeature;
import org.apache.cxf.interceptor.AbstractBasicInterceptorProvider;
public class CXFBusImpl extends AbstractBasicInterceptorProvider implements
Bus {
@@ -33,6 +35,7 @@
private BusLifeCycleManager lifeCycleManager;
private String id;
private BusState state;
+ private Collection<AbstractFeature> features;
public CXFBusImpl() {
this(null);
@@ -100,6 +103,18 @@
}
}
+ public void initialize() {
+ initializeFeatures();
+ }
+
+ private void initializeFeatures() {
+ if (features != null) {
+ for (AbstractFeature f : features) {
+ f.initialize(this);
+ }
+ }
+ }
+
public void shutdown(boolean wait) {
lifeCycleManager = this.getExtension(BusLifeCycleManager.class);
if (null != lifeCycleManager) {
@@ -120,4 +135,17 @@
protected BusState getState() {
return state;
}
+
+ public Collection<AbstractFeature> getFeatures() {
+ return features;
+ }
+
+ public synchronized void setFeatures(Collection<AbstractFeature> features)
{
+ this.features = features;
+
+ if (state == BusState.RUNNING) {
+ initializeFeatures();
+ }
+ }
+
}
Added:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java?view=auto&rev=550965
==============================================================================
---
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java
(added)
+++
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java
Tue Jun 26 14:50:27 2007
@@ -0,0 +1,66 @@
+/**
+ * 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.List;
+
+import org.w3c.dom.Element;
+
+import org.apache.cxf.bus.CXFBusImpl;
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.xml.ParserContext;
+
+public class BusDefinitionParser extends AbstractBeanDefinitionParser {
+
+ public BusDefinitionParser() {
+ super();
+ setBeanClass(CXFBusImpl.class);
+ }
+
+ @Override
+ protected void doParse(Element element, ParserContext ctx,
BeanDefinitionBuilder bean) {
+ bean.setInitMethodName("initialize");
+
+ super.doParse(element, ctx, bean);
+ }
+
+ @Override
+ protected void mapElement(ParserContext ctx,
+ BeanDefinitionBuilder bean,
+ Element e,
+ String name) {
+ if ("inInterceptors".equals(name) || "inFaultInterceptors".equals(name)
+ || "outInterceptors".equals(name) ||
"outFaultInterceptors".equals(name)
+ || "features".equals(name)) {
+ List list = ctx.getDelegate().parseListElement(e,
bean.getBeanDefinition());
+ bean.addPropertyValue(name, list);
+ }
+ }
+
+ protected String getIdOrName(Element elem) {
+ String id = super.getIdOrName(elem);
+ if (StringUtils.isEmpty(id)) {
+ id = "cxf";
+ }
+ return id;
+ }
+}
Propchange:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java
------------------------------------------------------------------------------
svn:executable = *
Propchange:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/NamespaceHandler.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/NamespaceHandler.java?view=auto&rev=550965
==============================================================================
---
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/NamespaceHandler.java
(added)
+++
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/NamespaceHandler.java
Tue Jun 26 14:50:27 2007
@@ -0,0 +1,28 @@
+/**
+ * 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 org.springframework.beans.factory.xml.NamespaceHandlerSupport;
+
+public class NamespaceHandler extends NamespaceHandlerSupport {
+ public void init() {
+ registerBeanDefinitionParser("bus",
+ new BusDefinitionParser());
+ }
+}
Propchange:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/NamespaceHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/NamespaceHandler.java
------------------------------------------------------------------------------
svn:executable = *
Propchange:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/NamespaceHandler.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml?view=diff&rev=550965&r1=550964&r2=550965
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
(original)
+++ incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml Tue Jun
26 14:50:27 2007
@@ -23,7 +23,7 @@
xsi:schemaLocation="
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="cxf" class="org.apache.cxf.bus.CXFBusImpl"
init-method="initialize"/>
<bean class="org.apache.cxf.bus.spring.Jsr250BeanPostProcessor"/>
<bean class="org.apache.cxf.bus.spring.BusExtensionPostProcessor">
<property name="bus" ref="cxf"/>
Modified:
incubator/cxf/trunk/rt/core/src/main/resources/META-INF/spring.handlers
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/resources/META-INF/spring.handlers?view=diff&rev=550965&r1=550964&r2=550965
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/resources/META-INF/spring.handlers
(original)
+++ incubator/cxf/trunk/rt/core/src/main/resources/META-INF/spring.handlers Tue
Jun 26 14:50:27 2007
@@ -19,3 +19,4 @@
#
#
http\://cxf.apache.org/clustering=org.apache.cxf.clustering.spring.NamespaceHandler
+http\://cxf.apache.org/bus=org.apache.cxf.bus.spring.NamespaceHandler
Added: incubator/cxf/trunk/rt/core/src/main/resources/META-INF/spring.schemas
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/resources/META-INF/spring.schemas?view=auto&rev=550965
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/resources/META-INF/spring.schemas
(added)
+++ incubator/cxf/trunk/rt/core/src/main/resources/META-INF/spring.schemas Tue
Jun 26 14:50:27 2007
@@ -0,0 +1,21 @@
+#
+#
+# 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.
+#
+#
+http\://cxf.apache.org/schemas/bus.xsd=schemas/bus.xsd
\ No newline at end of file
Propchange:
incubator/cxf/trunk/rt/core/src/main/resources/META-INF/spring.schemas
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/cxf/trunk/rt/core/src/main/resources/schemas/bus.xsd
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/resources/schemas/bus.xsd?view=auto&rev=550965
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/resources/schemas/bus.xsd (added)
+++ incubator/cxf/trunk/rt/core/src/main/resources/schemas/bus.xsd Tue Jun 26
14:50:27 2007
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xmlns:cxf-beans="http://cxf.apache.org/configuration/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ targetNamespace="http://cxf.apache.org/bus"
+ elementFormDefault="qualified"
+ attributeFormDefault="unqualified" >
+
+ <xsd:import namespace="http://www.springframework.org/schema/beans"
schemaLocation="http://www.springframework.org/schema/beans/spring-beans.xsd"/>
+ <xsd:import namespace="http://cxf.apache.org/configuration/beans"
schemaLocation="http://cxf.apache.org/schemas/configuration/cxf-beans.xsd"/>
+
+ <xsd:element name="bus">
+ <xsd:complexType>
+ <xsd:all>
+ <xsd:element name="features" type="xsd:anyType" minOccurs="0"/>
+ <xsd:element name="inInterceptors" type="xsd:anyType" minOccurs="0"/>
+ <xsd:element name="inFaultInterceptors" type="xsd:anyType"
minOccurs="0"/>
+ <xsd:element name="outInterceptors" type="xsd:anyType" minOccurs="0"/>
+ <xsd:element name="outFaultInterceptors" type="xsd:anyType"
minOccurs="0"/>
+ </xsd:all>
+ <xsd:attributeGroup ref="cxf-beans:beanAttributes"/>
+ </xsd:complexType>
+ </xsd:element>
+</xsd:schema>
Propchange: incubator/cxf/trunk/rt/core/src/main/resources/schemas/bus.xsd
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/core/src/main/resources/schemas/bus.xsd
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/rt/core/src/main/resources/schemas/bus.xsd
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/rt/core/src/main/resources/schemas/bus.xsd
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java?view=auto&rev=550965
==============================================================================
---
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java
(added)
+++
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java
Tue Jun 26 14:50:27 2007
@@ -0,0 +1,47 @@
+/**
+ * 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.List;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class BusDefinitionParserTest extends Assert {
+
+ @Test
+ public void testFeatures() {
+ String cfgFile = "org/apache/cxf/bus/spring/bus.xml";
+ Bus bus = new SpringBusFactory().createBus(cfgFile, true);
+
+ List<Interceptor> in = bus.getInInterceptors();
+ boolean found = false;
+ for (Interceptor i : in) {
+ if (i instanceof LoggingInInterceptor) {
+ found = true;
+ }
+ }
+ assertTrue("could not find logging interceptor.", found);
+ }
+
+}
Propchange:
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java
------------------------------------------------------------------------------
svn:executable = *
Propchange:
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/bus.xml
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/bus.xml?view=auto&rev=550965
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/bus.xml
(added)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/bus.xml
Tue Jun 26 14:50:27 2007
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:b="http://cxf.apache.org/bus"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
+http://cxf.apache.org/bus http://cxf.apache.org/schemas/bus.xsd">
+
+ <b:bus>
+ <b:features>
+ <bean class="org.apache.cxf.feature.LoggingFeature" />
+ </b:features>
+ </b:bus>
+
+</beans>
\ No newline at end of file
Propchange:
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/bus.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/bus.xml
------------------------------------------------------------------------------
svn:executable = *
Propchange:
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/bus.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/bus.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/JaxWsProxyFactoryBeanDefinitionParser.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/JaxWsProxyFactoryBeanDefinitionParser.java?view=diff&rev=550965&r1=550964&r2=550965
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/JaxWsProxyFactoryBeanDefinitionParser.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/JaxWsProxyFactoryBeanDefinitionParser.java
Tue Jun 26 14:50:27 2007
@@ -24,11 +24,13 @@
public class JaxWsProxyFactoryBeanDefinitionParser extends
ClientProxyFactoryBeanDefinitionParser {
@Override
+ protected Class getFactoryClass() {
+ return JaxWsProxyFactoryBean.class;
+ }
+
+ @Override
protected String getSuffix() {
return ".jaxws-client";
}
-
- protected Class getProxyFactoryClass() {
- return JaxWsProxyFactoryBean.class;
- }
+
}
Modified:
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/spring/ClientProxyFactoryBeanDefinitionParser.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/spring/ClientProxyFactoryBeanDefinitionParser.java?view=diff&rev=550965&r1=550964&r2=550965
==============================================================================
---
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/spring/ClientProxyFactoryBeanDefinitionParser.java
(original)
+++
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/spring/ClientProxyFactoryBeanDefinitionParser.java
Tue Jun 26 14:50:27 2007
@@ -23,18 +23,15 @@
import javax.xml.namespace.QName;
-import org.w3c.dom.Attr;
import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser;
+import org.apache.cxf.configuration.spring.AbstractFactoryBeanDefinitionParser;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
-public class ClientProxyFactoryBeanDefinitionParser extends
AbstractBeanDefinitionParser {
+public class ClientProxyFactoryBeanDefinitionParser
+ extends AbstractFactoryBeanDefinitionParser {
public ClientProxyFactoryBeanDefinitionParser() {
super();
@@ -42,79 +39,42 @@
}
@Override
+ protected Class getFactoryClass() {
+ return ClientProxyFactoryBean.class;
+ }
+
+ @Override
+ protected String getFactoryIdSuffix() {
+ return ".proxyFactory";
+ }
+
+ @Override
protected String getSuffix() {
return ".simple-client";
}
@Override
- protected void doParse(Element element, ParserContext ctx,
BeanDefinitionBuilder clientBean) {
-
- BeanDefinitionBuilder bean =
BeanDefinitionBuilder.rootBeanDefinition(getProxyFactoryClass());
-
- NamedNodeMap atts = element.getAttributes();
- boolean createdFromAPI = false;
- boolean setBus = false;
- for (int i = 0; i < atts.getLength(); i++) {
- Attr node = (Attr) atts.item(i);
- String val = node.getValue();
- String pre = node.getPrefix();
- String name = node.getLocalName();
-
- if ("createdFromAPI".equals(name)) {
- bean.setAbstract(true);
- clientBean.setAbstract(true);
- createdFromAPI = true;
- } else if (!"id".equals(name) && isAttribute(pre, name)) {
- if ("endpointName".equals(name) || "serviceName".equals(name))
{
- QName q = parseQName(element, val);
- bean.addPropertyValue(name, q);
- } else if (!"name".equals(name)) {
- if ("bus".equals(name)) {
- setBus = true;
- }
- mapToProperty(bean, name, val);
- }
- } else if ("abstract".equals(name)) {
- bean.setAbstract(true);
- clientBean.setAbstract(true);
- }
+ protected void mapAttribute(BeanDefinitionBuilder bean, Element e, String
name, String val) {
+ if ("endpointName".equals(name) || "serviceName".equals(name)) {
+ QName q = parseQName(e, val);
+ bean.addPropertyValue(name, q);
+ } else {
+ mapToProperty(bean, name, val);
}
-
- if (!setBus && ctx.getRegistry().containsBeanDefinition("cxf")) {
- bean.addPropertyReference("bus", "cxf");
- }
-
- NodeList children = element.getChildNodes();
- for (int i = 0; i < children.getLength(); i++) {
- Node n = children.item(i);
- if (n.getNodeType() == Node.ELEMENT_NODE) {
- String name = n.getLocalName();
- if ("properties".equals(n.getLocalName())) {
- Map map = ctx.getDelegate().parseMapElement((Element) n,
bean.getBeanDefinition());
- bean.addPropertyValue("properties", map);
- } else if ("inInterceptors".equals(name) ||
"inFaultInterceptors".equals(name)
- || "outInterceptors".equals(name) ||
"outFaultInterceptors".equals(name)
- || "features".equals(name)) {
- List list = ctx.getDelegate().parseListElement((Element)
n, bean.getBeanDefinition());
- bean.addPropertyValue(n.getLocalName(), list);
- } else {
- setFirstChildAsProperty((Element) n, ctx, bean,
n.getLocalName());
- }
- }
- }
- String id = getIdOrName(element);
- if (createdFromAPI) {
- id = id + getSuffix();
- }
- String factoryId = id + ".proxyFactory";
-
- ctx.getRegistry().registerBeanDefinition(factoryId,
bean.getBeanDefinition());
- clientBean.getBeanDefinition().setAttribute("id", id);
- clientBean.setFactoryBean(factoryId, "create");
}
- protected Class getProxyFactoryClass() {
- return ClientProxyFactoryBean.class;
+ @Override
+ protected void mapElement(ParserContext ctx, BeanDefinitionBuilder bean,
Element e, String name) {
+ if ("properties".equals(name)) {
+ Map map = ctx.getDelegate().parseMapElement(e,
bean.getBeanDefinition());
+ bean.addPropertyValue("properties", map);
+ } else if ("inInterceptors".equals(name) ||
"inFaultInterceptors".equals(name)
+ || "outInterceptors".equals(name) ||
"outFaultInterceptors".equals(name)
+ || "features".equals(name)) {
+ List list = ctx.getDelegate().parseListElement(e,
bean.getBeanDefinition());
+ bean.addPropertyValue(name, list);
+ } else {
+ setFirstChildAsProperty(e, ctx, bean, name);
+ }
}
-
}
Modified:
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/spring/ServerFactoryBeanDefinitionParser.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/spring/ServerFactoryBeanDefinitionParser.java?view=diff&rev=550965&r1=550964&r2=550965
==============================================================================
---
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/spring/ServerFactoryBeanDefinitionParser.java
(original)
+++
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/spring/ServerFactoryBeanDefinitionParser.java
Tue Jun 26 14:50:27 2007
@@ -71,11 +71,11 @@
}
@Override
- protected void mapAttribute(BeanDefinitionBuilder bean, String name,
String val) {
+ protected void mapAttribute(BeanDefinitionBuilder bean, Element e, String
name, String val) {
if (name.equals(IMPLEMENTOR)) {
loadImplementor(bean, val);
} else {
- super.mapAttribute(bean, name, val);
+ super.mapAttribute(bean, e, name, val);
}
}
Modified:
incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java?view=diff&rev=550965&r1=550964&r2=550965
==============================================================================
---
incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java
(original)
+++
incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java
Tue Jun 26 14:50:27 2007
@@ -57,7 +57,6 @@
assertTrue(sbc.getVersion() instanceof Soap12);
}
-
@Test
public void testClients() throws Exception {
ClassPathXmlApplicationContext ctx =