1 package org.apache.maven.archiva.common.spring;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import java.io.InputStream;
24 import javax.xml.transform.Source;
25 import javax.xml.transform.Transformer;
26 import javax.xml.transform.TransformerFactory;
27 import javax.xml.transform.dom.DOMResult;
28 import javax.xml.transform.dom.DOMSource;
29 import javax.xml.transform.stream.StreamSource;
31 import org.springframework.beans.factory.xml.BeanDefinitionDocumentReader;
32 import org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader;
33 import org.springframework.beans.factory.xml.XmlReaderContext;
34 import org.w3c.dom.Document;
37 * A Spring {@link BeanDefinitionDocumentReader} that converts on the fly the
38 * Plexus components descriptor to a spring XML context.
40 * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
43 public class PlexusBeanDefinitionDocumentReader
44 extends DefaultBeanDefinitionDocumentReader
47 public void registerBeanDefinitions( Document doc, XmlReaderContext readerContext )
49 doc = convertPlexusDescriptorToSpringBeans( doc );
50 super.registerBeanDefinitions( doc, readerContext );
53 protected Document convertPlexusDescriptorToSpringBeans( Document doc )
57 Source xmlSource = new DOMSource( doc );
58 InputStream is = getClass().getResourceAsStream( "plexus2spring.xsl" );
59 Source xsltSource = new StreamSource( is );
61 DOMResult transResult = new DOMResult();
63 // FIXME : uses Xalan extension. need either to force Xalan as Transformer or
64 // register a XpathFunctionResolver (how ?)
65 TransformerFactory tf = TransformerFactory.newInstance();
66 Transformer t = tf.newTransformer( xsltSource );
67 t.transform( xmlSource, transResult );
69 return (Document) transResult.getNode();
73 // FIXME log the error;