// Path: cdi-properties-main/src/main/java/com/byteslounge/cdi/exception/ExtensionInitializationException.java
// public class ExtensionInitializationException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     public ExtensionInitializationException(String message) {
//         super(message);
//     }
// 
//     public ExtensionInitializationException(Throwable cause) {
//         super(cause);
//     }
// 
//     public ExtensionInitializationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
// }


import java.util.Collections;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.byteslounge.cdi.exception.ExtensionInitializationException;
/*
 * Copyright 2015 byteslounge.com (Gonçalo Marques).
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
package com.byteslounge.cdi.resolver.bean;





/**
 * Lazy resolver bean initializer created to solve bean resolution problems 
 * in older versions of Weld (ex: Weld 1.1.3 that is shipped with Weblogic 12.1.1).
 * 
 * Basically we fall back to the Bean Manager that is fetched through JNDI in case
 * the Bean Manager provided to the extension fails to resolve the Property/Locale resolvers.
 * 
 * @author Gonçalo Marques
 * @since 1.1.1
 */
public class ResolverInstanceLazyInitializer {

    private static final Logger logger = LoggerFactory.getLogger(ResolverInstanceLazyInitializer.class);
    private volatile ResolverInstance resolverInstance;
    private final Class<?> resolverClass;
    private final BeanManagerList beanManagers;

    public ResolverInstanceLazyInitializer(BeanManager beanManager, Class<?> resolverClass) {
        this.beanManagers = new BeanManagerList(beanManager);
        this.resolverClass = resolverClass;
    }

    public ResolverInstance get() {
        ResolverInstance result = resolverInstance;
        if (result == null) {
            synchronized (this) {
                result = resolverInstance;
                if (result == null) {
                    BeanResolverResult beanResolverResult = CDIBeanResolver.resolve(beanManagers, resolverClass);
                    BeanManager activeBeanManager = beanResolverResult.activeBeanManager;
                    Bean<?> resolverBean = activeBeanManager.resolve(beanResolverResult.beans);
                    if (resolverBean == null) {
// Path: cdi-properties-main/src/main/java/com/byteslounge/cdi/exception/ExtensionInitializationException.java
// public class ExtensionInitializationException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     public ExtensionInitializationException(String message) {
//         super(message);
//     }
// 
//     public ExtensionInitializationException(Throwable cause) {
//         super(cause);
//     }
// 
//     public ExtensionInitializationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
// }


// Path: cdi-properties-main/src/main/java/com/byteslounge/cdi/resolver/bean/ResolverInstanceLazyInitializer.java
import java.util.Collections;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.byteslounge.cdi.exception.ExtensionInitializationException;

/*
 * Copyright 2015 byteslounge.com (Gonçalo Marques).
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
package com.byteslounge.cdi.resolver.bean;





/**
 * Lazy resolver bean initializer created to solve bean resolution problems 
 * in older versions of Weld (ex: Weld 1.1.3 that is shipped with Weblogic 12.1.1).
 * 
 * Basically we fall back to the Bean Manager that is fetched through JNDI in case
 * the Bean Manager provided to the extension fails to resolve the Property/Locale resolvers.
 * 
 * @author Gonçalo Marques
 * @since 1.1.1
 */
public class ResolverInstanceLazyInitializer {

    private static final Logger logger = LoggerFactory.getLogger(ResolverInstanceLazyInitializer.class);
    private volatile ResolverInstance resolverInstance;
    private final Class<?> resolverClass;
    private final BeanManagerList beanManagers;

    public ResolverInstanceLazyInitializer(BeanManager beanManager, Class<?> resolverClass) {
        this.beanManagers = new BeanManagerList(beanManager);
        this.resolverClass = resolverClass;
    }

    public ResolverInstance get() {
        ResolverInstance result = resolverInstance;
        if (result == null) {
            synchronized (this) {
                result = resolverInstance;
                if (result == null) {
                    BeanResolverResult beanResolverResult = CDIBeanResolver.resolve(beanManagers, resolverClass);
                    BeanManager activeBeanManager = beanResolverResult.activeBeanManager;
                    Bean<?> resolverBean = activeBeanManager.resolve(beanResolverResult.beans);
                    if (resolverBean == null) {
                        throw new ExtensionInitializationException(