(pluginMap.values());
+ }
+}
diff --git a/hera-core/src/main/java/org/synyx/hera/core/support/BeanListBeanFactoryPostProcessor.java b/hera-core/src/main/java/org/synyx/hera/core/support/BeanListBeanFactoryPostProcessor.java
deleted file mode 100644
index f0b0426..0000000
--- a/hera-core/src/main/java/org/synyx/hera/core/support/BeanListBeanFactoryPostProcessor.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright 2002-2008 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
- *
- * 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.synyx.hera.core.support;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.beans.factory.config.ListFactoryBean;
-import org.springframework.beans.factory.config.RuntimeBeanReference;
-import org.springframework.beans.factory.support.AbstractBeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.beans.factory.support.ManagedList;
-import org.springframework.core.Ordered;
-import org.synyx.hera.core.SimplePluginRegistry;
-
-
-/**
- * Simple {@link BeanFactoryPostProcessor} to autocreate lists of the configured
- * {@code lists} property. The post processor will register
- * {@link ListFactoryBean}s for each list named with the given key containing
- * all beans of the {@link org.springframework.context.ApplicationContext}
- * implementing the interface defines as lists value. E.g.:
- *
- *
- * <bean class="org.synyx.plugin.core.support.BeanListFactoryPostProcessor">
- * <property name="lists">
- * <map>
- * <entry key="beanName" value="org.synyx.plugin.core.Plugin" />
- * </map>
- * </property>
- * </bean>
- *
- *
- * This would register all Spring beans implementing the
- * {@link org.synyx.hera.core.Plugin} interface in a list bean with the name
- * {@coder beanName}.
- *
- * @author Oliver Gierke - gierke@synyx.de
- */
-public class BeanListBeanFactoryPostProcessor implements
- BeanFactoryPostProcessor, Ordered {
-
- private static final Log log =
- LogFactory.getLog(BeanListBeanFactoryPostProcessor.class);
-
- private Map> lists = new HashMap>();
-
- private boolean initFactories = false;
-
-
- /**
- * Setter to inject required plugin registry configuration. The map's keys
- * will be used as bean ids for the resulting {@link SimplePluginRegistry}
- * instances. These registry instances will contain all beans having the
- * given type.
- *
- * @param registryMap
- */
- public void setLists(Map> lists) {
-
- this.lists = lists;
- }
-
-
- /**
- * Setter to activate {@link org.springframework.beans.factory.FactoryBean}
- * scanning. This allows auto-registration of factory bean targets (the
- * objects actually created by the factory bean} but comes with the drawback
- * of having to initialize those factories eagerly. This can cause
- * unpredictable behaviour if other {@link BeanFactoryPostProcessor}s would
- * have been applied to these factories. Defaults to {@value #initFactories}
- * .
- *
- * @param initFactories the allowEagerInit to set
- */
- public void setInitFactories(boolean initFactories) {
-
- this.initFactories = initFactories;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @seeorg.springframework.beans.factory.config.BeanFactoryPostProcessor#
- * postProcessBeanFactory
- * (org.springframework.beans.factory.config.ConfigurableListableBeanFactory
- * )
- */
- public void postProcessBeanFactory(
- ConfigurableListableBeanFactory beanFactory) throws BeansException {
-
- if (!(beanFactory instanceof BeanDefinitionRegistry)) {
- throw new IllegalArgumentException(
- "Given beanFactory is not a BeanDefinitionRegistry!");
- }
-
- BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
-
- // Do for each required wrapper
- for (String wrapperName : lists.keySet()) {
-
- Class> requiredType = lists.get(wrapperName);
-
- // Find implementations of the component type
- List beans =
- getBeanReferencesOfType(beanFactory, requiredType);
-
- registerListBeanDefinition(wrapperName, requiredType, beans,
- registry);
- }
- }
-
-
- /**
- * Registers a {@link ListFactoryBean} containing the given beans under the
- * given id. Allows subclasses to modify or wrap the actually registered
- * bean definition by calling
- * {@link #wrapListBeanDefinition(BeanDefinition)} with the bean definition
- * of the {Īlinl {@link ListFactoryBean}.
- *
- * @param id
- * @param beans
- * @param registry
- */
- protected void registerListBeanDefinition(String id, Class type,
- List beans, BeanDefinitionRegistry registry) {
-
- // Create ListFactory bean definition
- BeanDefinitionBuilder listDefinitionBuilder =
- BeanDefinitionBuilder.rootBeanDefinition(ListFactoryBean.class);
-
- // Set the implementations as source for the wrapper
- listDefinitionBuilder.addPropertyValue("sourceList", beans);
-
- BeanDefinition beanDefinition =
- wrapListBeanDefinition(getSourcedBeanDefinition(listDefinitionBuilder));
-
- if (log.isDebugEnabled()) {
- log.debug(String.format(
- "Registering bean '%s' of type %s containing %s!", id,
- beanDefinition.getBeanClassName(), beans.toString()));
- }
-
- // Register wrapper under defined name
- registry.registerBeanDefinition(id, beanDefinition);
- }
-
-
- /**
- * Template method to allow subclasses to wrap the list bean definition into
- * another bean definition that will actually be registered. The default
- * implementation simply returns the given bean definition.
- *
- * @param beanDefinition
- * @return
- */
- protected BeanDefinition wrapListBeanDefinition(
- BeanDefinition beanDefinition) {
-
- return beanDefinition;
- }
-
-
- /**
- * Returns a {@link BeanDefinitionBuilder}s {@link BeanDefinition} setting
- * the current {@link PluginRegistryBeanFactoryPostProcessor} as source.
- *
- * @param builder
- * @return
- */
- protected BeanDefinition getSourcedBeanDefinition(
- BeanDefinitionBuilder builder) {
-
- AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();
- beanDefinition.setSource(this);
-
- return beanDefinition;
- }
-
-
- /**
- * Returns bean references to beans with the given type.
- *
- * @param beanFactory
- * @param type
- * @return
- */
- @SuppressWarnings("unchecked")
- protected List getBeanReferencesOfType(
- ConfigurableListableBeanFactory beanFactory, Class> type) {
-
- // Lookup bean candidates either via Spring or manually
- List beanNames =
- Arrays.asList(beanFactory.getBeanNamesForType(type, true,
- initFactories));
-
- List beanReferences =
- new ManagedList(beanNames.size());
-
- for (String beanName : beanNames) {
-
- RuntimeBeanReference reference = new RuntimeBeanReference(beanName);
- reference.setSource(this);
-
- beanReferences.add(reference);
- }
-
- return (List) beanReferences;
- }
-
-
- /**
- * Declare lowest precedence to ensure all other
- * {@link BeanFactoryPostProcessor}s have already been applied.
- *
- * @see org.springframework.core.Ordered#getOrder()
- */
- public int getOrder() {
-
- return Ordered.LOWEST_PRECEDENCE;
- }
-}
diff --git a/hera-core/src/main/java/org/synyx/hera/core/support/BeanListFactoryBean.java b/hera-core/src/main/java/org/synyx/hera/core/support/BeanListFactoryBean.java
new file mode 100644
index 0000000..3c5c26e
--- /dev/null
+++ b/hera-core/src/main/java/org/synyx/hera/core/support/BeanListFactoryBean.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2002-2008 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
+ *
+ * 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.synyx.hera.core.support;
+
+import java.awt.List;
+
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.context.ApplicationContext;
+
+
+/**
+ * Factory to create bean lists for a given type. Exposes all beans of the
+ * configured type that can be found in the {@link ApplicationContext}.
+ *
+ * @author Oliver Gierke - gierke@synyx.de
+ */
+public class BeanListFactoryBean extends AbstractTypeAwareSupport
+ implements FactoryBean {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.springframework.beans.factory.FactoryBean#getObject()
+ */
+ public Object getObject() throws Exception {
+
+ return getBeans();
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.springframework.beans.factory.FactoryBean#getObjectType()
+ */
+ @SuppressWarnings("unchecked")
+ public Class getObjectType() {
+
+ return List.class;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.springframework.beans.factory.FactoryBean#isSingleton()
+ */
+ public boolean isSingleton() {
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/hera-core/src/main/java/org/synyx/hera/core/support/PluginRegistryBeanFactoryPostProcessor.java b/hera-core/src/main/java/org/synyx/hera/core/support/PluginRegistryBeanFactoryPostProcessor.java
deleted file mode 100644
index 3013248..0000000
--- a/hera-core/src/main/java/org/synyx/hera/core/support/PluginRegistryBeanFactoryPostProcessor.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2002-2008 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
- *
- * 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.synyx.hera.core.support;
-
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.synyx.hera.core.OrderAwarePluginRegistry;
-
-
-/**
- * This {@link BeanFactoryPostProcessor} automatically looksup bean instances
- * from the {@link BeanFactory} hierarchy and registers
- * {@link OrderAwarePluginRegistry} instances for them.
- *
- * @see org.synyx.hera.core.support.BeanListBeanFactoryPostProcessor
- * @author Oliver Gierke - gierke@synyx.de
- */
-public class PluginRegistryBeanFactoryPostProcessor extends
- BeanListBeanFactoryPostProcessor {
-
- /**
- * Additionally wraps the
- * {@link org.springframework.beans.factory.config.ListFactoryBean}
- * {@link BeanDefinition} into a {@link OrderAwarePluginRegistry}.
- *
- * @see com.synyx.minos.core.plugin.support.BeanListBeanFactoryPostProcessor#
- * wrapBeanDefinition
- * (org.springframework.beans.factory.config.BeanDefinition)
- * @return a {@link BeanDefinition} containing a
- * {@link OrderAwarePluginRegistry}
- */
- @Override
- protected BeanDefinition wrapListBeanDefinition(
- BeanDefinition beanDefinition) {
-
- // Create PluginRegistry bean definition to wrap actual bean definition
- BeanDefinitionBuilder builder =
- BeanDefinitionBuilder
- .rootBeanDefinition(OrderAwarePluginRegistry.class);
-
- builder.addPropertyValue("plugins", beanDefinition);
-
- return getSourcedBeanDefinition(builder);
- }
-}
diff --git a/hera-core/src/main/java/org/synyx/hera/core/support/PluginRegistryFactoryBean.java b/hera-core/src/main/java/org/synyx/hera/core/support/PluginRegistryFactoryBean.java
new file mode 100644
index 0000000..aced105
--- /dev/null
+++ b/hera-core/src/main/java/org/synyx/hera/core/support/PluginRegistryFactoryBean.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2002-2008 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
+ *
+ * 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.synyx.hera.core.support;
+
+import org.springframework.beans.factory.FactoryBean;
+import org.synyx.hera.core.OrderAwarePluginRegistry;
+import org.synyx.hera.core.Plugin;
+import org.synyx.hera.core.PluginRegistry;
+
+
+/**
+ * {@link FactoryBean} to create {@link PluginRegistry} instances. Wraps a
+ * {@link BeanListFactoryBean}.
+ *
+ * @author Oliver Gierke - gierke@synyx.de
+ */
+public class PluginRegistryFactoryBean, S> extends
+ AbstractTypeAwareSupport implements FactoryBean {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.springframework.beans.factory.FactoryBean#getObject()
+ */
+ public Object getObject() throws Exception {
+
+ return OrderAwarePluginRegistry.create(getBeans());
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.springframework.beans.factory.FactoryBean#getObjectType()
+ */
+ @SuppressWarnings("unchecked")
+ public Class getObjectType() {
+
+ return PluginRegistry.class;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.springframework.beans.factory.FactoryBean#isSingleton()
+ */
+ public boolean isSingleton() {
+
+ return true;
+ }
+}
diff --git a/hera-core/src/test/java/org/synyx/hera/core/config/PluginConfigurationIntegrationTest.java b/hera-core/src/test/java/org/synyx/hera/core/config/PluginConfigurationIntegrationTest.java
index 5fb688d..bb67243 100644
--- a/hera-core/src/test/java/org/synyx/hera/core/config/PluginConfigurationIntegrationTest.java
+++ b/hera-core/src/test/java/org/synyx/hera/core/config/PluginConfigurationIntegrationTest.java
@@ -39,11 +39,19 @@ public class PluginConfigurationIntegrationTest {
@Qualifier("otherHost")
SamplePluginHost otherHost;
+ @Autowired
+ SamplePlugin plugin;
+
@Test
public void test() throws Exception {
+ assertNotNull(samplePlugins);
+
assertSame(pluginRegistry, host.getRegistry());
assertNotSame(pluginRegistry, otherHost.getRegistry());
+
+ assertTrue(samplePlugins.contains(plugin));
+ assertTrue(pluginRegistry.contains(plugin));
}
}
diff --git a/hera-core/src/test/resources/application-context.xml b/hera-core/src/test/resources/application-context.xml
index 1b91a2c..c7d4ec7 100644
--- a/hera-core/src/test/resources/application-context.xml
+++ b/hera-core/src/test/resources/application-context.xml
@@ -14,8 +14,7 @@
-
-
+