Determines the injection target {@link Resource} by its lookup name

@param lookup
the lookup name for the resoure
@return this {@link ResourceInjection}
428770
public ResourceInjection byLookup(final String lookup) {

        final ResourceLiteral resource = new ResourceLiteral();
        resource.setLookup(lookup);
        matchingResources.add(resource);
        return this;
    }
279134
@Override
    public ICodeBaseEntry lookupResource(String resourceName) {
        // Translate resource name, in case a resource name
        // has been overridden and the resource is being accessed
        // using the overridden name.
        resourceName = translateResourceName(resourceName);

        File file = getFullPathOfResource(resourceName);
        if (!file.exists()) {
            return null;
        }
        return new DirectoryCodeBaseEntry(this, resourceName);
    }
1327194
private static ControllerRegistry build(ControllerLookup lookup) {
        List<BaseController> controllers = new LinkedList<>();
        controllers.addAll(lookup.getControllers());
        return new ControllerRegistry(controllers);
    }
245107
public static <T> T lookup(String name) {
        InitialContext initialContext = initialContext();
        try {
            @SuppressWarnings("unchecked")
            T object = (T) initialContext.lookup(name);
            if (object == null) {
                throw new NameNotFoundException(name + " was found but is null");
            }
            return object;
        } catch (NameNotFoundException e) {
            throw new IllegalArgumentException(name + " was not found in JNDI", e);
        } catch (NamingException e) {
            throw new IllegalArgumentException("JNDI lookup failed", e);
        } finally {
            closeContext(initialContext);
        }
    }
827666
@Override
    public ICodeBaseEntry lookupResource(String resourceName) {
        if (!resourceName.equals(getResourceName())) {
            return null;
        }

        return new SingleFileCodeBaseEntry(this);
    }
1344721
public Iterable<ActionImport> build(FactoryLookup lookup) {
        List<ActionImport> actionImports = new ArrayList<>();
        for (ActionImportImpl.Builder actionImportBuilder : actionImportBuilders) {
            actionImportBuilder.setEntitySet(
                    lookup.getEntitySet(actionImportBuilder.getEntitySetName()));
            actionImportBuilder.setAction(
                    lookup.getAction(actionImportBuilder.getActionName()));
            actionImports.add(actionImportBuilder.build());
        }

        return Collections.unmodifiableList(actionImports);
    }
124026
public ResourceLookup getResourceLookup() {
        checkState(InitializedState.INITIALIZING, InitializedState.INITIALIZED);
        return new MultiResourceLookup(aggregatedModule.getResourceLookups());
    }
1047120
@Override
  public <T> Provider<T> provider(InjectionPoint<T> ip)
  {
    Objects.requireNonNull(ip);

    Provider<T> provider = lookupProvider(ip);

    if (provider != null) {
      return provider;
    }

    provider = autoProvider(ip);

    if (provider != null) {
      return provider;
    }

    return new ProviderNull(ip.key(), -10000, new InjectScopeSingleton());
  }
