code: public static final <T> T getContextAttribute(ServletContext ctx, String name, Class<T> cls, Set<GetOpts> opts, T defaultValue)
  	{
  		Object o;
  
  		if((o = ctx.getAttribute(name))==null)
  		{
  			if(opts.contains(GetOpts.THROW_ON_MISSING))
  				throw new IllegalStateException("ServletContext attribute " + name + " was expected to exist but it didn't");
  			if(opts.contains(GetOpts.LOG_ON_MISSING))
  				logger.warn("ServletContext attribute {} was expected to exist but it didn't", name);
  			return defaultValue;
  		}
  		if(!cls.isInstance(o))
  		{
  			if(opts.contains(GetOpts.THROW_ON_WRONG_TYPE))
  				throw new IllegalStateException("ServletContext attribute " + name + " was expected to be of type " + cls.getName() + " but it was of type " + o.getClass().getName());
  			if(opts.contains(GetOpts.LOG_ON_WRONG_TYPE) && logger.isWarnEnabled())
  				logger.warn("ServletContext attribute " + name + " was expected to be of type " + cls.getName() + " but it was of type " + o.getClass().getName());
  			return defaultValue;
  		}
  		return cls.cast(o);
  	}
docs: Get a servlet context attribute. If there is no such attribute, an {@link IllegalStateException} is thrown with notFoundError as the message. Similarly if the attribute is not of type cls then a {@link IllegalStateException} is thrown with an error message of wrongTypeError and the actual class name appended.
  @param ctx Context to retrieve the attribute from
  @param name Attribute name to retrieve
  @param cls Expected type
  @param opts set of options defining how to handle conditions
  @param defaultValue the default value if opts allow
  @return The attribute value