public class SourceNameMapper
extends java.lang.Object
The mapping data is loaded from the directory into data structures that
are static
. This means that at this time this mapping data
is global to the entire server rather than being context-local. The
reason for this is to reduce the amount of memory used for this data
since 2+ map entries exist for each original source file (thus these maps
each contain thousands of entries for any reasonably sized
application).
The current implementation assumes a single root path for all Progress procedure file names and single base package path for the generated Java classes. Despite these assumptions it is possible to translate Progress procedure names incorrectly (to a Java class name which does not belong to the subtree specified by the single root or which does not belong to the base package path). These problems are caused by using mismatching absolute paths for Progress names or names which start with a dot ('.') for Java class names. The leading dot is stripped from the returned class name and is not returned as a result of a mapping.
The source file name can be in one of the many forms: relative path, absolute path, can contain references to current and to upper level directories. Also, the source file name can use the file naming format of the original operating system used to run the Progress program rather than the current operating system used to run the converted Java application. To this the directory contains values that define the original source system's parameters such as path delimiter, file name delimiter and case sensitivity.
Modifier and Type | Class and Description |
---|---|
private static class |
SourceNameMapper.ExternalProgram
Container for all external program information.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ATTR_JNAME
Java name attribute.
|
private static java.lang.String |
ATTR_LIBNAME
LIBNAME attribute.
|
private static java.lang.String |
ATTR_MAP_TO
MAP-TO attribute.
|
private static java.lang.String |
ATTR_PARAM_MODE
Parameter MODE attribute.
|
private static java.lang.String |
ATTR_PNAME
Progress name attribute.
|
private static java.lang.String |
ATTR_TYPE
TYPE attribute.
|
private static boolean |
caseSens
Case sensitivity flag for the Progress file name data.
|
private static java.lang.String |
custpkgroot
Custom package to init data for.
|
private static java.lang.String |
ELEM_CMAP
Class mappings element.
|
private static java.lang.String |
ELEM_MMAP
Methods mappings element.
|
private static java.lang.String |
ELEM_PARAM
Parameter info element.
|
private static java.lang.String |
fileSep
Name element separator used for the Progress file name data.
|
private static java.util.Map<java.lang.String,SourceNameMapper.ExternalProgram> |
j2pMap
Progress Java class name to procedure file name map table.
|
private static java.lang.String[] |
legacyRoots
The 4GL legacy roots for source files.
|
private static java.util.Map<java.lang.String,SourceNameMapper.ExternalProgram> |
p2jMap
Progress procedure file name to Java class name map table.
|
private static java.lang.String |
pathSep
Path separator used for the Progress file name data.
|
private static java.lang.String |
pkgroot
Base path for all Java packages.
|
private static java.lang.String |
proroot
Base path for Progress 4GL code.
|
private static java.lang.String |
PUBLISHED_EVENTS
Named events attribute.
|
Constructor and Description |
---|
SourceNameMapper() |
Modifier and Type | Method and Description |
---|---|
private static java.lang.String |
addPkg(java.lang.String name)
Construct a full class name (including packages) for the stored package
root and the given class name.
|
private static SourceNameMapper.ExternalProgram |
buildExternalProgram(java.lang.String pname,
java.lang.String jname,
org.w3c.dom.Element classMap)
Collect the
SourceNameMapper.ExternalProgram info contained in the classMap
node. |
private static java.lang.String |
buildInternalEntries(SourceNameMapper.ExternalProgram extProg,
boolean prv)
Build the internal-entries 4GL attribute for the given external program.
|
private static InternalEntry |
buildMethod(java.lang.String pname,
java.lang.String jname,
org.w3c.dom.Element methMap)
Collect the
InternalEntry info contained in the methMap node. |
private static void |
buildParameters(org.w3c.dom.Element node,
InternalEntry ie)
Build the parameters for the specified internal entry.
|
private static java.lang.String |
canonicalize(java.lang.String progName)
Convert the given Progress file name into a simple relative path
form.
|
static java.lang.String |
convertJavaMethod(java.lang.String clsName,
java.lang.String methodName,
boolean function)
Convert a java method name to a legacy name.
|
static java.lang.String |
convertJavaProg(java.lang.String jname)
Get the legacy 4gL name for the Java class name.
|
static java.lang.String |
convertJavaProg(java.lang.String customRoot,
java.lang.String jname)
Get the legacy 4gL name for the Java class name.
|
static java.lang.String |
convertJavaProgSafe(java.lang.String jname)
Get the legacy 4gL name for the Java class name or, if not a legacy program, return the
java class name, without the base package.
|
private static java.lang.String[] |
convertName(java.lang.String legacyProgName)
Convert a Progress file name into Java class name.
|
static java.lang.String |
convertNameToClass(java.lang.String legacy)
Uses the
convertName(String) worker for finding the name of the Java class name of
a converted P4GL procedure name. |
static int |
getExtentForParam(java.lang.String pname,
java.lang.String iename,
boolean func,
int param)
Get the extent of the parameter at 0-based position (for the given internal entry).
|
static java.lang.String |
getInternalEntries(java.lang.String pname,
boolean prv)
Get the internal-entries attribute of the given external procedure.
|
static InternalEntry |
getInternalEntry(java.lang.String pname,
java.lang.String iename,
boolean func)
Helper function to obtain the Java object that holds the state of a single internal entry.
|
static java.lang.String |
getLibraryName(java.lang.String pname,
java.lang.String iename)
Get the library name attribute of the given internal-entry.
|
static java.lang.String |
getMapTo(java.lang.String pname,
java.lang.String ieName)
Get the map-to attribute of the passed internal-entry.
|
static java.lang.String |
getMethodName(java.lang.String pname,
java.lang.String ieName,
boolean function)
Get the java name of the passed internal-entry and 4GL program.
|
private static Parameter |
getParameter(java.lang.String pname,
java.lang.String iename,
boolean func,
int param)
Private utility method for locating a parameter of a routine.
|
static java.lang.String |
getParameterModes(java.lang.String pname)
Get the string representation of the parameter modes for this external
procedure.
|
static java.lang.String |
getParameterModes(java.lang.String pname,
java.lang.String ieName,
boolean function)
Get the string representation of the parameter modes for this internal
entry.
|
static java.util.List<Parameter> |
getParameters(java.lang.String pname,
java.lang.String ieName,
boolean function)
Get the parameters for this internal entry.
|
static java.lang.String |
getPublishedEvents(java.lang.String pname)
Get the published named events by the specified procedure.
|
static java.lang.String |
getSignature(java.lang.String pname,
java.lang.String ieName)
Get the 4GL-style signature of the given internal-entry.
|
static java.lang.Class |
getTypeForParam(java.lang.String pname,
java.lang.String iename,
boolean func,
int param)
Get the type/class of the parameter at 0-based position (for the given internal entry).
|
private static void |
initMappingData()
This method loads all mapping data from a URL which is calculated
using the
pkgroot and the name_map.xml with
all "." characters converted to file separators and an extra file
separator added before the file name portion. |
static boolean |
isFunction(java.lang.String pname,
java.lang.String iename)
Check if the specified internal-entry is a function.
|
static boolean |
isInHandle(java.lang.String pname,
java.lang.String iename,
boolean function)
Check if the specified internal-entry is defined IN handle.
|
static boolean |
isPrivate(java.lang.String pname,
java.lang.String iename,
boolean function)
Check if the specified internal-entry is defined PRIVATE.
|
static boolean |
isSuper(java.lang.String pname,
java.lang.String iename,
boolean function)
Check if the specified internal-entry is defined IN SUPER.
|
static java.lang.String |
lookupLegacyName(java.lang.String legacy)
Uses the
convertName(String) worker for detecting the if the legacy is a
name of a converted legacy procedure. |
static java.lang.String |
normalizeLegacyName(java.lang.String legacy)
Normalize the given legacy external program name, considering the
caseSens state. |
static void |
overwriteMappingData(java.util.Map<java.lang.String,SourceNameMapper.ExternalProgram> p2jMap,
java.util.Map<java.lang.String,SourceNameMapper.ExternalProgram> j2pMap,
java.lang.String pkgroot,
java.lang.String proroot,
java.lang.String fileSep,
java.lang.String pathSep,
boolean caseSens)
This method loads all mapping data from an external source.
|
private static java.lang.String |
removePkg(java.lang.String name)
Remove the package prefix from the given class name.
|
private static final java.lang.String ELEM_CMAP
private static final java.lang.String ELEM_MMAP
private static final java.lang.String ELEM_PARAM
private static final java.lang.String ATTR_PNAME
private static final java.lang.String ATTR_JNAME
private static final java.lang.String ATTR_TYPE
private static final java.lang.String ATTR_LIBNAME
private static final java.lang.String ATTR_MAP_TO
private static final java.lang.String ATTR_PARAM_MODE
private static final java.lang.String PUBLISHED_EVENTS
private static volatile java.util.Map<java.lang.String,SourceNameMapper.ExternalProgram> p2jMap
private static java.util.Map<java.lang.String,SourceNameMapper.ExternalProgram> j2pMap
private static java.lang.String[] legacyRoots
private static java.lang.String pkgroot
private static java.lang.String custpkgroot
private static java.lang.String proroot
private static java.lang.String fileSep
private static java.lang.String pathSep
private static boolean caseSens
public static java.lang.String convertJavaProg(java.lang.String jname)
jname
- The external-program's converted java name.null
if the given java
program is not registered in name_map.xml.public static java.lang.String convertJavaProgSafe(java.lang.String jname)
jname
- A java class name which may or may not be associated with a legacy 4GL program.public static java.lang.String convertJavaProg(java.lang.String customRoot, java.lang.String jname)
jname
- The external-program's converted java name.customRoot
- Custom root package name.null
if the given java
program is not registered in name_map.xml.public static java.lang.String convertJavaMethod(java.lang.String clsName, java.lang.String methodName, boolean function)
clsName
- The class name where the method is defined.methodName
- The method's name.function
- Flag indicating that this method maps a legacy function (when true)
or
procedure (when false
).null
if not found.public static java.lang.String normalizeLegacyName(java.lang.String legacy)
caseSens
state.legacy
- The legacy name to be normalizedpublic static java.lang.String convertNameToClass(java.lang.String legacy)
convertName(String)
worker for finding the name of the Java class name of
a converted P4GL procedure name.legacy
- Progress file name.null
is returned.public static java.lang.String lookupLegacyName(java.lang.String legacy)
convertName(String)
worker for detecting the if the legacy
is a
name of a converted legacy procedure. In affirmative case, the normalized name of the
procedure filename is returned.legacy
- Progress file name.null
is
returned.public static void overwriteMappingData(java.util.Map<java.lang.String,SourceNameMapper.ExternalProgram> p2jMap, java.util.Map<java.lang.String,SourceNameMapper.ExternalProgram> j2pMap, java.lang.String pkgroot, java.lang.String proroot, java.lang.String fileSep, java.lang.String pathSep, boolean caseSens)
p2jMap
- Progress procedure file name to Java class name map table.j2pMap
- Progress Java class name to procedure file name map table.pkgroot
- Base path for all Java packages.proroot
- Base path for 4GL code.fileSep
- Name element separator used for the Progress file name data.pathSep
- Path separator used for the Progress file name data.caseSens
- Case sensitivity flag for the Progress file name data.public static java.lang.String getMethodName(java.lang.String pname, java.lang.String ieName, boolean function)
pname
- Legacy 4GL program name.ieName
- Legacy internal-entry name.function
- true
if the search is for a user-defined
function.null
public static java.lang.String getMapTo(java.lang.String pname, java.lang.String ieName)
pname
- Legacy 4GL program name.ieName
- Legacy internal-entry name.null
if the ATTR_MAP_TO
does not exist or the internal
entry does not resolve to a function.public static java.lang.String getLibraryName(java.lang.String pname, java.lang.String iename)
pname
- Legacy 4GL program name.iename
- Legacy internal-entry name.null
.public static java.lang.String getParameterModes(java.lang.String pname)
pname
- Legacy 4GL program name.public static java.lang.String getParameterModes(java.lang.String pname, java.lang.String ieName, boolean function)
pname
- Legacy 4GL program name.ieName
- Legacy internal-entry name. If null or the empty string, the
external procedure's parameters are used.function
- true
if this is a function call.public static java.util.List<Parameter> getParameters(java.lang.String pname, java.lang.String ieName, boolean function)
pname
- Legacy 4GL program name.ieName
- Legacy internal-entry name. If null or the empty string, the
external procedure's parameters are used.function
- true
if this is a function call.public static java.lang.String getSignature(java.lang.String pname, java.lang.String ieName)
null
.pname
- Legacy 4GL program name.ieName
- Legacy internal-entry name.public static java.lang.String getInternalEntries(java.lang.String pname, boolean prv)
null
.pname
- Legacy 4GL program name.prv
- Flag to include or not the private members.public static java.lang.String getPublishedEvents(java.lang.String pname)
pname
- Legacy 4GL program name.public static int getExtentForParam(java.lang.String pname, java.lang.String iename, boolean func, int param)
pname
- Legacy 4GL program name.iename
- Legacy internal-entry name.func
- Flag indicating if this is a function or a procedure.param
- 0-based index of the parameter to be checked.public static java.lang.Class getTypeForParam(java.lang.String pname, java.lang.String iename, boolean func, int param)
pname
- Legacy 4GL program name.iename
- Legacy internal-entry name.func
- Flag indicating if this is a function or a procedure.param
- 0-based index of the parameter to be checked.null
if parameters do not point
to a valid parameter.public static boolean isSuper(java.lang.String pname, java.lang.String iename, boolean function)
false
.pname
- Legacy 4GL program name.iename
- Legacy internal-entry name.function
- Flag indicating if this is a function or a procedure.public static boolean isFunction(java.lang.String pname, java.lang.String iename)
false
.pname
- Legacy 4GL program name.iename
- Legacy internal-entry name.public static boolean isPrivate(java.lang.String pname, java.lang.String iename, boolean function)
false
.pname
- Legacy 4GL program name.iename
- Legacy internal-entry name.function
- Flag indicating if this is a function or a procedure.public static boolean isInHandle(java.lang.String pname, java.lang.String iename, boolean function)
false
.pname
- Legacy 4GL program name.iename
- Legacy internal-entry name.function
- Flag indicating if this is a function or a procedure.public static InternalEntry getInternalEntry(java.lang.String pname, java.lang.String iename, boolean func)
pname
- Legacy 4GL program name (the external procedure).iename
- Legacy internal-entry name.func
- true
if the search should be for a function.null
if the external procedure does not exist
or if the external procedure has no such internal entry.private static java.lang.String[] convertName(java.lang.String legacyProgName)
canonicalize(java.lang.String)
.
A simple lookup is tried first. If this fails direct check for absolute path if attempted
using one of the roots from legacyRoots
. In multiple project scenario, the project
name is also added as a path token in order o match the structure from name_map.xml
.
If these mapping does not exist then each path segment of the PROPATH is tried in order. The given program name is check to see if it is prefixed with the PROPATH segment, if so that prefix is removed and a lookup is done with this name. The first match found ends the search.
Absolute paths are converted into relative paths based on the existence of a matching path
in the legacy PROPATH (see EnvironmentOps.getLegacySearchPath()
). To handle additional
absolute paths, one must add the appropriate path prefix to the legacy PROPATH and it will
be removed here.
This same PROPATH processing is how names relative to the current directory can be handled. This is the only way to handle that case since the current directory in the source system is runtime information that is not available here.
The legacy PROPATH is the key configuration tool by which one specifies to this method how to remove absolute and current directory relative prefixes. This means that the legacy PROPATH that is used here may need to be different than the PROPATH on the original system.
As a fallback, if no mapping can be found and if the given progName
is a fully
qualified Java class name which references a valid Java class, then the progName
is
returned unchanged.
In Windows it can verify the absolute or relative program name is in current PROPATH directory set. This allows to properly map the following program names used in PROGRESS RUN statement: "c:/path/to/project/stcases/uast/rundir/absolute/program.p" "rundir/../../uast/rundir/relative/test11.p." "../uast/rundir/relative/test5.p"
legacyProgName
- Progress file name.String
array with two components: Java class name for the given Progress
file name as first element and the legacy procedure name in second element of the
array. If no appropriate mapping is present null
is returned.private static Parameter getParameter(java.lang.String pname, java.lang.String iename, boolean func, int param)
pname
- Legacy 4GL program name.iename
- Legacy internal-entry name.func
- Flag indicating if this is a function or a procedure.param
- 0-based index of the parameter to be checked.null
if parameters do not point to a valid
parameter.private static void initMappingData()
pkgroot
and the name_map.xml
with
all "." characters converted to file separators and an extra file
separator added before the file name portion. This URL is expected to
be found in the application's JAR file. Note that this will silently
return if the mapping data is not found. Any file system configuration
data will be read from the directory via the EnvironmentOps
helper.private static SourceNameMapper.ExternalProgram buildExternalProgram(java.lang.String pname, java.lang.String jname, org.w3c.dom.Element classMap)
SourceNameMapper.ExternalProgram
info contained in the classMap
node.pname
- The legacy 4GL program name.jname
- The converted class name.classMap
- The DOM node containing the info for this external program.SourceNameMapper.ExternalProgram
instance for this DOM node.private static InternalEntry buildMethod(java.lang.String pname, java.lang.String jname, org.w3c.dom.Element methMap)
InternalEntry
info contained in the methMap
node.pname
- The legacy 4GL internal-entry name.jname
- The converted internal-entry name.methMap
- The DOM node containing the info for this internal-entry.InternalEntry
instance for this DOM node.private static void buildParameters(org.w3c.dom.Element node, InternalEntry ie)
node
- The current node from where the parameters are read.ie
- The internal entry where to save the parameters.private static java.lang.String buildInternalEntries(SourceNameMapper.ExternalProgram extProg, boolean prv)
extProg
- The SourceNameMapper.ExternalProgram
instance.prv
- Flag to include or not the private members.private static java.lang.String canonicalize(java.lang.String progName)
.
and ..
are
processed. Empty path elements are removed.
If caseSens
is false, the program name is lower-cased.
progName
- Input name.private static java.lang.String addPkg(java.lang.String name)
name
- Class name.private static java.lang.String removePkg(java.lang.String name)
name
- Class name.