public class NameConverterWorker.Library
extends java.lang.Object
Constructor and Description |
---|
Library() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
convert(java.lang.String name,
int type)
Convert the given name using the specified conversion type and using
all defaults.
|
java.lang.String |
convert(java.lang.String name,
int type,
int phrases,
boolean replace,
java.lang.String detail,
java.lang.Object[] pairs)
Convert the given name using the specified conversion type.
|
java.lang.String |
convert(java.lang.String name,
int type,
java.lang.String detail,
java.util.Map replacements)
Convert the given name using the specified conversion type and
phrase map.
|
java.lang.String |
convert(java.lang.String name,
int type,
java.lang.String detail,
java.lang.Object[] pairs)
Convert the given name using the specified conversion type.
|
java.lang.String |
convertPackage(java.lang.String pkg)
Lowercase and split the input into individual package names, then ensure that each
one is not a conflict with a Java reserved word.
|
java.lang.String |
generateBeanName(java.lang.String field,
boolean getter,
boolean bool)
Create a (mostly) Java-bean compatible getter or setter name for a
given field.
|
boolean |
generateReport(java.lang.String filename)
Generate a name conversion report and write it to the specified
file.
|
void |
resetDialects(java.lang.String schema)
Reset the reserved keyword exclusion list.
|
void |
setReportMode(boolean enable)
Turn automatic name conversion report mode on or off.
|
public void resetDialects(java.lang.String schema)
schema
. The NameConverter
will lookup in
p2j.cfg.xml
for the schema name and use the getReservedKeywords()
static
method of each defined P2JDialect
to create
the keyword exclusion list for each schema.
This method must be called for each processed database because each one can have its
own list of dialects, otherwise the generated schema won't be compatible with respective
dialects or the NameConverter
will impose unneeded constraints to identifiers
that matched keywords from other dialects.schema
- The schema whose dialects are used for configuring the keyword compatibility
list.public java.lang.String convert(java.lang.String name, int type)
name
- Symbol name to be converted.type
- Type of symbol conversion to be applied to
name
. Must be one of the MatchPhraseConstants
constants.public java.lang.String convert(java.lang.String name, int type, java.lang.String detail, java.lang.Object[] pairs)
name
- Symbol name to be converted.type
- Type of symbol conversion to be applied to
name
. Must be one of the MatchPhraseConstants
constants.detail
- Optional, additional information to association with this
conversion in the conversion report. May be
null
. Ignored if not in reporting mode.pairs
- An even number of strings which represent key/value pairs.
These pairs are used to add to or override existing match
phrase replacement entries, including those provided by
any hints. If empty, only the default entries and those
provided by hints are used.public java.lang.String convert(java.lang.String name, int type, java.lang.String detail, java.util.Map replacements)
replacements
are in addition
to the default conversion phrases, and may override defaults.name
- Symbol name to be converted.type
- Type of symbol conversion to be applied to
name
. Must be one of the MatchPhraseConstants
constants.detail
- Optional, additional information to association with this
conversion in the conversion report. May be
null
. Ignored if not in reporting mode.replacements
- Replacement phrase mappings, where the key is the match
text, and the value is the replacement text. If
null
or empty, only the default phrases are
used.public java.lang.String convert(java.lang.String name, int type, int phrases, boolean replace, java.lang.String detail, java.lang.Object[] pairs)
name
- Symbol name to be converted.type
- Type of symbol conversion to be applied to
name
. Must be one of the MatchPhraseConstants
TYPE_*
constants.phrases
- A bitwise-OR'd combination of MatchPhraseConstants
flags indicating which set of default match phrase entries
to load from the project-specific match phrase dictionary.replace
- If true
, any token from the match phrase
entries defined by phrases
which is found
within name
is replaced with its designated
replacement string. If false
, only tokens
from the standard entries (if phrases
includes the constant STANDARD
) are replaced.
All other tokens are recognized as separate syllables,
but are not replaced.detail
- Optional, additional information to association with this
conversion in the conversion report. May be
null
. Ignored if not in reporting mode.pairs
- An even number of strings which represent key/value pairs.
These pairs are used to add to or override existing match
phrase replacement entries, including those provided by
any hints. If empty, only the default entries and those
provided by hints are used.public java.lang.String convertPackage(java.lang.String pkg)
pkg
- A candidate Java package name, possibly including multiple period-separated
directories.public java.lang.String generateBeanName(java.lang.String field, boolean getter, boolean bool) throws java.lang.IllegalArgumentException
boolean
and a getter is
requested, then the prefix will be "is", otherwise getters are prefixed
with "get". All setters are prefixed with "set". The name of the
field always has its first character uppercased which is slightly
different than how Sun defines the standard.field
- The name to use as the basis, must be non-null and non-empty.getter
- If true
the resulting bean name will be a
getter.bool
- If getter
is true
and this is
true
then the resulting bean name will prefixed
with "is" instead of "get". Ignored for setters.java.lang.IllegalArgumentException
- If the field name is null
or is the empty
string.public void setReportMode(boolean enable)
post-rule
. Actual report generation
is triggered with a call to the generateReport(java.lang.String)
user
function.
Report mode is disabled by default when this pattern worker is first created.
enable
- true
to enable report mode; false
to disable it.public boolean generateReport(java.lang.String filename) throws java.io.IOException
setReportMode(boolean)
user function previous to name
conversion. All names converted from the time report mode was
enabled to the time this method is called are included in the
report.filename
- Report destination filename. If not an absolute path, it
is considered relative to the working directory (i.e.,
no P2J_HOME normalization is performed).true
if report mode is enabled, else
false
.java.io.IOException
- if any I/O errors occur while persisting the report.