package com.msg.xt.jee.cdi.jira_weld_1131;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;

public class CustomerInject {
	@Inject
	@Named("selected")
	Customer injectField = new Customer("Peter", "Huber", 40);

	@PostConstruct
	void init() {

		try {
			//
			// VERSION which does NOT work
			//
			final BeanInfo bi = Introspector
					.getBeanInfo(injectField.getClass());
			//
			// VERSION which DOES work
			//
			/*
			 * final BeanInfo bi =
			 * Introspector.getBeanInfo(injectField.getClass()
			 * .getSuperclass());
			 */

			final PropertyDescriptor[] pd = bi.getPropertyDescriptors();
			for (int i = 0; i < pd.length; i++) {
				System.out.println("####### " + pd[i]);
				final Method m = pd[i].getReadMethod();
				if (null != m) {
					final PredicateDef predDef = m
							.getAnnotation(PredicateDef.class);
					if (null != predDef) {
						// WE WANT to see this output here
						System.out.println("++++++ " + predDef);
					}
				}
			}
		} catch (IntrospectionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
