public static T lookupFromEnvironment()

in core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/util/CodiUtils.java [615:663]


    public static <T extends Serializable> T lookupFromEnvironment(String key,
                                                                   Class<T> targetType,
                                                                   Aggregatable<T> aggregatable,
                                                                   T... defaultImplementation)
    {
        checkDefaultImplementation(defaultImplementation);

        List<T> results = ConfiguredArtifactUtils.getCachedArtifact(key, targetType);

        if(results == null)
        {
            T defaultInstance = null;

            if(defaultImplementation != null && defaultImplementation.length == 1)
            {
                //only one is supported
                defaultInstance = defaultImplementation[0];
            }
            results = ConfiguredArtifactUtils
                    .resolveFromEnvironment(key, targetType, aggregatable != null, defaultInstance);

            if(String.class.isAssignableFrom(targetType))
            {
                ConfiguredArtifactUtils.processConfiguredArtifact(key, (List<String>)results);
            }
            else
            {
                ConfiguredArtifactUtils.processFoundArtifact(key, targetType, results);
            }
        }

        if(results.isEmpty())
        {
            return null;
        }

        if(aggregatable != null)
        {
            for(T currentEntry : results)
            {
                aggregatable.add(currentEntry);
            }
            return aggregatable.create();
        }
        else
        {
            return results.iterator().next();
        }
    }