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

reconf.client.proxy.Customization Maven / Gradle / Ivy

There is a newer version: 2.1.16
Show newest version
/*
 *    Copyright 1996-2014 UOL 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 reconf.client.proxy;

import java.util.*;
import org.apache.commons.lang.*;
import reconf.client.notification.*;


public class Customization {

    private String productPrefix;
    private String productSuffix;
    private String componentPrefix;
    private String componentSuffix;
    private String namePrefix;
    private String nameSuffix;
    private Collection configurationItemListeners = new ArrayList();

    public String getProductPrefix() {
        return productPrefix;
    }
    public void setProductPrefix(String productPrefix) {
        this.productPrefix = productPrefix;
    }

    public String getProductSuffix() {
        return productSuffix;
    }
    public void setProductSuffix(String productSuffix) {
        this.productSuffix = productSuffix;
    }

    public String getComponentPrefix() {
        return componentPrefix;
    }
    public void setComponentPrefix(String componentPrefix) {
        this.componentPrefix = componentPrefix;
    }

    public String getComponentSuffix() {
        return componentSuffix;
    }
    public void setComponentSuffix(String componentSuffix) {
        this.componentSuffix = componentSuffix;
    }

    public String getComponentItemPrefix() {
        return namePrefix;
    }
    public void setComponentItemPrefix(String namePrefix) {
        this.namePrefix = namePrefix;
    }

    public String getComponentItemSuffix() {
        return nameSuffix;
    }
    public void setComponentItemSuffix(String nameSuffix) {
        this.nameSuffix = nameSuffix;
    }

    @Override
    public int hashCode() {
        return this.toString().hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof Customization)) {
            return false;
        }
        return this.toString().equals(obj.toString());
    }

    public boolean isValid() {
        return StringUtils.isNotBlank(productPrefix) ||
            StringUtils.isNotBlank(productSuffix) ||
            StringUtils.isNotBlank(componentPrefix) ||
            StringUtils.isNotBlank(componentSuffix) ||
            StringUtils.isNotBlank(namePrefix) ||
            StringUtils.isNotBlank(nameSuffix);
    }

    @Override
    public String toString() {
        return new StringBuilder().append("productPrefix[").append(StringUtils.defaultString(productPrefix)).append("] ")
            .append("productSuffix[").append(StringUtils.defaultString(productSuffix)).append("] ")
            .append("componentPrefix [").append(StringUtils.defaultString(componentPrefix)).append("] ")
            .append("componentSuffix [").append(StringUtils.defaultString(componentSuffix)).append("] ")
            .append("keyPrefix [").append(StringUtils.defaultString(namePrefix)).append("] ")
            .append("keySuffix [").append(StringUtils.defaultString(nameSuffix)).append("] ")
            .toString();
    }

    public String toCompare() {
        Set listenerNames = new TreeSet();
        for (ConfigurationItemListener listener : configurationItemListeners) {
            listenerNames.add(listener.toString());
        }

        String partial = this.toString();
        return partial += "listeners " + listenerNames.toString();
    }

    public String getCustomProduct(String originalProduct) {
        if (StringUtils.isBlank(originalProduct) || (StringUtils.isBlank(getProductPrefix()) && StringUtils.isBlank(getProductSuffix()))) {
            return originalProduct;
        }

        StringBuilder builder = new StringBuilder();
        if (StringUtils.isNotBlank(getProductPrefix())) {
            builder.append(getProductPrefix());
        }
        builder.append(originalProduct);
        if (StringUtils.isNotBlank(getProductSuffix())) {
            builder.append(getProductSuffix());
        }
        return builder.toString();

    }

    public String getCustomComponent(String originalComponent) {
        if (StringUtils.isBlank(originalComponent) || (StringUtils.isBlank(getComponentPrefix()) && StringUtils.isBlank(getComponentSuffix()))) {
            return originalComponent;
        }

        StringBuilder builder = new StringBuilder();
        if (StringUtils.isNotBlank(getComponentPrefix())) {
            builder.append(getComponentPrefix());
        }
        builder.append(originalComponent);
        if (StringUtils.isNotBlank(getComponentSuffix())) {
            builder.append(getComponentSuffix());
        }
        return builder.toString();

    }

    public String getCustomItem(String originalKey) {
        if (StringUtils.isBlank(originalKey) || (StringUtils.isBlank(getComponentItemPrefix()) && StringUtils.isBlank(getComponentItemSuffix()))) {
            return originalKey;
        }

        StringBuilder builder = new StringBuilder();
        if (StringUtils.isNotBlank(getComponentItemPrefix())) {
            builder.append(getComponentItemPrefix());
        }
        builder.append(originalKey);
        if (StringUtils.isNotBlank(getComponentItemSuffix())) {
            builder.append(getComponentItemSuffix());
        }
        return builder.toString();
    }
    public Collection getConfigurationItemListeners() {
        return configurationItemListeners;
    }

    public void setConfigurationItemListeners(Collection configurationItemListeners) {
        if (configurationItemListeners != null) {
            this.configurationItemListeners = configurationItemListeners;
        }
    }

    public void addConfigurationItemListener(ConfigurationItemListener configurationItemListener) {
        if (configurationItemListener != null) {
            this.configurationItemListeners.add(configurationItemListener);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy