Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BCF4B200B8D for ; Fri, 23 Sep 2016 13:29:36 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id BB76C160ACA; Fri, 23 Sep 2016 11:29:36 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 893B7160AD6 for ; Fri, 23 Sep 2016 13:29:34 +0200 (CEST) Received: (qmail 21803 invoked by uid 500); 23 Sep 2016 11:29:33 -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 21514 invoked by uid 99); 23 Sep 2016 11:29:33 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Sep 2016 11:29:33 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1069DE05D9; Fri, 23 Sep 2016 11:29:32 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: cschneider@apache.org To: commits@cxf.apache.org Date: Fri, 23 Sep 2016 11:29:33 -0000 Message-Id: <775c3706a1774f0a97ab7376f92d4cd8@git.apache.org> In-Reply-To: <312f08acd5bc4593aa29646e06c04bb8@git.apache.org> References: <312f08acd5bc4593aa29646e06c04bb8@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/4] cxf git commit: Experimentally simply remove spring and blueprint related classes to see how much cxf is tied to it archived-at: Fri, 23 Sep 2016 11:29:36 -0000 http://git-wip-us.apache.org/repos/asf/cxf/blob/5e965955/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java b/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java deleted file mode 100644 index 1e34cf0..0000000 --- a/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java +++ /dev/null @@ -1,441 +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.blueprint; - -import java.io.StringReader; -import java.io.StringWriter; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -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.apache.aries.blueprint.ComponentDefinitionRegistry; -import org.apache.aries.blueprint.ParserContext; -import org.apache.aries.blueprint.PassThroughMetadata; -import org.apache.aries.blueprint.mutable.MutableBeanMetadata; -import org.apache.aries.blueprint.mutable.MutableCollectionMetadata; -import org.apache.aries.blueprint.mutable.MutablePassThroughMetadata; -import org.apache.aries.blueprint.mutable.MutableRefMetadata; -import org.apache.aries.blueprint.mutable.MutableValueMetadata; -import org.apache.cxf.bus.blueprint.BlueprintBus; -import org.apache.cxf.common.jaxb.JAXBContextCache; -import org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas; -import org.apache.cxf.common.jaxb.JAXBUtils; -import org.apache.cxf.common.util.PackageUtils; -import org.apache.cxf.common.util.StringUtils; -import org.apache.cxf.helpers.DOMUtils; -import org.apache.cxf.staxutils.StaxUtils; -import org.osgi.service.blueprint.reflect.BeanMetadata; -import org.osgi.service.blueprint.reflect.CollectionMetadata; -import org.osgi.service.blueprint.reflect.ComponentMetadata; -import org.osgi.service.blueprint.reflect.MapMetadata; -import org.osgi.service.blueprint.reflect.Metadata; -import org.osgi.service.blueprint.reflect.RefMetadata; -import org.osgi.service.blueprint.reflect.ValueMetadata; - -public abstract class AbstractBPBeanDefinitionParser { - - private static final String XMLNS_BLUEPRINT = "http://www.osgi.org/xmlns/blueprint/v1.0.0"; - private static final String COMPONENT_ID = "component-id"; - - private JAXBContext jaxbContext; - private Set> jaxbClasses; - - protected boolean hasBusProperty() { - return false; - } - - public Metadata createValue(ParserContext context, QName qName) { - MutableBeanMetadata v = context.createMetadata(MutableBeanMetadata.class); - v.setRuntimeClass(QName.class); - v.addArgument(createValue(context, qName.getNamespaceURI()), null, 0); - v.addArgument(createValue(context, qName.getLocalPart()), null, 1); - return v; - } - - protected Metadata parseListData(ParserContext context, - ComponentMetadata enclosingComponent, - Element element) { - MutableCollectionMetadata m - = (MutableCollectionMetadata) context.parseElement(CollectionMetadata.class, - enclosingComponent, element); - m.setCollectionClass(List.class); - return m; - } - - protected Metadata parseMapData(ParserContext context, - ComponentMetadata enclosingComponent, - Element element) { - return context.parseElement(MapMetadata.class, enclosingComponent, element); - } - - protected void setFirstChildAsProperty(Element element, - ParserContext ctx, - MutableBeanMetadata bean, - String propertyName) { - - Element first = DOMUtils.getFirstElement(element); - - if (first == null) { - throw new IllegalStateException(propertyName + " property must have child elements!"); - } - - String id; - if (first.getNamespaceURI().equals(XMLNS_BLUEPRINT)) { - String name = first.getLocalName(); - if ("ref".equals(name)) { - id = first.getAttribute(COMPONENT_ID); - if (id == null) { - throw new IllegalStateException(" elements must have a \"component-id\" attribute!"); - } - bean.addProperty(propertyName, createRef(ctx, id)); - } else { - //Rely on BP to handle these ones. - bean.addProperty(propertyName, ctx.parseElement(Metadata.class, bean, first)); - } - } else { - bean.addProperty(propertyName, ctx.parseElement(Metadata.class, bean, first)); - } - } - - public QName parseQName(Element element, String t) { - String t1 = t; - String ns = null; - String pre = null; - String local = null; - - if (t1.startsWith("{")) { - int i = t1.indexOf('}'); - if (i == -1) { - throw new RuntimeException("Namespace bracket '{' must having a closing bracket '}'."); - } - - ns = t1.substring(1, i); - t1 = t1.substring(i + 1); - } - - int colIdx = t1.indexOf(':'); - if (colIdx == -1) { - local = t1; - pre = ""; - - ns = DOMUtils.getNamespace(element, ""); - } else { - pre = t1.substring(0, colIdx); - local = t1.substring(colIdx + 1); - - ns = DOMUtils.getNamespace(element, pre); - } - - return new QName(ns, local, pre); - } - - protected boolean parseAttributes(Element element, ParserContext ctx, MutableBeanMetadata 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) || "abstract".equals(name)) { - bean.setScope(BeanMetadata.SCOPE_PROTOTYPE); - } else { - if ("depends-on".equals(name)) { - bean.addDependsOn(val); - } else if ("name".equals(name)) { - processNameAttribute(element, ctx, bean, val); - } else if ("bus".equals(name)) { - processBusAttribute(element, ctx, bean, val); - } else if (!"id".equals(name) && isAttribute(pre, name)) { - mapAttribute(bean, element, name, val, ctx); - } - } - } - return setBus; - } - protected void processBusAttribute(Element element, ParserContext ctx, - MutableBeanMetadata bean, String val) { - if (this.hasBusProperty()) { - bean.addProperty("bus", getBusRef(ctx, val)); - } else { - bean.addArgument(getBusRef(ctx, val), null, 0); - } - } - - protected void processNameAttribute(Element element, - ParserContext ctx, - MutableBeanMetadata bean, - String val) { - //nothing - } - protected void mapAttribute(MutableBeanMetadata bean, Element e, - String name, String val, ParserContext context) { - mapToProperty(bean, name, val, context); - } - - 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 boolean isNamespace(String name, String prefix) { - return "xmlns".equals(prefix) || prefix == null && "xmlns".equals(name); - } - - protected void mapElement(ParserContext ctx, MutableBeanMetadata bean, Element el, String name) { - } - - protected void mapToProperty(MutableBeanMetadata bean, - String propertyName, - String val, - ParserContext context) { - if ("id".equals(propertyName)) { - return; - } - - if (!StringUtils.isEmpty(val)) { - if (val.startsWith("#")) { - bean.addProperty(propertyName, createRef(context, val.substring(1))); - } else { - bean.addProperty(propertyName, createValue(context, val)); - } - } - } - - public static ValueMetadata createValue(ParserContext context, String value) { - MutableValueMetadata v = context.createMetadata(MutableValueMetadata.class); - v.setStringValue(value); - return v; - } - - public static RefMetadata createRef(ParserContext context, String value) { - MutableRefMetadata r = context.createMetadata(MutableRefMetadata.class); - r.setComponentId(value); - return r; - } - - public static PassThroughMetadata createPassThrough(ParserContext context, Object value) { - MutablePassThroughMetadata v = context.createMetadata(MutablePassThroughMetadata.class); - v.setObject(value); - return v; - } - - public static MutableBeanMetadata createObjectOfClass(ParserContext context, String value) { - MutableBeanMetadata v = context.createMetadata(MutableBeanMetadata.class); - v.setClassName(value); - return v; - } - - protected MutableBeanMetadata getBus(ParserContext context, String name) { - ComponentDefinitionRegistry cdr = context.getComponentDefinitionRegistry(); - ComponentMetadata meta = cdr.getComponentDefinition("blueprintBundle"); - - if (!cdr.containsComponentDefinition(InterceptorTypeConverter.class.getName())) { - MutablePassThroughMetadata md = context.createMetadata(MutablePassThroughMetadata.class); - md.setObject(new InterceptorTypeConverter()); - - md.setId(InterceptorTypeConverter.class.getName()); - context.getComponentDefinitionRegistry().registerTypeConverter(md); - } - if (!cdr.containsComponentDefinition(name)) { - //Create a bus - - MutableBeanMetadata bus = context.createMetadata(MutableBeanMetadata.class); - bus.setId(name); - bus.setRuntimeClass(BlueprintBus.class); - if (meta != null) { - //blueprint-no-osgi does not provide a bundleContext - bus.addProperty("bundleContext", createRef(context, "blueprintBundleContext")); - } - bus.addProperty("blueprintContainer", createRef(context, "blueprintContainer")); - bus.setDestroyMethod("shutdown"); - bus.setInitMethod("initialize"); - - context.getComponentDefinitionRegistry().registerComponentDefinition(bus); - - return bus; - } - return (MutableBeanMetadata) cdr.getComponentDefinition(name); - } - - protected RefMetadata getBusRef(ParserContext context, String name) { - if ("cxf".equals(name)) { - getBus(context, name); - } - return createRef(context, name); - } - - protected void parseChildElements(Element element, ParserContext ctx, MutableBeanMetadata bean) { - Element el = DOMUtils.getFirstElement(element); - while (el != null) { - String name = el.getLocalName(); - mapElement(ctx, bean, el, name); - el = DOMUtils.getNextElement(el); - } - } - - protected void mapElementToJaxbProperty(ParserContext ctx, - MutableBeanMetadata bean, Element parent, - QName name, - String propertyName, - Class c) { - Element data = DOMUtils.getFirstChildWithName(parent, name); - if (data == null) { - return; - } - - mapElementToJaxbProperty(ctx, bean, data, propertyName, c); - } - - public static class JAXBBeanFactory { - final JAXBContext ctx; - final Class cls; - public JAXBBeanFactory(JAXBContext c, Class c2) { - ctx = c; - cls = c2; - } - - - public Object createJAXBBean(String v) { - XMLStreamReader reader = StaxUtils.createXMLStreamReader(new StringReader(v)); - try { - Object o = JAXBUtils.unmarshall(ctx, reader, cls); - if (o instanceof JAXBElement) { - JAXBElement el = (JAXBElement)o; - o = el.getValue(); - } - return o; - } catch (JAXBException e) { - throw new RuntimeException(e); - } finally { - try { - reader.close(); - } catch (XMLStreamException e) { - //ignore - } - } - } - } - - protected void mapElementToJaxbProperty(ParserContext ctx, - MutableBeanMetadata bean, - Element data, - String propertyName, - Class c) { - try { - XMLStreamWriter xmlWriter = null; - Unmarshaller u = null; - try { - StringWriter writer = new StringWriter(); - xmlWriter = StaxUtils.createXMLStreamWriter(writer); - StaxUtils.copy(data, xmlWriter); - xmlWriter.flush(); - - - MutableBeanMetadata factory = ctx.createMetadata(MutableBeanMetadata.class); - factory.setClassName(c.getName()); - factory.setFactoryComponent(createPassThrough(ctx, new JAXBBeanFactory(getContext(c), c))); - factory.setFactoryMethod("createJAXBBean"); - factory.addArgument(createValue(ctx, writer.toString()), String.class.getName(), 0); - bean.addProperty(propertyName, factory); - - } catch (Exception ex) { - u = getContext(c).createUnmarshaller(); - u.setEventHandler(null); - 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) { - MutablePassThroughMetadata value = ctx.createMetadata(MutablePassThroughMetadata.class); - value.setObject(obj); - bean.addProperty(propertyName, value); - } - } finally { - StaxUtils.close(xmlWriter); - JAXBUtils.closeUnmarshaller(u); - } - } catch (JAXBException e) { - throw new RuntimeException("Could not parse configuration.", e); - } - } - - - protected synchronized JAXBContext getContext(Class cls) { - if (jaxbContext == null || jaxbClasses == null || !jaxbClasses.contains(cls)) { - try { - Set> tmp = new HashSet>(); - if (jaxbClasses != null) { - tmp.addAll(jaxbClasses); - } - JAXBContextCache.addPackage(tmp, PackageUtils.getPackageName(cls), - 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); - jaxbClasses = ccs.getClasses(); - jaxbContext = ccs.getContext(); - } catch (JAXBException e) { - throw new RuntimeException(e); - } - } - return jaxbContext; - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/5e965955/core/src/main/java/org/apache/cxf/configuration/blueprint/InterceptorTypeConverter.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/configuration/blueprint/InterceptorTypeConverter.java b/core/src/main/java/org/apache/cxf/configuration/blueprint/InterceptorTypeConverter.java deleted file mode 100644 index fca633c..0000000 --- a/core/src/main/java/org/apache/cxf/configuration/blueprint/InterceptorTypeConverter.java +++ /dev/null @@ -1,42 +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.blueprint; - -import org.apache.cxf.interceptor.Interceptor; -import org.osgi.service.blueprint.container.Converter; -import org.osgi.service.blueprint.container.ReifiedType; - -/** - * - */ -public class InterceptorTypeConverter implements Converter { - - /** {@inheritDoc}*/ - public boolean canConvert(Object sourceObject, ReifiedType targetType) { - return sourceObject instanceof Interceptor - && targetType.getRawClass().isInstance(sourceObject); - } - - /** {@inheritDoc}*/ - public Object convert(Object sourceObject, ReifiedType targetType) throws Exception { - return sourceObject; - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/5e965955/core/src/main/java/org/apache/cxf/configuration/blueprint/SimpleBPBeanDefinitionParser.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/configuration/blueprint/SimpleBPBeanDefinitionParser.java b/core/src/main/java/org/apache/cxf/configuration/blueprint/SimpleBPBeanDefinitionParser.java deleted file mode 100644 index 77ce8b3..0000000 --- a/core/src/main/java/org/apache/cxf/configuration/blueprint/SimpleBPBeanDefinitionParser.java +++ /dev/null @@ -1,87 +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.blueprint; - -import org.w3c.dom.Element; - -import org.apache.aries.blueprint.ParserContext; -import org.apache.aries.blueprint.mutable.MutableBeanMetadata; -import org.osgi.service.blueprint.reflect.BeanProperty; -import org.osgi.service.blueprint.reflect.Metadata; - -/** - * - */ -public class SimpleBPBeanDefinitionParser extends AbstractBPBeanDefinitionParser { - protected Class cls; - - public SimpleBPBeanDefinitionParser(Class cls) { - this.cls = cls; - } - - public String getFactorySuffix() { - return null; - } - public String getFactoryCreateType(Element element) { - return null; - } - - public String getId(Element element, ParserContext context) { - return element.hasAttribute("id") ? element.getAttribute("id") : null; - } - - public Metadata parse(Element element, ParserContext context) { - - MutableBeanMetadata cxfBean = context.createMetadata(MutableBeanMetadata.class); - cxfBean.setRuntimeClass(cls); - String fact = getFactorySuffix(); - if (fact == null) { - cxfBean.setId(getId(element, context)); - } else { - cxfBean.setId(getId(element, context) + fact); - } - parseAttributes(element, context, cxfBean); - parseChildElements(element, context, cxfBean); - if (hasBusProperty()) { - boolean foundBus = false; - for (BeanProperty bp : cxfBean.getProperties()) { - if ("bus".equals(bp.getName())) { - foundBus = true; - } - } - if (!foundBus) { - cxfBean.addProperty("bus", getBusRef(context, "cxf")); - } - } - if (fact != null) { - context.getComponentDefinitionRegistry().registerComponentDefinition(cxfBean); - - MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class); - bean.setId(getId(element, context)); - bean.setFactoryComponent(cxfBean); - bean.setFactoryMethod("create"); - bean.setClassName(getFactoryCreateType(element)); - return bean; - } - return cxfBean; - } - - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/5e965955/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 e6e55de..0000000 --- a/core/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java +++ /dev/null @@ -1,533 +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.jaxb.JAXBUtils; -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); - - setBus |= parseAttribute(element, node, ctx, bean); - } - return setBus; - } - protected boolean parseAttribute(Element element, Attr node, - ParserContext ctx, BeanDefinitionBuilder bean) { - String val = node.getValue(); - String pre = node.getPrefix(); - String name = node.getLocalName(); - String prefix = node.getPrefix(); - - // Don't process namespaces - if (isNamespace(name, prefix)) { - return false; - } - - 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)) { - return processBusAttribute(element, ctx, bean, val); - } else if (!"id".equals(name) && isAttribute(pre, name)) { - mapAttribute(bean, element, name, val); - } - return false; - } - - - 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; - Unmarshaller u = 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) { - u = getContext(c).createUnmarshaller(); - u.setEventHandler(null); - 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); - JAXBUtils.closeUnmarshaller(u); - } - } 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); - Unmarshaller u = null; - try { - 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); - } - JAXBUtils.closeUnmarshaller(u); - } - } - - 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/5e965955/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/5e965955/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/5e965955/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 2e0de2a..0000000 --- a/core/src/main/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java +++ /dev/null @@ -1,289 +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.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -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 TreeMap>(); - private BeanFactory beanFactory; - - static class MatcherHolder implements Comparable { - Matcher matcher; - String wildCardId; - MatcherHolder(String orig, Matcher matcher) { - wildCardId = orig; - this.matcher = matcher; - } - @Override - public int compareTo(MatcherHolder mh) { - Integer literalCharsLen1 = this.wildCardId.replaceAll("\\*", "").length(); - Integer literalCharsLen2 = mh.wildCardId.replaceAll("\\*", "").length(); - // The expression with more literal characters should end up on the top of the list - return literalCharsLen1.compareTo(literalCharsLen2) * -1; - } - } - - 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/5e965955/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 9c606df..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.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.cxf.common.jaxb.JAXBUtils; -import org.apache.cxf.staxutils.StaxUtils; - -/** - * - */ -public final class JAXBBeanFactory { - private JAXBBeanFactory() { - //nothing - } - - public static T createJAXBBean(JAXBContext context, - String s, - Class c) { - - StringReader reader = new StringReader(s); - XMLStreamReader data = StaxUtils.createXMLStreamReader(reader); - try { - - T obj = null; - if (c != null) { - obj = JAXBUtils.unmarshall(context, data, c).getValue(); - } else { - Object o = JAXBUtils.unmarshall(context, data); - if (o instanceof JAXBElement) { - JAXBElement el = (JAXBElement)o; - @SuppressWarnings("unchecked") - T ot = (T)el.getValue(); - obj = ot; - } - } - 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/5e965955/core/src/main/java/org/apache/cxf/configuration/spring/MappingBeanDefinitionParser.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/configuration/spring/MappingBeanDefinitionParser.java b/core/src/main/java/org/apache/cxf/configuration/spring/MappingBeanDefinitionParser.java deleted file mode 100644 index 776edc5..0000000 --- a/core/src/main/java/org/apache/cxf/configuration/spring/MappingBeanDefinitionParser.java +++ /dev/null @@ -1,59 +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.util.Collections; -import java.util.Map; - -import javax.xml.stream.XMLStreamException; - -import org.w3c.dom.Element; - -import org.apache.cxf.staxutils.StaxUtils; -import org.apache.cxf.staxutils.W3CDOMStreamWriter; -import org.apache.cxf.staxutils.transform.OutTransformWriter; -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.xml.ParserContext; - -public class MappingBeanDefinitionParser - extends org.springframework.beans.factory.xml.AbstractBeanDefinitionParser { - - private final Map transformMap; - public MappingBeanDefinitionParser(String oldns, String newns) { - transformMap = Collections.singletonMap("{" + oldns + "}*", "{" + newns + "}*"); - } - - @Override - protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { - element = transformElement(element); - return (AbstractBeanDefinition)parserContext.getDelegate().parseCustomElement(element); - } - private Element transformElement(Element element) { - - W3CDOMStreamWriter domWriter = new W3CDOMStreamWriter(); - OutTransformWriter transformWriter = new OutTransformWriter(domWriter, transformMap); - try { - StaxUtils.copy(element, transformWriter); - } catch (XMLStreamException e) { - throw new RuntimeException(e); - } - return domWriter.getDocument().getDocumentElement(); - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/5e965955/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/5e965955/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/5e965955/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/5e965955/core/src/main/java/org/apache/cxf/internal/CXFAPINamespaceHandler.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/internal/CXFAPINamespaceHandler.java b/core/src/main/java/org/apache/cxf/internal/CXFAPINamespaceHandler.java deleted file mode 100644 index 507e1ca..0000000 --- a/core/src/main/java/org/apache/cxf/internal/CXFAPINamespaceHandler.java +++ /dev/null @@ -1,114 +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.internal; - -import java.net.URL; -import java.util.Set; - -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -import org.apache.aries.blueprint.NamespaceHandler; -import org.apache.aries.blueprint.Namespaces; -import org.apache.aries.blueprint.ParserContext; -import org.apache.aries.blueprint.mutable.MutableBeanMetadata; -import org.apache.cxf.bus.blueprint.BusDefinitionParser; -import org.apache.cxf.configuration.blueprint.SimpleBPBeanDefinitionParser; -import org.apache.cxf.feature.FastInfosetFeature; -import org.apache.cxf.feature.LoggingFeature; -import org.apache.cxf.workqueue.AutomaticWorkQueueImpl; -import org.osgi.service.blueprint.reflect.ComponentMetadata; -import org.osgi.service.blueprint.reflect.Metadata; - -@Namespaces({"http://cxf.apache.org/blueprint/core", - "http://cxf.apache.org/configuration/beans", - "http://cxf.apache.org/configuration/parameterized-types", - "http://cxf.apache.org/configuration/security", - "http://schemas.xmlsoap.org/wsdl/", - "http://www.w3.org/2005/08/addressing", - "http://schemas.xmlsoap.org/ws/2004/08/addressing"}) -public class CXFAPINamespaceHandler implements NamespaceHandler { - - public URL getSchemaLocation(String namespace) { - String location = null; - - if ("http://cxf.apache.org/configuration/beans".equals(namespace)) { - location = "schemas/configuration/cxf-beans.xsd"; - } else if ("http://cxf.apache.org/configuration/parameterized-types".equals(namespace)) { - location = "schemas/configuration/parameterized-types.xsd"; - } else if ("http://cxf.apache.org/configuration/security".equals(namespace)) { - location = "schemas/configuration/security.xsd"; - } else if ("http://schemas.xmlsoap.org/wsdl/".equals(namespace)) { - location = "schemas/wsdl/wsdl.xsd"; - } else if ("http://www.w3.org/2005/08/addressing".equals(namespace)) { - location = "schemas/wsdl/ws-addr.xsd"; - } else if ("http://schemas.xmlsoap.org/ws/2004/08/addressing".equals(namespace)) { - location = "schemas/wsdl/addressing.xsd"; - } else if ("http://cxf.apache.org/blueprint/core".equals(namespace)) { - location = "schemas/blueprint/core.xsd"; - } - if (location != null) { - return getClass().getClassLoader().getResource(location); - } - return null; - } - - - public Metadata parse(Element element, ParserContext context) { - String s = element.getLocalName(); - if ("bus".equals(s)) { - //parse bus - return new BusDefinitionParser().parse(element, context); - } else if ("logging".equals(s)) { - //logging feature - return new SimpleBPBeanDefinitionParser(LoggingFeature.class).parse(element, context); - } else if ("fastinfoset".equals(s)) { - //fastinfosetfeature - return new SimpleBPBeanDefinitionParser(FastInfosetFeature.class).parse(element, context); - } else if ("workqueue".equals(s)) { - return new SimpleBPBeanDefinitionParser(AutomaticWorkQueueImpl.class) { - public String getId(Element element, ParserContext context) { - String id = element.hasAttribute("id") ? element.getAttribute("id") : null; - if (id == null) { - id = "cxf.workqueue."; - id += element.hasAttribute("name") ? element.getAttribute("name") : "def"; - } - return id; - } - - protected void processNameAttribute(Element element, ParserContext ctx, - MutableBeanMetadata bean, String val) { - bean.addProperty("name", createValue(ctx, val)); - } - } .parse(element, context); - } - return null; - } - - @SuppressWarnings("rawtypes") - public Set getManagedClasses() { - //probably should have the various stuff in cxf-api in here? - return null; - } - public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) { - return null; - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/5e965955/core/src/main/java/org/apache/cxf/service/invoker/spring/SpringBeanFactory.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/service/invoker/spring/SpringBeanFactory.java b/core/src/main/java/org/apache/cxf/service/invoker/spring/SpringBeanFactory.java deleted file mode 100644 index d5911b3..0000000 --- a/core/src/main/java/org/apache/cxf/service/invoker/spring/SpringBeanFactory.java +++ /dev/null @@ -1,65 +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.service.invoker.spring; - -import org.apache.cxf.message.Exchange; -import org.apache.cxf.service.invoker.Factory; -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; - -/** - * Factory that will query the Spring ApplicationContext for the - * appropriate bean for each request. - * - * This can be expensive. If the bean is "prototype" or similar such that a - * new instance is created each time, this could slow things down. In that - * case, it's recommended to use this in conjunction with the PooledFactory - * to pool the beans or the SessionFactory or similar. - */ -public class SpringBeanFactory implements Factory, ApplicationContextAware { - volatile ApplicationContext ctx; - final String beanName; - - public SpringBeanFactory(String name) { - beanName = name; - } - public SpringBeanFactory(Class c, String[] args) { //NOPMD - beanName = args[0]; - } - - /** {@inheritDoc}*/ - public Object create(Exchange e) throws Throwable { - if (ctx == null) { - ctx = e.getBus().getExtension(ApplicationContext.class); - } - return ctx.getBean(beanName); - } - - /** {@inheritDoc}*/ - public void release(Exchange e, Object o) { - //nothing - } - - public void setApplicationContext(ApplicationContext arg0) throws BeansException { - ctx = arg0; - } - -}