package com.outbrain.ob1k.server.spring;

import org.springframework.context.support.AbstractApplicationContext;

import java.util.Map;

/**
 * User: aronen
 * Date: 6/25/13
 * Time: 6:50 PM
 */
public class SpringBeanContext {
  private final Map<String, AbstractApplicationContext> contexts;

  public SpringBeanContext(final Map<String, AbstractApplicationContext> contexts) {
    this.contexts = contexts;
  }

  public <T> T getBean(final String ctxName, final Class<T> type) {
    return contexts.get(ctxName).getBean(type);
  }

  public <T> T getBean(final String ctxName, final String id, final Class<T> type) {
    return contexts.get(ctxName).getBean(id, type);
  }

  public boolean contextExists(final String ctxName) {
    return contexts.containsKey(ctxName);
  }
}

@@ -484,174 +484,524 @@
     
-return contexts.get(ctxName).getBean(type);%0A  %7D%0A%0A  public %3CT%3E T getBean(final String ctxName, final String id, final Class%3CT%3E type) %7B%0A    return contexts.get(ctxName)
+final AbstractApplicationContext context = contexts.get(ctxName);%0A    if (context == null) %7B%0A      throw new NullPointerException(%22Context not found for name '%22 + ctxName + %22'%22);%0A    %7D%0A    return context.getBean(type);%0A  %7D%0A%0A  public %3CT%3E T getBean(final String ctxName, final String id, final Class%3CT%3E type) %7B%0A    final AbstractApplicationContext context = contexts.get(ctxName);%0A    if (context == null) %7B%0A      throw new NullPointerException(%22Context not found for name '%22 + ctxName + %22'%22);%0A    %7D%0A    return context
 .get

make NPE little bit more clear