560046
public static void injectContextProxiesAndApplication(AbstractResourceInfo cri,
                                                          Object instance,
                                                          Application app,
                                                          ProviderFactory factory) {

        /** inject proxy for singleton only */
        if (!cri.isSingleton())
            return;

        /** application inject has been done earlier. @see LibertyJaxRsServerFactoryBean.injectContextApplication() */
        if (cri instanceof ApplicationInfo)
            return;

        JaxRsFactoryBeanCustomizer beanCustomizer = InjectionRuntimeContextHelper.findBeanCustomizer(instance.getClass(), cri.getBus());
        Boolean isManagedBean = beanCustomizer == null ? false : true;

        InjectionRuntimeContext irc = InjectionRuntimeContextHelper.getRuntimeContext();
        synchronized (instance) {
            for (Map.Entry<Class<?>, Method> entry : cri.getContextMethods().entrySet()) {
                Method method = entry.getValue();
                Object value = null;
                Class<?> cls = method.getParameterTypes()[0];
                if (cls == Application.class) {
                  value = app;
                } else if (VALUE_CONTEXTS.contains(cls.getName()) && factory != null) {
                    ContextProvider<?> p = factory.createContextProvider(cls, null);
                    if (p != null) {
                        value = p.createContext(null);
                    }
                } else {
                    value = cri.getContextSetterProxy(method);
                }

                if (isManagedBean)
                    irc.setRuntimeCtxObject(entry.getKey().getName(), value);
                else
                    InjectionUtils.injectThroughMethod(instance, method, value);
            }

            for (Field f : cri.getContextFields()) {
                Object value = null;
                Class<?> cls = f.getType();
                if (cls == Application.class) {
                    value = app;
                } else if (VALUE_CONTEXTS.contains(cls.getName()) && factory != null) {
                    ContextProvider<?> p = factory.createContextProvider(cls, null);
                    if (p != null) {
                        value = p.createContext(null);
                    }
                } else {
                    value = cri.getContextFieldProxy(f);
                }

                if (isManagedBean)
                    irc.setRuntimeCtxObject(f.getType().getName(), value);
                else
                    InjectionUtils.injectFieldValue(f, instance, value);
            }
        }

        Object o = null;
        //replace singleton resource after context injection is done.
        if (isManagedBean && (cri instanceof ClassResourceInfo)) {
            o = beanCustomizer.onSingletonServiceInit(instance,
                                                      InjectionRuntimeContextHelper.getBeanCustomizerContext(beanCustomizer, cri.getBus()));

            SingletonResourceProvider sp = new SingletonResourceProvider(o);
            ((ClassResourceInfo) cri).setResourceProvider(sp);
            instance = o;
        }

        if (!isManagedBean && (cri instanceof ClassResourceInfo))
        {
            //call postConstruct method for singleton resource which are non-CDI/EJB
            Method postConstructMethod = ResourceUtils.findPostConstructMethod(instance.getClass());
            InjectionUtils.invokeLifeCycleMethod(instance, postConstructMethod);
        }

    }
1136010
@Override
    public InjectionTarget[] getInjectionTargets(final Class<?> classToInjectInto) throws InjectionException {
        // This method attempts to cache the InjectTargets that are associated
        // with the specified class, so that if this method is invoked again and
        // the same class is specified, we can just grab the list from the Map
        // and not re-calculate it.
        //
        // EJB container should not need this caching, because it caches the list
        // of InjectionTargets in BeanMetaData and InterceptorMetaData.
        //
        // However, WebContainer will use this caching.  Under most circumstances,
        // they only inject into a class once...but I WebContainer team lead says
        // its possible to have multiple servlets share the same class, and in that
        // scenario they would be injecting into the same class multiple times,
        // and take advantage of the caching.

        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isDebugEnabled())
            Tr.entry(tc, "getInjectionTargets: " + classToInjectInto + ", " + this);

        InjectionTarget[] injectionTargetsForClass = ivInjectionTargetMap.get(classToInjectInto);
        if (injectionTargetsForClass == null) {
            synchronized (ivInjectionTargetMap) {
                injectionTargetsForClass = ivInjectionTargetMap.get(classToInjectInto);
                if (injectionTargetsForClass == null) {
                    // If targets were not found in cache from app start, then rebuilding them
                    // needs to run privileged, as this may run in the context of tha appliation
                    try {
                        injectionTargetsForClass = AccessController.doPrivileged(new PrivilegedExceptionAction<InjectionTarget[]>() {
                            @Override
                            public InjectionTarget[] run() throws Exception {
                                return ivInjectionEngine.getInjectionTargets(ivDeclaredInjectionTargets, classToInjectInto, ivCheckAppConfig);
                            }
                        });
                    } catch (PrivilegedActionException ex) {
                        Throwable cause = ex.getCause();
                        if (cause instanceof InjectionException) {
                            throw (InjectionException) cause;
                        }
                        if (cause instanceof RuntimeException) {
                            throw (RuntimeException) cause;
                        }
                        throw new InjectionException(cause);
                    }
                    if (ivInjectionTargetMap.size() <= svInjTarMapCacheSize || injectionTargetsForClass.length > 0) {
                        ivInjectionTargetMap.put(classToInjectInto, injectionTargetsForClass);
                    }
                }
            }
        }

        if (isTraceOn && tc.isDebugEnabled())
            Tr.exit(tc, "getInjectionTargets", Arrays.asList(injectionTargetsForClass));
        return injectionTargetsForClass;
    }
719978
private static String getResourceLookup(Resource resource) // F743-16274.1
    {
        if (svResourceLookupMethod == null)
        {
            return "";
        }

        try
        {
            return (String) svResourceLookupMethod.invoke(resource, (Object[]) null);
        } catch (Exception ex)
        {
            throw new IllegalStateException(ex);
        }
    }
