DATACASS-468 - Refactored NamespaceHandler setup to correct package dependency direction.
Introduced CassandraRepositoryNamespaceHandler to extend the core one and register the parser for the repositories element. Consolidated schemas into cassandra.config package. Reduced configuration class visibility where possible.
This commit is contained in:
committed by
Mark Paluch
parent
d400dea386
commit
780981e971
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2017 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.springframework.data.cassandra.config;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parameter used in conjunction with:
|
||||
* <p/>
|
||||
* {@link BeanDefinitionBuilder#addConstructorArgReference(String)},
|
||||
* {@link BeanDefinitionBuilder#addConstructorArgValue(Object)},
|
||||
* {@link BeanDefinitionBuilder#addPropertyReference(String, String)}, and
|
||||
* {@link BeanDefinitionBuilder#addPropertyValue(String, Object)}.
|
||||
* <p/>
|
||||
* Easy and succinct to create if methods {@link #ref(CharSequence)} or {@link #val(Object)} are used and imported
|
||||
* statically.
|
||||
*
|
||||
* @see BeanDefinitionBuilderArgument#ref(CharSequence)
|
||||
* @see BeanDefinitionBuilderArgument#val(Object)
|
||||
*/
|
||||
public class BeanDefinitionBuilderArgument {
|
||||
|
||||
/**
|
||||
* Returns a {@link BeanDefinitionBuilderArgument} with {@link #reference} equal to {@code true}. Convenient if
|
||||
* imported statically.
|
||||
*
|
||||
* @param value The name of the bean reference.
|
||||
*/
|
||||
public static BeanDefinitionBuilderArgument ref(CharSequence value) {
|
||||
return new BeanDefinitionBuilderArgument(true, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link BeanDefinitionBuilderArgument} with {@link #reference} equal to {@code false}. Convenient if
|
||||
* imported statically.
|
||||
*
|
||||
* @param value The constructor argument's value.
|
||||
*/
|
||||
public static BeanDefinitionBuilderArgument val(Object value) {
|
||||
return new BeanDefinitionBuilderArgument(false, value);
|
||||
}
|
||||
|
||||
protected boolean reference;
|
||||
protected Object value;
|
||||
|
||||
protected BeanDefinitionBuilderArgument(boolean reference, Object value) {
|
||||
this.reference = reference;
|
||||
if (this.reference && (value == null || !(value instanceof CharSequence))) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("reference argument must have value of type CharSequence, not [%s]",
|
||||
value == null ? "null" : value.getClass().getName()));
|
||||
}
|
||||
if (!StringUtils.hasText((CharSequence) value)) {
|
||||
throw new IllegalArgumentException("given CharSequence has no text");
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean isReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import org.w3c.dom.Element;
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class CassandraClusterParser extends CassandraCqlClusterParser {
|
||||
class CassandraClusterParser extends CassandraCqlClusterParser {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.config.xml.CassandraCqlClusterParser#parseInternal(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
|
||||
|
||||
@@ -45,7 +45,7 @@ import com.datastax.driver.core.SocketOptions;
|
||||
* @author John Blum
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
|
||||
class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#resolveId(org.w3c.dom.Element, org.springframework.beans.factory.support.AbstractBeanDefinition, org.springframework.beans.factory.xml.ParserContext)
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.w3c.dom.NamedNodeMap;
|
||||
* @author David Webb
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class CassandraCqlSessionParser extends AbstractSingleBeanDefinitionParser {
|
||||
class CassandraCqlSessionParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#getBeanClass(org.w3c.dom.Element)
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.w3c.dom.Element;
|
||||
* @author David Webb
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class CassandraCqlTemplateParser extends AbstractSingleBeanDefinitionParser {
|
||||
class CassandraCqlTemplateParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#getBeanClass(org.w3c.dom.Element)
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.w3c.dom.Element;
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class CassandraMappingContextParser extends AbstractSingleBeanDefinitionParser {
|
||||
class CassandraMappingContextParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#getBeanClass(org.w3c.dom.Element)
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.w3c.dom.Element;
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class CassandraMappingConverterParser extends AbstractSingleBeanDefinitionParser {
|
||||
class CassandraMappingConverterParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#getBeanClass(org.w3c.dom.Element)
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.w3c.dom.Element;
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class CassandraMappingXmlBeanFactoryPostProcessorRegistrar {
|
||||
class CassandraMappingXmlBeanFactoryPostProcessorRegistrar {
|
||||
|
||||
/**
|
||||
* Ensures that a {@link CassandraMappingBeanFactoryPostProcessor} is registered. This method is a no-op if one is
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
package org.springframework.data.cassandra.config;
|
||||
|
||||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
import org.springframework.data.cassandra.repository.config.CassandraRepositoryConfigurationExtension;
|
||||
import org.springframework.data.repository.config.RepositoryBeanDefinitionParser;
|
||||
|
||||
/**
|
||||
* Namespace handler for spring-data-cassandra.
|
||||
@@ -25,10 +23,12 @@ import org.springframework.data.repository.config.RepositoryBeanDefinitionParser
|
||||
* @author Alex Shvid
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class CassandraNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.xml.NamespaceHandler#init()
|
||||
*/
|
||||
@Override
|
||||
@@ -39,7 +39,5 @@ public class CassandraNamespaceHandler extends NamespaceHandlerSupport {
|
||||
registerBeanDefinitionParser("template", new CassandraTemplateParser());
|
||||
registerBeanDefinitionParser("converter", new CassandraMappingConverterParser());
|
||||
registerBeanDefinitionParser("mapping", new CassandraMappingContextParser());
|
||||
registerBeanDefinitionParser("repositories",
|
||||
new RepositoryBeanDefinitionParser(new CassandraRepositoryConfigurationExtension()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.w3c.dom.Element;
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class CassandraSessionParser extends CassandraCqlSessionParser {
|
||||
class CassandraSessionParser extends CassandraCqlSessionParser {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.config.xml.CassandraCqlSessionParser#getBeanClass(org.w3c.dom.Element)
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.w3c.dom.Element;
|
||||
* @author Mark Paluch
|
||||
* @author Mateusz Szymczak
|
||||
*/
|
||||
public class CassandraTemplateParser extends AbstractSingleBeanDefinitionParser {
|
||||
class CassandraTemplateParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.config.xml.CassandraCqlTemplateParser#getBeanClass(org.w3c.dom.Element)
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.w3c.dom.Element;
|
||||
* @see org.w3c.dom.Attr
|
||||
* @see org.w3c.dom.Element
|
||||
*/
|
||||
public abstract class ParsingUtils {
|
||||
abstract class ParsingUtils {
|
||||
|
||||
/**
|
||||
* Convenience method delegating to
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.w3c.dom.Element;
|
||||
* @author Christoph Strobl
|
||||
* @author Mateusz Szymczak
|
||||
*/
|
||||
public class CassandraRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport {
|
||||
class CassandraRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport {
|
||||
|
||||
private static final String CASSANDRA_TEMPLATE_REF = "cassandra-template-ref";
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2017 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.springframework.data.cassandra.repository.config;
|
||||
|
||||
import org.springframework.data.cassandra.config.CassandraNamespaceHandler;
|
||||
import org.springframework.data.cassandra.repository.config.CassandraRepositoryConfigurationExtension;
|
||||
import org.springframework.data.repository.config.RepositoryBeanDefinitionParser;
|
||||
|
||||
/**
|
||||
* Namespace handler for spring-data-cassandra.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
class CassandraRepositoryNamespaceHandler extends CassandraNamespaceHandler {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.xml.NamespaceHandler#init()
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
super.init();
|
||||
|
||||
registerBeanDefinitionParser("repositories",
|
||||
new RepositoryBeanDefinitionParser(new CassandraRepositoryConfigurationExtension()));
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
http\://www.springframework.org/schema/cql=org.springframework.data.cassandra.config.CqlNamespaceHandler
|
||||
http\://www.springframework.org/schema/data/cassandra=org.springframework.data.cassandra.config.CassandraNamespaceHandler
|
||||
http\://www.springframework.org/schema/data/cassandra=org.springframework.data.cassandra.repository.config.CassandraRepositoryNamespaceHandler
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
http\://www.springframework.org/schema/cql/spring-cql-1.0.xsd=org/springframework/data/cql/config/spring-cql-1.0.xsd
|
||||
http\://www.springframework.org/schema/cql/spring-cql-1.5.xsd=org/springframework/data/cql/config/spring-cql-1.5.xsd
|
||||
http\://www.springframework.org/schema/cql/spring-cql-2.0.xsd=org/springframework/data/cql/config/spring-cql-2.0.xsd
|
||||
http\://www.springframework.org/schema/cql/spring-cql.xsd=org/springframework/data/cql/config/spring-cql-2.0.xsd
|
||||
http\://www.springframework.org/schema/cql/spring-cql-1.0.xsd=org/springframework/data/cassandra/config/spring-cql-1.0.xsd
|
||||
http\://www.springframework.org/schema/cql/spring-cql-1.5.xsd=org/springframework/data/cassandra/config/spring-cql-1.5.xsd
|
||||
http\://www.springframework.org/schema/cql/spring-cql-2.0.xsd=org/springframework/data/cassandra/config/spring-cql-2.0.xsd
|
||||
http\://www.springframework.org/schema/cql/spring-cql.xsd=org/springframework/data/cassandra/config/spring-cql-2.0.xsd
|
||||
|
||||
http\://www.springframework.org/schema/data/cassandra/spring-cassandra-1.0.xsd=org/springframework/data/cassandra/config/spring-cassandra-1.0.xsd
|
||||
http\://www.springframework.org/schema/data/cassandra/spring-cassandra-1.5.xsd=org/springframework/data/cassandra/config/spring-cassandra-1.5.xsd
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Tooling related information for the cql namespace
|
||||
http\://www.springframework.org/schema/cql@name=Spring Cassandra CQL Namespace
|
||||
http\://www.springframework.org/schema/cql@prefix=cql
|
||||
http\://www.springframework.org/schema/cql@icon=org/springframework/data/cql/config/spring-cql.gif
|
||||
http\://www.springframework.org/schema/cql@icon=org/springframework/data/cassandra/config/spring-cql.gif
|
||||
|
||||
# Tooling related information for the cassandra namespace
|
||||
http\://www.springframework.org/schema/data/cassandra@name=Spring Data Cassandra Namespace
|
||||
|
||||
|
Before Width: | Height: | Size: 581 B After Width: | Height: | Size: 581 B |
@@ -5,8 +5,8 @@
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:cql="http://www.springframework.org/schema/cql"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/cassandra http://www.springframework.org/schema/data/cassandra/spring-cassandra.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/cql http://www.springframework.org/schema/cql/spring-cql.xsd">
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/cql http://www.springframework.org/schema/cql/spring-cql.xsd">
|
||||
|
||||
<bean id="nettyOptions" class="org.springframework.data.cassandra.support.IntegrationTestNettyOptions"/>
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:cass="http://www.springframework.org/schema/data/cassandra"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/cassandra http://www.springframework.org/schema/data/cassandra/spring-cassandra-1.0.xsd
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/cassandra http://www.springframework.org/schema/data/cassandra/spring-cassandra.xsd
|
||||
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<cass:cluster/>
|
||||
<bean id="mockSession1" class="org.springframework.data.cassandra.config.CassandraMappingBeanFactoryPostProcessorUnitTests.MockSessionFactory"/>
|
||||
|
||||
Reference in New Issue
Block a user