Copied from Tomcat 7 StandardContext

@param namingResources
@return injectionMap
426353
private Map<String, Map<String, String>> buildInjectionMap(NamingResources namingResources) {
        Map<String, Map<String, String>> injectionMap = new HashMap<String, Map<String, String>>();
        for (Injectable resource: namingResources.findLocalEjbs()) {
            addInjectionTarget(resource, injectionMap);
        }
        for (Injectable resource: namingResources.findEjbs()) {
            addInjectionTarget(resource, injectionMap);
        }
        for (Injectable resource: namingResources.findEnvironments()) {
            addInjectionTarget(resource, injectionMap);
        }
        for (Injectable resource: namingResources.findMessageDestinationRefs()) {
            addInjectionTarget(resource, injectionMap);
        }
        for (Injectable resource: namingResources.findResourceEnvRefs()) {
            addInjectionTarget(resource, injectionMap);
        }
        for (Injectable resource: namingResources.findResources()) {
            addInjectionTarget(resource, injectionMap);
        }
        for (Injectable resource: namingResources.findServices()) {
            addInjectionTarget(resource, injectionMap);
        }
        return injectionMap;
    }
1060836
@Override
    public T addAsWebResource(String resourceName, String target) throws IllegalArgumentException {
        Validate.notNull(resourceName, "ResourceName should be specified");
        Validate.notNull(target, "Target should be specified");

        return addAsWebResource(new ClassLoaderAsset(resourceName), target);
    }
124216
protected void configureContext(Context context,
			ServletContextInitializer[] initializers) {
		TomcatStarter starter = new TomcatStarter(initializers);
		if (context instanceof TomcatEmbeddedContext) {
			TomcatEmbeddedContext embeddedContext = (TomcatEmbeddedContext) context;
			embeddedContext.setStarter(starter);
			embeddedContext.setFailCtxIfServletStartFails(true);
		}
		context.addServletContainerInitializer(starter, NO_CLASSES);
		for (LifecycleListener lifecycleListener : this.contextLifecycleListeners) {
			context.addLifecycleListener(lifecycleListener);
		}
		for (Valve valve : this.contextValves) {
			context.getPipeline().addValve(valve);
		}
		for (ErrorPage errorPage : getErrorPages()) {
			new TomcatErrorPage(errorPage).addToContext(context);
		}
		for (MimeMappings.Mapping mapping : getMimeMappings()) {
			context.addMimeMapping(mapping.getExtension(), mapping.getMimeType());
		}
		configureSession(context);
		new DisableReferenceClearingContextCustomizer().customize(context);
		for (TomcatContextCustomizer customizer : this.tomcatContextCustomizers) {
			customizer.customize(context);
		}
	}
1212637
static JndiContext createJndiContext() throws NamingException
    {
        try
        {
            if (!NamingManager.hasInitialContextFactoryBuilder())
            {
                JndiContext ctx = new JndiContext();
                NamingManager.setInitialContextFactoryBuilder(ctx);
                return ctx;
            }
            else
            {
                return (JndiContext) NamingManager.getInitialContext(null);
            }
        }
        catch (Exception e)
        {
            jqmlogger.error("Could not create JNDI context: " + e.getMessage());
            NamingException ex = new NamingException("Could not initialize JNDI Context");
            ex.setRootCause(e);
            throw ex;
        }
    }
1192052
@Override
    public T addAsWebResources(Package resourcePackage, String... resourceNames) throws IllegalArgumentException {
        Validate.notNull(resourcePackage, "ResourcePackage must be specified");
        Validate.notNullAndNoNullValues(resourceNames,
            "ResourceNames must be specified and can not container null values");
        for (final String resourceName : resourceNames) {
            addAsWebResource(resourcePackage, resourceName);
        }
        return covarientReturn();
    }
634064
@Override
  public <CS, CD> MappingContext<CS, CD> create(CS source, Class<CD> destinationType) {
    Assert.notNull(source, "source");
    Assert.notNull(destinationType, "destinationType");

    return new MappingContextImpl<CS, CD>(this, source, Types.<CS>deProxy(source.getClass()), null,
        destinationType, null, null, false);
  }
680474
@Override
    public InjectionBinding<AdministeredObjectDefinition> createInjectionBinding(AdministeredObjectDefinition annotation, Class<?> instanceClass, Member member, String jndiName) throws InjectionException {
        InjectionBinding<AdministeredObjectDefinition> injectionBinding =
                        new AdministeredObjectDefinitionInjectionBinding(jndiName, ivNameSpaceConfig);
        injectionBinding.merge(annotation, instanceClass, null);
        return injectionBinding;
    }
1076891
public static UrlMappingsHolder lookupUrlMappings(ServletContext servletContext) {
        WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        return (UrlMappingsHolder)wac.getBean(UrlMappingsHolder.BEAN_ID);
    }
660960
public void xmlns(Map<String, String> definition) {
        Assert.notNull(namespaceHandlerResolver, "You cannot define a Spring namespace without a [namespaceHandlerResolver] set");
        if (definition.isEmpty()) {
            return;
        }

        for (Map.Entry<String, String> entry : definition.entrySet()) {
            String namespace = entry.getKey();
            String uri = entry.getValue() == null ? null : entry.getValue();

            Assert.notNull(uri, "Namespace definition cannot supply a null URI");

            final NamespaceHandler namespaceHandler = namespaceHandlerResolver.resolve(uri);
            if (namespaceHandler == null) {
                throw new BeanDefinitionParsingException(
                      new Problem("No namespace handler found for URI: " + uri,
                            new Location(readerContext.getResource())));
            }
            namespaceHandlers.put(namespace, namespaceHandler);
            namespaces.put(namespace, uri);
        }
    }
865064
@Override
  public StringMap injectContextData(@Nullable List<Property> properties, StringMap reusable) {
    return ContextDataUtils.injectContextData(properties, reusable);
  }
86341
public static NamespaceContext createNamespaceContext() {
    return new NamespaceContext() {
      private HashMap<String, String> namespaces = new HashMap<String, String>(1);

      {
        namespaces.put(DEFAULT_NAMESPACE_PREFIX, DEFAULT_NAMESPACE_URI);
      }

      public String getNamespaceURI(String prefix) {
        if (namespaces.isEmpty() || StringUtil.isNullOrEmpty(prefix) || !namespaces.containsKey(prefix))
          return StringUtil.empty;
        return namespaces.get(prefix);
      }

      public Iterator getPrefixes(String namespaceURI) {
        return namespaces.values().iterator();
      }

      public String getPrefix(String namespaceURI) {
        if (StringUtil.isNullOrEmpty(namespaceURI))
          return StringUtil.empty;

        for(Entry<String, String> entry : namespaces.entrySet())
          if (namespaceURI.equals(entry.getValue()))
            return entry.getKey();

        return StringUtil.empty;
      }
    };
  }
1121397
public JNDIContentRepositoryBuilder withContextProperty(final String name, final Object value) {

        contextProperties.put(name, value);
        return this;
    }
