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

com.servicerocket.confluence.plugin.utility.library.EnvironmentProviderModuleDescriptor Maven / Gradle / Ivy

The newest version!
package com.servicerocket.confluence.plugin.utility.library;

import com.atlassian.plugin.Plugin;
import com.atlassian.plugin.PluginParseException;
import com.atlassian.plugin.descriptors.AbstractModuleDescriptor;
import com.atlassian.plugin.module.ModuleFactory;
import com.servicerocket.confluence.randombits.support.core.env.AbstractEnvironmentProvider;
import com.servicerocket.confluence.randombits.support.core.env.EnvironmentProvider;
import org.dom4j.Element;

/**
 * Allows definitions of <environment-provider> elements.
 */
public class EnvironmentProviderModuleDescriptor extends AbstractModuleDescriptor {

    private EnvironmentProvider provider;

    int weight = 0;

    public EnvironmentProviderModuleDescriptor(ModuleFactory moduleFactory) {
        super(moduleFactory);
    }

    @Override
    public void init(@NotNull Plugin plugin, @NotNull Element element) {
        super.init(plugin, element);
        String weightValue = element.attributeValue("weight");
        if (weightValue != null) {
            try {
                weight = Integer.parseInt(weightValue);
            } catch (NumberFormatException e) {
                throw new PluginParseException("Please provide an integer value for the weight: '" + weightValue + "'");
            }
        }
    }

    @Override
    public EnvironmentProvider getModule() {
        if (provider == null) {
            provider = moduleFactory.createModule(moduleClassName, this);
            if (weight != 0 && provider instanceof AbstractEnvironmentProvider) {
                ((AbstractEnvironmentProvider) provider).setWeight(weight);
            }

        }
        return provider;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy