/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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.apache.webbeans.arquillian.standalone;

import org.jboss.arquillian.container.spi.ConfigurationException;
import org.jboss.arquillian.container.spi.client.container.ContainerConfiguration;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * Validate if the Owb Container is correctly configured
 */
public class OwbStandaloneConfiguration implements ContainerConfiguration
{
    /**
     * used to skip classpath resources which are not in the archive,
     * can be useful when a resource should appear a single time in an app
     */
    private boolean useOnlyArchiveResources = false;
    private String useOnlyArchiveResourcesExcludes = null;

    /**
     * config
     */
    private String properties = null;

    @Override
    public void validate() throws ConfigurationException
    {
        // not needed right now
    }

    public boolean isUseOnlyArchiveResources()
    {
        return useOnlyArchiveResources;
    }

    public void setUseOnlyArchiveResources(final boolean useOnlyArchiveResources)
    {
        this.useOnlyArchiveResources = useOnlyArchiveResources;
    }

    public String getUseOnlyArchiveResourcesExcludes()
    {
        return useOnlyArchiveResourcesExcludes;
    }

    public void setUseOnlyArchiveResourcesExcludes(final String useOnlyArchiveResourcesExcludes)
    {
        this.useOnlyArchiveResourcesExcludes = useOnlyArchiveResourcesExcludes;
    }

    public String getProperties()
    {
        return properties;
    }

    public void setProperties(final String properties)
    {
        this.properties = properties;
    }

    public Properties properties()
    {
        final Properties instance = new Properties();
        if (properties == null)
        {
            return instance;
        }

        final ByteArrayInputStream bais = new ByteArrayInputStream(properties.getBytes());
        try
        {
            instance.load(bais);
        }
        catch (final IOException e)
        {
            // no-op
        }

        return instance;
    }
}
