Instantiates a provider using service loader.

@param allowTestProvider        whether test provider is allowed (must be
false for normal cases)
@return instantiated provider or null
424010
public static HOTPProvider instantiateProvider(boolean allowTestProvider) {
        HOTPProvider resultProvider = null;
        ServiceLoader<HOTPProvider> loader = ServiceLoader.load(HOTPProvider.class);
        Iterator<HOTPProvider> iterator = loader.iterator();
        if (iterator.hasNext()) {
            while (iterator.hasNext()) {
                HOTPProvider provider = iterator.next();
                if (!"com.payneteasy.superfly.spring.TestHOTPProvider".equals(provider.getClass().getName())
                        || allowTestProvider) {
                    resultProvider = provider;
                    break;
                }
            }
        }
        return resultProvider;
    }
178612
public static <T> void initSingletonEJBCDIProvider(AbstractResourceInfo resource, Message message, T resourceObject) {

        /*
         * Only @Provider will use logic here.
         * As EJB can only be default constructor, CDI can be default constructor or 1 param with @Inject constructor
         * And a provider must have 1 public constructor(default constructor or @Context params constructor)
         * then the intersection is only default constructor.
         * so if ConstructorProxies!=null means there are some other invalid constructors to EJB or CDI container
         */
        if ((!(resource instanceof ProviderInfo)) || (resource instanceof ApplicationInfo) || resource.getConstructorProxies() != null) {
            return;
        }

        ProviderInfo<T> pi = (ProviderInfo<T>) resource;

        /**
         * if this provider is inited which means it may be replaced by EJB or CDI bean or it may be invoked with @PostConstrcut
         */
        if (pi.isInit()) {
            return;
        }

        synchronized(pi) {
            if (pi.isInit()) {
                return;
            }
            Class clz = pi.getProvider().getClass();
            Bus bus = resource.getBus();

            if (bus != null) { // if bus is null, then we don't need to do injection on this provider
                List<JaxRsFactoryBeanCustomizer> beanCustomizers = (List<JaxRsFactoryBeanCustomizer>) bus.getProperty(JaxRsConstants.ENDPOINT_LIST_BEANCUSTOMIZER);
                Map<String, Object> beanCustomizerContexts = (Map<String, Object>) bus.getProperty(JaxRsConstants.ENDPOINT_BEANCUSTOMIZER_CONTEXTOBJ);

                if (beanCustomizers != null && !beanCustomizers.isEmpty() && beanCustomizerContexts != null) {

                    Object newProviderInstance = null;
                    for (JaxRsFactoryBeanCustomizer beanCustomizer : beanCustomizers) {
                        if (beanCustomizer.isCustomizableBean(clz, beanCustomizerContexts.get(Integer.toString(beanCustomizer.hashCode())))) {

                            newProviderInstance = beanCustomizer.onSingletonProviderInit(pi.getProvider(), beanCustomizerContexts.get(Integer.toString(beanCustomizer.hashCode())), message);

                            /**
                             * if newProviderInstance!= the original object, which means it is replaced to EJB or CDI, so just return
                             * no need call @PostConstruct
                             */
                            if (newProviderInstance != null) {
                                //call setProvider to set isInit==true
                                pi.setProvider(newProviderInstance);
                                pi.setIsInit(true);
                                return;
                            }
                        }
                    }
                }
                //No replacement happens which means this is a POJO, call @PostConstruct
                pi.setIsInit(true);
                Method postConstructMethod = ResourceUtils.findPostConstructMethod(clz);
                InjectionUtils.invokeLifeCycleMethod(pi.getProvider(), postConstructMethod);
            }
        }
    }
1172809
protected Provider<ObjectMapper> getJacksonProvider()
    {
        return new Provider<ObjectMapper>()
        {
            @Override
            public ObjectMapper get()
            {
                final ObjectMapper mapper = new ObjectMapper();
                mapper.registerModule(new JodaModule());
                mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
                return mapper;
            }
        };
    }
454352
public static ServiceProvider init(ServiceProvider serviceProvider) {
        Objects.requireNonNull(serviceProvider);
        synchronized (LOCK) {
            if (Objects.isNull(Bootstrap.serviceProviderDelegate)) {
                Bootstrap.serviceProviderDelegate = serviceProvider;
                Logger.getLogger(Bootstrap.class.getName())
                        .info("Money Bootstrap: new ServiceProvider set: " + serviceProvider.getClass().getName());
                return null;
            } else {
                ServiceProvider prevProvider = Bootstrap.serviceProviderDelegate;
                Bootstrap.serviceProviderDelegate = serviceProvider;
                Logger.getLogger(Bootstrap.class.getName())
                        .warning("Money Bootstrap: ServiceProvider replaced: " + serviceProvider.getClass().getName());
                return prevProvider;
            }
        }
    }
655248
public static StorageBuilder forProvider( String providerName )
    {
        Class<?> providerClass = PROVIDERS.get( providerName );

        if ( providerClass == null ) {
            throw new IllegalArgumentException( "No provider implementation registered for name: " + providerName );
        }

        return new StorageBuilder( providerName, providerClass );
    }
127084
public synchronized <T> T load(final PluggableService<T> service, final String providerName) throws
        ProviderLoaderException {
        if (!(service instanceof ScriptPluginProviderLoadable)) {
            return null;
        }
        ScriptPluginProviderLoadable<T> loader =(ScriptPluginProviderLoadable<T>) service;
        final ProviderIdent ident = new ProviderIdent(service.getName(), providerName);

        if (null == pluginProviderDefs.get(ident)) {
            //look for plugin def
            final PluginMeta pluginMeta;
            try {
                pluginMeta = getPluginMeta();
            } catch (IOException e) {
                throw new ProviderLoaderException(e, service.getName(), providerName);
            }
            if (null == pluginMeta) {
                throw new ProviderLoaderException("Unable to load plugin metadata for file: " + file, service.getName(),
                    providerName);
            }
            for (final ProviderDef pluginDef : pluginMeta.getPluginDefs()) {
                if (matchesProvider(ident, pluginDef)) {
                    final ScriptPluginProvider provider;
                    try {
                        provider = getPlugin(pluginMeta, file, pluginDef, ident);
                    } catch (PluginException e) {
                        throw new ProviderLoaderException(e, service.getName(), providerName);
                    }
                    pluginProviderDefs.put(ident, provider);
                    break;
                }
            }
        }
        final ScriptPluginProvider scriptPluginProvider = pluginProviderDefs.get(ident);

        try {
            getResourceLoader().listResources();
        } catch(IOException iex) {
            throw new ProviderLoaderException(iex,service.getName(),providerName);
        }
        catch (PluginException e) {
            throw new ProviderLoaderException(e, service.getName(), providerName);
        }
        if (null != scriptPluginProvider) {
            try {
                return loader.createScriptProviderInstance(scriptPluginProvider);
            } catch (PluginException e) {
                throw new ProviderLoaderException(e, service.getName(), providerName);
            }
        }
        return null;
    }
128470
public function createUserProvider($provider = null)
    {
        if (is_null($config = $this->getProviderConfiguration($provider))) {
            return;
        }

        if (isset($this->customProviderCreators[$driver = ($config['driver'] ?? null)])) {
            return call_user_func(
                $this->customProviderCreators[$driver], $this->app, $config
            );
        }

        switch ($driver) {
            case 'database':
                return $this->createDatabaseProvider($config);
            case 'eloquent':
                return $this->createEloquentProvider($config);
            default:
                throw new InvalidArgumentException(
                    "Authentication user provider [{$driver}] is not defined."
                );
        }
    }
996264
public static ProxyClassLoader convertClassloader(ClassLoader loader) {
        if (loader == null) {
            return ProxyClient.DEFAULT_LOADER;
        } else if (loader instanceof ProxyClassLoader) {
            return (ProxyClassLoader) loader;
        } else {
            return new ProxyClassLoader(loader);
        }
    }
