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

com.cloudbees.sdk.commands.config.model.Environment Maven / Gradle / Ivy

/*
 * Copyright 2010-2013, CloudBees Inc.
 *
 * 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.cloudbees.sdk.commands.config.model;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author Fabian Donze
 */
@XStreamAlias("env")
public class Environment {
    @XStreamAsAttribute
    private String name;

    @XStreamImplicit(itemFieldName = "resource")
    private List resources;

    @XStreamImplicit(itemFieldName="param")
    private List parameters;

    @XStreamImplicit(itemFieldName="runtime-param")
    private List runtimeParameters;

    public Environment() {
    }

    public Environment(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List getResources() {
        if (resources == null)
            resources = new ArrayList();
        return resources;
    }

    public void setResources(List resources) {
        this.resources = resources;
    }
    public void setResource(ResourceSettings resource) {
        deleteResource(resource.getName());
        getResources().add(resource);
    }

    public ResourceSettings getResource(String name) {
        for (ResourceSettings resource : getResources()) {
            if (resource.getName().equals(name))
                return resource;
        }
        return null;
    }
    public void deleteResource(String name) {
        Iterator it = getResources().iterator();
        while (it.hasNext()) {
            if (it.next().getName().equals(name)) {
                it.remove();
            }
        }
    }

    public List getParameters() {
        if (parameters == null)
            parameters = new ArrayList();
        return parameters;
    }

    public void setParameters(List parameters) {
        this.parameters = parameters;
    }

    public void deleteParameter(String name) {
        Iterator it = getParameters().iterator();
        while (it.hasNext()) {
            if (it.next().getName().equals(name)) {
                it.remove();
            }
        }
    }
    public void setParameter(ParameterSettings parameter) {
        deleteParameter(parameter.getName());
        getParameters().add(parameter);
    }

    public ParameterSettings getParameter(String name) {
        for (ParameterSettings resource : getParameters()) {
            if (resource.getName().equals(name))
                return resource;
        }
        return null;
    }

    public List getRuntimeParameters() {
        if (runtimeParameters == null)
            runtimeParameters = new ArrayList();
        return runtimeParameters;
    }

    public void setRuntimeParameters(List runtimeParameters) {
        this.runtimeParameters = runtimeParameters;
    }

    public void deleteRuntimeParameter(String name) {
        Iterator it = getRuntimeParameters().iterator();
        while (it.hasNext()) {
            if (it.next().getName().equals(name)) {
                it.remove();
            }
        }
    }
    public void setRuntimeParameter(ParameterSettings parameter) {
        deleteRuntimeParameter(parameter.getName());
        getRuntimeParameters().add(parameter);
    }

    public ParameterSettings getRuntimeParameter(String name) {
        for (ParameterSettings resource : getParameters()) {
            if (resource.getName().equals(name))
                return resource;
        }
        return null;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy