All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.shrinkwrap.api.Configuration Maven / Gradle / Ivy

There is a newer version: 2.0.0-beta-2
Show newest version
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2010, Red Hat Middleware LLC, and individual contributors
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * 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.jboss.shrinkwrap.api;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.ExecutorService;

/**
 * Encapsulates all configuration for a given {@link Domain}. Each {@link Archive} created by the domain's
 * {@link ArchiveFactory} will consult the configuration internally. An {@link Archive}'s configuration may not be
 * changed after construction; if a new config is required it must be created under a new domain. The default
 * configuration is defined by {@link ConfigurationBuilder}, and new configurations are created via
 * {@link ConfigurationBuilder#build()}. Note that while the {@link Configuration} is immutable, its properties may have
 * internal state that may be changed. For true isolation, use separate {@link Domain}s when creating {@link Archive}s.
 *
 * @author ALR
 * @author Ken Gullaksen
 * @version $Revision: $
 */
public class Configuration {
    // -------------------------------------------------------------------------------------||
    // Class Members ----------------------------------------------------------------------||
    // -------------------------------------------------------------------------------------||

    // -------------------------------------------------------------------------------------||
    // Instance Members -------------------------------------------------------------------||
    // -------------------------------------------------------------------------------------||

    /**
     * Loader mapping archive types to the appropriate underlying implementation
     */
    private final ExtensionLoader extensionLoader;

    /**
     * {@link ExecutorService} used for all asynchronous operations
     * @deprecated No longer used by the implementation, will be removed in SW 2.0
     */
    @Deprecated
    private final ExecutorService executorService;

    /**
     * {@link ClassLoader}s used for extension loading
     */
    private final Iterable classLoaders;

    // -------------------------------------------------------------------------------------||
    // Constructor ------------------------------------------------------------------------||
    // -------------------------------------------------------------------------------------||

    /**
     * Creates a new configuration instance using properties contained in the specified {@link ConfigurationBuilder}.
     *
     * @param builder
     *            Construction object encapsulating the properties to use in this configuration
     * @throws IllegalArgumentException
     *             If the builder was not specified
     */
    Configuration(final ConfigurationBuilder builder) throws IllegalArgumentException {
        // Precondition checks
        if (builder == null) {
            throw new IllegalArgumentException("builder must be specified");
        }

        // Let the builder set defaults
        builder.setDefaults();

        // Set
        this.extensionLoader = builder.getExtensionLoader();
        this.executorService = builder.getExecutorService();
        // Defensive copy
        Collection cls = new ArrayList();
        if (builder.getClassLoaders() instanceof Collection) {
            cls = (Collection) builder.getClassLoaders();
        } else {
            for (final ClassLoader cl : builder.getClassLoaders()) {
                cls.add(cl);
            }
        }
        this.classLoaders = Collections.unmodifiableCollection(cls);
    }

    // -------------------------------------------------------------------------------------||
    // Accessors --------------------------------------------------------------------------||
    // -------------------------------------------------------------------------------------||

    /**
     * @return the extensionLoader
     */
    public ExtensionLoader getExtensionLoader() {
        return extensionLoader;
    }

    /**
     * @return the executorService
     * @deprecated No longer used by the implementation, will be removed in SW 2.0
     */
    @Deprecated
    public ExecutorService getExecutorService() {
        return executorService;
    }

    /**
     * @return The {@link ClassLoader}s to be used in this configuration; used in extension loading and adding CL
     *         resources to the archive, etc
     */
    public Iterable getClassLoaders() {
        return classLoaders;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy