public final class SchemaConfig
extends java.lang.Object
Configuration
reading input data from an XML
configuration file. The syntax of that XML file is specified external to this class. The
purpose of this class is to store and provide access to the configuration. How that
configuration is read is not of concern here.
Each database used by an application is configured in an XML element in the configuration file.
That element contains a short name or handle for the database, which matches the logical name
of the database. It also contains a path to the DF file exported from the Progress data
dictionary (the import file from our perspective), as well as the XML file to which the
imported schema information will be written for use in conversion (the schema file). Finally, a
database can be a default database (always loaded into the schema dictionary when parsing
source code), or non-default (only loaded on demand by the Progress parser). All of this
information about a particular database is encoded in an instance of the NsConfig
inner class (which is public
since the external configuration reading process must
create instances of it). Those NsConfig
instances are then added using addNamespace(com.goldencode.p2j.schema.SchemaConfig.NsConfig)
.
One database is designated the "metadata" database. This is the database which contains
metadata about the schema structure used to define all databases in Progress (for a specific
version of Progress). The tables and fields of this database are referenced in source code as
if they were members of every other logical database. Thus, the schema information included in
the metadata database schema is merged with each logical database as it is loaded into the
schema dictionary. The metadata schema configuration is accessible via the getMetadata()
method.
SchemaLoader
,
SchemaDictionary
Modifier and Type | Class and Description |
---|---|
static class |
SchemaConfig.Metadata
Encapsulates information about the project's use of database metadata, including the name of
the metadata schema and the metadata tables used by the application, if any.
|
static class |
SchemaConfig.NsConfig
Encapsulates information about a namespace configuration, including name, XML file, and whether
namespace should be loaded into the schema dictionary by default.
|
static class |
SchemaConfig.Profile
An immutable structure which holds information about a single configuration profile.
|
Modifier and Type | Field and Description |
---|---|
private SchemaConfig.Profile |
defaultProfile
This is the default profile when the configuration is queried.
|
private static boolean |
developerModeWarned
Flag used for simplify the log by avoiding multiple messages for trying developing mode search.
|
private static java.util.logging.Logger |
log
Logger for objects of this type.
|
private SchemaConfig.Metadata |
metadata
Name of metadata definition applied to every loaded schema
|
private java.lang.String |
primaryKeyName
Primary key name, hardcoded the same as
Session.DEFAULT_PK |
private java.util.Map<java.lang.String,SchemaConfig.Profile> |
profiles
Map of database names to namespace configuration data.
|
private SchemaConfig.Profile |
unnamedProfile
This is the unnamed profile.
|
Constructor and Description |
---|
SchemaConfig()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addNamespace(SchemaConfig.NsConfig cfg)
Add a namespace configuration object to the default profile configuration.
|
void |
addNamespace(java.lang.String profile,
SchemaConfig.NsConfig cfg)
Add a namespace configuration object to a specific profile configuration.
|
void |
addProfile(SchemaConfig.Profile p)
Add a profile object to this configuration.
|
java.util.Iterator<java.lang.String> |
databases()
Get an iterator for the configured database names of default profile.
|
java.util.Iterator<java.lang.String> |
databases(java.lang.String profile)
Get an iterator for the configured database names of the requested profile.
|
java.util.Iterator<java.lang.String> |
defaultDatabases()
Get an iterator of names of those databases which have been configured as default schemas for namespace
lookup purposes.
|
java.util.Iterator<java.lang.String> |
defaultDatabases(java.lang.String profile)
Get an iterator of names of those databases which have been configured as default schemas for namespace
lookup purposes.
|
private SchemaConfig.Profile |
getDefaultProfile()
Returns the default profile.
|
java.io.File |
getImportFile(java.lang.String nsName)
Returns a file object representing the import (DF) file associated with the specified database schema
name of the default profile.
|
java.io.File |
getImportFile(java.lang.String profile,
java.lang.String nsName)
Returns a file object representing the import (DF) file associated with the specified database schema
name in a specific profile.
|
SchemaConfig.Metadata |
getMetadata()
Get the metadata identifier name associated with all schemas.
|
java.lang.String |
getNamespaceParameter(java.lang.String name,
java.lang.String param)
Get the value for the given namespace parameter in the default profile.
|
java.lang.String |
getNamespaceParameter(java.lang.String profile,
java.lang.String name,
java.lang.String param)
Get the value for the given namespace parameter in the specific profile.
|
java.lang.String |
getPrimaryKeyName()
Get the name of the surrogate primary key column used by the current project.
|
private SchemaConfig.Profile |
getProfile(java.lang.String profile,
boolean read)
Obtain a profile based on its name.
|
java.io.File |
getSchemaFile(java.lang.String nsName,
java.lang.String type)
Returns a file object representing the XML document associated with the specified database schema name
of the default profile.
|
java.io.File |
getSchemaFile(java.lang.String profile,
java.lang.String nsName,
java.lang.String type)
Returns a file object representing the XML document associated with the specified database schema name
of the specific profile.
|
java.lang.String |
getSchemaFileName(java.lang.String nsName,
java.lang.String type)
Returns path to the resource representing the XML document associated with the specified
database schema name in the default profile.
|
java.lang.String |
getSchemaFileName(java.lang.String profile,
java.lang.String nsName,
java.lang.String type)
Returns path to the resource representing the XML document associated with the specified database schema
name in the requested profile.
|
java.lang.String |
getSchemaResource(java.lang.String nsName,
java.lang.String type)
Returns path to the resource representing the XML document associated with the specified
database schema name in the default profile.
|
java.lang.String |
getSchemaResource(java.lang.String profile,
java.lang.String nsName,
java.lang.String type)
Returns path to the resource representing the XML document associated with the specified database schema
name in the requested profile.
|
java.util.List<java.lang.String> |
getSchemas(boolean omitMeta)
Get a list of schema names of the default profile, optionally omitting the name of the metadata schema.
|
java.util.List<java.lang.String> |
getSchemas(java.lang.String profile,
boolean omitMeta)
Get a list of schema names, optionally omitting the name of the metadata schema.
|
boolean |
isMetadataActive()
Determine whether metadata is active for the current application.
|
boolean |
isPreferred(java.lang.String nsName)
Reports whether the database should be preferred in cases where its entities are involved in
ambiguous name conflicts.
|
boolean |
isPreferred(java.lang.String profile,
java.lang.String nsName)
Reports whether the database should be preferred in cases where its entities are involved in
ambiguous name conflicts.
|
void |
setDefaultProfile(java.lang.String profileName)
Sets the default configuration profile to be used during this process.
|
void |
setMetadata(SchemaConfig.Metadata metadata)
Name of metadata definition applied to every loaded schema.
|
void |
setPrimaryKeyName(java.lang.String primaryKeyName)
Set the name of the surrogate primary key name, overriding the default name of
recid . |
java.lang.String |
toString()
Returns a string representation of this
SchemaConfig 's object graph. |
private static final java.util.logging.Logger log
private static boolean developerModeWarned
private SchemaConfig.Metadata metadata
private final java.util.Map<java.lang.String,SchemaConfig.Profile> profiles
private final SchemaConfig.Profile unnamedProfile
schema
node.
This is the best configuration in a single profile configuration. Also, if there are some namespaces
defined here and no other profiles was marked as default otherwise, this will become the default
profile.private SchemaConfig.Profile defaultProfile
private java.lang.String primaryKeyName
Session.DEFAULT_PK
public boolean isMetadataActive()
true
if the application uses metadata, else false
.public SchemaConfig.Metadata getMetadata()
public void setMetadata(SchemaConfig.Metadata metadata)
metadata
- Metadata definition name.public java.lang.String getPrimaryKeyName()
public void setPrimaryKeyName(java.lang.String primaryKeyName)
recid
.primaryKeyName
- New surrogate primary key name.public java.util.List<java.lang.String> getSchemas(boolean omitMeta)
omitMeta
- true
to omit the metadata schema, false
to include it.public java.util.List<java.lang.String> getSchemas(java.lang.String profile, boolean omitMeta)
profile
- The profile to be processed.omitMeta
- true
to omit the metadata schema, false
to include it.public java.util.Iterator<java.lang.String> databases()
public java.util.Iterator<java.lang.String> databases(java.lang.String profile)
profile
- The profile to be processed. If null
the default profile will be used.public java.util.Iterator<java.lang.String> defaultDatabases()
SchemaDictionary
object
at construction.public java.util.Iterator<java.lang.String> defaultDatabases(java.lang.String profile)
SchemaDictionary
object
at construction.profile
- The profile to be processed. If null
the default profile will be used.public void setDefaultProfile(java.lang.String profileName)
SchemaConfig
which do not have the profile as parameter as the default referrer.
It is illegal to call this method twice during a process runtime. It is illegal to call this method
after the object has already accessed with default getters. If this method was not called, when a
default getter is invoked, a defaultProfile
is selected automatically using the algorithm
described in getDefaultProfile()
.
profileName
- The name of the profile to be set as default.public void addProfile(SchemaConfig.Profile p)
p
- The new profile object.public void addNamespace(SchemaConfig.NsConfig cfg)
cfg
- Namespace configuration object.public void addNamespace(java.lang.String profile, SchemaConfig.NsConfig cfg)
profile
- The profile to be processed. If null
the default profile will be used.cfg
- Namespace configuration object.public java.io.File getImportFile(java.lang.String nsName) throws ConfigurationException
nsName
- Name of desired namespace configurationConfigurationException
- if environment has not been configured correctly.public java.io.File getImportFile(java.lang.String profile, java.lang.String nsName) throws ConfigurationException
profile
- The profile to be processed. If null
the default profile will be used.nsName
- Name of desired namespace configurationConfigurationException
- if environment has not been configured correctly.public java.io.File getSchemaFile(java.lang.String nsName, java.lang.String type) throws ConfigurationException
nsName
- Name of desired namespace configurationtype
- the type of resource (the file extension, including the dot).ConfigurationException
- if environment has not been configured correctly.public java.io.File getSchemaFile(java.lang.String profile, java.lang.String nsName, java.lang.String type) throws ConfigurationException
profile
- The profile to be processed. If null
the default profile will be used.nsName
- Name of desired namespace configurationtype
- the type of resource (the file extension, including the dot).ConfigurationException
- if environment has not been configured correctly.public java.lang.String getSchemaFileName(java.lang.String nsName, java.lang.String type)
nsName
- Name of desired namespace configurationtype
- the type of resource (the file extension, including the dot).null
if the resource
doesn't exist.public java.lang.String getSchemaFileName(java.lang.String profile, java.lang.String nsName, java.lang.String type)
profile
- The profile to be processed. If null
the default profile will be used.nsName
- Name of desired namespace configurationtype
- the type of resource (the file extension, including the dot).null
if the resource
doesn't exist.public java.lang.String getSchemaResource(java.lang.String nsName, java.lang.String type)
nsName
- Name of desired namespace configurationtype
- the type of resource (the file extension, including the dot).null
if the resource
doesn't exist.public java.lang.String getSchemaResource(java.lang.String profile, java.lang.String nsName, java.lang.String type)
profile
- The profile to be processed. If null
the default profile will be used.nsName
- Name of desired namespace configurationtype
- the type of resource (the file extension, including the dot).null
if the resource
doesn't exist.public boolean isPreferred(java.lang.String nsName)
nsName
- Name of desired namespace configurationtrue
if the database is preferred.public boolean isPreferred(java.lang.String profile, java.lang.String nsName)
profile
- The profile to be processed. If null
the default profile will be used.nsName
- Name of desired namespace configurationtrue
if the database is preferred.public java.lang.String getNamespaceParameter(java.lang.String name, java.lang.String param)
name
- The namespace name.param
- The parameter name or path.null
if name
or param
are invalid.public java.lang.String getNamespaceParameter(java.lang.String profile, java.lang.String name, java.lang.String param)
profile
- The profile to be processed. If null
the default profile will be used.name
- The namespace name.param
- The parameter name or path.null
if name
or param
are invalid.public java.lang.String toString()
SchemaConfig
's object graph.toString
in class java.lang.Object
Object.toString()
private SchemaConfig.Profile getDefaultProfile()
default
attribute set;unnamed
profile if not empty. The unnamed profile is the profile
composed from the namespaces located directly in schema
tag, at the same level with the
other named profile
-s. In case there are no named profiles, this cause the unnamed
profile to be the default, naturally matching the old configuration files where profiles were not
supported (backward compatibility); unnamed
profilenull
.private SchemaConfig.Profile getProfile(java.lang.String profile, boolean read)
profile
- The name of the profile to be returned. If null
, the unnamed profile is returned.read
- Use true
is the configuration is read from file, during the SchemaConfig
construction. Use false
when accessing from a getter.