Skip to content

Commit

Permalink
added support for retrieving all constraint descriptions at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen van Schagen committed Apr 17, 2015
1 parent 3abf3ca commit 2fe0440
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
Expand Up @@ -20,10 +20,29 @@
*/
public class BeanConstraintDescriptor {

/**
* Enhances the property descriptions.
*/
private final List<PropertyConstraintEnhancer> enhancers = new ArrayList<PropertyConstraintEnhancer>();

/**
* Registry of all supported beans.
*/
private BeanRegistry beanRegistry = new MapBeanRegistry();

/**
* Generate all beans constraint meta data.
*
* @return the beans constraint meta data
*/
public List<BeanConstraintDescription> describeAll() {
List<BeanConstraintDescription> descriptions = new ArrayList<BeanConstraintDescription>();
for (Class<?> beanClass : beanRegistry.getAll()) {
descriptions.add(describeBean(beanClass));
}
return descriptions;
}

/**
* Generate bean constraint meta data.
*
Expand Down
Expand Up @@ -3,6 +3,8 @@
*/
package org.jarbframework.constraint.metadata;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -24,6 +26,12 @@ public class BeanConstraintDescriptorController {
public BeanConstraintDescriptorController(BeanConstraintDescriptor beanConstraintDescriptor) {
this.beanConstraintDescriptor = beanConstraintDescriptor;
}

@ResponseBody
@RequestMapping(method = RequestMethod.GET)
public List<BeanConstraintDescription> describeAll() {
return beanConstraintDescriptor.describeAll();
}

@ResponseBody
@RequestMapping(value = "/{beanType}", method = RequestMethod.GET)
Expand Down
Expand Up @@ -3,6 +3,8 @@
*/
package org.jarbframework.utils.bean;

import java.util.Set;

/**
* Retrieves the bean class based on a type name.
*
Expand All @@ -19,4 +21,11 @@ public interface BeanRegistry {
*/
Class<?> getBeanClass(String beanType);

/**
* Retrieves all bean classes.
*
* @return the bean classes
*/
Set<Class<?>> getAll();

}
Expand Up @@ -4,7 +4,9 @@
package org.jarbframework.utils.bean;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
* Default implementation of bean registry.
Expand All @@ -16,6 +18,14 @@ public class MapBeanRegistry implements BeanRegistry {

private final Map<String, Class<?>> bindings = new HashMap<String, Class<?>>();

/**
* {@inheritDoc}
*/
@Override
public Set<Class<?>> getAll() {
return new HashSet<Class<?>>(bindings.values());
}

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit 2fe0440

Please sign in to comment.