From d5e0517517f131e2da85e8cabed3a7e0133a69d8 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 28 Nov 2012 15:41:42 +0100 Subject: [PATCH] DATACMNS-255 - Made TypeFilterParser public. Moved it into common config package. Changed visibility to public. Polished JavaDoc now that it's available to public consumption. --- .../config/TypeFilterParser.java | 29 ++++++++++++------- .../XmlRepositoryConfigurationSource.java | 3 +- .../config/TypeFilterParserUnitTests.java | 5 ++-- .../config/type-filter-test.xml | 0 4 files changed, 23 insertions(+), 14 deletions(-) rename spring-data-commons-core/src/main/java/org/springframework/data/{repository => }/config/TypeFilterParser.java (91%) rename spring-data-commons-core/src/test/java/org/springframework/data/{repository => }/config/TypeFilterParserUnitTests.java (95%) rename spring-data-commons-core/src/test/resources/org/springframework/data/{repository => }/config/type-filter-test.xml (100%) diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/TypeFilterParser.java b/spring-data-commons-core/src/main/java/org/springframework/data/config/TypeFilterParser.java similarity index 91% rename from spring-data-commons-core/src/main/java/org/springframework/data/repository/config/TypeFilterParser.java rename to spring-data-commons-core/src/main/java/org/springframework/data/config/TypeFilterParser.java index 9abaa7ade..340b88038 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/TypeFilterParser.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/config/TypeFilterParser.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.repository.config; +package org.springframework.data.config; import java.lang.annotation.Annotation; import java.util.Collection; @@ -41,7 +41,7 @@ import org.w3c.dom.NodeList; * * @author Oliver Gierke */ -class TypeFilterParser { +public class TypeFilterParser { private static final String FILTER_TYPE_ATTRIBUTE = "type"; private static final String FILTER_EXPRESSION_ATTRIBUTE = "expression"; @@ -74,6 +74,14 @@ class TypeFilterParser { this.classLoader = classLoader; } + /** + * Returns all {@link TypeFilter} declared in nested elements of the given {@link Element}. Allows to selectively + * retrieve including or excluding filters based on the given {@link Type}. + * + * @param element must not be {@literal null}. + * @param type must not be {@literal null}. + * @return + */ public Iterable parseTypeFilters(Element element, Type type) { NodeList nodeList = element.getChildNodes(); @@ -97,6 +105,13 @@ class TypeFilterParser { return filters; } + /** + * Createsa a {@link TypeFilter} instance from the given {@link Element} and {@link ClassLoader}. + * + * @param element must not be {@literal null}. + * @param classLoader must not be {@literal null}. + * @return + */ protected TypeFilter createTypeFilter(Element element, ClassLoader classLoader) { String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE); @@ -125,7 +140,6 @@ class TypeFilterParser { @Override @SuppressWarnings("unchecked") public TypeFilter getFilter(String expression, ClassLoader classLoader) throws ClassNotFoundException { - return new AnnotationTypeFilter((Class) classLoader.loadClass(expression)); } }, @@ -133,28 +147,22 @@ class TypeFilterParser { ASSIGNABLE { @Override public TypeFilter getFilter(String expression, ClassLoader classLoader) throws ClassNotFoundException { - return new AssignableTypeFilter(classLoader.loadClass(expression)); } - }, ASPECTJ { @Override public TypeFilter getFilter(String expression, ClassLoader classLoader) { - return new AspectJTypeFilter(expression, classLoader); } - }, REGEX { @Override public TypeFilter getFilter(String expression, ClassLoader classLoader) { - return new RegexPatternTypeFilter(Pattern.compile(expression)); } - }, CUSTOM { @@ -199,14 +207,13 @@ class TypeFilterParser { } } - static enum Type { + public static enum Type { INCLUDE("include-filter"), EXCLUDE("exclude-filter"); private String elementName; private Type(String elementName) { - this.elementName = elementName; } diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/XmlRepositoryConfigurationSource.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/XmlRepositoryConfigurationSource.java index e3aba429c..09ec18ade 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/XmlRepositoryConfigurationSource.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/config/XmlRepositoryConfigurationSource.java @@ -19,7 +19,8 @@ import java.util.Arrays; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.core.type.filter.TypeFilter; -import org.springframework.data.repository.config.TypeFilterParser.Type; +import org.springframework.data.config.TypeFilterParser; +import org.springframework.data.config.TypeFilterParser.Type; import org.springframework.data.repository.query.QueryLookupStrategy; import org.springframework.util.Assert; import org.springframework.util.StringUtils; diff --git a/spring-data-commons-core/src/test/java/org/springframework/data/repository/config/TypeFilterParserUnitTests.java b/spring-data-commons-core/src/test/java/org/springframework/data/config/TypeFilterParserUnitTests.java similarity index 95% rename from spring-data-commons-core/src/test/java/org/springframework/data/repository/config/TypeFilterParserUnitTests.java rename to spring-data-commons-core/src/test/java/org/springframework/data/config/TypeFilterParserUnitTests.java index c15200e97..1b3da26d3 100644 --- a/spring-data-commons-core/src/test/java/org/springframework/data/repository/config/TypeFilterParserUnitTests.java +++ b/spring-data-commons-core/src/test/java/org/springframework/data/config/TypeFilterParserUnitTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.repository.config; +package org.springframework.data.config; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; @@ -36,7 +36,8 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.type.filter.AssignableTypeFilter; import org.springframework.core.type.filter.TypeFilter; -import org.springframework.data.repository.config.TypeFilterParser.Type; +import org.springframework.data.config.TypeFilterParser; +import org.springframework.data.config.TypeFilterParser.Type; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; import org.xml.sax.SAXException; diff --git a/spring-data-commons-core/src/test/resources/org/springframework/data/repository/config/type-filter-test.xml b/spring-data-commons-core/src/test/resources/org/springframework/data/config/type-filter-test.xml similarity index 100% rename from spring-data-commons-core/src/test/resources/org/springframework/data/repository/config/type-filter-test.xml rename to spring-data-commons-core/src/test/resources/org/springframework/data/config/type-filter-test.xml