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

com.aspectran.core.context.config.ContextConfig Maven / Gradle / Ivy

There is a newer version: 8.1.5
Show newest version
/*
 * Copyright (c) 2008-2023 The Aspectran Project
 *
 * 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.aspectran.core.context.config;

import com.aspectran.core.context.rule.params.AspectranParameters;
import com.aspectran.core.util.apon.AbstractParameters;
import com.aspectran.core.util.apon.ParameterKey;
import com.aspectran.core.util.apon.ValueType;

public class ContextConfig extends AbstractParameters {

    private static final ParameterKey base;
    private static final ParameterKey rules;
    private static final ParameterKey encoding;
    private static final ParameterKey resources;
    private static final ParameterKey scan;
    private static final ParameterKey profiles;
    private static final ParameterKey autoReload;
    private static final ParameterKey singleton;
    private static final ParameterKey parameters;

    private static final ParameterKey[] parameterKeys;

    static {
        base = new ParameterKey("base", ValueType.STRING);
        rules = new ParameterKey("rules", ValueType.STRING, true);
        encoding = new ParameterKey("encoding", ValueType.STRING);
        resources = new ParameterKey("resources", ValueType.STRING, true);
        scan = new ParameterKey("scan", ValueType.STRING, true);
        profiles = new ParameterKey("profiles", ContextProfilesConfig.class);
        autoReload = new ParameterKey("autoReload", ContextAutoReloadConfig.class);
        singleton = new ParameterKey("singleton", ValueType.BOOLEAN);
        parameters = new ParameterKey("parameters", AspectranParameters.class);

        parameterKeys = new ParameterKey[] {
                base,
                rules,
                encoding,
                resources,
                scan,
                profiles,
                autoReload,
                singleton,
                parameters
        };
    }

    public ContextConfig() {
        super(parameterKeys);
    }

    public String getBasePath() {
        return getString(base);
    }

    public ContextConfig setBasePath(String basePath) {
        putValue(base, basePath);
        return this;
    }

    public String[] getContextRules() {
        return getStringArray(rules);
    }

    public ContextConfig setContextRules(String[] contextRules) {
        removeValue(rules);
        putValue(rules, contextRules);
        return this;
    }

    public ContextConfig addContextRule(String contextRule) {
        putValue(rules, contextRule);
        return this;
    }

    public String getEncoding() {
        return getString(encoding);
    }

    public ContextConfig setEncoding(String encoding) {
        putValue(ContextConfig.encoding, encoding);
        return this;
    }

    public String[] getResourceLocations() {
        return getStringArray(resources);
    }

    public ContextConfig setResourceLocations(String[] resourceLocations) {
        removeValue(resources);
        putValue(resources, resourceLocations);
        return this;
    }

    public ContextConfig addResourceLocation(String resourceLocation) {
        putValue(resources, resourceLocation);
        return this;
    }

    public String[] getBasePackages() {
        return getStringArray(scan);
    }

    public ContextConfig setBasePackage(String[] basePackages) {
        removeValue(scan);
        putValue(scan, basePackages);
        return this;
    }

    public ContextConfig addBasePackage(String basePackage) {
        putValue(scan, basePackage);
        return this;
    }

    public ContextProfilesConfig getProfilesConfig() {
        return getParameters(profiles);
    }

    public ContextProfilesConfig newProfilesConfig() {
        return newParameters(profiles);
    }

    public ContextProfilesConfig touchProfilesConfig() {
        return touchParameters(profiles);
    }

    public boolean hasProfilesConfig() {
        return hasValue(profiles);
    }

    public ContextAutoReloadConfig getAutoReloadConfig() {
        return getParameters(autoReload);
    }

    public ContextAutoReloadConfig newAutoReloadConfig() {
        return newParameters(autoReload);
    }

    public ContextAutoReloadConfig touchAutoReloadConfig() {
        return touchParameters(autoReload);
    }

    public boolean isSingleton() {
        return getBoolean(singleton, false);
    }

    public ContextConfig setSingleton(boolean singleton) {
        putValue(ContextConfig.singleton, singleton);
        return this;
    }

    public AspectranParameters getAspectranParameters() {
        return getParameters(parameters);
    }

    public AspectranParameters newAspectranParameters() {
        return newParameters(parameters);
    }

    public AspectranParameters touchAspectranParameters() {
        return touchParameters(parameters);
    }

    public boolean hasAspectranParameters() {
        return hasValue(parameters);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy