Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5D92710192 for ; Thu, 1 May 2014 15:50:07 +0000 (UTC) Received: (qmail 24430 invoked by uid 500); 1 May 2014 15:49:50 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 24124 invoked by uid 500); 1 May 2014 15:49:41 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 24024 invoked by uid 99); 1 May 2014 15:49:40 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 May 2014 15:49:39 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id B3F4588B8F9; Thu, 1 May 2014 15:49:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dkulp@apache.org To: commits@cxf.apache.org Date: Thu, 01 May 2014 15:49:43 -0000 Message-Id: In-Reply-To: <3cb956ae9e154f49b8eacddab2853e07@git.apache.org> References: <3cb956ae9e154f49b8eacddab2853e07@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [5/9] Experiment with pulling spring out of core http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java b/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java deleted file mode 100644 index 648431d..0000000 --- a/core/src/main/java/org/apache/cxf/bus/spring/SpringBus.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * 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.apache.cxf.bus.extension.ExtensionManagerBus; -import org.apache.cxf.configuration.ConfiguredBeanLocator; -import org.apache.cxf.configuration.Configurer; -import org.apache.cxf.configuration.spring.ConfigurerImpl; -import org.apache.cxf.resource.ResourceManager; -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.ApplicationEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.context.event.ContextClosedEvent; -import org.springframework.context.event.ContextRefreshedEvent; -import org.springframework.context.support.AbstractApplicationContext; - -/** - * - */ -public class SpringBus extends ExtensionManagerBus - implements ApplicationContextAware { - - AbstractApplicationContext ctx; - boolean closeContext; - - public SpringBus() { - } - - public void setBusConfig(BusDefinitionParser.BusConfig bc) { - bc.setBus(this); - } - - public void loadAdditionalFeatures() { - super.loadAdditionalFeatures(); - } - - /** {@inheritDoc}*/ - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - ctx = (AbstractApplicationContext)applicationContext; - @SuppressWarnings("rawtypes") - ApplicationListener listener = new ApplicationListener() { - public void onApplicationEvent(ApplicationEvent event) { - SpringBus.this.onApplicationEvent(event); - } - }; - ctx.addApplicationListener(listener); - ApplicationContext ac = applicationContext.getParent(); - while (ac != null) { - if (ac instanceof AbstractApplicationContext) { - ((AbstractApplicationContext)ac).addApplicationListener(listener); - } - ac = ac.getParent(); - } - - // set the classLoader extension with the application context classLoader - setExtension(applicationContext.getClassLoader(), ClassLoader.class); - - setExtension(new ConfigurerImpl(applicationContext), Configurer.class); - - ResourceManager m = getExtension(ResourceManager.class); - m.addResourceResolver(new BusApplicationContextResourceResolver(applicationContext)); - - setExtension(applicationContext, ApplicationContext.class); - ConfiguredBeanLocator loc = getExtension(ConfiguredBeanLocator.class); - if (!(loc instanceof SpringBeanLocator)) { - setExtension(new SpringBeanLocator(applicationContext, this), ConfiguredBeanLocator.class); - } - if (getState() != BusState.RUNNING) { - initialize(); - } - } - - public void onApplicationEvent(ApplicationEvent event) { - if (ctx == null) { - return; - } - boolean doIt = false; - ApplicationContext ac = ctx; - while (ac != null && !doIt) { - if (event.getSource() == ac) { - doIt = true; - break; - } - ac = ac.getParent(); - } - if (doIt) { - if (event instanceof ContextRefreshedEvent) { - if (getState() != BusState.RUNNING) { - initialize(); - } - } else if (event instanceof ContextClosedEvent && getState() == BusState.RUNNING) { - // The bus could be create by using SpringBusFactory.createBus("/cxf.xml"); - // Just to make sure the shutdown is called rightly - shutdown(); - } - } - } - - public void destroyBeans() { - if (closeContext) { - ctx.close(); - } - super.destroyBeans(); - } - - public String getId() { - if (id == null) { - try { - Class clsbc = Class.forName("org.osgi.framework.BundleContext"); - Class clsb = Class.forName("org.osgi.framework.Bundle"); - Object o = getExtension(clsbc); - Object o2 = clsbc.getMethod("getBundle").invoke(o); - String s = (String)clsb.getMethod("getSymbolicName").invoke(o2); - id = s + "-" + DEFAULT_BUS_ID + Integer.toString(this.hashCode()); - } catch (Throwable t) { - id = super.getId(); - } - } - return id; - } - - public void setCloseContext(boolean b) { - closeContext = b; - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java b/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java deleted file mode 100644 index 04ea866..0000000 --- a/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java +++ /dev/null @@ -1,227 +0,0 @@ -/** - * 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.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.cxf.Bus; -import org.apache.cxf.BusFactory; -import org.apache.cxf.buslifecycle.BusLifeCycleListener; -import org.apache.cxf.buslifecycle.BusLifeCycleManager; -import org.apache.cxf.common.logging.LogUtils; -import org.apache.cxf.common.util.SystemPropertyAction; -import org.apache.cxf.configuration.Configurer; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.xml.NamespaceHandlerResolver; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.io.Resource; - -public class SpringBusFactory extends BusFactory { - - private static final Logger LOG = LogUtils.getL7dLogger(SpringBusFactory.class); - - private final ApplicationContext context; - private NamespaceHandlerResolver resolver; - - public SpringBusFactory() { - this.context = null; - } - - public SpringBusFactory(ApplicationContext context) { - this.context = context; - this.resolver = tryFindNamespaceHandler(context); - } - public SpringBusFactory(NamespaceHandlerResolver r) { - context = null; - this.resolver = r; - } - - private static NamespaceHandlerResolver tryFindNamespaceHandler(ApplicationContext ctx) { - try { - SpringBeanLocator sbl = new SpringBeanLocator(ctx); - List r = sbl.getOSGiServices(NamespaceHandlerResolver.class); - if (r != null && !r.isEmpty()) { - return r.get(0); - } - } catch (Throwable t) { - //ignore - } - return null; - } - - public ApplicationContext getApplicationContext() { - return context; - } - public void setNamespaceHandlerResolver(NamespaceHandlerResolver r) { - resolver = r; - } - - public Bus createBus() { - return createBus((String)null); - } - - private boolean defaultBusNotExists() { - if (null != context) { - return !context.containsBean(Bus.DEFAULT_BUS_ID); - } - return true; - } - - public Bus createBus(String cfgFile) { - return createBus(cfgFile, defaultBusNotExists()); - } - - public Bus createBus(String cfgFiles[]) { - return createBus(cfgFiles, defaultBusNotExists()); - } - - protected Bus finishCreatingBus(ConfigurableApplicationContext bac) { - final Bus bus = (Bus)bac.getBean(Bus.DEFAULT_BUS_ID); - - bus.setExtension(bac, ApplicationContext.class); - if (bac instanceof BusApplicationContext) { - bus.setExtension((BusApplicationContext)bac, BusApplicationContext.class); - } - possiblySetDefaultBus(bus); - - initializeBus(bus); - - registerApplicationContextLifeCycleListener(bus, bac); - - if (bus instanceof SpringBus && defaultBusNotExists()) { - ((SpringBus)bus).setCloseContext(true); - } - return bus; - } - - public Bus createBus(String cfgFile, boolean includeDefaults) { - if (cfgFile == null) { - return createBus((String[])null, includeDefaults); - } - return createBus(new String[] {cfgFile}, includeDefaults); - } - - public Bus createBus(String cfgFiles[], boolean includeDefaults) { - try { - String userCfgFile - = SystemPropertyAction.getPropertyOrNull(Configurer.USER_CFG_FILE_PROPERTY_NAME); - String sysCfgFileUrl - = SystemPropertyAction.getPropertyOrNull(Configurer.USER_CFG_FILE_PROPERTY_URL); - final Resource r = BusApplicationContext.findResource(Configurer.DEFAULT_USER_CFG_FILE); - - boolean exists = true; - if (r != null) { - exists = AccessController - .doPrivileged(new PrivilegedAction() { - public Boolean run() { - return r.exists(); - } - }); - } - if (context == null && userCfgFile == null && cfgFiles == null && sysCfgFileUrl == null - && (r == null || !exists) && includeDefaults) { - return new org.apache.cxf.bus.CXFBusFactory().createBus(); - } - return finishCreatingBus(createApplicationContext(cfgFiles, includeDefaults)); - } catch (BeansException ex) { - LogUtils.log(LOG, Level.WARNING, "APP_CONTEXT_CREATION_FAILED_MSG", ex, (Object[])null); - throw new RuntimeException(ex); - } - } - - protected ConfigurableApplicationContext createApplicationContext(String cfgFiles[], boolean includeDefaults) { - try { - return new BusApplicationContext(cfgFiles, includeDefaults, context, resolver); - } catch (BeansException ex) { - LogUtils.log(LOG, Level.WARNING, "INITIAL_APP_CONTEXT_CREATION_FAILED_MSG", ex, (Object[])null); - ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); - if (contextLoader != BusApplicationContext.class.getClassLoader()) { - Thread.currentThread().setContextClassLoader( - BusApplicationContext.class.getClassLoader()); - try { - return new BusApplicationContext(cfgFiles, includeDefaults, context); - } finally { - Thread.currentThread().setContextClassLoader(contextLoader); - } - } else { - throw ex; - } - } - } - - public Bus createBus(URL url) { - return createBus(url, defaultBusNotExists()); - } - public Bus createBus(URL[] urls) { - return createBus(urls, defaultBusNotExists()); - } - - public Bus createBus(URL url, boolean includeDefaults) { - if (url == null) { - return createBus((URL[])null, includeDefaults); - } - return createBus(new URL[] {url}, includeDefaults); - } - - public Bus createBus(URL[] urls, boolean includeDefaults) { - try { - return finishCreatingBus(createAppContext(urls, includeDefaults)); - } catch (BeansException ex) { - LogUtils.log(LOG, Level.WARNING, "APP_CONTEXT_CREATION_FAILED_MSG", ex, (Object[])null); - throw new RuntimeException(ex); - } - } - - protected ConfigurableApplicationContext createAppContext(URL[] urls, boolean includeDefaults) { - return new BusApplicationContext(urls, includeDefaults, context, resolver); - } - - void registerApplicationContextLifeCycleListener(Bus bus, ConfigurableApplicationContext bac) { - BusLifeCycleManager lm = bus.getExtension(BusLifeCycleManager.class); - if (null != lm) { - lm.registerLifeCycleListener(new BusApplicationContextLifeCycleListener(bac)); - } - } - - static class BusApplicationContextLifeCycleListener implements BusLifeCycleListener { - private ConfigurableApplicationContext bac; - - BusApplicationContextLifeCycleListener(ConfigurableApplicationContext b) { - bac = b; - } - - public void initComplete() { - } - - public void preShutdown() { - } - - public void postShutdown() { - bac.close(); - } - - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java b/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java deleted file mode 100644 index b67fd94..0000000 --- a/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java +++ /dev/null @@ -1,146 +0,0 @@ -/** - * 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.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.logging.Logger; - -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.transform.sax.SAXSource; - -import org.w3c.dom.Document; - -import org.xml.sax.EntityResolver; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; - -import com.sun.xml.fastinfoset.stax.StAXDocumentParser; - -import org.apache.cxf.common.classloader.ClassLoaderUtils; -import org.apache.cxf.common.logging.LogUtils; -import org.apache.cxf.staxutils.StaxUtils; -import org.apache.cxf.staxutils.W3CDOMStreamWriter; -import org.springframework.beans.factory.xml.DefaultDocumentLoader; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; - -/** - * A Spring DocumentLoader that uses WoodStox when we are not validating to speed up the process. - */ -class TunedDocumentLoader extends DefaultDocumentLoader { - private static final Logger LOG = LogUtils.getL7dLogger(TunedDocumentLoader.class); - - private static boolean hasFastInfoSet; - - static { - try { - ClassLoaderUtils - .loadClass("com.sun.xml.fastinfoset.stax.StAXDocumentParser", - TunedDocumentLoader.class); - hasFastInfoSet = true; - } catch (Throwable e) { - LOG.fine("FastInfoset not found on classpath. Disabling context load optimizations."); - hasFastInfoSet = false; - } - } - private SAXParserFactory saxParserFactory; - private SAXParserFactory nsasaxParserFactory; - - TunedDocumentLoader() { - try { - Class cls = ClassLoaderUtils.loadClass("com.ctc.wstx.sax.WstxSAXParserFactory", - TunedDocumentLoader.class); - saxParserFactory = (SAXParserFactory)cls.newInstance(); - nsasaxParserFactory = (SAXParserFactory)cls.newInstance(); - } catch (Throwable e) { - //woodstox not found, use any other Stax parser - saxParserFactory = SAXParserFactory.newInstance(); - nsasaxParserFactory = SAXParserFactory.newInstance(); - } - - try { - nsasaxParserFactory.setFeature("http://xml.org/sax/features/namespaces", true); - nsasaxParserFactory.setFeature("http://xml.org/sax/features/namespace-prefixes", - true); - } catch (Throwable e) { - //ignore - } - - } - - public static boolean hasFastInfoSet() { - return hasFastInfoSet; - } - - @Override - public Document loadDocument(InputSource inputSource, EntityResolver entityResolver, - ErrorHandler errorHandler, int validationMode, boolean namespaceAware) - throws Exception { - if (validationMode == XmlBeanDefinitionReader.VALIDATION_NONE) { - SAXParserFactory parserFactory = - namespaceAware ? nsasaxParserFactory : saxParserFactory; - SAXParser parser = parserFactory.newSAXParser(); - XMLReader reader = parser.getXMLReader(); - reader.setEntityResolver(entityResolver); - reader.setErrorHandler(errorHandler); - SAXSource saxSource = new SAXSource(reader, inputSource); - W3CDOMStreamWriter writer = new W3CDOMStreamWriter(); - StaxUtils.copy(saxSource, writer); - return writer.getDocument(); - } else { - return super.loadDocument(inputSource, entityResolver, errorHandler, validationMode, - namespaceAware); - } - } - - @Override - protected DocumentBuilderFactory createDocumentBuilderFactory(int validationMode, boolean namespaceAware) - throws ParserConfigurationException { - DocumentBuilderFactory factory = super.createDocumentBuilderFactory(validationMode, namespaceAware); - try { - factory.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false); - } catch (Throwable e) { - // we can get all kinds of exceptions from this - // due to old copies of Xerces and whatnot. - } - - return factory; - } - - static Document loadFastinfosetDocument(URL url) - throws IOException, ParserConfigurationException, XMLStreamException { - InputStream is = url.openStream(); - InputStream in = new BufferedInputStream(is); - XMLStreamReader staxReader = new StAXDocumentParser(in); - W3CDOMStreamWriter writer = new W3CDOMStreamWriter(); - StaxUtils.copy(staxReader, writer); - in.close(); - return writer.getDocument(); - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java b/core/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java deleted file mode 100644 index 7fcc99f..0000000 --- a/core/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java +++ /dev/null @@ -1,520 +0,0 @@ -/** - * 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.io.StringReader; -import java.io.StringWriter; -import java.util.HashSet; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.logging.Logger; - -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 javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.apache.cxf.common.jaxb.JAXBContextCache; -import org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas; -import org.apache.cxf.common.logging.LogUtils; -import org.apache.cxf.common.util.StringUtils; -import org.apache.cxf.helpers.DOMUtils; -import org.apache.cxf.staxutils.StaxUtils; -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; - -public abstract class AbstractBeanDefinitionParser - extends org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser { - public static final String WIRE_BUS_ATTRIBUTE = AbstractBeanDefinitionParser.class.getName() + ".wireBus"; - public static final String WIRE_BUS_NAME = AbstractBeanDefinitionParser.class.getName() + ".wireBusName"; - public static final String WIRE_BUS_CREATE - = AbstractBeanDefinitionParser.class.getName() + ".wireBusCreate"; - public static final String WIRE_BUS_HANDLER - = "org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor"; - private static final Logger LOG = LogUtils.getL7dLogger(AbstractBeanDefinitionParser.class); - - private Class beanClass; - private JAXBContext context; - private Set> classes; - - public AbstractBeanDefinitionParser() { - } - - @Override - protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) { - boolean setBus = parseAttributes(element, ctx, bean); - if (!setBus && hasBusProperty()) { - addBusWiringAttribute(bean, BusWiringType.PROPERTY); - } - parseChildElements(element, ctx, bean); - } - - protected boolean parseAttributes(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 pre = node.getPrefix(); - String name = node.getLocalName(); - String prefix = node.getPrefix(); - - // Don't process namespaces - if (isNamespace(name, prefix)) { - continue; - } - - if ("createdFromAPI".equals(name)) { - bean.setAbstract(true); - } else if ("abstract".equals(name)) { - bean.setAbstract(true); - } else if ("depends-on".equals(name)) { - bean.addDependsOn(val); - } else if ("name".equals(name)) { - processNameAttribute(element, ctx, bean, val); - } else if ("bus".equals(name)) { - setBus = processBusAttribute(element, ctx, bean, val); - } else if (!"id".equals(name) && isAttribute(pre, name)) { - mapAttribute(bean, element, name, val); - } - } - return setBus; - } - - - protected boolean processBusAttribute(Element element, ParserContext ctx, - BeanDefinitionBuilder bean, - String val) { - if (val != null && val.trim().length() > 0) { - if (ctx.getRegistry().containsBeanDefinition(val)) { - bean.addPropertyReference("bus", val); - } else { - addBusWiringAttribute(bean, BusWiringType.PROPERTY, - val, ctx); - } - return true; - } - return false; - } - - protected void processNameAttribute(Element element, - ParserContext ctx, - BeanDefinitionBuilder bean, - String val) { - //nothing - } - - private boolean isNamespace(String name, String prefix) { - return "xmlns".equals(prefix) || prefix == null && "xmlns".equals(name); - } - - protected void parseChildElements(Element element, ParserContext ctx, BeanDefinitionBuilder bean) { - Element el = DOMUtils.getFirstElement(element); - while (el != null) { - String name = el.getLocalName(); - mapElement(ctx, bean, el, name); - el = DOMUtils.getNextElement(el); - } - } - - 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("createdFromAPI"); - - 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) { - - Element first = getFirstChild(element); - - if (first == null) { - throw new IllegalStateException(propertyName + " property must have child elements!"); - } - - 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(" elements must have a \"bean\" attribute!"); - } - bean.addPropertyReference(propertyName, id); - return; - } else if ("bean".equals(name)) { - BeanDefinitionHolder bdh = ctx.getDelegate().parseBeanDefinitionElement(first); - child = bdh.getBeanDefinition(); - bean.addPropertyValue(propertyName, child); - return; - } else { - throw new UnsupportedOperationException("Elements with the name " + name - + " are not currently " - + "supported as sub elements of " - + element.getLocalName()); - } - } - child = ctx.getDelegate().parseCustomElement(first, bean.getBeanDefinition()); - bean.addPropertyValue(propertyName, child); - } - - protected Element getFirstChild(Element element) { - return DOMUtils.getFirstElement(element); - } - - protected void addBusWiringAttribute(BeanDefinitionBuilder bean, - BusWiringType type) { - addBusWiringAttribute(bean, type, null, null); - } - - protected void addBusWiringAttribute(BeanDefinitionBuilder bean, - BusWiringType type, - String busName, - ParserContext ctx) { - LOG.fine("Adding " + WIRE_BUS_ATTRIBUTE + " attribute " + type + " to bean " + bean); - bean.getRawBeanDefinition().setAttribute(WIRE_BUS_ATTRIBUTE, type); - if (!StringUtils.isEmpty(busName)) { - if (busName.charAt(0) == '#') { - busName = busName.substring(1); - } - bean.getRawBeanDefinition().setAttribute(WIRE_BUS_NAME, busName); - } - - if (ctx != null - && !ctx.getRegistry().containsBeanDefinition(WIRE_BUS_HANDLER)) { - BeanDefinitionBuilder b - = BeanDefinitionBuilder.rootBeanDefinition(WIRE_BUS_HANDLER); - ctx.getRegistry().registerBeanDefinition(WIRE_BUS_HANDLER, b.getBeanDefinition()); - } - } - - 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) { - Element data = null; - - Node node = parent.getFirstChild(); - while (node != null) { - if (node.getNodeType() == Node.ELEMENT_NODE && name.getLocalPart().equals(node.getLocalName()) - && name.getNamespaceURI().equals(node.getNamespaceURI())) { - data = (Element)node; - break; - } - node = node.getNextSibling(); - } - - if (data == null) { - return; - } - mapElementToJaxbProperty(data, bean, propertyName, c); - } - - private synchronized JAXBContext getContext(Class cls) { - if (context == null || classes == null || !classes.contains(cls)) { - try { - Set> tmp = new HashSet>(); - if (classes != null) { - tmp.addAll(classes); - } - JAXBContextCache.addPackage(tmp, getJaxbPackage(), - cls == null - ? getClass().getClassLoader() - : cls.getClassLoader()); - if (cls != null) { - boolean hasOf = false; - for (Class c : tmp) { - if (c.getPackage() == cls.getPackage() - && "ObjectFactory".equals(c.getSimpleName())) { - hasOf = true; - } - } - if (!hasOf) { - tmp.add(cls); - } - } - JAXBContextCache.scanPackages(tmp); - CachedContextAndSchemas ccs - = JAXBContextCache.getCachedContextAndSchemas(tmp, null, null, null, false); - classes = ccs.getClasses(); - context = ccs.getContext(); - } catch (JAXBException e) { - throw new RuntimeException(e); - } - } - return context; - } - - protected void mapElementToJaxbProperty(Element data, - BeanDefinitionBuilder bean, - String propertyName, - Class c) { - try { - XMLStreamWriter xmlWriter = null; - try { - StringWriter writer = new StringWriter(); - xmlWriter = StaxUtils.createXMLStreamWriter(writer); - StaxUtils.copy(data, xmlWriter); - xmlWriter.flush(); - - BeanDefinitionBuilder jaxbbean - = BeanDefinitionBuilder.rootBeanDefinition(JAXBBeanFactory.class); - jaxbbean.getRawBeanDefinition().setFactoryMethodName("createJAXBBean"); - jaxbbean.addConstructorArgValue(getContext(c)); - jaxbbean.addConstructorArgValue(writer.toString()); - jaxbbean.addConstructorArgValue(c); - bean.addPropertyValue(propertyName, jaxbbean.getBeanDefinition()); - } catch (Exception ex) { - Unmarshaller u = getContext(c).createUnmarshaller(); - Object obj; - if (c != null) { - obj = u.unmarshal(data, c); - } else { - obj = u.unmarshal(data); - } - if (obj instanceof JAXBElement) { - JAXBElement el = (JAXBElement)obj; - obj = el.getValue(); - } - if (obj != null) { - bean.addPropertyValue(propertyName, obj); - } - } finally { - StaxUtils.close(xmlWriter); - } - } catch (JAXBException e) { - throw new RuntimeException("Could not parse configuration.", e); - } - } - - - public void mapElementToJaxbPropertyFactory(Element data, - BeanDefinitionBuilder bean, - String propertyName, - Class type, - Class factory, - String method, - Object ... args) { - bean.addPropertyValue(propertyName, mapElementToJaxbBean(data, - factory, - null, type, method, args)); - } - public AbstractBeanDefinition mapElementToJaxbBean(Element data, - Class cls, - Class factory, - String method, - Object ... args) { - return mapElementToJaxbBean(data, cls, factory, cls, method, args); - } - - public AbstractBeanDefinition mapElementToJaxbBean(Element data, - Class cls, - Class factory, - Class jaxbClass, - String method, - Object ... args) { - StringWriter writer = new StringWriter(); - XMLStreamWriter xmlWriter = StaxUtils.createXMLStreamWriter(writer); - try { - StaxUtils.copy(data, xmlWriter); - xmlWriter.flush(); - } catch (XMLStreamException e) { - throw new RuntimeException(e); - } finally { - StaxUtils.close(xmlWriter); - } - - BeanDefinitionBuilder jaxbbean - = BeanDefinitionBuilder.rootBeanDefinition(cls); - if (factory != null) { - jaxbbean.getRawBeanDefinition().setFactoryBeanName(factory.getName()); - } - jaxbbean.getRawBeanDefinition().setFactoryMethodName(method); - jaxbbean.addConstructorArgValue(writer.toString()); - jaxbbean.addConstructorArgValue(getContext(jaxbClass)); - if (args != null) { - for (Object o : args) { - jaxbbean.addConstructorArgValue(o); - } - } - return jaxbbean.getBeanDefinition(); - } - - protected static T unmarshalFactoryString(String s, JAXBContext ctx, Class cls) { - StringReader reader = new StringReader(s); - XMLStreamReader data = StaxUtils.createXMLStreamReader(reader); - try { - Unmarshaller u = ctx.createUnmarshaller(); - JAXBElement obj = u.unmarshal(data, cls); - return cls.cast(obj.getValue()); - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - throw new RuntimeException(e); - } finally { - try { - StaxUtils.close(data); - } catch (XMLStreamException ex) { - throw new RuntimeException(ex); - } - } - } - - protected String getJaxbPackage() { - return ""; - } - - protected void mapToProperty(BeanDefinitionBuilder bean, String propertyName, String val) { - if (ID_ATTRIBUTE.equals(propertyName)) { - return; - } - - if (!StringUtils.isEmpty(val)) { - if (val.startsWith("#") && !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); - } - - /* This id-or-name resolution logic follows that in Spring's - * org.springframework.beans.factory.xml.BeanDefinitionParserDelegate object - * Intent is to have resolution of CXF custom beans follow that of Spring beans - */ - protected String getIdOrName(Element elem) { - String id = elem.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE); - - if (null == id || "".equals(id)) { - String names = elem.getAttribute("name"); - if (null != names) { - StringTokenizer st = - new StringTokenizer(names, BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS); - if (st.countTokens() > 0) { - id = st.nextToken(); - } - } - } - return id; - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java b/core/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java deleted file mode 100644 index b8ab25d..0000000 --- a/core/src/main/java/org/apache/cxf/configuration/spring/AbstractFactoryBeanDefinitionParser.java +++ /dev/null @@ -1,153 +0,0 @@ -/** - * 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.apache.cxf.common.util.StringUtils; -import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; -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 { - private static boolean factoriesAreAbstract = true; - public static void setFactoriesAreAbstract(boolean b) { - factoriesAreAbstract = b; - } - - protected String getDestroyMethod() { - return null; - } - - @Override - protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) { - Class factoryClass = getFactoryClass(); - BeanDefinitionBuilder factoryBean = bean; - if (!FactoryBean.class.isAssignableFrom(factoryClass)) { - 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 ("depends-on".equals(name)) { - factoryBean.addDependsOn(val); - bean.addDependsOn(val); - } else if (!"id".equals(name) && !"name".equals(name) && isAttribute(pre, name)) { - if ("bus".equals(name)) { - setBus = true; - if (!val.startsWith("#")) { - //bus attributes always need to be a reference - val = "#" + val; - } - } - mapAttribute(factoryBean, element, name, val); - } - } - - if (!setBus) { - addBusWiringAttribute(factoryBean, BusWiringType.PROPERTY); - } - - Node node = element.getFirstChild(); - while (node != null) { - if (node.getNodeType() == Node.ELEMENT_NODE) { - String name = node.getLocalName(); - mapElement(ctx, factoryBean, (Element) node, name); - } - node = node.getNextSibling(); - } - - String id = getIdOrName(element); - BeanDefinition container = ctx.getContainingBeanDefinition(); - boolean noFactory = false; - if (StringUtils.isEmpty(id)) { - if (container == null) { - id = BeanDefinitionReaderUtils.generateBeanName(bean.getBeanDefinition(), - ctx.getRegistry(), - false); - } else { - id = BeanDefinitionReaderUtils.generateBeanName(bean.getBeanDefinition(), - ctx.getRegistry(), - true); - noFactory = true; - //inner bean, no need for the factory to be public at all - } - } - if (createdFromAPI) { - id = id + getSuffix(); - } - - if (FactoryBean.class.isAssignableFrom(getFactoryClass())) { - if (!noFactory) { - AbstractBeanDefinition def = factoryBean.getRawBeanDefinition().cloneBeanDefinition(); - def.setBeanClass(getRawFactoryClass()); - def.setAbstract(factoriesAreAbstract); - def.setLazyInit(true); - ctx.getRegistry().registerBeanDefinition(id + getFactoryIdSuffix(), - def); - } - bean.getBeanDefinition().setAttribute("id", id); - } else { - String factoryId = id + getFactoryIdSuffix(); - ctx.getRegistry().registerBeanDefinition(factoryId, factoryBean.getBeanDefinition()); - bean.getRawBeanDefinition().setAttribute("id", id); - bean.getRawBeanDefinition().setFactoryBeanName(factoryId); - bean.getRawBeanDefinition().setFactoryMethodName("create"); - } - if (getDestroyMethod() != null) { - bean.setDestroyMethodName(getDestroyMethod()); - } - } - - protected abstract Class getFactoryClass(); - - protected Class getRawFactoryClass() { - return getFactoryClass(); - } - - /** - * @return The Spring ID of the factory bean. - */ - protected abstract String getFactoryIdSuffix(); -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/main/java/org/apache/cxf/configuration/spring/BusWiringType.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/configuration/spring/BusWiringType.java b/core/src/main/java/org/apache/cxf/configuration/spring/BusWiringType.java deleted file mode 100644 index 4a7042a..0000000 --- a/core/src/main/java/org/apache/cxf/configuration/spring/BusWiringType.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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. - */ -public enum BusWiringType { - /** - * Wire the bus into the bus property of the target bean. - */ - PROPERTY, - - /** - * Wire the bus into the first indexed constructor argument of the target - * bean. - */ - CONSTRUCTOR -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java b/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java deleted file mode 100644 index 0b59288..0000000 --- a/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java +++ /dev/null @@ -1,281 +0,0 @@ -/** - * 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.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -import org.apache.cxf.common.injection.NoJSR250Annotations; -import org.apache.cxf.common.logging.LogUtils; -import org.apache.cxf.configuration.Configurable; -import org.apache.cxf.configuration.Configurer; -import org.apache.cxf.extension.BusExtension; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.beans.factory.config.AutowireCapableBeanFactory; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.support.AbstractBeanFactory; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.wiring.BeanConfigurerSupport; -import org.springframework.beans.factory.wiring.BeanWiringInfo; -import org.springframework.beans.factory.wiring.BeanWiringInfoResolver; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.ConfigurableApplicationContext; - -@NoJSR250Annotations -public class ConfigurerImpl extends BeanConfigurerSupport - implements Configurer, ApplicationContextAware, BusExtension { - - private static final Logger LOG = LogUtils.getL7dLogger(ConfigurerImpl.class); - - private Set appContexts; - private final Map> wildCardBeanDefinitions - = new HashMap>(); - private BeanFactory beanFactory; - - static class MatcherHolder { - Matcher matcher; - String wildCardId; - public MatcherHolder(String orig, Matcher matcher) { - wildCardId = orig; - this.matcher = matcher; - } - } - - public ConfigurerImpl() { - // complete - } - - public ConfigurerImpl(ApplicationContext ac) { - setApplicationContext(ac); - } - - public void setBeanFactory(BeanFactory beanFactory) { - this.beanFactory = beanFactory; - super.setBeanFactory(beanFactory); - } - - private void initWildcardDefinitionMap() { - if (null != appContexts) { - for (ApplicationContext appContext : appContexts) { - for (String n : appContext.getBeanDefinitionNames()) { - if (isWildcardBeanName(n)) { - AutowireCapableBeanFactory bf = appContext.getAutowireCapableBeanFactory(); - BeanDefinitionRegistry bdr = (BeanDefinitionRegistry) bf; - BeanDefinition bd = bdr.getBeanDefinition(n); - String className = bd.getBeanClassName(); - if (null != className) { - String orig = n; - if (n.charAt(0) == '*') { - //old wildcard - n = "." + n.replaceAll("\\.", "\\."); - } - try { - Matcher matcher = Pattern.compile(n).matcher(""); - List m = wildCardBeanDefinitions.get(className); - if (m == null) { - m = new ArrayList(); - wildCardBeanDefinitions.put(className, m); - } - MatcherHolder holder = new MatcherHolder(orig, matcher); - m.add(holder); - } catch (PatternSyntaxException npe) { - //not a valid patter, we'll ignore - } - } else { - LogUtils.log(LOG, Level.WARNING, "WILDCARD_BEAN_ID_WITH_NO_CLASS_MSG", n); - } - } - } - } - } - } - - public void configureBean(Object beanInstance) { - configureBean(null, beanInstance, true); - } - - public void configureBean(String bn, Object beanInstance) { - configureBean(bn, beanInstance, true); - } - public synchronized void configureBean(String bn, Object beanInstance, boolean checkWildcards) { - - if (null == appContexts) { - return; - } - - if (null == bn) { - bn = getBeanName(beanInstance); - } - - if (null == bn) { - return; - } - if (checkWildcards) { - configureWithWildCard(bn, beanInstance); - } - - final String beanName = bn; - setBeanWiringInfoResolver(new BeanWiringInfoResolver() { - public BeanWiringInfo resolveWiringInfo(Object instance) { - if (!"".equals(beanName)) { - return new BeanWiringInfo(beanName); - } - return null; - } - }); - - for (ApplicationContext appContext : appContexts) { - if (appContext.containsBean(bn)) { - this.setBeanFactory(appContext.getAutowireCapableBeanFactory()); - } - } - - try { - //this will prevent a call into the AbstractBeanFactory.markBeanAsCreated(...) - //which saves ALL the names into a HashSet. For URL based configuration, - //this can leak memory - if (beanFactory instanceof AbstractBeanFactory) { - ((AbstractBeanFactory)beanFactory).getMergedBeanDefinition(bn); - } - super.configureBean(beanInstance); - if (LOG.isLoggable(Level.FINE)) { - LOG.fine("Successfully performed injection."); - } - } catch (NoSuchBeanDefinitionException ex) { - // users often wonder why the settings in their configuration files seem - // to have no effect - the most common cause is that they have been using - // incorrect bean ids - if (LOG.isLoggable(Level.FINE)) { - LOG.log(Level.FINE, "NO_MATCHING_BEAN_MSG", beanName); - } - } - } - - private void configureWithWildCard(String bn, Object beanInstance) { - if (!wildCardBeanDefinitions.isEmpty()) { - Class clazz = beanInstance.getClass(); - while (!Object.class.equals(clazz)) { - String className = clazz.getName(); - List matchers = wildCardBeanDefinitions.get(className); - if (matchers != null) { - for (MatcherHolder m : matchers) { - synchronized (m.matcher) { - m.matcher.reset(bn); - if (m.matcher.matches()) { - configureBean(m.wildCardId, beanInstance, false); - return; - } - } - } - } - clazz = clazz.getSuperclass(); - } - } - } - - private boolean isWildcardBeanName(String bn) { - return bn.indexOf('*') != -1 || bn.indexOf('?') != -1 - || (bn.indexOf('(') != -1 && bn.indexOf(')') != -1); - } - - protected String getBeanName(Object beanInstance) { - if (beanInstance instanceof Configurable) { - return ((Configurable)beanInstance).getBeanName(); - } - String beanName = null; - Method m = null; - try { - m = beanInstance.getClass().getDeclaredMethod("getBeanName", (Class[])null); - } catch (NoSuchMethodException ex) { - try { - m = beanInstance.getClass().getMethod("getBeanName", (Class[])null); - } catch (NoSuchMethodException e) { - //ignore - } - } - if (m != null) { - try { - beanName = (String)(m.invoke(beanInstance)); - } catch (Exception ex) { - LogUtils.log(LOG, Level.WARNING, "ERROR_DETERMINING_BEAN_NAME_EXC", ex); - } - } - - if (null == beanName) { - LogUtils.log(LOG, Level.FINE, "COULD_NOT_DETERMINE_BEAN_NAME_MSG", - beanInstance.getClass().getName()); - } - - return beanName; - } - - public final void setApplicationContext(ApplicationContext ac) { - appContexts = new CopyOnWriteArraySet(); - addApplicationContext(ac); - this.beanFactory = ac.getAutowireCapableBeanFactory(); - super.setBeanFactory(this.beanFactory); - } - - public final void addApplicationContext(ApplicationContext ac) { - if (!appContexts.contains(ac)) { - appContexts.add(ac); - List inactiveApplicationContexts = new ArrayList(); - Iterator it = appContexts.iterator(); - while (it.hasNext()) { - ApplicationContext c = it.next(); - if (c instanceof ConfigurableApplicationContext - && !((ConfigurableApplicationContext)c).isActive()) { - inactiveApplicationContexts.add(c); - } - } - // Remove the inactive application context here can avoid the UnsupportedOperationException - for (ApplicationContext context : inactiveApplicationContexts) { - appContexts.remove(context); - } - initWildcardDefinitionMap(); - } - } - - public void destroy() { - super.destroy(); - appContexts.clear(); - } - - public Class getRegistrationType() { - return Configurer.class; - } - - protected Set getAppContexts() { - return appContexts; - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/main/java/org/apache/cxf/configuration/spring/JAXBBeanFactory.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/configuration/spring/JAXBBeanFactory.java b/core/src/main/java/org/apache/cxf/configuration/spring/JAXBBeanFactory.java deleted file mode 100644 index c542482..0000000 --- a/core/src/main/java/org/apache/cxf/configuration/spring/JAXBBeanFactory.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * 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.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.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.cxf.staxutils.StaxUtils; - -/** - * - */ -public final class JAXBBeanFactory { - private JAXBBeanFactory() { - //nothing - } - - public static Object createJAXBBean(JAXBContext context, - String s, - Class c) { - - StringReader reader = new StringReader(s); - XMLStreamReader data = StaxUtils.createXMLStreamReader(reader); - Unmarshaller u; - try { - Object obj; - 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(); - - } - return obj; - } catch (JAXBException e) { - throw new RuntimeException(e); - } finally { - try { - StaxUtils.close(data); - } catch (XMLStreamException ex) { - throw new RuntimeException(ex); - } - } - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/main/java/org/apache/cxf/configuration/spring/Messages.properties ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/configuration/spring/Messages.properties b/core/src/main/java/org/apache/cxf/configuration/spring/Messages.properties deleted file mode 100644 index ed8f59a..0000000 --- a/core/src/main/java/org/apache/cxf/configuration/spring/Messages.properties +++ /dev/null @@ -1,26 +0,0 @@ -# -# -# 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. -# -# -NO_MATCHING_BEAN_MSG = Could not find a definition for bean with id {0} - no injection will be performed. -COULD_NOT_DETERMINE_BEAN_NAME_MSG = Could not determine bean name for instance of class {0}. -ERROR_DETERMINING_BEAN_NAME_EXC = Failed to determine bean name. -JAXB_PROPERTY_EDITOR_EXC = Property editor failed to bind element {0}. -WILDCARD_BEAN_ID_WITH_NO_CLASS_MSG = Configuration bean with id {0} that uses a ''*'' or wildcard must have a class attribute. -ONE_WILDCARD_BEAN_ID_PER_CLASS_MSG = A wildcard configuration bean with id {0} already exists for class {1}. The wildcard bean with id {2} will be ignored. http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/main/java/org/apache/cxf/configuration/spring/SimpleBeanDefinitionParser.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/configuration/spring/SimpleBeanDefinitionParser.java b/core/src/main/java/org/apache/cxf/configuration/spring/SimpleBeanDefinitionParser.java deleted file mode 100644 index 442970c..0000000 --- a/core/src/main/java/org/apache/cxf/configuration/spring/SimpleBeanDefinitionParser.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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; - -/** - * This bean parser will map all the attributes to properties on the bean. - * - */ -public class SimpleBeanDefinitionParser extends AbstractBeanDefinitionParser { - - public SimpleBeanDefinitionParser(Class beanClass) { - super(); - setBeanClass(beanClass); - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/main/java/org/apache/cxf/configuration/spring/StringBeanDefinitionParser.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/configuration/spring/StringBeanDefinitionParser.java b/core/src/main/java/org/apache/cxf/configuration/spring/StringBeanDefinitionParser.java deleted file mode 100644 index 064c43d..0000000 --- a/core/src/main/java/org/apache/cxf/configuration/spring/StringBeanDefinitionParser.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * 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.Element; - -import org.apache.cxf.helpers.DOMUtils; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; - -public class StringBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { - - @Override - protected void doParse(Element element, BeanDefinitionBuilder builder) { - builder.addConstructorArgValue(DOMUtils.getRawContent(element)); - } - - @Override - protected Class getBeanClass(Element arg0) { - return String.class; - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/main/resources/META-INF/spring.handlers ---------------------------------------------------------------------- diff --git a/core/src/main/resources/META-INF/spring.handlers b/core/src/main/resources/META-INF/spring.handlers deleted file mode 100644 index 0db2322..0000000 --- a/core/src/main/resources/META-INF/spring.handlers +++ /dev/null @@ -1,21 +0,0 @@ -# -# -# 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/core=org.apache.cxf.bus.spring.NamespaceHandler http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/test/java/org/apache/cxf/bus/spring/BusApplicationContextTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/cxf/bus/spring/BusApplicationContextTest.java b/core/src/test/java/org/apache/cxf/bus/spring/BusApplicationContextTest.java deleted file mode 100644 index 60d6101..0000000 --- a/core/src/test/java/org/apache/cxf/bus/spring/BusApplicationContextTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.junit.Assert; -import org.junit.Test; - -import org.springframework.beans.BeansException; - -public class BusApplicationContextTest extends Assert { - - @Test - public void testGetResources() { - BusApplicationContext ctx = null; - - try { - ctx = new BusApplicationContext("nowhere.xml", false); - fail("Bus creation should have thrown exception."); - } catch (BeansException bex) { - //Expected - } - - String cfgFile = "/org/apache/cxf/bus/spring/resources/bus-overwrite.xml"; - ctx = new BusApplicationContext(cfgFile, false); - assertEquals("Unexpected number of resources", 1, ctx.getConfigResources().length); - ctx.close(); - ctx = new BusApplicationContext(cfgFile, true); - assertEquals("Unexpected number of resources", 2, ctx.getConfigResources().length); - ctx.close(); - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/test/java/org/apache/cxf/bus/spring/BusApplicationListenerTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/cxf/bus/spring/BusApplicationListenerTest.java b/core/src/test/java/org/apache/cxf/bus/spring/BusApplicationListenerTest.java deleted file mode 100644 index 9b0b7a3..0000000 --- a/core/src/test/java/org/apache/cxf/bus/spring/BusApplicationListenerTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.apache.cxf.Bus; -import org.apache.cxf.bus.managers.CXFBusLifeCycleManager; -import org.apache.cxf.buslifecycle.BusLifeCycleListener; -import org.easymock.EasyMock; -import org.junit.Assert; -import org.junit.Test; -import org.springframework.context.support.AbstractRefreshableApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - - - -public class BusApplicationListenerTest extends Assert { - - @Test - public void testParentApplicationEvent() { - AbstractRefreshableApplicationContext parent = new ClassPathXmlApplicationContext(); - parent.refresh(); - SpringBusFactory factory = new SpringBusFactory(parent); - Bus bus = factory.createBus(); - CXFBusLifeCycleManager manager = bus.getExtension(CXFBusLifeCycleManager.class); - BusLifeCycleListener listener = EasyMock.createMock(BusLifeCycleListener.class); - manager.registerLifeCycleListener(listener); - EasyMock.reset(listener); - listener.preShutdown(); - EasyMock.expectLastCall().times(1); - listener.postShutdown(); - EasyMock.expectLastCall().times(1); - EasyMock.replay(listener); - parent.close(); - EasyMock.verify(listener); - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e46d0180/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java b/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java deleted file mode 100644 index 2c63150..0000000 --- a/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/** - * 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.Collection; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - -import javax.annotation.PostConstruct; - -import org.apache.cxf.Bus; -import org.apache.cxf.buslifecycle.BusLifeCycleListener; -import org.apache.cxf.buslifecycle.BusLifeCycleManager; -import org.apache.cxf.feature.AbstractFeature; -import org.apache.cxf.feature.Feature; -import org.apache.cxf.interceptor.Interceptor; -import org.apache.cxf.interceptor.LoggingInInterceptor; -import org.apache.cxf.message.Message; - -import org.junit.Assert; -import org.junit.Test; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - -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> in = bus.getInInterceptors(); - boolean found = false; - for (Interceptor i : in) { - if (i instanceof LoggingInInterceptor) { - found = true; - } - } - assertTrue("could not find logging interceptor.", found); - - Collection features = bus.getFeatures(); - TestFeature tf = null; - for (Feature f : features) { - if (f instanceof TestFeature) { - tf = (TestFeature)f; - break; - } - } - - assertNotNull(tf); - assertTrue("test feature has not been initialised", tf.initialised); - assertNotNull("test feature has not been injected", tf.testBean); - assertTrue("bean injected into test feature has not been initialised", tf.testBean.initialised); - } - - @Test - public void testBusConfigure() { - ClassPathXmlApplicationContext context = null; - try { - context = new ClassPathXmlApplicationContext("org/apache/cxf/bus/spring/customerBus.xml"); - Bus cxf1 = (Bus)context.getBean("cxf1"); - - assertTrue(cxf1.getOutInterceptors().size() == 1); - assertTrue(cxf1.getInInterceptors().size() == 0); - - Bus cxf2 = (Bus)context.getBean("cxf2"); - assertTrue(cxf2.getInInterceptors().size() == 1); - assertTrue(cxf2.getOutInterceptors().size() == 0); - } finally { - if (context != null) { - context.close(); - } - } - } - @Test - public void testBusConfigureCreateBus() { - ClassPathXmlApplicationContext context = null; - final AtomicBoolean b = new AtomicBoolean(); - try { - context = new ClassPathXmlApplicationContext("org/apache/cxf/bus/spring/customerBus2.xml"); - Bus cxf1 = (Bus)context.getBean("cxf1"); - - assertTrue(cxf1.getOutInterceptors().size() == 1); - assertTrue(cxf1.getInInterceptors().size() == 0); - - Bus cxf2 = (Bus)context.getBean("cxf2"); - - assertTrue(cxf2.getInInterceptors().size() == 1); - assertTrue(cxf2.getOutInterceptors().size() == 0); - - cxf2.getExtension(BusLifeCycleManager.class) - .registerLifeCycleListener(new BusLifeCycleListener() { - public void initComplete() { - } - - public void preShutdown() { - } - - public void postShutdown() { - b.set(true); - } - - }); - } finally { - if (context != null) { - context.close(); - } - } - assertTrue("postShutdown not called", b.get()); - } - @Test - public void testLazyInit() { - String cfgFile = "org/apache/cxf/bus/spring/lazyInitBus.xml"; - Bus bus = new SpringBusFactory().createBus(cfgFile, true); - - List> in = bus.getInInterceptors(); - boolean found = false; - for (Interceptor i : in) { - if (i instanceof LoggingInInterceptor) { - found = true; - } - } - assertTrue("could not find logging interceptor.", found); - } - - static class TestBean { - - boolean initialised; - - @PostConstruct - public void initialise() { - initialised = true; - } - } - - static class TestFeature extends AbstractFeature { - - boolean initialised; - TestBean testBean; - - @PostConstruct - public void initialise() { - initialised = true; - } - - public void setTestBean(TestBean tb) { - testBean = tb; - } - } - -}