<commit_before>/*
 * Copyright 2012 <NAME>.
 *
 * 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 org.ops4j.pax.cdi.weld.impl;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

import org.jboss.weld.bootstrap.api.SingletonProvider;
import org.jboss.weld.bootstrap.api.helpers.RegistrySingletonProvider;
import org.ops4j.pax.cdi.spi.CdiContainer;
import org.ops4j.pax.cdi.spi.CdiContainerFactory;
import org.ops4j.pax.cdi.spi.CdiContainerListener;
import org.ops4j.pax.cdi.spi.CdiContainerType;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

/**
 * {@link CdiContainerFactory} implementation based on Apache OpenWebBeans.
 * 
 * @author <NAME>
 * 
 */
public class WeldCdiContainerFactory implements CdiContainerFactory {

    private Map<Long, CdiContainer> containers = new HashMap<Long, CdiContainer>();
    private List<CdiContainerListener> listeners = new CopyOnWriteArrayList<CdiContainerListener>();
    private BundleContext bundleContext;

    public void activate(BundleContext bc) {
        this.bundleContext = bc;
        SingletonProvider.initialize(new RegistrySingletonProvider());        
    }

    public void deactivate() {
        SingletonProvider.reset();        
    }

    @Override
    public String getProviderName() {
        return "Weld";
    }

    @Override
    public CdiContainer createContainer(Bundle bundle, Collection<Bundle> extensions, CdiContainerType containerType) {
        WeldCdiContainer container = new WeldCdiContainer(containerType, bundleContext.getBundle(), bundle, extensions);
        containers.put(bundle.getBundleId(), container);
        for (CdiContainerListener listener : listeners) {
            listener.postCreate(container);
        }
        return container;
    }

    @Override
    public CdiContainer getContainer(Bundle bundle) {
        return containers.get(bundle.getBundleId());
    }

    @Override
    public Collection<CdiContainer> getContainers() {
        return Collections.unmodifiableCollection(containers.values());
    }

    @Override
    public void removeContainer(Bundle bundle) {
        CdiContainer container = containers.remove(bundle.getBundleId());
        for (CdiContainerListener listener : listeners) {
            listener.preDestroy(container);
        }
    }

    @Override
    public void addListener(CdiContainerListener listener) {
        listeners.add(listener);
        for (CdiContainer container : containers.values()) {
            listener.postCreate(container);
        }
    }

    @Override
    public void removeListener(CdiContainerListener listener) {
        listeners.remove(listener);
    }

}
<commit_msg>Add logging support to display message that a WeldContainer has been created<commit_after>/*
 * Copyright 2012 <NAME>.
 *
 * 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 org.ops4j.pax.cdi.weld.impl;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

import org.jboss.weld.bootstrap.api.SingletonProvider;
import org.jboss.weld.bootstrap.api.helpers.RegistrySingletonProvider;
import org.ops4j.pax.cdi.spi.CdiContainer;
import org.ops4j.pax.cdi.spi.CdiContainerFactory;
import org.ops4j.pax.cdi.spi.CdiContainerListener;
import org.ops4j.pax.cdi.spi.CdiContainerType;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * {@link CdiContainerFactory} implementation based on Apache OpenWebBeans.
 * 
 * @author <NAME>
 * 
 */
public class WeldCdiContainerFactory implements CdiContainerFactory {

    private Logger log = LoggerFactory.getLogger(WeldCdiContainerFactory.class);

    private Map<Long, CdiContainer> containers = new HashMap<Long, CdiContainer>();
    private List<CdiContainerListener> listeners = new CopyOnWriteArrayList<CdiContainerListener>();
    private BundleContext bundleContext;

    public void activate(BundleContext bc) {
        this.bundleContext = bc;
        SingletonProvider.initialize(new RegistrySingletonProvider());        
    }

    public void deactivate() {
        SingletonProvider.reset();        
    }

    @Override
    public String getProviderName() {
        return "Weld";
    }

    @Override
    public CdiContainer createContainer(Bundle bundle, Collection<Bundle> extensions, CdiContainerType containerType) {
        WeldCdiContainer container = new WeldCdiContainer(containerType, bundleContext.getBundle(), bundle, extensions);
        containers.put(bundle.getBundleId(), container);
        for (CdiContainerListener listener : listeners) {
            listener.postCreate(container);
        }
        log.debug("Weld Container created");
        return container;
    }

    @Override
    public CdiContainer getContainer(Bundle bundle) {
        return containers.get(bundle.getBundleId());
    }

    @Override
    public Collection<CdiContainer> getContainers() {
        return Collections.unmodifiableCollection(containers.values());
    }

    @Override
    public void removeContainer(Bundle bundle) {
        CdiContainer container = containers.remove(bundle.getBundleId());
        for (CdiContainerListener listener : listeners) {
            listener.preDestroy(container);
        }
    }

    @Override
    public void addListener(CdiContainerListener listener) {
        listeners.add(listener);
        for (CdiContainer container : containers.values()) {
            listener.postCreate(container);
        }
    }

    @Override
    public void removeListener(CdiContainerListener listener) {
        listeners.remove(listener);
    }

}

{'fraction_non_alphanumeric': 0.09004808392831123, 'fraction_numerical': 0.0040798484627713825, 'mean_word_length': 3.6315789473684212, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4267809', 'n_tokens_mistral': 1866, 'n_tokens_neox': 1832, 'n_words': 476}