Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package play.modules.hazelcast;
 
 import java.util.List;
 
 
import play.Play;
public class NamedInjector {
    
For now, inject beans in controllers
    public static void inject(NamedBeanSource source) {
        List<Classclasses = ..getAssignableClasses(ControllerSupport.class);
        classes.addAll(..getAssignableClasses(Mailer.class));
        classes.addAll(..getAssignableClasses(Job.class));
        for(Class<?> clazz : classes) {
            for(Field field : clazz.getDeclaredFields()) {
                if(Modifier.isStatic(field.getModifiers()) && field.isAnnotationPresent(Named.class)) {
                    Class<?> type = field.getType();
                    field.setAccessible(true);
                    try {
                    	Named named = field.getAnnotation(Named.class);
                    	if(named.value() != null || named.value().trim().length() > 0){
                    		Object o = source.getBeanOfType(typenamed.value());
                    		if(o != null){
                                field.set(nullo);
                    		}
                    	}
                    } catch(RuntimeException e) {
                        throw e;
                    } catch(Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X