871950
@FFDCIgnore(value = { Throwable.class })
    public static Object createJsonpProvider() {

        // We can only create the JSON-P provider if the jsonp feature is provisioned. This usually
        // requires the user to explicitly add the jsonp-1.0 feature in the server.xml (or some feature
        // that includes it).  The following classloading code checks to see if this bundle can load
        // (via dynamic import) the JSON-P classes.  If so, then it returns the JSON-P provider.  If not,
        // it returns null.
        Object provider = null;
        ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {

            @Override
            public ClassLoader run() {
                return ProviderFactory.class.getClassLoader();
            }
        });
        Class<?> c = ProviderFactory.loadClass(cl, JSONPCLASS);
        if (c != null) {
            // Use reflection so that we do not load JSON classes if jsonp feature is not enabled.
            String className = "com.ibm.ws.jaxrs20.providers.jsonp.JsonPProvider";
            Class<?> pProviderCls = ProviderFactory.loadClass(cl, className);
            try {
                provider = pProviderCls.newInstance();
            } catch (Throwable ex) {
                String message = "Problem with creating the Jsonp provider " + className;
                if (ex.getMessage() != null) {
                    message += ": " + ex.getMessage();
                } else {
                    message += ", exception class : " + ex.getClass().getName();
                }
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, message);
                }
            }
        }

        return provider;
    }
1133224
public <T> T loadImpl(Class<T> service) {
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        if (loader == null) {
            loader = ClassLoader.getSystemClassLoader();
        }
        Enumeration<URL> resources;
        try {
            resources = loader.getResources("mockito-extensions/" + service.getName());
        } catch (IOException e) {
            throw new IllegalStateException("Failed to load " + service, e);
        }

        try {
            String classOrAlias = new PluginFinder(pluginSwitch).findPluginClass(Iterables.toIterable(resources));
            if (classOrAlias != null) {
                if (classOrAlias.equals(alias)) {
                    classOrAlias = plugins.getDefaultPluginClass(alias);
                }
                Class<?> pluginClass = loader.loadClass(classOrAlias);
                Object plugin = pluginClass.newInstance();
                return service.cast(plugin);
            }
            return null;
        } catch (Exception e) {
            throw new IllegalStateException(
                "Failed to load " + service + " implementation declared in " + resources, e);
        }
    }
1008055
static Type forTypeProvider(final TypeProvider provider) {
        LettuceAssert.notNull(provider, "Provider must not be null");
        if (provider.getType() instanceof Serializable || provider.getType() == null) {
            return provider.getType();
        }

        for (Class<?> type : SUPPORTED_SERIALIZABLE_TYPES) {
            if (type.isAssignableFrom(provider.getType().getClass())) {
                ClassLoader classLoader = provider.getClass().getClassLoader();
                Class<?>[] interfaces = new Class<?>[] { type, SerializableTypeProxy.class, Serializable.class };
                InvocationHandler handler = new TypeProxyInvocationHandler(provider);
                return (Type) Proxy.newProxyInstance(classLoader, interfaces, handler);
            }
        }
        throw new IllegalArgumentException("Unsupported Type class: " + provider.getType().getClass().getName());
    }
42100
public static LazyProxyFactory createDefaultProxyFactory() {
        if (testDependencyFullFilled()) {
            final String factoryClassName = "dev.morphia.mapping.lazy.CGLibLazyProxyFactory";
            try {
                return (LazyProxyFactory) Class.forName(factoryClassName).newInstance();
            } catch (Exception e) {
                LOG.error("While instantiating " + factoryClassName, e);
            }
        }
        return null;
    }
1168966
public Provider getProvider(String name) {
        ProviderConfig config = getProviderConfig(name);
        return (config == null) ? null : config.getProvider();
    }
1357506
private static Provider validateProvider(Provider provider) {
        Set<String> ids = provider.getAvailableIDs();
        if (ids == null || ids.size() == 0) {
            throw new IllegalArgumentException("The provider doesn't have any available ids");
        }
        if (!ids.contains("UTC")) {
            throw new IllegalArgumentException("The provider doesn't support UTC");
        }
        if (!UTC.equals(provider.getZone("UTC"))) {
            throw new IllegalArgumentException("Invalid UTC zone provided");
        }
        return provider;
    }
