/**
* Copyright 2011 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.neo4j.config;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.data.neo4j.repository.GraphRepositoryFactoryBean;
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport;
import org.springframework.data.repository.config.XmlRepositoryConfigurationSource;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* Neo4j specific extension for the repository namespace and annotation parsing.
*
* @author Oliver Gierke
* @author Michael Hunger
*/
public class Neo4jRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport {
static final String NEO4J_TEMPLATE_REF = "neo4j-template-ref";
static final String DEFAULT_NEO4J_TEMPLATE_REF = "neo4jTemplate";
static final String DEFAULT_NEO4J_MAPPING_CONTEXT_REF = "neo4jMappingContext";
static final String ANN_NEO4J_TEMPLATE_REF = "neo4jTemplateRef";
/*
* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationExtension#getRepositoryFactoryClassName()
*/
@Override
public String getRepositoryFactoryClassName() {
return GraphRepositoryFactoryBean.class.getName();
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getModulePrefix()
*/
@Override
protected String getModulePrefix() {
return "neo4j";
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource)
*/
@Override
public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) {
AnnotationAttributes attributes = config.getAttributes();
builder.addPropertyReference("neo4jTemplate", attributes.getString(ANN_NEO4J_TEMPLATE_REF));
builder.addPropertyReference("neo4jMappingContext", DEFAULT_NEO4J_MAPPING_CONTEXT_REF);
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.data.repository.config.XmlRepositoryConfigurationSource)
*/
@Override
public void postProcess(BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config) {
Element element = config.getElement();
String templateRef = element.getAttribute(NEO4J_TEMPLATE_REF);
templateRef = StringUtils.hasText(templateRef) ? templateRef : DEFAULT_NEO4J_TEMPLATE_REF;
builder.addPropertyReference("neo4jTemplate", templateRef);
builder.addPropertyReference("neo4jMappingContext", DEFAULT_NEO4J_MAPPING_CONTEXT_REF);
}
}