ProfileConfig.java
/*
** Module : ProfileConfig.java
** Abstract : A 'profile' configuration read from the main configuration file.
**
** Copyright (c) 2022, Golden Code Development Corporation.
**
** -#- -I- --Date-- --------------------------- Description --------------------------------------
** 001 CA 20220430 Created initial version.
*/
/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Affero General Public License for more details.
**
** You may find a copy of the GNU Affero GPL version 3 at the following
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
**
** Additional terms under GNU Affero GPL version 3 section 7:
**
** Under Section 7 of the GNU Affero GPL version 3, the following additional
** terms apply to the works covered under the License. These additional terms
** are non-permissive additional terms allowed under Section 7 of the GNU
** Affero GPL version 3 and may not be removed by you.
**
** 0. Attribution Requirement.
**
** You must preserve all legal notices or author attributions in the covered
** work or Appropriate Legal Notices displayed by works containing the covered
** work. You may not remove from the covered work any author or developer
** credit already included within the covered work.
**
** 1. No License To Use Trademarks.
**
** This license does not grant any license or rights to use the trademarks
** Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
** of Golden Code Development Corporation. You are not authorized to use the
** name Golden Code, FWD, or the names of any author or contributor, for
** publicity purposes without written authorization.
**
** 2. No Misrepresentation of Affiliation.
**
** You may not represent yourself as Golden Code Development Corporation or FWD.
**
** You may not represent yourself for publicity purposes as associated with
** Golden Code Development Corporation, FWD, or any author or contributor to
** the covered work, without written authorization.
**
** 3. No Misrepresentation of Source or Origin.
**
** You may not represent the covered work as solely your work. All modified
** versions of the covered work must be marked in a reasonable way to make it
** clear that the modified work is not originating from Golden Code Development
** Corporation or FWD. All modified versions must contain the notices of
** attribution required in this license.
*/
package com.goldencode.p2j.cfg;
import java.util.*;
import com.goldencode.p2j.schema.*;
/**
* Contains a profile configuration from the main configuration file.
*/
public class ProfileConfig
{
/** The explicit parameters specified for this profile. */
private final Map<String, String> parameters = new LinkedHashMap<>();
/** The FILE-SET specified at the profile. */
private FileSet fileSet = null;
/** Profile's schema configuration. */
private SchemaConfig schema = null;
/** Profile's include remapping. */
private final Map<String, String> includeRemap = new LinkedHashMap<>();
/** Profile name. */
private String name;
/** Flag indicating if this profile is loaded by default, if no explicit profile is used. */
private boolean isDefault;
/**
* Used at runtime, to save state at this profile, to be able to restore it when switching back to this
* profile.
*/
private Map<Object, Object> savedStates = new HashMap<>();
/** The PROPATH paths for this config. */
private String[] paths;
/** The file list resolved from the {@link #fileSet}. */
private Set<String> fileList;
/**
* Create a new instance.
*/
public ProfileConfig()
{
// no-op
}
/**
* Get the {@link #isDefault} flag.
*
* @return See above.
*/
public boolean isDefault()
{
return isDefault;
}
/**
* Set the {@link #isDefault} flag.
*
* @param isDefault
* Flag indicating if this profile is loaded by default, if no explicit profile is used.
*/
public void setDefault(boolean isDefault)
{
this.isDefault = isDefault;
}
/**
* Get the profile name.
*
* @return See above.
*/
public String getName()
{
return name;
}
/**
* Set the profile name.
*
* @param name
* See above.
*/
public void setName(String name)
{
this.name = name;
}
/**
* Add these parameters to the profile.
*
* @param name
* The parameter name.
* @param value
* The parameter's value.
*
* @throws ConfigurationException
* If the parameter is already set.
*/
public void addParameter(String name, String value)
throws ConfigurationException
{
if (parameters.containsKey(name))
{
throw new ConfigurationException("Parameter " + name + " is already set for profile " + name);
}
parameters.put(name, value);
}
/**
* Get a copy of the profile's {@link #parameters}.
*
* @return See above.
*/
public Map<String, String> getParameters()
{
return new LinkedHashMap<>(parameters);
}
/**
* Get a copy of the profile's {@link #fileSet}.
*
* @return See above.
*/
public FileSet getFileSet()
{
return fileSet == null ? null : new FileSet(fileSet);
}
/**
* Set the profile's file-set.
*
* @param fileSet
* The file-set to use.
*
* @throws ConfigurationException
* If the {@link #fileSet} is already set.
*/
public void setFileSet(FileSet fileSet)
throws ConfigurationException
{
if (this.fileSet != null)
{
throw new ConfigurationException("FILE-SET is already set for profile " + name);
}
this.fileSet = fileSet;
}
/**
* Get the profile's {@link #schema schema config}.
*
* @return See above.
*/
public SchemaConfig getSchema()
{
return schema;
}
/**
* Set the profile's schema configuration.
*
* @param schema
* The schema configuration.
*
* @throws ConfigurationException
* If the schema is already set.
*/
public void setSchema(SchemaConfig schema)
throws ConfigurationException
{
if (this.schema != null)
{
throw new ConfigurationException("SCHEMA is already set for profile " + name);
}
this.schema = schema;
}
/**
* Get a copy of the profile's {@link #includeRemap include remapping}.
*
* @return See above.
*/
public Map<String, String> getIncludeRemap()
{
return new LinkedHashMap<>(includeRemap);
}
/**
* Add all include remappings to this profile.
*
* @param remap
* The include remappings.
*/
public void addIncludeRemap(Map<String, String> remap)
throws ConfigurationException
{
this.includeRemap.putAll(remap);
}
/**
* Add all the parameters to this profile.
*
* @param parameters
* The parameters to add.
*/
public void addParameters(Map<String, String> parameters)
{
this.parameters.putAll(parameters);
}
/**
* Get a state for the specified key.
*
* @param key
* The key.
*
* @return The saved state.
*/
public Object getState(Object key)
{
return savedStates.get(key);
}
/**
* Save a state with the specified key.
*
* @param key
* The state's key.
* @param state
* The state.
*/
public void addState(Object key, Object state)
{
savedStates.put(key, state);
}
/**
* Set the paths.
*
* @param paths
* The PROPATH paths for this config.
*/
public void setPaths(String[] paths)
{
this.paths = paths;
}
/**
* Get the {@link #paths}.
*
* @return See above.
*/
public String[] getPaths()
{
return paths;
}
/**
* Get the profile's file-list.
*
* @return The {@link #fileList}.
*/
Set<String> getFileList()
{
return fileList;
}
/**
* Set the profile's file-list.
*
* @param fl
* The file-list associated with the {@link #fileSet}.
*/
void setFileList(Set<String> fl)
{
fileList = fl;
}
}