GH-106 - Remove support for XML namespace.

This commit is contained in:
Oliver Drotbohm
2025-02-13 12:41:58 +01:00
parent e9a0184556
commit 4d7d024c98
9 changed files with 20 additions and 256 deletions

View File

@@ -1,80 +0,0 @@
/*
* Copyright 2008-2012 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.plugin.core.config;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;
/**
* Bean definition parser to register {@code <list />} elements from the plugin namespace.
*
* @author Oliver Gierke
*/
public class PluginListDefinitionParser extends AbstractBeanDefinitionParser {
protected static final String PACKAGE = "org.springframework.plugin.core.support.";
/**
* Returns the name of the {@link org.springframework.beans.factory.config.BeanFactoryPostProcessor} to be registered.
*
* @return
*/
protected String getPostProcessorName() {
return PACKAGE + "BeanListFactoryBean";
}
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#parseInternal(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
*/
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext context) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(getPostProcessorName());
builder.addPropertyValue("type", element.getAttribute("class"));
return getSourcedBeanDefinition(builder, element, context);
}
/**
* Returns the bean definition prepared by the builder and has connected it to the {@code source} object.
*
* @param builder
* @param source
* @param context
* @return
*/
private AbstractBeanDefinition getSourcedBeanDefinition(BeanDefinitionBuilder builder, Object source,
ParserContext context) {
AbstractBeanDefinition definition = builder.getRawBeanDefinition();
definition.setSource(context.extractSource(source));
return definition;
}
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#shouldGenerateIdAsFallback()
*/
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
}
}

View File

@@ -1,35 +0,0 @@
/*
* Copyright 2008-2012 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.plugin.core.config;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
/**
* Simple namespace handler for {@literal plugin-config} namespace.
*
* @author Oliver Gierke
*/
public class PluginNamespaceHandler extends NamespaceHandlerSupport {
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.xml.NamespaceHandler#init()
*/
public void init() {
registerBeanDefinitionParser("list", new PluginListDefinitionParser());
registerBeanDefinitionParser("registry", new PluginRegistryDefinitionParser());
}
}

View File

@@ -1,35 +0,0 @@
/*
* Copyright 2008-2012 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.plugin.core.config;
/**
* Simple extension of {@link PluginListDefinitionParser}. Simply registers a
* {@link PluginRegistryBeanFactoryPostProcessor} instead of the original class.
*
* @author Oliver Gierke
*/
public class PluginRegistryDefinitionParser extends PluginListDefinitionParser {
/*
* (non-Javadoc)
* @see org.springframework.plugin.core.config.PluginListDefinitionParser#getPostProcessorName()
*/
@Override
protected String getPostProcessorName() {
return PACKAGE + "PluginRegistryFactoryBean";
}
}

View File

@@ -1 +0,0 @@
http\://www.springframework.org/schema/plugin=org.springframework.plugin.core.config.PluginNamespaceHandler

View File

@@ -1 +0,0 @@
http\://www.springframework.org/schema/plugin/spring-plugin.xsd=org/springframework/plugin/core/config/spring-plugin.xsd

View File

@@ -1,4 +0,0 @@
# Tooling related information for the Spring Plugin namespace
http\://www.springframework.org/schema/plugin@name=Spring Plugin Namespace
http\://www.springframework.org/schema/plugin@prefix=plugin
http\://www.springframework.org/schema/plugin@icon=org/springframework/beans/factory/xml/spring-beans.gif

View File

@@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns="http://www.springframework.org/schema/plugin" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:tool="http://www.springframework.org/schema/tool"
targetNamespace="http://www.springframework.org/schema/plugin" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:import namespace="http://www.springframework.org/schema/tool" />
<xsd:element name="list" type="pluginType">
<xsd:annotation>
<xsd:documentation>
Collects all beans implementing the
configured interface and exposes them as list under the
configured id. Can be used in a nested manner, too. Will
regard the order of the collected beans if they either
implement Ordered or are annotated with @Order.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports identifier="@id"
type="java.util.List" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="registry" type="pluginType">
<xsd:annotation>
<xsd:documentation>
Creates a PluginRegistry for all beans
implementing the configured type. Thus the type
configured in the class attribute has to extend Plugin.
The registry will consider the order of the plugins if
they implement Ordered or are annotated with @Order.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="org.springframework.plugin.core.OrderAwarePluginRegistry" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:complexType name="pluginType">
<xsd:attribute name="id" type="xsd:string" />
<xsd:attribute name="class" type="classType" />
<xsd:attribute name="init-factories" type="xsd:boolean" default="false" />
</xsd:complexType>
<xsd:simpleType name="classType">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="direct">
<tool:expected-type type="java.lang.Class" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:union memberTypes="xsd:string" />
</xsd:simpleType>
</xsd:schema>

View File

@@ -17,16 +17,15 @@ package org.springframework.plugin.core.config;
import static org.assertj.core.api.Assertions.*;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.plugin.core.PluginRegistry;
import org.springframework.plugin.core.SamplePlugin;
import org.springframework.plugin.core.SamplePluginHost;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.plugin.core.SamplePluginImplementation;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
@@ -35,28 +34,35 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
* @author Oliver Gierke
*/
@ExtendWith(SpringExtension.class)
@ContextConfiguration(locations = "classpath:application-context.xml")
class PluginConfigurationIntegrationTest {
@Autowired List<SamplePlugin> samplePlugins;
@Configuration
@EnablePluginRegistries(SamplePlugin.class)
static class Config {
@Autowired @Qualifier("bar") PluginRegistry<SamplePlugin, String> pluginRegistry;
@Bean
SamplePluginHost samplePluginHost(PluginRegistry<SamplePlugin, String> registry) {
@Autowired @Qualifier("host") SamplePluginHost host;
var host = new SamplePluginHost();
host.setRegistry(registry);
@Autowired @Qualifier("otherHost") SamplePluginHost otherHost;
return host;
}
@Bean
SamplePluginImplementation samplePluginImplementation() {
return new SamplePluginImplementation();
}
}
@Autowired PluginRegistry<SamplePlugin, String> pluginRegistry;
@Autowired SamplePluginHost host;
@Autowired SamplePlugin plugin;
@Test
void test() throws Exception {
assertThat(samplePlugins).isNotNull();
assertThat(pluginRegistry).isSameAs(host.getRegistry());
assertThat(pluginRegistry).isNotSameAs(otherHost.getRegistry());
assertThat(samplePlugins).contains(plugin);
assertThat(pluginRegistry).contains(plugin);
}
}

View File

@@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:plugin="http://www.springframework.org/schema/plugin"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/plugin https://www.springframework.org/schema/plugin/spring-plugin.xsd">
<plugin:list id="foo" class="org.springframework.plugin.core.SamplePlugin" />
<plugin:registry id="bar" class="org.springframework.plugin.core.SamplePlugin" />
<bean class="org.springframework.plugin.core.SamplePluginImplementation" />
<bean id="host" class="org.springframework.plugin.core.SamplePluginHost">
<property name="registry" ref="bar" />
</bean>
<bean id="otherHost" class="org.springframework.plugin.core.SamplePluginHost">
<property name="registry">
<plugin:registry id="tadaa" class="org.springframework.plugin.core.SamplePlugin" />
</property>
</bean>
</beans>