diff --git a/.gitignore b/.gitignore index 89bff9f..34f9ada 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .classpath +.project +.settings/ target/ \ No newline at end of file diff --git a/core/.project b/core/.project index 404d1a4..1229eba 100644 --- a/core/.project +++ b/core/.project @@ -15,11 +15,6 @@ - - org.springframework.ide.eclipse.core.springbuilder - - - org.eclipse.wst.validation.validationbuilder @@ -32,7 +27,6 @@ - org.springframework.ide.eclipse.core.springnature org.maven.ide.eclipse.maven2Nature org.eclipse.jdt.core.javanature org.eclipse.wst.common.project.facet.core.nature diff --git a/core/.settings/org.eclipse.jdt.core.prefs b/core/.settings/org.eclipse.jdt.core.prefs index 21bc0b2..e33afb0 100644 --- a/core/.settings/org.eclipse.jdt.core.prefs +++ b/core/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,9 @@ -#Wed Aug 05 19:23:44 CEST 2009 +#Wed Feb 15 21:22:56 CET 2012 eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/core/.settings/org.eclipse.wst.common.component b/core/.settings/org.eclipse.wst.common.component index 35c62cd..c03ab12 100644 --- a/core/.settings/org.eclipse.wst.common.component +++ b/core/.settings/org.eclipse.wst.common.component @@ -3,5 +3,7 @@ + + diff --git a/core/.settings/org.eclipse.wst.common.project.facet.core.xml b/core/.settings/org.eclipse.wst.common.project.facet.core.xml index 16a4875..318363e 100644 --- a/core/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/core/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,5 +1,5 @@ - + diff --git a/core/pom.xml b/core/pom.xml index 6735062..2b0888c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -23,6 +23,11 @@ spring-context ${spring.version} + + org.springframework + spring-aop + ${spring.version} + org.springframework @@ -33,16 +38,4 @@ - - - - - maven-compiler-plugin - - 1.5 - 1.5 - - - - diff --git a/core/src/main/java/org/synyx/hera/core/MutablePluginRegistry.java b/core/src/main/java/org/synyx/hera/core/MutablePluginRegistry.java index 064d771..960d919 100644 --- a/core/src/main/java/org/synyx/hera/core/MutablePluginRegistry.java +++ b/core/src/main/java/org/synyx/hera/core/MutablePluginRegistry.java @@ -1,53 +1,38 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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; -import java.util.List; - - /** - * Extension of {@link PluginRegistry} with additional methods to modify the - * registry. + * Extension of {@link PluginRegistry} with additional methods to modify the registry. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ -public interface MutablePluginRegistry, S> extends - PluginRegistry { +public interface MutablePluginRegistry, S> extends PluginRegistry { - /** - * Register plugins. - * - * @param plugins the plugins to set - */ - void setPlugins(List plugins); + /** + * Adds a given plugin to the registry. + * + * @param plugin must not be {@literal null}. + */ + MutablePluginRegistry addPlugin(T plugin); - - /** - * Adds a given plugin to the registry. - * - * @param plugin - */ - MutablePluginRegistry addPlugin(T plugin); - - - /** - * Removes a given plugin from the registry. - * - * @param plugin - */ - boolean removePlugin(T plugin); + /** + * Removes a given plugin from the registry. + * + * @param plugin must not be {@literal null}. + */ + boolean removePlugin(T plugin); } diff --git a/core/src/main/java/org/synyx/hera/core/OrderAwarePluginRegistry.java b/core/src/main/java/org/synyx/hera/core/OrderAwarePluginRegistry.java index 4879f55..76b8acf 100644 --- a/core/src/main/java/org/synyx/hera/core/OrderAwarePluginRegistry.java +++ b/core/src/main/java/org/synyx/hera/core/OrderAwarePluginRegistry.java @@ -1,21 +1,21 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -23,192 +23,144 @@ import java.util.List; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.util.comparator.InvertibleComparator; - /** - * {@link PluginRegistry} implementation that be made aware of a certain - * ordering of {@link Plugin}s. By default it orders {@link Plugin}s by - * regarding {@link org.springframework.core.Ordered} interface or - * {@link org.springframework.core.annotation.Order} annotation. To alter - * ordering behaviour use one of the factory methods accepting a - * {@link Comparator} as parameter. + * {@link PluginRegistry} implementation that be made aware of a certain ordering of {@link Plugin}s. By default it + * orders {@link Plugin}s by regarding {@link org.springframework.core.Ordered} interface or + * {@link org.springframework.core.annotation.Order} annotation. To alter ordering behaviour use one of the factory + * methods accepting a {@link Comparator} as parameter. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ -public class OrderAwarePluginRegistry, S> extends - SimplePluginRegistry { +public class OrderAwarePluginRegistry, S> extends SimplePluginRegistry { - /** - * Comparator regarding {@link org.springframework.core.Ordered} interface - * or {@link org.springframework.core.annotation.Order} annotation. - */ - @SuppressWarnings("unchecked") - private static final Comparator DEFAULT_COMPARATOR = - new AnnotationAwareOrderComparator(); + /** + * Comparator regarding {@link org.springframework.core.Ordered} interface or + * {@link org.springframework.core.annotation.Order} annotation. + */ + private static final Comparator DEFAULT_COMPARATOR = new AnnotationAwareOrderComparator(); - /** - * Comparator reverting the {@value #DEFAULT_COMPARATOR}. - */ - @SuppressWarnings("unchecked") - private static final Comparator DEFAULT_REVERSE_COMPARATOR = - new InvertibleComparator(DEFAULT_COMPARATOR, false); + /** + * Comparator reverting the {@value #DEFAULT_COMPARATOR}. + */ + private static final Comparator DEFAULT_REVERSE_COMPARATOR = new InvertibleComparator( + DEFAULT_COMPARATOR, false); - private Comparator comparator; + private Comparator comparator; + /** + * Creates a new {@link OrderAwarePluginRegistry} with the given {@link Plugin}s and {@link Comparator}. + * + * @param plugins the {@link Plugin}s to be contained in the registry or {@literal null} if the registry shall be + * empty initally. + * @param comparator the {@link Comparator} to be used for ordering the {@link Plugin}s or {@literal null} if the + * {@code #DEFAULT_COMPARATOR} shall be used. + */ + protected OrderAwarePluginRegistry(List plugins, Comparator comparator) { - /** - * Creates a new {@link OrderAwarePluginRegistry} with the given - * {@link Plugin}s and {@link Comparator}. - * - * @param plugins the {@link Plugin}s to be contained in the registry or - * {@literal null} if the registry shall be empty initally. - * @param comparator the {@link Comparator} to be used for ordering the - * {@link Plugin}s or {@literal null} if the - * {@code #DEFAULT_COMPARATOR} shall be used. - */ - protected OrderAwarePluginRegistry(List plugins, - Comparator comparator) { + super(plugins); + setComparator(comparator); + } - super(plugins); - setComparator(comparator); - } + /** + * Creates a new {@link OrderAwarePluginRegistry} using the {@code #DEFAULT_COMPARATOR}. + * + * @param + * @param + * @return + */ + public static > OrderAwarePluginRegistry create() { + return create(null, null); + } - /** - * Creates a new {@link OrderAwarePluginRegistry} using the - * {@code #DEFAULT_COMPARATOR}. - * - * @param - * @param - * @return - */ - public static > OrderAwarePluginRegistry create() { + /** + * Creates a new {@link OrderAwarePluginRegistry} using the given {@link Comparator} for ordering contained + * {@link Plugin}s. + * + * @param + * @param + * @return + */ + public static > OrderAwarePluginRegistry create(Comparator comparator) { + return create(null, comparator); + } - return create(null, null); - } + /** + * Creates a new {@link OrderAwarePluginRegistry} with the given plugins. + * + * @param + * @param + * @param plugins + * @return + */ + public static > OrderAwarePluginRegistry create(List plugins) { + return create(plugins, DEFAULT_COMPARATOR); + } + /** + * Creates a new {@link OrderAwarePluginRegistry} with the given plugins and the order of the plugins reverted. + * + * @param + * @param + * @param plugins + * @return + */ + public static > OrderAwarePluginRegistry createReverse(List plugins) { + return create(plugins, DEFAULT_REVERSE_COMPARATOR); + } - /** - * Creates a new {@link OrderAwarePluginRegistry} using the given - * {@link Comparator} for ordering contained {@link Plugin}s. - * - * @param - * @param - * @return - */ - public static > OrderAwarePluginRegistry create( - Comparator comparator) { + /** + * Creates a new {@link OrderAwarePluginRegistry} with the given plugins. + * + * @param + * @param + * @param plugins + * @return + */ + public static > OrderAwarePluginRegistry create(List plugins, + Comparator comparator) { + return new OrderAwarePluginRegistry(plugins, comparator); + } - return create(null, comparator); - } + /** + * Sets the comparator to use. Resorts the contained {@link Plugin}s if any available. + * + * @param comparator the comparator to set + */ + private void setComparator(Comparator comparator) { + this.comparator = DEFAULT_COMPARATOR; - /** - * Creates a new {@link OrderAwarePluginRegistry} with the given plugins. - * - * @param - * @param - * @param plugins - * @return - */ - public static > OrderAwarePluginRegistry create( - List plugins) { + if (comparator != null) { + this.comparator = comparator; + } - return create(plugins, DEFAULT_COMPARATOR); - } + if (plugins != null) { + Collections.sort(plugins, comparator); + } + } + /* + * (non-Javadoc) + * @see org.synyx.hera.core.SimplePluginRegistry#addPlugin(org.synyx.hera.core.Plugin) + */ + @Override + public OrderAwarePluginRegistry addPlugin(T plugin) { - /** - * Creates a new {@link OrderAwarePluginRegistry} with the given plugins and - * the order of the plugins reverted. - * - * @param - * @param - * @param plugins - * @return - */ - public static > OrderAwarePluginRegistry createReverse( - List plugins) { + super.addPlugin(plugin); + Collections.sort(plugins, comparator); + return this; + } - return create(plugins, DEFAULT_REVERSE_COMPARATOR); - } + /** + * Returns a new {@link OrderAwarePluginRegistry} with the order of the plugins reverted. + * + * @return + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + public OrderAwarePluginRegistry reverse() { - - /** - * Creates a new {@link OrderAwarePluginRegistry} with the given plugins. - * - * @param - * @param - * @param plugins - * @return - */ - public static > OrderAwarePluginRegistry create( - List plugins, Comparator comparator) { - - return new OrderAwarePluginRegistry(plugins, comparator); - } - - - /** - * Sets the comparator to use. Resorts the contained {@link Plugin}s if any - * available. - * - * @param comparator the comparator to set - */ - private void setComparator(Comparator comparator) { - - this.comparator = DEFAULT_COMPARATOR; - - if (comparator != null) { - this.comparator = comparator; - } - - if (plugins != null) { - Collections.sort(plugins, comparator); - } - } - - - /* - * (non-Javadoc) - * - * @see org.synyx.hera.core.PluginRegistry#setPlugins(java.util.List) - */ - @Override - public void setPlugins(List plugins) { - - super.setPlugins(plugins); - - if (!this.plugins.isEmpty()) { - Collections.sort(this.plugins, comparator); - } - - } - - - /* - * (non-Javadoc) - * - * @see - * org.synyx.hera.core.PluginRegistry#addPlugin(org.synyx.hera.core.Plugin) - */ - @Override - public OrderAwarePluginRegistry addPlugin(T plugin) { - - super.addPlugin(plugin); - Collections.sort(plugins, comparator); - return this; - } - - - /** - * Returns a new {@link OrderAwarePluginRegistry} with the order of the - * plugins reverted. - * - * @return - */ - @SuppressWarnings("unchecked") - public OrderAwarePluginRegistry reverse() { - - return create(plugins, new InvertibleComparator(comparator, false)); - } + ArrayList copy = new ArrayList(plugins); + return create(copy, new InvertibleComparator(comparator, false)); + } } diff --git a/core/src/main/java/org/synyx/hera/core/Plugin.java b/core/src/main/java/org/synyx/hera/core/Plugin.java index 17430b7..c490537 100644 --- a/core/src/main/java/org/synyx/hera/core/Plugin.java +++ b/core/src/main/java/org/synyx/hera/core/Plugin.java @@ -1,37 +1,35 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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; /** - * Central interface for plugins for the system. This interface is meant to be - * extended by concrete plugin interfaces. Its core responsibility is to define - * a delimiter type and a selection callback with the delimiter as parameter. - * The delimiter is some kind of decision object concrete plugin implementations - * can use to decide if they are capable to be executed. + * Central interface for plugins for the system. This interface is meant to be extended by concrete plugin interfaces. + * Its core responsibility is to define a delimiter type and a selection callback with the delimiter as parameter. The + * delimiter is some kind of decision object concrete plugin implementations can use to decide if they are capable to be + * executed. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ public interface Plugin { - /** - * Returns if a plugin should be invoked according to the given delimiter. - * - * @param delimiter - * @return if the plugin should be invoked - */ - boolean supports(S delimiter); + /** + * Returns if a plugin should be invoked according to the given delimiter. + * + * @param delimiter + * @return if the plugin should be invoked + */ + boolean supports(S delimiter); } diff --git a/core/src/main/java/org/synyx/hera/core/PluginRegistry.java b/core/src/main/java/org/synyx/hera/core/PluginRegistry.java index 80b89e1..084ea13 100644 --- a/core/src/main/java/org/synyx/hera/core/PluginRegistry.java +++ b/core/src/main/java/org/synyx/hera/core/PluginRegistry.java @@ -1,138 +1,116 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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; import java.util.List; - /** - * Registry for plugins. Allows sophisticated typesafe access to implementations - * of interfaces extending {link Plugin}. + * Registry for plugins. Allows sophisticated typesafe access to implementations of interfaces extending {link Plugin}. * * @param the concrete plugin interface * @param the delimiter type - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ public interface PluginRegistry, S> extends Iterable { - /** - * Returns the first plugin found for the given originating system. Thus, - * further configured plugins are ignored. - * - * @param originatingSystem - * @return a plugin for the given originating system or {@code null} if none - * found - */ - T getPluginFor(S delimiter); + /** + * Returns the first plugin found for the given originating system. Thus, further configured plugins are ignored. + * + * @param originatingSystem + * @return a plugin for the given originating system or {@code null} if none found + */ + T getPluginFor(S delimiter); + /** + * Returns all plugins for the given delimiter. + * + * @param delimiter + * @return a list of plugins or an empty list if none found + */ + List getPluginsFor(S delimiter); - /** - * Returns all plugins for the given delimiter. - * - * @param delimiter - * @return a list of plugins or an empty list if none found - */ - List getPluginsFor(S delimiter); + /** + * Retrieves a required plugin from the registry or throw the given exception if none can be found. If more than one + * plugins are found the first one will be returned. + * + * @param the exception type to be thrown in case no plugin can be found + * @param delimiter + * @param ex the exception to be thrown in case no plugin can be found + * @return a single plugin for the given delimiter + * @throws E if no plugin can be found for the given delimiter + */ + T getPluginFor(S delimiter, E ex) throws E; + /** + * Retrieves all plugins for the given delimiter or throws an exception if no plugin can be found. + * + * @param the exception type to be thrown + * @param delimiter + * @param ex + * @return all plugins for the given delimiter + * @throws E if no plugin can be found + */ + List getPluginsFor(S delimiter, E ex) throws E; - /** - * Retrieves a required plugin from the registry or throw the given - * exception if none can be found. If more than one plugins are found the - * first one will be returned. - * - * @param the exception type to be thrown in case no plugin can be found - * @param delimiter - * @param ex the exception to be thrown in case no plugin can be found - * @return a single plugin for the given delimiter - * @throws E if no plugin can be found for the given delimiter - */ - T getPluginFor(S delimiter, E ex) throws E; + /** + * Returns the first {@link Plugin} supporting the given delimiter or the given plugin if none can be found. + * + * @param delimiter + * @param plugin + * @return a single {@link Plugin} supporting the given delimiter or the given {@link Plugin} if none found + */ + T getPluginFor(S delimiter, T plugin); + /** + * Returns all {@link Plugin}s supporting the given delimiter or the given plugins if none found. + * + * @param delimiter + * @param plugins + * @return all {@link Plugin}s supporting the given delimiter or the given {@link Plugin}s if none found + */ + List getPluginsFor(S delimiter, List plugins); - /** - * Retrieves all plugins for the given delimiter or throws an exception if - * no plugin can be found. - * - * @param the exception type to be thrown - * @param delimiter - * @param ex - * @return all plugins for the given delimiter - * @throws E if no plugin can be found - */ - List getPluginsFor(S delimiter, E ex) throws E; + /** + * Returns the number of registered plugins. + * + * @return the number of plugins in the registry + */ + int countPlugins(); + /** + * Returns whether the registry contains a given plugin. + * + * @param plugin + * @return + */ + boolean contains(T plugin); - /** - * Returns the first {@link Plugin} supporting the given delimiter or the - * given plugin if none can be found. - * - * @param delimiter - * @param plugin - * @return a single {@link Plugin} supporting the given delimiter or the - * given {@link Plugin} if none found - */ - T getPluginFor(S delimiter, T plugin); + /** + * Returns whether the registry contains a {@link Plugin} matching the given delimiter. + * + * @param delimiter + * @return + */ + boolean hasPluginFor(S delimiter); - - /** - * Returns all {@link Plugin}s supporting the given delimiter or the given - * plugins if none found. - * - * @param delimiter - * @param plugins - * @return all {@link Plugin}s supporting the given delimiter or the given - * {@link Plugin}s if none found - */ - List getPluginsFor(S delimiter, List plugins); - - - /** - * Returns the number of registered plugins. - * - * @return the number of plugins in the registry - */ - int countPlugins(); - - - /** - * Returns whether the registry contains a given plugin. - * - * @param plugin - * @return - */ - boolean contains(T plugin); - - - /** - * Returns whether the registry contains a {@link Plugin} matching the given - * delimiter. - * - * @param delimiter - * @return - */ - boolean hasPluginFor(S delimiter); - - - /** - * Returns all {@link Plugin}s contained in this registry. Will return an - * immutable {@link List} to prevent outside modifications of the - * {@link PluginRegistry} content. - * - * @return - */ - List getPlugins(); + /** + * Returns all {@link Plugin}s contained in this registry. Will return an immutable {@link List} to prevent outside + * modifications of the {@link PluginRegistry} content. + * + * @return + */ + List getPlugins(); } \ No newline at end of file diff --git a/core/src/main/java/org/synyx/hera/core/SimplePluginRegistry.java b/core/src/main/java/org/synyx/hera/core/SimplePluginRegistry.java index 98ade56..66ee94a 100644 --- a/core/src/main/java/org/synyx/hera/core/SimplePluginRegistry.java +++ b/core/src/main/java/org/synyx/hera/core/SimplePluginRegistry.java @@ -1,19 +1,18 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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; import java.util.ArrayList; @@ -21,277 +20,197 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; - /** - * Basic implementation of {@link PluginRegistry}. Simply holds all given - * plugins in a list dropping {@literal null} values silently on adding. + * Basic implementation of {@link PluginRegistry}. Simply holds all given plugins in a list dropping {@literal null} + * values silently on adding. * * @param the concrete plugin interface * @param the delimiter type - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ -public class SimplePluginRegistry, S> implements - MutablePluginRegistry { - - protected List plugins; - - - /** - * Creates a new {@code SimplePluginRegistry}. Will create an empty registry - * if {@literal null} is provided. - */ - protected SimplePluginRegistry(List plugins) { - - this.plugins = filterNulls(plugins); - } - - - /** - * Creates a new {@link SimplePluginRegistry}. - * - * @param - * @param - * @return - */ - public static > SimplePluginRegistry create() { - - return new SimplePluginRegistry(null); - } - - - /** - * Creates a new {@link SimplePluginRegistry} with the given {@link Plugin} - * s. - * - * @param - * @param - * @return - */ - public static > SimplePluginRegistry create( - List plugins) { - - return new SimplePluginRegistry(plugins); - } - - - /* - * (non-Javadoc) - * - * @see org.synyx.hera.core.MutablePluginRegistry#setPlugins(java.util.List) - */ - public void setPlugins(List plugins) { - - this.plugins = filterNulls(plugins); - } - - - /** - * Filters {@literal null} values from the given list. - * - * @param plugins - * @return an empty {@link List} if the given list is {@literal null} or - * empty, or the original list without its {@literal null} elements. - */ - private List filterNulls(List plugins) { - - if (plugins == null || plugins.isEmpty()) { - return new ArrayList(); - } - - List result = new ArrayList(); - - for (T plugin : plugins) { - if (plugin != null) { - result.add(plugin); - } - } - - return result; - } - - - /* - * (non-Javadoc) - * - * @see - * org.synyx.hera.core.MutablePluginRegistry#addPlugin(org.synyx.hera.core - * .Plugin) - */ - public SimplePluginRegistry addPlugin(T plugin) { - - if (plugin != null) { - this.plugins.add(plugin); - } - - return this; - } - - - /* - * (non-Javadoc) - * - * @see - * org.synyx.hera.core.MutablePluginRegistry#removePlugin(org.synyx.hera - * .core.Plugin) - */ - public boolean removePlugin(T plugin) { - - return this.plugins.remove(plugin); - } - - - /* - * (non-Javadoc) - * - * @see org.synyx.hera.core.PluginRegistry#getPluginFor(S) - */ - public T getPluginFor(S delimiter) { - - List result = getPluginsFor(delimiter); - - if (0 < result.size()) { - return result.get(0); - } - - return null; - } - - - /* - * (non-Javadoc) - * - * @see org.synyx.hera.core.PluginRegistry#getPluginsFor(S) - */ - public List getPluginsFor(S delimiter) { - - List result = new ArrayList(); - - for (T plugin : plugins) { - if (plugin.supports(delimiter)) { - result.add(plugin); - } - } - - return result; - } - - - /* - * (non-Javadoc) - * - * @see org.synyx.hera.core.PluginRegistry#getPluginFor(S, E) - */ - public T getPluginFor(S delimiter, E ex) throws E { - - T plugin = getPluginFor(delimiter); - - if (null == plugin) { - throw ex; - } - - return plugin; - } - - - /* - * (non-Javadoc) - * - * @see org.synyx.hera.core.PluginRegistry#getPluginsFor(S, E) - */ - public List getPluginsFor(S delimiter, E ex) - throws E { - - List result = getPluginsFor(delimiter); - - if (0 == result.size()) { - throw ex; - } - - return result; - } - - - /* - * (non-Javadoc) - * - * @see org.synyx.hera.core.PluginRegistry#getPluginFor(S, T) - */ - public T getPluginFor(S delimiter, T plugin) { - - T candidate = getPluginFor(delimiter); - - return null == candidate ? plugin : candidate; - } - - - /* - * (non-Javadoc) - * - * @see org.synyx.hera.core.PluginRegistry#getPluginsFor(S, java.util.List) - */ - public List getPluginsFor(S delimiter, List plugins) { - - List candidates = getPluginsFor(delimiter); - - return candidates.size() == 0 ? new ArrayList(plugins) : candidates; - } - - - /* - * (non-Javadoc) - * - * @see org.synyx.hera.core.PluginRegistry#countPlugins() - */ - public int countPlugins() { - - return plugins.size(); - } - - - /** - * Returns all registered plugins. Only use this method if you really need - * to access all plugins. For distinguished access to certain plugins favour - * accessor methods like {link #getPluginFor} over this one. This method - * should only be used for testing purposes to check registry configuration. - * - * @return all plugins of the registry - */ - public List getPlugins() { - - return Collections.unmodifiableList(plugins); - } - - - /* - * (non-Javadoc) - * - * @see - * org.synyx.hera.core.PluginRegistry#contains(org.synyx.hera.core.Plugin) - */ - public boolean contains(T plugin) { - - return this.plugins.contains(plugin); - } - - - /* - * (non-Javadoc) - * - * @see org.synyx.hera.core.PluginRegistry#hasPluginFor(java.lang.Object) - */ - public boolean hasPluginFor(S delimter) { - - return null != getPluginFor(delimter); - } - - - /* - * (non-Javadoc) - * - * @see java.lang.Iterable#iterator() - */ - public Iterator iterator() { - - return plugins.iterator(); - } +public class SimplePluginRegistry, S> implements MutablePluginRegistry { + + protected final List plugins; + + /** + * Creates a new {@code SimplePluginRegistry}. Will create an empty registry if {@literal null} is provided. + * + * @param plugins must not be {@literal null}. + */ + @SuppressWarnings("unchecked") + protected SimplePluginRegistry(List plugins) { + this.plugins = plugins == null ? new ArrayList() : (List) plugins; + } + + /** + * Creates a new {@link SimplePluginRegistry}. + * + * @param the plugin type + * @param the delimiter type + * @return + */ + public static > SimplePluginRegistry create() { + return new SimplePluginRegistry(null); + } + + /** + * Creates a new {@link SimplePluginRegistry} with the given {@link Plugin} s. + * + * @param the plugin type + * @param the delimiter type + * @return + */ + public static > SimplePluginRegistry create(List plugins) { + return new SimplePluginRegistry(plugins); + } + + /* + * (non-Javadoc) + * @see org.synyx.hera.core.MutablePluginRegistry#addPlugin(org.synyx.hera.core.Plugin) + */ + public SimplePluginRegistry addPlugin(T plugin) { + + if (plugin != null) { + this.plugins.add(plugin); + } + + return this; + } + + /* + * (non-Javadoc) + * @see org.synyx.hera.core.MutablePluginRegistry#removePlugin(org.synyx.hera.core.Plugin) + */ + public boolean removePlugin(T plugin) { + + return this.plugins.remove(plugin); + } + + /* + * (non-Javadoc) + * @see org.synyx.hera.core.PluginRegistry#getPluginFor(java.lang.Object) + */ + public T getPluginFor(S delimiter) { + + List result = getPluginsFor(delimiter); + + if (0 < result.size()) { + return result.get(0); + } + + return null; + } + + /* + * (non-Javadoc) + * @see org.synyx.hera.core.PluginRegistry#getPluginsFor(java.lang.Object) + */ + public List getPluginsFor(S delimiter) { + + List result = new ArrayList(); + + for (T plugin : plugins) { + if (plugin != null && plugin.supports(delimiter)) { + result.add(plugin); + } + } + + return result; + } + + /* + * (non-Javadoc) + * @see org.synyx.hera.core.PluginRegistry#getPluginFor(java.lang.Object, java.lang.Exception) + */ + public T getPluginFor(S delimiter, E ex) throws E { + + T plugin = getPluginFor(delimiter); + + if (null == plugin) { + throw ex; + } + + return plugin; + } + + /* + * (non-Javadoc) + * @see org.synyx.hera.core.PluginRegistry#getPluginsFor(java.lang.Object, java.lang.Exception) + */ + public List getPluginsFor(S delimiter, E ex) throws E { + + List result = getPluginsFor(delimiter); + + if (result.isEmpty()) { + throw ex; + } + + return result; + } + + /* + * (non-Javadoc) + * @see org.synyx.hera.core.PluginRegistry#getPluginFor(java.lang.Object, org.synyx.hera.core.Plugin) + */ + public T getPluginFor(S delimiter, T plugin) { + + T candidate = getPluginFor(delimiter); + + return null == candidate ? plugin : candidate; + } + + /* + * (non-Javadoc) + * @see org.synyx.hera.core.PluginRegistry#getPluginsFor(java.lang.Object, java.util.List) + */ + public List getPluginsFor(S delimiter, List plugins) { + + List candidates = getPluginsFor(delimiter); + + return candidates.isEmpty() ? new ArrayList(plugins) : candidates; + } + + /* + * (non-Javadoc) + * @see org.synyx.hera.core.PluginRegistry#countPlugins() + */ + public int countPlugins() { + + return plugins.size(); + } + + /** + * Returns all registered plugins. Only use this method if you really need to access all plugins. For distinguished + * access to certain plugins favour accessor methods like {link #getPluginFor} over this one. This method should only + * be used for testing purposes to check registry configuration. + * + * @return all plugins of the registry + */ + public List getPlugins() { + return Collections.unmodifiableList(plugins); + } + + /* + * (non-Javadoc) + * @see org.synyx.hera.core.PluginRegistry#contains(org.synyx.hera.core.Plugin) + */ + public boolean contains(T plugin) { + return this.plugins.contains(plugin); + } + + /* + * (non-Javadoc) + * @see org.synyx.hera.core.PluginRegistry#hasPluginFor(java.lang.Object) + */ + public boolean hasPluginFor(S delimter) { + return null != getPluginFor(delimter); + } + + /* + * (non-Javadoc) + * @see java.lang.Iterable#iterator() + */ + public Iterator iterator() { + return plugins.iterator(); + } } diff --git a/core/src/main/java/org/synyx/hera/core/config/PluginListDefinitionParser.java b/core/src/main/java/org/synyx/hera/core/config/PluginListDefinitionParser.java index dea8898..a59d816 100644 --- a/core/src/main/java/org/synyx/hera/core/config/PluginListDefinitionParser.java +++ b/core/src/main/java/org/synyx/hera/core/config/PluginListDefinitionParser.java @@ -1,19 +1,18 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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.config; import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -22,79 +21,60 @@ 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 } elements from the plugin - * namespace. + * Bean definition parser to register {@code } elements from the plugin namespace. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ public class PluginListDefinitionParser extends AbstractBeanDefinitionParser { - protected static final String PACKAGE = "org.synyx.hera.core.support."; + protected static final String PACKAGE = "org.synyx.hera.core.support."; + /** + * Returns the name of the {@link org.springframework.beans.factory.config.BeanFactoryPostProcessor} to be registered. + * + * @return + */ + protected String getPostProcessorName() { + return PACKAGE + "BeanListFactoryBean"; + } - /** - * Returns the name of the - * {@link org.springframework.beans.factory.config.BeanFactoryPostProcessor} - * to be registered. - * - * @return - */ - protected String getPostProcessorName() { + /* + * (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) { - return PACKAGE + "BeanListFactoryBean"; - } + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(getPostProcessorName()); + builder.addPropertyValue("type", element.getAttribute("class")); + return getSourcedBeanDefinition(builder, element, context); + } - /* - * (non-Javadoc) - * - * @seeorg.springframework.beans.factory.xml.AbstractBeanDefinitionParser# - * parseInternal(org.w3c.dom.Element, - * org.springframework.beans.factory.xml.ParserContext) - */ - @Override - protected AbstractBeanDefinition parseInternal(Element element, - ParserContext 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) { - BeanDefinitionBuilder builder = - BeanDefinitionBuilder - .genericBeanDefinition(getPostProcessorName()); - builder.addPropertyValue("type", element.getAttribute("class")); + AbstractBeanDefinition definition = builder.getRawBeanDefinition(); + definition.setSource(context.extractSource(source)); - return getSourcedBeanDefinition(builder, element, context); - } + return definition; + } - - /** - * 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) - * - * @seeorg.springframework.beans.factory.xml.AbstractBeanDefinitionParser# - * shouldGenerateIdAsFallback() - */ - @Override - protected boolean shouldGenerateIdAsFallback() { - - return true; - } + /* + * (non-Javadoc) + * @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#shouldGenerateIdAsFallback() + */ + @Override + protected boolean shouldGenerateIdAsFallback() { + return true; + } } diff --git a/core/src/main/java/org/synyx/hera/core/config/PluginNamespaceHandler.java b/core/src/main/java/org/synyx/hera/core/config/PluginNamespaceHandler.java index 169ba24..b09c34a 100644 --- a/core/src/main/java/org/synyx/hera/core/config/PluginNamespaceHandler.java +++ b/core/src/main/java/org/synyx/hera/core/config/PluginNamespaceHandler.java @@ -1,40 +1,35 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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.config; import org.springframework.beans.factory.xml.NamespaceHandlerSupport; - /** * Simple namespace handler for {@literal plugin-config} namespace. * - * @author Oliver Gierke - gierke@synyx.de + * @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()); - } + /* + * (non-Javadoc) + * @see org.springframework.beans.factory.xml.NamespaceHandler#init() + */ + public void init() { + registerBeanDefinitionParser("list", new PluginListDefinitionParser()); + registerBeanDefinitionParser("registry", new PluginRegistryDefinitionParser()); + } } diff --git a/core/src/main/java/org/synyx/hera/core/config/PluginRegistryDefinitionParser.java b/core/src/main/java/org/synyx/hera/core/config/PluginRegistryDefinitionParser.java index 98308cd..3bd448e 100644 --- a/core/src/main/java/org/synyx/hera/core/config/PluginRegistryDefinitionParser.java +++ b/core/src/main/java/org/synyx/hera/core/config/PluginRegistryDefinitionParser.java @@ -1,39 +1,35 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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.config; + /** * Simple extension of {@link PluginListDefinitionParser}. Simply registers a - * {@code PluginRegistryBeanFactoryPostProcessor} instead of the original class. + * {@link PluginRegistryBeanFactoryPostProcessor} instead of the original class. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ public class PluginRegistryDefinitionParser extends PluginListDefinitionParser { - /* - * (non-Javadoc) - * - * @see - * org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser - * #getBeanClassName(org.w3c.dom.Element) - */ - @Override - protected String getPostProcessorName() { - - return PACKAGE + "PluginRegistryFactoryBean"; - } + /* + * (non-Javadoc) + * @see org.synyx.hera.core.config.PluginListDefinitionParser#getPostProcessorName() + */ + @Override + protected String getPostProcessorName() { + return PACKAGE + "PluginRegistryFactoryBean"; + } } diff --git a/core/src/main/java/org/synyx/hera/core/config/package-info.java b/core/src/main/java/org/synyx/hera/core/config/package-info.java new file mode 100644 index 0000000..c09bb6f --- /dev/null +++ b/core/src/main/java/org/synyx/hera/core/config/package-info.java @@ -0,0 +1,5 @@ +/** + * This package contains configuration support classes to ease registry configuration with Spring namespaces. + */ +package org.synyx.hera.core.config; + diff --git a/core/src/main/java/org/synyx/hera/core/config/package.html b/core/src/main/java/org/synyx/hera/core/config/package.html deleted file mode 100644 index e0999e4..0000000 --- a/core/src/main/java/org/synyx/hera/core/config/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - - -This package contains configuration support classes to ease registry configuration with -Spring namespaces. - - \ No newline at end of file diff --git a/core/src/main/java/org/synyx/hera/core/package-info.java b/core/src/main/java/org/synyx/hera/core/package-info.java new file mode 100644 index 0000000..1c6518e --- /dev/null +++ b/core/src/main/java/org/synyx/hera/core/package-info.java @@ -0,0 +1,5 @@ +/** + * This package contains the core plugin API. It allows other modules implementing components that extend functionality defined by a plugin interface. Plugin clients can be equipped with plugin implementations. + */ +package org.synyx.hera.core; + diff --git a/core/src/main/java/org/synyx/hera/core/package.html b/core/src/main/java/org/synyx/hera/core/package.html deleted file mode 100644 index 40faeb5..0000000 --- a/core/src/main/java/org/synyx/hera/core/package.html +++ /dev/null @@ -1,8 +0,0 @@ - - - -This package contains the core plugin API. It allows other modules implementing -components that extend functionality defined by a plugin interface. Plugin clients -can be equipped with plugin implementations. - - \ No newline at end of file diff --git a/core/src/main/java/org/synyx/hera/core/support/AbstractTypeAwareSupport.java b/core/src/main/java/org/synyx/hera/core/support/AbstractTypeAwareSupport.java index 653eee4..3b44d5a 100644 --- a/core/src/main/java/org/synyx/hera/core/support/AbstractTypeAwareSupport.java +++ b/core/src/main/java/org/synyx/hera/core/support/AbstractTypeAwareSupport.java @@ -1,74 +1,181 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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.ArrayList; +import java.util.Collection; import java.util.List; -import java.util.Map; +import org.springframework.aop.TargetSource; +import org.springframework.aop.framework.ProxyFactory; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; - +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.util.Assert; /** - * Abstract base class to implement types that need access to all beans of a - * given type from the {@link ApplicationContext}. + * Abstract base class to implement types that need access to all beans of a given type from the + * {@link ApplicationContext}. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ -public abstract class AbstractTypeAwareSupport implements - ApplicationContextAware { +public abstract class AbstractTypeAwareSupport implements ApplicationContextAware, + ApplicationListener, InitializingBean { - private ApplicationContext context; - private Class type; + private ApplicationContext context; + private Class type; + private BeansOfTypeTargetSource targetSource; + /* + * (non-Javadoc) + * + * @see + * org.springframework.context.ApplicationContextAware#setApplicationContext + * (org.springframework.context.ApplicationContext) + */ + public void setApplicationContext(ApplicationContext context) { - /* - * (non-Javadoc) - * - * @see - * org.springframework.context.ApplicationContextAware#setApplicationContext - * (org.springframework.context.ApplicationContext) - */ - public void setApplicationContext(ApplicationContext context) { + this.context = context; + } - this.context = context; - } + /** + * @param type the type to set + */ + public void setType(Class type) { + this.type = type; + } - /** - * @param type the type to set - */ - public void setType(Class type) { + /** + * Returns all beans from the {@link ApplicationContext} that match the given type. + * + * @return + */ + @SuppressWarnings("unchecked") + protected List getBeans() { - this.type = type; - } + ProxyFactory factory = new ProxyFactory(List.class, targetSource); + return (List) factory.getProxy(); + } + /* + * (non-Javadoc) + * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() + */ + public void afterPropertiesSet() { + this.targetSource = new BeansOfTypeTargetSource(context, type, false); + } - /** - * Returns all beans from the {@link ApplicationContext} that match the - * given type. - * - * @return - */ - @SuppressWarnings("unchecked") - protected List getBeans() { + /* + * (non-Javadoc) + * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent) + */ + public void onApplicationEvent(ContextRefreshedEvent event) { - Map pluginMap = context.getBeansOfType(type); + if (context.equals(event.getApplicationContext())) { + targetSource.freeze(); + } + } - return new ArrayList(pluginMap.values()); - } + /** + * {@link TargetSource} implementation that returns all beans of the configured type from the + * {@link ListableBeanFactory} the instance was set up with. Allows freezing the lookup as calls to + * {@link ListableBeanFactory#getBeansOfType(Class, boolean, boolean)} are potentially expensive as the entire factory + * has to be scanned for type information. + * + * @author Oliver Gierke + */ + private static class BeansOfTypeTargetSource implements TargetSource { + + private final ListableBeanFactory context; + private final Class type; + private final boolean eagerInit; + + private boolean frozen = false; + private Collection components; + + /** + * Creates a new {@link BeansOfTypeTargetSource} using the given {@link ListableBeanFactory} to lookup beans of the + * given type. + * + * @param context must not be {@literal null}. + * @param type must not be {@literal null}. + * @param eagerInit whether to eagerly init {@link FactoryBean}s, defaults to {@literal false}. + */ + public BeansOfTypeTargetSource(ListableBeanFactory context, Class type, boolean eagerInit) { + + Assert.notNull(context); + Assert.notNull(type); + + this.context = context; + this.type = type; + this.eagerInit = eagerInit; + } + + /** + * Freezes the {@link TargetSource} so that the next access to {@link #getTarget()} will get the results cached and + * reused. + */ + public void freeze() { + this.frozen = true; + } + + /* + * (non-Javadoc) + * @see org.springframework.aop.TargetSource#getTargetClass() + */ + public Class getTargetClass() { + return List.class; + } + + /* + * (non-Javadoc) + * @see org.springframework.aop.TargetSource#isStatic() + */ + public boolean isStatic() { + return frozen; + } + + /* + * (non-Javadoc) + * @see org.springframework.aop.TargetSource#getTarget() + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + public synchronized Object getTarget() throws Exception { + + Collection components = this.components == null ? context.getBeansOfType(type, false, eagerInit).values() + : this.components; + + if (frozen && this.components == null) { + this.components = components; + } + + return new ArrayList(components); + } + + /* + * (non-Javadoc) + * @see org.springframework.aop.TargetSource#releaseTarget(java.lang.Object) + */ + public void releaseTarget(Object target) throws Exception { + + } + } } diff --git a/core/src/main/java/org/synyx/hera/core/support/BeanListFactoryBean.java b/core/src/main/java/org/synyx/hera/core/support/BeanListFactoryBean.java index bcf960a..d06b429 100644 --- a/core/src/main/java/org/synyx/hera/core/support/BeanListFactoryBean.java +++ b/core/src/main/java/org/synyx/hera/core/support/BeanListFactoryBean.java @@ -22,54 +22,41 @@ import java.util.List; import org.springframework.beans.factory.FactoryBean; import org.springframework.core.annotation.AnnotationAwareOrderComparator; - /** - * Factory to create bean lists for a given type. Exposes all beans of the - * configured type that can be found in the + * Factory to create bean lists for a given type. Exposes all beans of the configured type that can be found in the * {@link org.springframework.context.ApplicationContext}. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ -public class BeanListFactoryBean extends AbstractTypeAwareSupport - implements FactoryBean { +public class BeanListFactoryBean extends AbstractTypeAwareSupport implements FactoryBean> { - @SuppressWarnings("unchecked") - private static final Comparator COMPARATOR = - new AnnotationAwareOrderComparator(); + private static final Comparator COMPARATOR = new AnnotationAwareOrderComparator(); + /* + * (non-Javadoc) + * @see org.springframework.beans.factory.FactoryBean#getObject() + */ + public List getObject() { - /* - * (non-Javadoc) - * - * @see org.springframework.beans.factory.FactoryBean#getObject() - */ - public Object getObject() { + List beans = getBeans(); + Collections.sort(beans, COMPARATOR); - List beans = getBeans(); - Collections.sort(beans, COMPARATOR); + return beans; + } - return beans; - } + /* + * (non-Javadoc) + * @see org.springframework.beans.factory.FactoryBean#getObjectType() + */ + public Class getObjectType() { + return List.class; + } - - /* - * (non-Javadoc) - * - * @see org.springframework.beans.factory.FactoryBean#getObjectType() - */ - public Class getObjectType() { - - return List.class; - } - - - /* - * (non-Javadoc) - * - * @see org.springframework.beans.factory.FactoryBean#isSingleton() - */ - public boolean isSingleton() { - - return true; - } + /* + * (non-Javadoc) + * @see org.springframework.beans.factory.FactoryBean#isSingleton() + */ + public boolean isSingleton() { + return true; + } } \ No newline at end of file diff --git a/core/src/main/java/org/synyx/hera/core/support/PluginRegistryFactoryBean.java b/core/src/main/java/org/synyx/hera/core/support/PluginRegistryFactoryBean.java index f821ab8..3aae3b2 100644 --- a/core/src/main/java/org/synyx/hera/core/support/PluginRegistryFactoryBean.java +++ b/core/src/main/java/org/synyx/hera/core/support/PluginRegistryFactoryBean.java @@ -1,17 +1,17 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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; @@ -20,45 +20,35 @@ 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}. + * {@link FactoryBean} to create {@link PluginRegistry} instances. Wraps a {@link BeanListFactoryBean}. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ -public class PluginRegistryFactoryBean, S> extends - AbstractTypeAwareSupport implements FactoryBean { +public class PluginRegistryFactoryBean, S> extends AbstractTypeAwareSupport implements + FactoryBean> { - /* - * (non-Javadoc) - * - * @see org.springframework.beans.factory.FactoryBean#getObject() - */ - public Object getObject() { + /* + * (non-Javadoc) + * @see org.springframework.beans.factory.FactoryBean#getObject() + */ + public OrderAwarePluginRegistry getObject() { + return OrderAwarePluginRegistry.create(getBeans()); + } - return OrderAwarePluginRegistry.create(getBeans()); - } + /* + * (non-Javadoc) + * @see org.springframework.beans.factory.FactoryBean#getObjectType() + */ + public Class getObjectType() { + return PluginRegistry.class; + } - - /* - * (non-Javadoc) - * - * @see org.springframework.beans.factory.FactoryBean#getObjectType() - */ - public Class getObjectType() { - - return PluginRegistry.class; - } - - - /* - * (non-Javadoc) - * - * @see org.springframework.beans.factory.FactoryBean#isSingleton() - */ - public boolean isSingleton() { - - return true; - } + /* + * (non-Javadoc) + * @see org.springframework.beans.factory.FactoryBean#isSingleton() + */ + public boolean isSingleton() { + return true; + } } diff --git a/core/src/main/java/org/synyx/hera/core/support/package-info.java b/core/src/main/java/org/synyx/hera/core/support/package-info.java new file mode 100644 index 0000000..ca5715c --- /dev/null +++ b/core/src/main/java/org/synyx/hera/core/support/package-info.java @@ -0,0 +1,5 @@ +/** + * This package contains support classes to create bean lists or plugin registry instances out of beans implementing a certain interface. + */ +package org.synyx.hera.core.support; + diff --git a/core/src/main/java/org/synyx/hera/core/support/package.html b/core/src/main/java/org/synyx/hera/core/support/package.html deleted file mode 100644 index b52d726..0000000 --- a/core/src/main/java/org/synyx/hera/core/support/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - - -This package contains support classes to create bean lists or plugin -registry instances out of beans implementing a certain interface. - - \ No newline at end of file diff --git a/core/src/main/resources/org/synyx/hera/core/config/hera.xsd b/core/src/main/resources/org/synyx/hera/core/config/hera.xsd index 18b59aa..b855303 100644 --- a/core/src/main/resources/org/synyx/hera/core/config/hera.xsd +++ b/core/src/main/resources/org/synyx/hera/core/config/hera.xsd @@ -7,7 +7,6 @@ - @@ -37,8 +36,7 @@ - + @@ -47,8 +45,7 @@ - + diff --git a/core/src/test/java/org/synyx/hera/core/AbstractMutablePluginRegistryUnitTest.java b/core/src/test/java/org/synyx/hera/core/AbstractMutablePluginRegistryUnitTest.java index 12412ab..afba294 100644 --- a/core/src/test/java/org/synyx/hera/core/AbstractMutablePluginRegistryUnitTest.java +++ b/core/src/test/java/org/synyx/hera/core/AbstractMutablePluginRegistryUnitTest.java @@ -1,68 +1,48 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; -import java.util.Arrays; - import org.junit.Test; - /** * Unit test for implementations of {@link MutablePluginRegistry}. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ public abstract class AbstractMutablePluginRegistryUnitTest { - private SamplePlugin plugin = new SamplePluginImplementation(); + private SamplePlugin plugin = new SamplePluginImplementation(); + @Test + public void allowsAddingPluginsAfterCreation() throws Exception { - @Test - public void allowsAddingPluginsAfterCreation() throws Exception { + MutablePluginRegistry registry = getRegistry(); + registry.addPlugin(plugin); - MutablePluginRegistry registry = getRegistry(); - registry.addPlugin(plugin); + assertTrue(registry.contains(plugin)); + assertThat(registry.getPlugins().size(), is(1)); + } - assertTrue(registry.contains(plugin)); - assertThat(registry.getPlugins().size(), is(1)); - } - - - @Test - public void settingPluginsRemovesOldOnes() throws Exception { - - MutablePluginRegistry registry = getRegistry(); - registry.addPlugin(plugin); - - SamplePlugin anotherPlugin = new SamplePluginImplementation(); - - registry.setPlugins(Arrays.asList(anotherPlugin)); - assertTrue(registry.contains(anotherPlugin)); - assertFalse(registry.contains(plugin)); - } - - - /** - * Return the {@link MutablePluginRegistry} to test. - * - * @return - */ - protected abstract MutablePluginRegistry getRegistry(); + /** + * Return the {@link MutablePluginRegistry} to test. + * + * @return + */ + protected abstract MutablePluginRegistry getRegistry(); } diff --git a/core/src/test/java/org/synyx/hera/core/OrderAwarePluginRegistryUnitTest.java b/core/src/test/java/org/synyx/hera/core/OrderAwarePluginRegistryUnitTest.java index 224a9b0..99ae58a 100644 --- a/core/src/test/java/org/synyx/hera/core/OrderAwarePluginRegistryUnitTest.java +++ b/core/src/test/java/org/synyx/hera/core/OrderAwarePluginRegistryUnitTest.java @@ -1,19 +1,18 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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; import static org.hamcrest.CoreMatchers.*; @@ -23,151 +22,107 @@ import java.util.Arrays; import java.util.List; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.springframework.core.annotation.Order; - /** - * Unit test for {@link OrderAwarePluginRegistry} that especially concentrates - * on testing ordering functionality. + * Unit test for {@link OrderAwarePluginRegistry} that especially concentrates on testing ordering functionality. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ -public class OrderAwarePluginRegistryUnitTest extends - SimplePluginRegistryUnitTest { +public class OrderAwarePluginRegistryUnitTest extends SimplePluginRegistryUnitTest { - private OrderAwarePluginRegistry registry; + TestPlugin firstPlugin; + TestPlugin secondPlugin; - private TestPlugin firstPlugin; - private TestPlugin secondPlugin; + @Override + @Before + public void setUp() { + super.setUp(); - @Override - @Before - public void setUp() { + firstPlugin = new FirstImplementation(); + secondPlugin = new SecondImplementation(); + } - super.setUp(); + @Override + protected OrderAwarePluginRegistry getRegistry() { - registry = OrderAwarePluginRegistry.create(); + return OrderAwarePluginRegistry.create(); + } - firstPlugin = new FirstImplementation(); - secondPlugin = new SecondImplementation(); - } + @Test + public void honorsOrderOnAddPlugins() throws Exception { + PluginRegistry registry = OrderAwarePluginRegistry.create(Arrays.asList(firstPlugin, + secondPlugin)); + assertOrder(registry, secondPlugin, firstPlugin); + } - /* - * (non-Javadoc) - * - * @see org.synyx.hera.core.SimplePluginRegistryUnitTest#getRegistry() - */ - @Override - protected OrderAwarePluginRegistry getRegistry() { + @Test + @Ignore + public void assertsOrderOnAddingPlugins() throws Exception { - return OrderAwarePluginRegistry.create(); - } + MutablePluginRegistry registry = OrderAwarePluginRegistry.create(Arrays.asList(firstPlugin)); + registry.addPlugin(secondPlugin); + assertOrder(registry, secondPlugin, firstPlugin); + } - /** - * Adds the plugin implementations in order of their names, expecting the - * registry to order them correctly. - * - * @throws Exception - */ - @Test - public void honorsOrderOnAddPlugins() throws Exception { + private void assertOrder(PluginRegistry registry, TestPlugin... plugins) { - registry.setPlugins(Arrays.asList(firstPlugin, secondPlugin)); + List result = registry.getPluginsFor(null); - assertOrder(registry, secondPlugin, firstPlugin); - } + assertThat(plugins.length, is(result.size())); + for (int i = 0; i < plugins.length; i++) { + assertThat(result.get(i), is(result.get(i))); + } - @Test - public void assertsOrderOnAddingPlugins() throws Exception { + assertThat(registry.getPluginFor(null), is(plugins[0])); + } - registry.setPlugins(Arrays.asList(firstPlugin)); - registry.addPlugin(secondPlugin); + @Test + public void createsRevertedRegistryCorrectly() throws Exception { - assertOrder(registry, secondPlugin, firstPlugin); - } + OrderAwarePluginRegistry registry = OrderAwarePluginRegistry.create(Arrays.asList(firstPlugin, + secondPlugin)); + PluginRegistry reverse = registry.reverse(); + assertOrder(registry, secondPlugin, firstPlugin); + assertOrder(reverse, firstPlugin, secondPlugin); + } - private void assertOrder(PluginRegistry registry, - TestPlugin... plugins) { + private static interface TestPlugin extends Plugin { - List result = registry.getPluginsFor(null); + } - assertThat(plugins.length, is(result.size())); + @Order(5) + private static class FirstImplementation implements TestPlugin { - for (int i = 0; i < plugins.length; i++) { - assertThat(result.get(i), is(result.get(i))); - } + /* + * (non-Javadoc) + * + * @see org.synyx.hera.core.Plugin#supports(java.lang.Object) + */ + public boolean supports(String delimiter) { - assertThat(registry.getPluginFor(null), is(plugins[0])); - } + return true; + } + } + @Order(1) + private static class SecondImplementation implements TestPlugin { - @Test - public void createsRevertedRegistryCorrectly() throws Exception { + /* + * (non-Javadoc) + * + * @see org.synyx.hera.core.Plugin#supports(java.lang.Object) + */ + public boolean supports(String delimiter) { - basicPrepare(); - PluginRegistry reverse = registry.reverse(); - - assertOrder(registry, secondPlugin, firstPlugin); - assertOrder(reverse, firstPlugin, secondPlugin); - } - - - private void basicPrepare() { - - registry.setPlugins(Arrays.asList(firstPlugin, secondPlugin)); - assertOrder(registry, secondPlugin, firstPlugin); - } - - /** - * Simple test interface. - * - * @author Oliver Gierke - gierke@synyx.de - */ - private static interface TestPlugin extends Plugin { - - } - - /** - * Plugin implementation, that is orderd right AFTER the second one. - * - * @author Oliver Gierke - gierke@synyx.de - */ - @Order(5) - private static class FirstImplementation implements TestPlugin { - - /* - * (non-Javadoc) - * - * @see org.synyx.hera.core.Plugin#supports(java.lang.Object) - */ - public boolean supports(String delimiter) { - - return true; - } - } - - /** - * Plugin implementation that is ordered BEFORE the first one. - * - * @author Oliver Gierke - gierke@synyx.de - */ - @Order(1) - private static class SecondImplementation implements TestPlugin { - - /* - * (non-Javadoc) - * - * @see org.synyx.hera.core.Plugin#supports(java.lang.Object) - */ - public boolean supports(String delimiter) { - - return true; - } - } + return true; + } + } } diff --git a/core/src/test/java/org/synyx/hera/core/SamplePlugin.java b/core/src/test/java/org/synyx/hera/core/SamplePlugin.java index d2d2cee..bb2f09f 100644 --- a/core/src/test/java/org/synyx/hera/core/SamplePlugin.java +++ b/core/src/test/java/org/synyx/hera/core/SamplePlugin.java @@ -1,25 +1,24 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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; /** - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ public interface SamplePlugin extends Plugin { - void pluginMethod(); + void pluginMethod(); } diff --git a/core/src/test/java/org/synyx/hera/core/SamplePluginHost.java b/core/src/test/java/org/synyx/hera/core/SamplePluginHost.java index 8feeb0b..ae361d6 100644 --- a/core/src/test/java/org/synyx/hera/core/SamplePluginHost.java +++ b/core/src/test/java/org/synyx/hera/core/SamplePluginHost.java @@ -1,44 +1,40 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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; /** - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ public class SamplePluginHost { - private PluginRegistry registry = - SimplePluginRegistry.create(); + private PluginRegistry registry = SimplePluginRegistry.create(); + /** + * @param registry the registry to set + */ + public void setRegistry(PluginRegistry registry) { - /** - * @param registry the registry to set - */ - public void setRegistry(PluginRegistry registry) { + this.registry = registry; + } - this.registry = registry; - } + /** + * @return the registry + */ + public PluginRegistry getRegistry() { - - /** - * @return the registry - */ - public PluginRegistry getRegistry() { - - return registry; - } + return registry; + } } diff --git a/core/src/test/java/org/synyx/hera/core/SamplePluginImplementation.java b/core/src/test/java/org/synyx/hera/core/SamplePluginImplementation.java index a5dc158..7cfc7e6 100644 --- a/core/src/test/java/org/synyx/hera/core/SamplePluginImplementation.java +++ b/core/src/test/java/org/synyx/hera/core/SamplePluginImplementation.java @@ -1,43 +1,38 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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; /** - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ public class SamplePluginImplementation implements SamplePlugin { - /* - * (non-Javadoc) - * - * @see org.synyx.plugin.core.Plugin#supports(java.lang.Object) - */ - public boolean supports(String delimiter) { + /* + * (non-Javadoc) + * @see org.synyx.hera.core.Plugin#supports(java.lang.Object) + */ + public boolean supports(String delimiter) { + return "FOO".equals(delimiter); + } - return "FOO".equals(delimiter); - } + /* + * (non-Javadoc) + * @see org.synyx.hera.core.SamplePlugin#pluginMethod() + */ + public void pluginMethod() { - - /* - * (non-Javadoc) - * - * @see org.synyx.plugin.core.ISamplePlugin#pluginMethod() - */ - public void pluginMethod() { - - } + } } diff --git a/core/src/test/java/org/synyx/hera/core/SimplePluginRegistryUnitTest.java b/core/src/test/java/org/synyx/hera/core/SimplePluginRegistryUnitTest.java index 5d4a816..37bb8c5 100644 --- a/core/src/test/java/org/synyx/hera/core/SimplePluginRegistryUnitTest.java +++ b/core/src/test/java/org/synyx/hera/core/SimplePluginRegistryUnitTest.java @@ -1,17 +1,17 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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; @@ -25,155 +25,115 @@ import java.util.List; import org.junit.Before; import org.junit.Test; - /** * Unit test for {@link SimplePluginRegistry}. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ -public class SimplePluginRegistryUnitTest extends - AbstractMutablePluginRegistryUnitTest { +public class SimplePluginRegistryUnitTest extends AbstractMutablePluginRegistryUnitTest { - private SamplePlugin plugin; + SamplePlugin plugin; - private SimplePluginRegistry registry; + SimplePluginRegistry registry; + /** + * Initializes a {@code PluginRegistry} and equips it with an {@code EmailNotificationProvider}. + */ + @Before + public void setUp() { - /** - * Initializes a {@code PluginRegistry} and equips it with an {@code - * EmailNotificationProvider}. - */ - @Before - public void setUp() { + plugin = new SamplePluginImplementation(); + registry = SimplePluginRegistry.create(); + } - plugin = new SamplePluginImplementation(); + /* + * (non-Javadoc) + * @see org.synyx.hera.core.AbstractMutablePluginRegistryUnitTest#getRegistry() + */ + @Override + protected MutablePluginRegistry getRegistry() { - registry = SimplePluginRegistry.create(); - } + return SimplePluginRegistry.create(); + } + /** + * Asserts that the registry contains the plugin it was initialized with. + * + * @throws Exception + */ + @Test + public void assertRegistryInitialized() throws Exception { - /* - * (non-Javadoc) - * - * @see - * org.synyx.hera.core.AbstractMutablePluginRegistryUnitTest#getRegistry() - */ - @Override - protected MutablePluginRegistry getRegistry() { + registry.addPlugin(plugin); - return SimplePluginRegistry.create(); - } + assertThat(registry.countPlugins(), is(1)); + assertTrue(registry.contains(plugin)); + } + /** + * Asserts asking for a plugin with the {@code PluginMetadata} provided by the {@link EmailNotificationProvider}. + */ + @Test + public void assertFindsEmailNotificationProvider() { - /** - * Asserts that the registry contains the plugin it was initialized with. - * - * @throws Exception - */ - @Test - public void assertRegistryInitialized() throws Exception { + registry.addPlugin(plugin); - registry.addPlugin(plugin); + String delimiter = "FOO"; - assertThat(registry.countPlugins(), is(1)); - assertTrue(registry.contains(plugin)); - } + List plugins = registry.getPluginsFor(delimiter); + assertThat(plugins, is(notNullValue())); + assertThat(plugins.size(), is(1)); + SamplePlugin provider = plugins.get(0); + assertThat(provider, is(instanceOf(SamplePluginImplementation.class))); + } - /** - * Asserts asking for a plugin with the {@code PluginMetadata} provided by - * the {@link EmailNotificationProvider}. - */ - @Test - public void assertFindsEmailNotificationProvider() { + /** + * Expects the given exception to be thrown if no {@link Plugin} found. + */ + @Test(expected = IllegalArgumentException.class) + public void throwsExceptionIfNoPluginFound() { - registry.addPlugin(plugin); + registry.getPluginFor("BAR", new IllegalArgumentException()); + } - String delimiter = "FOO"; + /** + * Expects the given exception to be thrown if no {@link Plugin}s found. + */ + @Test(expected = IllegalArgumentException.class) + public void throwsExceptionIfNoPluginsFound() { - List plugins = registry.getPluginsFor(delimiter); - assertThat(plugins, is(notNullValue())); - assertThat(plugins.size(), is(1)); + registry.getPluginsFor("BAR", new IllegalArgumentException()); + } - SamplePlugin provider = plugins.get(0); - assertThat(provider, is(instanceOf(SamplePluginImplementation.class))); - } + /** + * Expect the defualt plugin to be returned if none found. + */ + @Test + public void returnsDefaultIfNoneFound() { + SamplePlugin defaultPlugin = new SamplePluginImplementation(); - /** - * Expects the given exception to be thrown if no {@link Plugin} found. - */ - @Test(expected = IllegalArgumentException.class) - public void throwsExceptionIfNoPluginFound() { + assertThat(registry.getPluginFor("BAR", defaultPlugin), is(defaultPlugin)); + } - registry.getPluginFor("BAR", new IllegalArgumentException()); - } + /** + * Expect the given default plugins to be returned if none found. + */ + @Test + public void returnsDefaultsIfNoneFound() { + List defaultPlugins = Arrays.asList(new SamplePluginImplementation()); - /** - * Expects the given exception to be thrown if no {@link Plugin}s found. - */ - @Test(expected = IllegalArgumentException.class) - public void throwsExceptionIfNoPluginsFound() { + List result = registry.getPluginsFor("BAR", defaultPlugins); + assertTrue(result.containsAll(defaultPlugins)); + } - registry.getPluginsFor("BAR", new IllegalArgumentException()); - } + @Test + public void handlesAddingNullPluginsCorrecty() throws Exception { + registry.addPlugin(null); - /** - * Expect the defualt plugin to be returned if none found. - */ - @Test - public void returnsDefaultIfNoneFound() { - - SamplePlugin defaultPlugin = new SamplePluginImplementation(); - - assertThat(registry.getPluginFor("BAR", defaultPlugin), - is(defaultPlugin)); - } - - - /** - * Expect the given default plugins to be returned if none found. - */ - @Test - public void returnsDefaultsIfNoneFound() { - - List defaultPlugins = - Arrays.asList(new SamplePluginImplementation()); - - List result = - registry.getPluginsFor("BAR", defaultPlugins); - assertTrue(result.containsAll(defaultPlugins)); - } - - - @Test - public void handlesAddingNullPluginsCorrecty() throws Exception { - - registry.addPlugin(null); - - assertThat(registry.countPlugins(), is(0)); - } - - - @Test - public void doesNotAddNullsOnSettingPlugins() throws Exception { - - registry.setPlugins(Arrays.asList(null, plugin, null)); - - assertThat(registry.countPlugins(), is(1)); - assertThat(registry.getPlugins().size(), is(1)); - } - - - @Test - public void dropsNullValuesOnCreation() throws Exception { - - registry = - SimplePluginRegistry.create(Arrays.asList(null, plugin, null)); - - assertThat(registry.countPlugins(), is(1)); - assertThat(registry.getPlugins().size(), is(1)); - } + assertThat(registry.countPlugins(), is(0)); + } } diff --git a/core/src/test/java/org/synyx/hera/core/config/PluginConfigurationIntegrationTest.java b/core/src/test/java/org/synyx/hera/core/config/PluginConfigurationIntegrationTest.java index bb67243..162cf04 100644 --- a/core/src/test/java/org/synyx/hera/core/config/PluginConfigurationIntegrationTest.java +++ b/core/src/test/java/org/synyx/hera/core/config/PluginConfigurationIntegrationTest.java @@ -1,3 +1,18 @@ +/* + * 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 + * + * 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.config; import static org.junit.Assert.*; @@ -14,44 +29,42 @@ import org.synyx.hera.core.PluginRegistry; import org.synyx.hera.core.SamplePlugin; import org.synyx.hera.core.SamplePluginHost; - /** * Integration test to simply check if the configuration gets parsed correctly. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:application-context.xml") public class PluginConfigurationIntegrationTest { - @Autowired - List samplePlugins; + @Autowired + List samplePlugins; - @Autowired - @Qualifier("bar") - PluginRegistry pluginRegistry; + @Autowired + @Qualifier("bar") + PluginRegistry pluginRegistry; - @Autowired - @Qualifier("host") - SamplePluginHost host; + @Autowired + @Qualifier("host") + SamplePluginHost host; - @Autowired - @Qualifier("otherHost") - SamplePluginHost otherHost; + @Autowired + @Qualifier("otherHost") + SamplePluginHost otherHost; - @Autowired - SamplePlugin plugin; + @Autowired + SamplePlugin plugin; + @Test + public void test() throws Exception { - @Test - public void test() throws Exception { + assertNotNull(samplePlugins); - assertNotNull(samplePlugins); + assertSame(pluginRegistry, host.getRegistry()); + assertNotSame(pluginRegistry, otherHost.getRegistry()); - assertSame(pluginRegistry, host.getRegistry()); - assertNotSame(pluginRegistry, otherHost.getRegistry()); - - assertTrue(samplePlugins.contains(plugin)); - assertTrue(pluginRegistry.contains(plugin)); - } + assertTrue(samplePlugins.contains(plugin)); + assertTrue(pluginRegistry.contains(plugin)); + } } diff --git a/core/src/test/java/org/synyx/hera/core/support/BeanListFactoryBeanUnitTest.java b/core/src/test/java/org/synyx/hera/core/support/BeanListFactoryBeanUnitTest.java index cbb5a57..5e6f8b5 100644 --- a/core/src/test/java/org/synyx/hera/core/support/BeanListFactoryBeanUnitTest.java +++ b/core/src/test/java/org/synyx/hera/core/support/BeanListFactoryBeanUnitTest.java @@ -1,3 +1,18 @@ +/* + * 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 + * + * 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 static org.junit.Assert.*; @@ -15,88 +30,82 @@ import org.mockito.runners.MockitoJUnitRunner; import org.springframework.context.ApplicationContext; import org.springframework.core.Ordered; - /** * Unit test for {@link BeanListFactoryBean}. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ @RunWith(MockitoJUnitRunner.class) public class BeanListFactoryBeanUnitTest { - private BeanListFactoryBean factory; + BeanListFactoryBean factory; - @Mock - private ApplicationContext context; + @Mock + ApplicationContext context; + @Before + public void setUp() { - @Before - public void setUp() { + factory = new BeanListFactoryBean(); + factory.setApplicationContext(context); + factory.setType(Ordered.class); + factory.afterPropertiesSet(); + } - factory = new BeanListFactoryBean(); - factory.setApplicationContext(context); - factory.setType(Ordered.class); - } + @Test + public void regardsOrderOfBeans() throws Exception { + // They shall be switched in the result. + Ordered first = getOrdered(5); + Ordered second = getOrdered(0); - @Test - public void regardsOrderOfBeans() throws Exception { + Map beans = new HashMap(); + beans.put("first", first); + beans.put("second", second); - // They shall be switched in the result. - Ordered first = getOrdered(5); - Ordered second = getOrdered(0); + when(context.getBeansOfType(Ordered.class, false, false)).thenReturn(beans); - Map beans = new HashMap(); - beans.put("first", first); - beans.put("second", second); + Object result = factory.getObject(); + assertTrue(result instanceof List); - when(context.getBeansOfType(Ordered.class)).thenReturn(beans); + List members = type(result); - Object result = factory.getObject(); - assertTrue(result instanceof List); + assertEquals(0, members.indexOf(second)); + assertEquals(1, members.indexOf(first)); + } - List members = type(result); + @Test + public void returnsEmptyListIfNoBeansFound() throws Exception { - assertEquals(0, members.indexOf(second)); - assertEquals(1, members.indexOf(first)); - } + when(context.getBeansOfType(Ordered.class)).thenReturn(new HashMap()); + Object result = factory.getObject(); + assertTrue(result instanceof List); - @Test - public void returnsEmptyListIfNoBeansFound() throws Exception { + List members = type(result); + assertTrue(members.isEmpty()); + } - when(context.getBeansOfType(Ordered.class)).thenReturn( - new HashMap()); + @SuppressWarnings("unchecked") + private List type(Object list) { - Object result = factory.getObject(); - assertTrue(result instanceof List); + return (List) list; + } - List members = type(result); - assertTrue(members.isEmpty()); - } + /** + * Returns an {@link Ordered} with the given order. + * + * @param order + * @return + */ + public Ordered getOrdered(final int order) { + return new Ordered() { - @SuppressWarnings("unchecked") - private List type(Object list) { + public int getOrder() { - return (List) list; - } - - - /** - * Returns an {@link Ordered} with the given order. - * - * @param order - * @return - */ - public Ordered getOrdered(final int order) { - - return new Ordered() { - - public int getOrder() { - - return order; - } - }; - } + return order; + } + }; + } } diff --git a/core/src/test/resources/log4j.properties b/core/src/test/resources/log4j.properties index 3774e1f..7e1b088 100644 --- a/core/src/test/resources/log4j.properties +++ b/core/src/test/resources/log4j.properties @@ -2,7 +2,7 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n # Root logger option log4j.rootLogger=WARN, stdout diff --git a/metadata/pom.xml b/metadata/pom.xml index b1c90b8..4c43e7f 100644 --- a/metadata/pom.xml +++ b/metadata/pom.xml @@ -18,11 +18,6 @@ ${project.version} - - - - - diff --git a/metadata/src/main/java/org/synyx/hera/metadata/AbstractMetadataBasedPlugin.java b/metadata/src/main/java/org/synyx/hera/metadata/AbstractMetadataBasedPlugin.java index 2f9a14d..b64e6d1 100644 --- a/metadata/src/main/java/org/synyx/hera/metadata/AbstractMetadataBasedPlugin.java +++ b/metadata/src/main/java/org/synyx/hera/metadata/AbstractMetadataBasedPlugin.java @@ -1,68 +1,57 @@ /* - * Copyright 2008-2010 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 - * + * Copyright 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 + * + * 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. + * 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.metadata; import org.synyx.hera.core.Plugin; - +import org.synyx.hera.core.PluginRegistry; /** - * Abstract base class for plugins based on {@code PluginMetadata}. Plugins - * based on this class can be selected from the {@code PluginRegistry} via an - * instance of {@code PluginMetadata}. Therefore you can regard this as a role - * model implementation of a base class for certain delimiter implmentations. + * Abstract base class for plugins based on {@link PluginMetadata}. Plugins based on this class can be selected from the + * {@link PluginRegistry} via an instance of {@link PluginMetadata}. Therefore you can regard this as a role model + * implementation of a base class for certain delimiter implmentations. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ -public abstract class AbstractMetadataBasedPlugin implements - Plugin, MetadataProvider { +public abstract class AbstractMetadataBasedPlugin implements Plugin, MetadataProvider { - private PluginMetadata metadata; + private final PluginMetadata metadata; + /** + * Creates a new instance of {@code AbstractMetadataBasedPlugin}. + * + * @param name must not be {@literal null}. + * @param version must not be {@literal null}. + */ + public AbstractMetadataBasedPlugin(String name, String version) { + this.metadata = new SimplePluginMetadata(name, version); + } - /** - * Creates a new instance of {@code AbstractMetadataBasedPlugin}. - * - * @param name - * @param version - */ - public AbstractMetadataBasedPlugin(String name, String version) { + /* + * (non-Javadoc) + * @see org.synyx.hera.core.Plugin#supports(java.lang.Object) + */ + public boolean supports(PluginMetadata delimiter) { + return getMetadata().equals(delimiter); + } - this.metadata = new SimplePluginMetadata(name, version); - } - - - /* - * (non-Javadoc) - * - * @see com.synyx.minos.core.plugin.Plugin#supports(java.lang.Object) - */ - public boolean supports(PluginMetadata delimiter) { - - return getMetadata().equals(delimiter); - } - - - /* - * (non-Javadoc) - * - * @see com.synyx.minos.core.plugin.MetadataProvider#getMetadata() - */ - public PluginMetadata getMetadata() { - - return metadata; - } + /* + * (non-Javadoc) + * @see org.synyx.hera.metadata.MetadataProvider#getMetadata() + */ + public PluginMetadata getMetadata() { + return metadata; + } } diff --git a/metadata/src/main/java/org/synyx/hera/metadata/MetadataProvider.java b/metadata/src/main/java/org/synyx/hera/metadata/MetadataProvider.java index d96b4dd..4e0f643 100644 --- a/metadata/src/main/java/org/synyx/hera/metadata/MetadataProvider.java +++ b/metadata/src/main/java/org/synyx/hera/metadata/MetadataProvider.java @@ -1,33 +1,31 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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.metadata; /** - * Interface for plugins providing metadata information. Usually the plugins - * will implement this interface themselves. + * Interface for plugins providing metadata information. Usually the plugins will implement this interface themselves. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ public interface MetadataProvider { - /** - * Returns the plugins metadata. - * - * @return the plugins metadata - */ - PluginMetadata getMetadata(); + /** + * Returns the plugins metadata. + * + * @return the plugins metadata + */ + PluginMetadata getMetadata(); } diff --git a/metadata/src/main/java/org/synyx/hera/metadata/PluginMetadata.java b/metadata/src/main/java/org/synyx/hera/metadata/PluginMetadata.java index fa3ea0c..7d09c5e 100644 --- a/metadata/src/main/java/org/synyx/hera/metadata/PluginMetadata.java +++ b/metadata/src/main/java/org/synyx/hera/metadata/PluginMetadata.java @@ -1,17 +1,17 @@ /* - * Copyright 2008-2010 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 - * + * 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 + * + * 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. + * 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.metadata; @@ -19,24 +19,21 @@ package org.synyx.hera.metadata; /** * Basic interface to define a set of metadata information for plugins. * - * @author Oliver Gierke - gierke@synyx.de + * @author Oliver Gierke */ public interface PluginMetadata { - /** - * Returns a unique plugin name. Plugins return a metadata implementation - * have to ensure uniqueness of this name. - * - * @return the name of the plugin - */ - String getName(); + /** + * Returns a unique plugin name. Plugins return a metadata implementation have to ensure uniqueness of this name. + * + * @return the name of the plugin + */ + String getName(); - - /** - * Returns the plugin version. This allows rudimentary versioning - * possibilities. - * - * @return the version of the plugin - */ - String getVersion(); + /** + * Returns the plugin version. This allows rudimentary versioning possibilities. + * + * @return the version of the plugin + */ + String getVersion(); } diff --git a/metadata/src/main/java/org/synyx/hera/metadata/SimplePluginMetadata.java b/metadata/src/main/java/org/synyx/hera/metadata/SimplePluginMetadata.java index 172e46f..0c65a6f 100644 --- a/metadata/src/main/java/org/synyx/hera/metadata/SimplePluginMetadata.java +++ b/metadata/src/main/java/org/synyx/hera/metadata/SimplePluginMetadata.java @@ -18,6 +18,7 @@ package org.synyx.hera.metadata; import static org.springframework.util.ObjectUtils.*; +import org.springframework.util.Assert; /** * Value object style implementation of {@code PluginMetadata}. @@ -26,90 +27,78 @@ import static org.springframework.util.ObjectUtils.*; */ public class SimplePluginMetadata implements PluginMetadata { - private String name; - private String version; + private final String name; + private final String version; + /** + * Creates a new instance of {@code SimplePluginMetadata}. + * + * @param name must not be {@literal null}. + * @param version must not be {@literal null}. + */ + public SimplePluginMetadata(String name, String version) { - /** - * Creates a new instance of {@code SimplePluginMetadata}. - * - * @param name - * @param version - */ - public SimplePluginMetadata(String name, String version) { + Assert.hasText(name, "Name must not be null or empty!"); + Assert.hasText(version, "Version must not be null or empty!"); - this.name = name; - this.version = version; - } + this.name = name; + this.version = version; + } + /* + * (non-Javadoc) + * @see org.synyx.hera.metadata.PluginMetadata#getName() + */ + public String getName() { + return name; + } - /* - * (non-Javadoc) - * - * @see com.synyx.minos.core.plugin.PluginMetadata#getName() - */ - public String getName() { + /* + * (non-Javadoc) + * @see org.synyx.hera.metadata.PluginMetadata#getVersion() + */ + public String getVersion() { + return version; + } - return name; - } + /* + * (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return String.format("%s:%s", getName(), getVersion()); + } + /* + * (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { - /* - * (non-Javadoc) - * - * @see com.synyx.minos.core.plugin.PluginMetadata#getVersion() - */ - public String getVersion() { + if (this == obj) { + return true; + } - return version; - } + if (!(obj instanceof PluginMetadata)) { + return false; + } + PluginMetadata that = (PluginMetadata) obj; - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { + boolean sameName = nullSafeEquals(this.getName(), that.getName()); + boolean sameVersion = nullSafeEquals(this.getName(), that.getName()); - return String.format("%s:%s", getName(), getVersion()); - } + return sameName && sameVersion; + } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - - if (this == obj) { - return true; - } - - if (!(obj instanceof PluginMetadata)) { - return false; - } - - PluginMetadata that = (PluginMetadata) obj; - - boolean sameName = nullSafeEquals(this.getName(), that.getName()); - boolean sameVersion = nullSafeEquals(this.getName(), that.getName()); - - return sameName && sameVersion; - } - - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - - return nullSafeHashCode(name) + nullSafeHashCode(version); - } + /* + * (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return nullSafeHashCode(name) + nullSafeHashCode(version); + } } diff --git a/pom.xml b/pom.xml index 1e62bc2..de85882 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ - 2.5.6.SEC02 + 3.0.6.RELEASE @@ -87,16 +87,19 @@ + org.apache.maven.plugins maven-compiler-plugin + 2.3.2 - 1.5 - 1.5 + 1.6 + 1.6 org.apache.maven.plugins maven-source-plugin + 2.1.2 attach-sources diff --git a/si/.settings/org.eclipse.jdt.core.prefs b/si/.settings/org.eclipse.jdt.core.prefs index d32fcd7..cc6246d 100644 --- a/si/.settings/org.eclipse.jdt.core.prefs +++ b/si/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#Wed May 25 12:22:34 CEST 2011 +#Wed Feb 15 21:50:38 CET 2012 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.compliance=1.5 diff --git a/si/pom.xml b/si/pom.xml index 214016f..a8464f1 100644 --- a/si/pom.xml +++ b/si/pom.xml @@ -12,7 +12,6 @@ 2.0.5.RELEASE - 3.0.5.RELEASE @@ -40,12 +39,6 @@ ${spring.version} - - org.springframework - spring-context - ${spring.version} - - org.springframework spring-test diff --git a/si/src/main/java/org/synyx/hera/si/PluginRegistryAwareMessageHandler.java b/si/src/main/java/org/synyx/hera/si/PluginRegistryAwareMessageHandler.java index 0bf8f56..bf9de08 100644 --- a/si/src/main/java/org/synyx/hera/si/PluginRegistryAwareMessageHandler.java +++ b/si/src/main/java/org/synyx/hera/si/PluginRegistryAwareMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-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. @@ -107,6 +107,7 @@ public class PluginRegistryAwareMessageHandler extends AbstractReplyProducingMes * @param delimiterExpression the delimiterExpression to set */ public void setDelimiterExpression(String expression) { + Assert.hasText(expression); this.delimiterExpression = parser.parseExpression(expression); } @@ -118,6 +119,7 @@ public class PluginRegistryAwareMessageHandler extends AbstractReplyProducingMes * @param invocationArgumentsExpression the invocationArgumentsExpression to set */ public void setInvocationArgumentsExpression(String expression) { + Assert.hasText(expression); this.invocationArgumentsExpression = parser.parseExpression(expression); } @@ -134,7 +136,10 @@ public class PluginRegistryAwareMessageHandler extends AbstractReplyProducingMes /* * (non-Javadoc) - * @see org.springframework.integration.handler.AbstractReplyProducingMessageHandler#handleRequestMessage(org.springframework.integration.Message) + * + * @see + * org.springframework.integration.handler.AbstractReplyProducingMessageHandler + * #handleRequestMessage(org.springframework.integration.Message) */ @SuppressWarnings("unchecked") @Override @@ -163,6 +168,7 @@ public class PluginRegistryAwareMessageHandler extends AbstractReplyProducingMes } private List invokePlugins(Collection> plugins, Message message) { + List results = new ArrayList(); if (LOG.isDebugEnabled()) { LOG.debug(String.format("Invoking plugin(s) %s with message %s", @@ -247,6 +253,7 @@ public class PluginRegistryAwareMessageHandler extends AbstractReplyProducingMes * @return */ private Class[] getTypes(Object[] source) { + Class[] result = new Class[source.length]; for (int i = 0; i < source.length; i++) { Object sourceElement = source[i]; @@ -255,10 +262,9 @@ public class PluginRegistryAwareMessageHandler extends AbstractReplyProducingMes return result; } - /** * Lookup methods for plugins. - * + * * @author Oliver Gierke */ private enum PluginLookupMethod { diff --git a/si/src/main/java/org/synyx/hera/si/config/DynamicServiceActivatorParser.java b/si/src/main/java/org/synyx/hera/si/config/DynamicServiceActivatorParser.java index 1e2290d..8f9048b 100644 --- a/si/src/main/java/org/synyx/hera/si/config/DynamicServiceActivatorParser.java +++ b/si/src/main/java/org/synyx/hera/si/config/DynamicServiceActivatorParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-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. @@ -28,7 +28,7 @@ import org.w3c.dom.Element; /** * {@link BeanDefinitionParser} to create {@link PluginRegistryAwareMessageHandler} beans. - * + * * @author Oliver Gierke */ public class DynamicServiceActivatorParser extends AbstractConsumerEndpointParser { diff --git a/si/src/main/java/org/synyx/hera/si/config/HeraSpringIntegrationNamespaceHandler.java b/si/src/main/java/org/synyx/hera/si/config/HeraSpringIntegrationNamespaceHandler.java index d417da3..afd504a 100644 --- a/si/src/main/java/org/synyx/hera/si/config/HeraSpringIntegrationNamespaceHandler.java +++ b/si/src/main/java/org/synyx/hera/si/config/HeraSpringIntegrationNamespaceHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-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. diff --git a/si/src/test/java/org/synyx/hera/si/PluginRegistryAwareMessageHandlerUnitTest.java b/si/src/test/java/org/synyx/hera/si/PluginRegistryAwareMessageHandlerUnitTest.java index f47c01c..abdaf22 100644 --- a/si/src/test/java/org/synyx/hera/si/PluginRegistryAwareMessageHandlerUnitTest.java +++ b/si/src/test/java/org/synyx/hera/si/PluginRegistryAwareMessageHandlerUnitTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-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. @@ -14,6 +14,7 @@ * limitations under the License. */ package org.synyx.hera.si; + import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -53,8 +54,9 @@ public class PluginRegistryAwareMessageHandlerUnitTest { @Before public void setUp() { + registry = OrderAwarePluginRegistry - .create(Arrays.asList(new FirstSamplePluginImpl(), new SecondSamplePluginImpl())); + .create(Arrays.asList(new FirstSamplePluginImpl(), new SecondSamplePluginImpl())); handler = new PluginRegistryAwareMessageHandler(registry, SamplePlugin.class, "myBusinessMethod"); handler.setOutputChannel(outputChannel); diff --git a/si/src/test/java/org/synyx/hera/si/config/DynamicServiceActivatorNamespaceIntegrationTest.java b/si/src/test/java/org/synyx/hera/si/config/DynamicServiceActivatorNamespaceIntegrationTest.java index e025d43..bfd1871 100644 --- a/si/src/test/java/org/synyx/hera/si/config/DynamicServiceActivatorNamespaceIntegrationTest.java +++ b/si/src/test/java/org/synyx/hera/si/config/DynamicServiceActivatorNamespaceIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-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. diff --git a/si/src/test/java/org/synyx/hera/si/sample/FirstSamplePluginImpl.java b/si/src/test/java/org/synyx/hera/si/sample/FirstSamplePluginImpl.java index 6c71cb1..2f0b4bf 100644 --- a/si/src/test/java/org/synyx/hera/si/sample/FirstSamplePluginImpl.java +++ b/si/src/test/java/org/synyx/hera/si/sample/FirstSamplePluginImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-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. @@ -16,19 +16,20 @@ package org.synyx.hera.si.sample; /** - * * @author Oliver Gierke */ public class FirstSamplePluginImpl implements SamplePlugin { - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.synyx.hera.core.Plugin#supports(java.lang.Object) */ public boolean supports(String delimiter) { return "FOO".equals(delimiter); } - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.synyx.hera.si.sample.SamplePlugin#myBusinessMethod() */ public String myBusinessMethod(String message) { diff --git a/si/src/test/java/org/synyx/hera/si/sample/SamplePlugin.java b/si/src/test/java/org/synyx/hera/si/sample/SamplePlugin.java index d30b1c8..fd5fa8b 100644 --- a/si/src/test/java/org/synyx/hera/si/sample/SamplePlugin.java +++ b/si/src/test/java/org/synyx/hera/si/sample/SamplePlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-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. @@ -18,7 +18,6 @@ package org.synyx.hera.si.sample; import org.synyx.hera.core.Plugin; /** - * * @author Oliver Gierke */ public interface SamplePlugin extends Plugin { diff --git a/si/src/test/java/org/synyx/hera/si/sample/SecondSamplePluginImpl.java b/si/src/test/java/org/synyx/hera/si/sample/SecondSamplePluginImpl.java index 637abe8..9019995 100644 --- a/si/src/test/java/org/synyx/hera/si/sample/SecondSamplePluginImpl.java +++ b/si/src/test/java/org/synyx/hera/si/sample/SecondSamplePluginImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-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. @@ -25,14 +25,16 @@ import org.springframework.core.annotation.Order; @Order(10) public class SecondSamplePluginImpl implements SamplePlugin { - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.synyx.hera.core.Plugin#supports(java.lang.Object) */ public boolean supports(String delimiter) { return "BAR".equals(delimiter); } - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.synyx.hera.si.sample.SamplePlugin#myBusinessMethod() */ public String myBusinessMethod(String message) { diff --git a/si/src/test/java/org/synyx/hera/si/sample/ThirdSamplePluginImpl.java b/si/src/test/java/org/synyx/hera/si/sample/ThirdSamplePluginImpl.java index 4a59d89..91c803a 100644 --- a/si/src/test/java/org/synyx/hera/si/sample/ThirdSamplePluginImpl.java +++ b/si/src/test/java/org/synyx/hera/si/sample/ThirdSamplePluginImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-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. @@ -25,14 +25,16 @@ import org.springframework.core.annotation.Order; @Order(20) class ThirdSamplePluginImpl implements SamplePlugin { - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.synyx.hera.core.Plugin#supports(java.lang.Object) */ public boolean supports(String delimiter) { return "BAR".equals(delimiter); } - /* (non-Javadoc) + /* + * (non-Javadoc) * @see org.synyx.hera.si.sample.SamplePlugin#myBusinessMethod() */ public String myBusinessMethod(String message) { diff --git a/si/src/test/resources/log4j.properties b/si/src/test/resources/log4j.properties index 3774e1f..7e1b088 100644 --- a/si/src/test/resources/log4j.properties +++ b/si/src/test/resources/log4j.properties @@ -2,7 +2,7 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n # Root logger option log4j.rootLogger=WARN, stdout