1100141
private void createContextPool(Integer poolSize, String providerURL) throws NamingException {
        final String METHODNAME = "createContextPool";

        /*
         * Validate provider URL
         */
        if (providerURL == null) {
            providerURL = getPrimaryURL();
        }

        /*
         * Default the pool size if one was not provided.
         */
        if (poolSize == null) {
            poolSize = DEFAULT_INIT_POOL_SIZE;
        }

        /*
         * Enable the context pool
         */
        if (iContextPoolEnabled) {
            long currentTimeMillisec = System.currentTimeMillis();
            long currentTimeSeconds = roundToSeconds(currentTimeMillisec);

            // Don't purge the pool more than once per second
            // This prevents multiple threads from purging the pool
            if (currentTimeMillisec - iPoolCreateTimestampMillisec > 1000) {
                List<TimedDirContext> contexts = new Vector<TimedDirContext>(poolSize);
                Hashtable<String, Object> env = getEnvironment(URLTYPE_SEQUENCE, providerURL);

                String currentURL = null;
                try {
                    for (int i = 0; i < poolSize; i++) {
                        TimedDirContext ctx = createDirContext(env, currentTimeSeconds);
                        currentURL = getProviderURL(ctx);
                        if (!providerURL.equalsIgnoreCase(currentURL)) {
                            env = getEnvironment(URLTYPE_SEQUENCE, currentURL);
                            providerURL = currentURL;
                        }
                        contexts.add(ctx);
                        //iLiveContexts++;
                    }
                } catch (NamingException e) {
                    if (tc.isDebugEnabled()) {
                        Tr.debug(tc, METHODNAME + " Context Pool creation FAILED for " + Thread.currentThread() + ", iLiveContext=" + iLiveContexts, e);
                    }
                    if (tc.isDebugEnabled()) {
                        Tr.debug(tc, METHODNAME + " Cleanup contexts in temp pool: " + contexts.size());
                    }
                    for (int j = 0; j < contexts.size(); j++) {
                        try {
                            TimedDirContext ctx = contexts.get(j);
                            ctx.close();
                        } catch (Exception ee) {
                        }
                    }
                    throw e;
                }
                iLiveContexts += poolSize;

                // set active URL
                setActiveURL(providerURL);

                List<TimedDirContext> oldCtxs = iContexts;
                iContexts = contexts;
                iPoolCreateTimestampSeconds = currentTimeSeconds;
                iPoolCreateTimestampMillisec = currentTimeMillisec;
                closeContextPool(oldCtxs);

                if (tc.isDebugEnabled()) {
                    Tr.debug(tc, METHODNAME + " Active Provider URL: " + getActiveURL());
                    Tr.debug(tc, METHODNAME + " ContextPool: total=" + iLiveContexts + ", poolSize=" + iContexts.size(),
                             ", iPoolCreateTimestampSeconds=" + iPoolCreateTimestampSeconds);
                }
            } else if (tc.isDebugEnabled()) {
                Tr.debug(tc, METHODNAME + " Pool has already been purged within past second... skipping purge");
            }
        } else {
            setActiveURL(providerURL);
        }
    }
342442
@Override
	public NamingEnumeration<Binding> listBindings(Name name) throws NamingException
    {
        if (name.isEmpty())
            return new ListOfBindings(bindings.keys());

        Object target = lookup(name);
        if (target instanceof Context)
        {
            try
            {
                return ((Context)target).listBindings("");
            }
            finally
            {
                ((Context)target).close();
            }
        }
        throw new NotContextException(name + " cannot be listed");
    }
569767
public static <T> void injectEEFields(Iterable<Set<ResourceInjection<?>>> resourceInjectionsHierarchy,
            T beanInstance, CreationalContext<T> ctx) {
        for (Set<ResourceInjection<?>> resourceInjections : resourceInjectionsHierarchy) {
            for (ResourceInjection<?> resourceInjection : resourceInjections) {
                resourceInjection.injectResourceReference(beanInstance, ctx);
            }
        }
    }
570146
@SuppressWarnings({ "rawtypes", "unchecked" })
   protected DirContext setupKerberosContext(Hashtable<String,Object> env) 
   throws NamingException
   {

      LoginContext lc = null;
      try
      {

    	 lc = new LoginContext(getClass().getName(), new JXCallbackHandler());
         lc.login();

      }
      catch (LoginException ex)
      {
         throw new NamingException("login problem: " + ex);
      }

      DirContext ctx = (DirContext) Subject.doAs(lc.getSubject(), new JndiAction(env));

      if (ctx == null)
         throw new NamingException("another problem with GSSAPI");
      else
         return ctx;
    
   }
764983
@Override
    public Enumeration<URL> getResources(String name) throws IOException {
        if (this.rootClassLoader == null) {
            return findResources(name);
        }
        return new ResourceEnumeration(this.rootClassLoader.getResources(name),
                findResources(name));
    }