/*
 * Copyright 2015 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.cloud.stream.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.binding.BindingBeanDefinitionRegistryUtils;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.ClassUtils;
import org.springframework.util.MultiValueMap;

/**
 * @author Marius Bogoevici
 * @author Dave Syer
 */

public class BindingBeansRegistrar implements ImportBeanDefinitionRegistrar {

	@Override
	public void registerBeanDefinitions(AnnotationMetadata metadata,
			BeanDefinitionRegistry registry) {
		MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(EnableBinding.class.getName(),
				false);
		for (Class<?> type : collectClasses(attributes.get("value"))) {
			BindingBeanDefinitionRegistryUtils.registerChannelBeanDefinitions(type, type.getName(), registry);
			BindingBeanDefinitionRegistryUtils.registerChannelsQualifiedBeanDefinitions(
					ClassUtils.resolveClassName(metadata.getClassName(), null), type,
					registry);
		}
	}

	private List<Class<?>> collectClasses(List<Object> list) {
		ArrayList<Class<?>> result = new ArrayList<Class<?>>();
		for (Object object : list) {
			for (Object value : (Object[]) object) {
				if (value instanceof Class && void.class != value) {
					result.add((Class<?>) value);
				}
			}
		}
		return result;
	}

}

@@ -1012,16 +1012,147 @@
 istrar;%0A
+import org.springframework.core.annotation.AnnotatedElementUtils;%0Aimport org.springframework.core.annotation.AnnotationAttributes;%0A
 import o
@@ -1247,55 +1247,8 @@
 ils;
-%0Aimport org.springframework.util.MultiValueMap;
 %0A%0A/*
@@ -1503,127 +1503,177 @@
 %7B%0A%09%09
-MultiValueMap%3CString, Object%3E attributes = metadata.getAllAnnotationAttributes(EnableBinding.class.getName(),%0A%09%09%09%09false
+AnnotationAttributes attrs = AnnotatedElementUtils.getMergedAnnotationAttributes(%0A%09%09%09%09ClassUtils.resolveClassName(metadata.getClassName(), null),%0A%09%09%09%09EnableBinding.class
 );%0A%09
@@ -1713,21 +1713,16 @@
 ses(attr
-ibute
 s.get(%22v
@@ -1806,17 +1806,22 @@
 ns(type,
- 
+%0A%09%09%09%09%09
 type.get
@@ -2057,24 +2057,20 @@
 ses(
-List%3C
 Object
-%3E lis
+ objec
 t) %7B
@@ -2132,40 +2132,8 @@
 ();%0A
-%09%09for (Object object : list) %7B%0A%09
 %09%09fo
@@ -2171,17 +2171,16 @@
 ject) %7B%0A
-%09
 %09%09%09if (v
@@ -2227,17 +2227,16 @@
 alue) %7B%0A
-%09
 %09%09%09%09resu
@@ -2265,14 +2265,8 @@
 e);%0A
-%09%09%09%09%7D%0A
 %09%09%09%7D

Use AnnotatedElementUtils to extend the reach of BindingBeansRegistrar