package de.taimos.springcxfdaemon;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.restdoc.cxf.provider.IClassesProvider;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class ServiceAnnotationClassesProvider implements IClassesProvider {
	
	private Class<? extends Annotation> serviceAnnotation;
	
	private ListableBeanFactory beanFactory;
	
	
	public ListableBeanFactory getBeanFactory() {
		return this.beanFactory;
	}
	
	@Autowired
	public void setBeanFactory(ListableBeanFactory beanFactory) {
		this.beanFactory = beanFactory;
	}
	
	public Class<? extends Annotation> getServiceAnnotation() {
		return this.serviceAnnotation;
	}
	
	public void setServiceAnnotation(Class<? extends Annotation> serviceAnnotation) {
		this.serviceAnnotation = serviceAnnotation;
	}
	
	@Override
	public Class<?>[] getClasses() {
		Map<String, Object> beansWithAnnotation = this.beanFactory.getBeansWithAnnotation(this.serviceAnnotation);
		List<Class<?>> classes = new ArrayList<>();
		for (Object bean : beansWithAnnotation.values()) {
			classes.add(bean.getClass());
			classes.addAll(Arrays.asList(bean.getClass().getInterfaces()));
		}
		return classes.toArray(new Class[0]);
	}
}

@@ -477,24 +477,36 @@
 otation;%0A%09%0A%09
+@Autowired%0A%09
 private List
@@ -524,200 +524,8 @@
 tory
- beanFactory;%0A%09%0A%09%0A%09public ListableBeanFactory getBeanFactory() %7B%0A%09%09return this.beanFactory;%0A%09%7D%0A%09%0A%09@Autowired%0A%09public void setBeanFactory(ListableBeanFactory beanFactory) %7B%0A%09%09this.beanFactory =
  bea
@@ -535,17 +535,16 @@
 ctory;%0A%09
-%7D
 %0A%09%0A%09publ

clean up