Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.
  */
 package org.springframework.hateoas.core;
 
 import java.util.Set;
 
org.springframework.beans.factory.FactoryBean implementation to create ControllerEntityLinks instances looking up controller classes from an org.springframework.context.ApplicationContext. The controller types are identified by the annotation type configured.

Author(s):
Oliver Gierke
 
 
 	private Class<? extends Annotationannotation;
Configures the annotation type to inspect the org.springframework.context.ApplicationContext for beans that carry the given annotation.

Parameters:
annotation must not be null.
 
 	public void setAnnotation(Class<? extends Annotationannotation) {
 		Assert.notNull(annotation);
 		this. = annotation;
 	}

Configures the org.springframework.hateoas.LinkBuilderFactory to be used to create org.springframework.hateoas.LinkBuilder instances.

Parameters:
linkBuilderFactory the linkBuilderFactory to set
 
 	public void setLinkBuilderFactory(LinkBuilderFactory<? extends LinkBuilderlinkBuilderFactory) {
 		this. = linkBuilderFactory;
 	}
 
 	/* 
 	 * (non-Javadoc)
 	 * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
 	 */
 	public void setApplicationContext(ApplicationContext context) {
 		this. = context;
 	}
 
 	/* 
 	 * (non-Javadoc)
 	 * @see org.springframework.beans.factory.config.AbstractFactoryBean#getObjectType()
 	 */
 	public Class<?> getObjectType() {
 		return ControllerEntityLinks.class;
 	}
 
 	/* 
 	 * (non-Javadoc)
 	 * @see org.springframework.beans.factory.config.AbstractFactoryBean#createInstance()
 	 */
 	protected ControllerEntityLinks createInstance() throws Exception {
 
 		Collection<Class<?>> controllerTypes = new HashSet<Class<?>>();
 
 		for (Class<?> controllerType : getBeanTypesWithAnnotation()) {
 			if (AnnotationUtils.findAnnotation(controllerTypeExposesResourceFor.class) != null) {
 				controllerTypes.add(controllerType);
 			}
 		}
 
 		return new ControllerEntityLinks(controllerTypes);
 	}
	/* 
	 * (non-Javadoc)
	 * @see org.springframework.beans.factory.config.AbstractFactoryBean#afterPropertiesSet()
	 */
	public void afterPropertiesSet() throws Exception {
		Assert.state( != null"Annotation type must be configured!");
		Assert.state( != null"LinkBuilderFactory must be configured!");
	}
	private Iterable<Class<?>> getBeanTypesWithAnnotation(Class<? extends Annotationtype) {
		Set<Class<?>> annotatedTypes = new HashSet<Class<?>>();
		for (String beanName : .getBeanDefinitionNames()) {
			Annotation annotation = .findAnnotationOnBean(beanNametype);
			if (annotation != null) {
				annotatedTypes.add(.getType(beanName));
			}
		}
		return annotatedTypes;
	}
New to GrepCode? Check out our FAQ X