217060
public static Resource getResource(String location) {
        Resource resource = resolver.getResource(location);
        return resource.exists() ? resource : null;
    }
610667
@CheckReturnValue
  public static Builder fromJndi(final Context context, final String lookupKey, Flavor flavor) {
    Options options = new OptionsDefault(flavor);

    return new BuilderImpl(null, () -> {
      DataSource ds;
      try {
        ds = (DataSource) context.lookup(lookupKey);
      } catch (Exception e) {
        throw new DatabaseException("Unable to locate the DataSource in JNDI using key " + lookupKey, e);
      }
      try {
        return ds.getConnection();
      } catch (Exception e) {
        throw new DatabaseException("Unable to obtain a connection from JNDI DataSource " + lookupKey, e);
      }
    }, options);
  }
1032584
private BasicInjectionTarget<T> prepareInjectionTarget(BasicInjectionTarget<T> injectionTarget) {
        try {
            postProcess(initialize(validate(injectionTarget)));
            return injectionTarget;
        } catch (Throwable e) {
            throw new IllegalArgumentException(e);
        }
    }
262424
public ResourceFactory findResourceFactory(String name, Type clazz) {
        Map<String, ResourceEntry> map = this.store.get(clazz);
        if (map != null && map.containsKey(name)) return this;
        if (parent != null) return parent.findResourceFactory(name, clazz);
        return null;
    }
560211
private void addInjectionTarget(Injectable resource, Map<String, Map<String, String>> injectionMap) {
        List<InjectionTarget> injectionTargets = resource.getInjectionTargets();
        if (injectionTargets != null && injectionTargets.size() > 0) {
            String jndiName = resource.getName();
            for (InjectionTarget injectionTarget: injectionTargets) {
                String clazz = injectionTarget.getTargetClass();
                Map<String, String> injections = injectionMap.get(clazz);
                if (injections == null) {
                    injections = new HashMap<String, String>();
                    injectionMap.put(clazz, injections);
                }
                injections.put(injectionTarget.getTargetName(), jndiName);
            }
        }
    }
66337
@Override
    public <T> CachedResource<T> getResource(
            Resource resource, Loader<T> builder, long checkInterval) throws IOException {
        if (Included.PLAIN == this.resourcesElementsProvider.getDefaultIncludedType()) {
            this.logger.trace(
                    "Resoure Aggregation Disabled, ignoring resource cache and loading '"
                            + resource
                            + "' directly");
            return this.loadResource(resource, builder);
        }

        // Look for the resource in the cache, since it has been wrapped with a SelfPopulatingCache
        // it should never return null.
        final GetResourceArguments<T> arguments = new GetResourceArguments<T>(resource, builder);
        final Element element =
                this.entryFactory.getWithData(this.resourceCache, resource, arguments);

        CachedResource<T> cachedResource = (CachedResource<T>) element.getObjectValue();
        if (this.logger.isTraceEnabled()) {
            this.logger.trace("Found " + cachedResource + " in cache");
        }

        // Found it, now check if the last-load time is within the check interval
        final long lastCheckTime = cachedResource.getLastCheckTime();
        if (lastCheckTime + checkInterval >= System.currentTimeMillis()) {
            if (this.logger.isTraceEnabled()) {
                this.logger.trace(
                        cachedResource
                                + " is within checkInterval "
                                + checkInterval
                                + ", returning");
            }
            return cachedResource;
        }
        if (this.logger.isTraceEnabled()) {
            this.logger.trace(
                    cachedResource
                            + " is older than checkInterval "
                            + checkInterval
                            + ", checking for modification");
        }

        // If the resource has not been modified return the cached resource.
        final boolean resourceModified = this.checkIfModified(cachedResource);
        if (!resourceModified) {
            cachedResource.setLastCheckTime(System.currentTimeMillis());
            this.resourceCache.put(
                    element); // do a cache put to notify the cache the object has been modified
            return cachedResource;
        }

        // The resource has been modified, reload it.
        cachedResource = this.loadResource(resource, builder);

        // Cache the loaded resource
        this.resourceCache.put(new Element(resource, cachedResource));

        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Loaded and cached " + cachedResource);
        }

        return cachedResource;
    }