1041380
@Inject
  @Provides
  @Singleton
  public RequestHandler provideRequestHandler(InstanceProvider instanceProvider) {
    return new DefaultRequestHandler(instanceProvider, new ValueConverterRegistry());
  }
1290178
public static synchronized JSSEProvider getInstance(String inputProvider) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "getInstance: " + inputProvider);

        String contextProvider = inputProvider;
        if (contextProvider == null) {
            if (null != defaultProvider) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                    Tr.exit(tc, "getInstance: " + defaultProvider);
                return defaultProvider;
            }
            contextProvider = getProviderFromProviderList();
        }

        // if still null, revert to default as usual.
        if (contextProvider == null) {
            contextProvider = Constants.IBMJSSE2_NAME;
        }

        JSSEProvider cachedProvider = providerCache.get(contextProvider);

        if (cachedProvider != null) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                Tr.exit(tc, "getInstance(cached) " + cachedProvider);
            return cachedProvider;
        }

        final String contextProviderPriv = contextProvider;
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
            @Override
            public Object run() {
                Provider provider = Security.getProvider(contextProviderPriv);

                if (provider == null) {
                    try {
                        if (contextProviderPriv.equalsIgnoreCase(Constants.IBMJSSE_NAME)) {
                            provider = (Provider) Class.forName(Constants.IBMJSSE2).newInstance();
                        } else if (contextProviderPriv.equalsIgnoreCase(Constants.SUNJSSE_NAME)) {
                            provider = (Provider) Class.forName("com.sun.net.ssl.internal.ssl.Provider").newInstance();
                        } else {
                            provider = (Provider) Class.forName(Constants.IBMJSSE2).newInstance();
                        }
                        if (provider != null) {
                            Security.addProvider(provider);
                        }
                    } catch (Exception e) {
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                            Tr.debug(tc, "Exception loading provider: " + contextProviderPriv + "; " + e);
                    }
                }
                return null;
            }
        });

        Provider[] providerList = Security.getProviders();

        for (int i = 0; i < providerList.length && null == cachedProvider; i++) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(tc, "Provider name [" + i + "]: " + providerList[i].getName());

            if (providerList[i].getName().equalsIgnoreCase(contextProvider)) {
                if (contextProvider.equalsIgnoreCase(Constants.IBMJSSE2_NAME) && validateProvider(Constants.IBMJSSE2_NAME)) {
                    cachedProvider = new IBMJSSEProvider();
                    providerCache.put(Constants.IBMJSSE2_NAME, cachedProvider);
                    providerCache.put(contextProvider, cachedProvider);
                } else if (contextProvider.equalsIgnoreCase(Constants.IBMJSSE_NAME) && validateProvider(Constants.IBMJSSE_NAME)) {
                    cachedProvider = new IBMJSSEProvider();
                    providerCache.put(Constants.IBMJSSE_NAME, cachedProvider);
                    providerCache.put(contextProvider, cachedProvider);
                } else if (contextProvider.equalsIgnoreCase(Constants.SUNJSSE_NAME) && validateProvider(Constants.SUNJSSE_NAME)) {
                    cachedProvider = new SunJSSEProvider();
                    providerCache.put(Constants.SUNJSSE_NAME, cachedProvider);
                    providerCache.put(contextProvider, cachedProvider);
                } else {
                    cachedProvider = new IBMJSSEProvider();
                    providerCache.put(Constants.IBMJSSE_NAME, cachedProvider);
                    providerCache.put(contextProvider, cachedProvider);
                }
            }
        } // end-provider-loop

        // if still null, default to IBM JSSE provider
        if (cachedProvider == null) {
            cachedProvider = new IBMJSSEProvider();
            providerCache.put(Constants.IBMJSSE_NAME, cachedProvider);
            providerCache.put(contextProvider, cachedProvider);
        }

        if (null == inputProvider) {
            defaultProvider = cachedProvider;
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "getInstance: " + cachedProvider);
        return cachedProvider;
    }
1167107
public static SessionProvider createAnonimProvider()
   {
      Identity id = new Identity(IdentityConstants.ANONIM, new HashSet<MembershipEntry>());
      return new SessionProvider(new ConversationState(id));
   }