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 |
|---|---|
(package private) static class |
SourceNameMapper.ExternalProgram
Container for all external program information.
|
private static class |
SourceNameMapper.InternalEntryKey
Map key for internal entry objects.
|
private static class |
SourceNameMapper.LegacyClass
Container for all legacy class information.
|
private static class |
SourceNameMapper.MonitorRunnable
A custom Runnable class that monitors identifiers represented by the propath hash code used
by the
SourceNameMapper.MonitorRunnable.task to create a source cache entry. |
private static class |
SourceNameMapper.MultiPathLookup
A lookup class which stores multiple SinglePathLookup instances.
|
private static interface |
SourceNameMapper.PathLookup
This interface is implemented by classes which search for a program name
representing a Progress procedure file name that can be matched to
an existent map table of Java classes.
|
private static class |
SourceNameMapper.SinglePathLookup
A lookup class which stores possible paths of a program and can be used to retrieve
the same ExternalProgram for each of those paths.
|
private static class |
SourceNameMapper.SourceNameMapperCache
A cache class that contains the propath and a map of indexes for search-specs mapped to their
target procedures (the result obtained from
fastConvertName(String)). |
private static class |
SourceNameMapper.SourceThreadFactory
A thread factory class that is used to create AssociatedThread(s) for creating source cache entries.
|
private static class |
SourceNameMapper.WorkArea
Container for context-local data.
|
| Modifier and Type | Field and Description |
|---|---|
private static java.util.Set<java.lang.String> |
allowedLegacyExtensions
Set of file extensions that were found for all procedure file name nodes
|
private static java.lang.String |
altFileSep
Alternative name element separator used for the Progress file name data.
|
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_PATHNAME
Filename name attribute.
|
private static java.lang.String |
ATTR_PNAME
Progress name attribute.
|
private static java.lang.String |
ATTR_TYPE
TYPE attribute.
|
private static java.util.Map<java.lang.String,java.lang.Boolean> |
CLASS_LOOKUPS
Set of
Class.forName(java.lang.String) lookups by convertName(java.lang.String, com.goldencode.p2j.util.SourceNameMapper.WorkArea, java.lang.String[]) which resolve (or not) to a Java class for
the given program name. |
private static java.util.Map<java.lang.Class<?>,SourceNameMapper.LegacyClass> |
classMap
Association between converted legacy 4GL programs to their defined internal entries.
|
private static java.lang.String |
custpkgroot
Custom package to init data for.
|
private static java.util.regex.Pattern |
dblBackslashRegexp
Double backslash precompiled regular expression pattern
|
static int |
DYNAMIC_EXTENT
Constant identifying dynamic-extent parameters.
|
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 |
ELEM_PMAP
Path mappings element.
|
private static java.lang.String |
ELEM_REST_SERVICE
Rest service mappings element.
|
private static java.lang.String |
fileSep
Name element separator used for the Progress file name data.
|
private static char |
fileSepChar
Character form of fileSep
|
private static java.util.regex.Pattern |
fileSepRegexp
Regular expression pattern for fileSep field
|
private static java.util.Map<java.lang.String,java.lang.Integer> |
initializationPaths
Search-spec paths found during conversion and read from name_map.xml.
|
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 ContextLocal<SourceNameMapper.WorkArea> |
local
Context-local data.
|
private static CentralLogger |
LOG
Logger
|
private static java.util.concurrent.atomic.AtomicInteger |
MAPPING_COUNTER
Counter value that is used when adding new values to
initializationPaths. |
private static boolean |
mappingDataInitialized
Mapping data initialization completion indicator
|
private static boolean |
mappingDataInitInProgess
Mapping data initialization in progress indicator
|
private static java.util.concurrent.ExecutorService |
mappingExecutor
Executor for operations that build source cache entries.
|
private static java.lang.String |
NAME_MAP_FILE
The name of the file containing mappings.
|
static int |
NO_EXTENT
Constant identifying no-extent parameters.
|
private static java.lang.String |
OONAME
Qualified OO name attribute.
|
private static java.util.regex.Pattern |
OVERLOAD_SUFFIX
The overload suffix pattern used by
getOverloads(java.lang.Class<?>, java.lang.String). |
private static java.util.Map<java.lang.String,SourceNameMapper.ExternalProgram> |
p2jMap
Progress procedure file name to Java class name map table.
|
private static java.util.Map<java.lang.String,SourceNameMapper.ExternalProgram> |
p2jMap_ci
Progress procedure file name to Java class name map table (case-insensitive).
|
private static java.util.Map<java.lang.String,java.util.List<SourceNameMapper.ExternalProgram>> |
p2jNonExtMap
Map of program names without extension to the programs which can be resolved with this name.
|
private static java.util.Map<java.lang.String,java.util.List<SourceNameMapper.ExternalProgram>> |
p2jNonExtMap_ci
Map of program names without extension to the programs which can be resolved with this name (ci).
|
private static java.util.concurrent.atomic.AtomicInteger |
PATH_INIT_THREADS_COUNTER
Counter for the number of active threads populating
initializationPaths. |
private static java.util.Map<java.lang.String,java.lang.String> |
pathAliases
Map of aliases (r-code folders) to their source folders (conversion folders).
|
private static java.util.Map<java.lang.String,java.lang.String> |
pathAliases_ci
Map of aliases (r-code folders) to their source folders (conversion folders).
|
private static java.util.Map<java.lang.String,SourceNameMapper.PathLookup> |
pathLookups
Map of lookup instances for unqualified program names.
|
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.
|
private static LRUCache<java.lang.String,java.lang.String[][]> |
searchPathCache
Cache of searchPaths to a String array containing the resulted propath and originalPrograpth.
|
private static java.util.List<SourceNameMapper.ExternalProgram> |
servicePrograms
The list of programs exposed as services (the 'with-services' attribute or 'rest-service' nodes).
|
private static LRUCache<java.lang.Long,SourceNameMapper.SourceNameMapperCache> |
sourceCache
Cache of preprocessed mapped paths to target procedures.
|
private static java.lang.String |
WITH_SERVICES
'with-services' 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,
java.lang.String ooname,
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.
|
static InternalEntry |
buildInternalEntry(LegacySignature ls,
java.lang.reflect.Method jmeth)
Build an
InternalEntry matching the specified legacy signature. |
(package private) static InternalEntry |
buildInternalEntry(LegacySignature ls,
java.lang.String jname)
Build an
InternalEntry matching the specified legacy signature. |
(package private) static SourceNameMapper.LegacyClass |
buildLegacyClass(java.lang.Class<?> cls)
Build a legacy class entry by resolving all the legacy methods (marked with the
LegacySignature annotation) and register them. |
(package private) static void |
buildLegacyProgram(SourceNameMapper.ExternalProgram extprog)
Build a map of legacy method names to their Java
Method, 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 Parameter |
buildParameter(LegacyParameter lp)
Build a
Parameter instance from the specified LegacyParameter annotation. |
private static void |
buildParameters(org.w3c.dom.Element node,
InternalEntry ie)
Build the parameters for the specified internal entry.
|
static java.lang.String |
canonicalize(java.lang.String progName,
boolean caseSens)
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 |
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,
java.util.function.Function<java.lang.String,SourceNameMapper.ExternalProgram> lookup,
SourceNameMapper.WorkArea wa,
java.lang.String[] searchPaths)
Convert a Progress file name into Java class name.
|
private static java.lang.String[] |
convertName(java.lang.String legacyProgName,
SourceNameMapper.WorkArea wa)
Uses
convertName(String, WorkArea, String[]) with the PROPATH segments for the second parameter. |
private static java.lang.String[] |
convertName(java.lang.String legacyProgName,
SourceNameMapper.WorkArea wa,
java.lang.String[] searchPaths)
Convert a Progress file name into Java class name.
|
static java.lang.String |
convertNameToClass(java.lang.String legacy)
Uses the
fastConvertName(String) worker for finding the name of the Java class name of
a converted P4GL procedure name. |
static java.lang.String |
convertNameToClass(java.lang.String legacy,
boolean fastConvert)
Uses the
fastConvertName(String) or convertName(String, WorkArea, String[])
worker for finding the name of the Java class name of a converted P4GL procedure name. |
static java.lang.String |
convertNameToClass(java.lang.String legacy,
java.lang.String[] searchPaths)
Uses the
convertName(String, WorkArea, String[]) worker for finding the name of the Java class name of
a converted P4GL procedure name. |
static java.lang.String |
convertOOToClass(java.lang.String legacyClsName)
Convert a legacy 4GL class name to a converted Java class file.
|
private static void |
createSourceCacheEntry(java.lang.String[] propath,
java.lang.Long propathHash)
Creates a new SourceNameMapperCache for the given propath value using an
AssociatedThread in order to access the current context.
|
private static java.lang.String[] |
fastConvertName(java.lang.String legacyProgName)
Convert a Progress file name into Java class name.
|
private static java.lang.String[] |
fastConvertName(java.lang.String legacyProgName,
boolean avoidCache)
Convert a Progress file name into Java class name.
|
static InternalEntry |
findLegacyAccessor(java.lang.Class<?> type,
java.lang.String pname,
boolean getter,
boolean indexed)
Look into all the properties with the specified legacy name (in the given legacy type) and
return the getter or setter matching exactly the specified signature.
|
static java.lang.String |
findLegacyEntryName(java.lang.Class<?> type,
java.lang.String mname)
Given a converted class name, find the legacy name for a Java method defined in that program or legacy
class.
|
static InternalEntry |
findLegacyMethod(java.lang.Class<?> type,
java.lang.String pname,
InternalEntry signature)
Look into all the methods with the specified legacy name (in the given type) and return the
one matching exactly the specified signature.
|
static java.lang.Integer |
findLegacyPropertyExtent(java.lang.Class<?> type,
java.lang.String pname)
Find the property's extent, if it applies.
|
static java.lang.String |
getAbsolutePrefix(java.lang.String path)
Returns the absolute prefix for a given path if it has one, or null otherwise.
|
static java.util.List<InternalEntry> |
getConstructors(java.lang.Class<? extends _BaseObject_> type)
Get the list of defined constructors for the legacy type.
|
static java.util.List<InternalEntry> |
getDestructors(java.lang.Class<? extends _BaseObject_> type)
Get the destructor for the legacy type.
|
static java.lang.reflect.Method[] |
getExecuteMethods(java.lang.Class<? extends _BaseObject_> type)
Get
execute method names names for this legacy class and its hierarchy. |
static int |
getExtentForParam(java.lang.String pname,
InternalEntry ie,
java.lang.String iename,
boolean func,
int param)
Get the extent of the parameter at 0-based position (for the given internal entry).
|
private static SourceNameMapper.ExternalProgram |
getExternalProgram(java.lang.String pname)
Get the
SourceNameMapper.ExternalProgram of the given Legacy 4GL program name. |
static java.lang.String |
getFileSep()
Static getter for the file separator.
|
static java.util.Map<java.lang.String,java.util.List<InternalEntry>> |
getGetters(java.lang.Class<? extends _BaseObject_> type)
Get all GET functions of a given class; only the getters for the class are included (any super-class GET
function will not be included).
|
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.
|
private static boolean |
getLegacyCaseSensitive()
Worker to get the case-sensitivity from the legacy environment.
|
static java.lang.String |
getLegacyClassName(java.lang.String javaClassName)
Get the legacy 4gL class name for the Java class name.
|
private static java.lang.String |
getLegacyPathSeparator()
Worker to get the path separator from the legacy environment.
|
static java.lang.String |
getLegacySourceName(java.lang.String javaClassName)
Get the legacy 4gL name for the Java class name.
|
static java.lang.String |
getLegacySourceName(java.lang.String customRoot,
java.lang.String javaClassName)
Get the legacy 4GL name for the Java class name.
|
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.
|
static java.util.List<InternalEntry> |
getOverloads(java.lang.Class<?> type,
java.lang.String iename)
Get all the overloaded methods in the given legacy class, with the specified name,
and with name with possible _[0-9]+ suffix.
|
static java.util.List<InternalEntry> |
getOverrides(java.lang.Class<?> type,
java.lang.String iename)
Get all overloads of this method name; only the overrides of the methods are included (their super-class
definitions matching name and parameters will not be included).
|
static java.lang.String |
getPackageRoot()
Get the
package root. |
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,
InternalEntry ie,
java.lang.String ieName,
boolean function)
Get the string representation of the parameter modes for this internal
entry.
|
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,
InternalEntry ie,
java.lang.String ieName,
boolean function)
Get the parameters for this internal entry.
|
static java.lang.String[] |
getPropath()
Static getter for the array of Strings representing the propath paths.
|
static java.lang.String |
getPublishedEvents(java.lang.String pname)
Get the published named events by the specified procedure.
|
static java.util.Map<java.lang.String,java.util.List<InternalEntry>> |
getSetters(java.lang.Class<? extends _BaseObject_> type)
Get all SET functions of a given class; only the getters for the class are included (any super-class SET
function will not be included).
|
static java.lang.String |
getSignature(java.lang.String pname,
java.lang.String ieName)
Get the 4GL-style signature of the given internal-entry.
|
static InternalEntry |
getStaticConstructor(java.lang.Class<? extends _BaseObject_> type)
Get the static constructor for the legacy type.
|
static java.lang.Class |
getTypeForParam(java.lang.String pname,
InternalEntry ie,
java.lang.String iename,
boolean func,
int param)
Get the type/class of the parameter at 0-based position (for the given internal entry).
|
static boolean |
hasLegacyMethod(java.lang.Class<?> type,
java.lang.String pname)
Check if the given legacy class defines a method with a given name.
|
static void |
initialize()
Initialize all the maps - this can be time-consuming, as the legacy OO classes are initialized from the
Java annotations.
|
private static void |
initMappingData()
This method loads all mapping data from a URL which is calculated
using the
pkgroot and the NAME_MAP_FILE 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,
InternalEntry ie,
java.lang.String iename,
boolean function)
Check if the specified internal-entry is defined IN handle.
|
private static boolean |
isPathMappingInitialized()
Returns
true if all path mapping initializer threads have completed work,
false otherwise. |
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.
|
private static void |
loadPathAliases()
Load the path aliases from the directory, into the
pathAliases map. |
static java.lang.String |
lookupLegacyName(java.lang.String legacy)
Uses the
fastConvertName(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
SourceNameMapper.WorkArea.caseSens state. |
private static boolean |
populateClasses(org.w3c.dom.Element mapRootNode)
Resolves and populates in-memory the class mappings from the xml root node.
|
private static void |
populateInitPaths(org.w3c.dom.Element mapRootNode,
java.net.URL mapUrl)
Resolves and populates in-memory the initialization paths from the xml root node.
|
private static void |
populateInMemoryMaps(java.net.URL mapUrl,
java.lang.String nameMappingXmlPath)
Reads the name map xml files from the provided URL and resolves all mappings.
|
private static void |
populateRestServices(org.w3c.dom.Element mapRootNode)
Resolves and populates in-memory the REST service mappings from the xml root node.
|
static void |
registerLegacyClass(java.lang.Class<?> type)
Register the specified legacy class.
|
static void |
registerServices()
Register all exposed legacy services.
|
private static void |
registerServices(SourceNameMapper.ExternalProgram extProg,
java.lang.String qname)
Given this external program (which may be associated with a legacy OO class), register all
of its exposed services.
|
static java.lang.String |
removeAbsolutePrefix(java.lang.String absolutePath,
java.lang.String absolutePrefix)
Remove the absolute prefix from a given path.
|
private static java.lang.String |
removePkg(java.lang.String name)
Remove the package prefix from the given class name.
|
static java.lang.String |
removeUpPath(java.lang.String relName)
Remove any
.. entries from the given relative path name. |
private static java.lang.reflect.Method |
resolveExecuteMethod(java.lang.Class<?> cls)
Resolve the name of this legacy class converted 'execute' method.
|
private static java.lang.reflect.Method[] |
resolveExecuteMethods(java.lang.Class<?> cls)
Resolve the execute method names for this legacy class and its hierarchy.
|
static java.lang.String[] |
resolvePathAliases(java.util.Map<java.lang.String,java.lang.String> pathAliases,
java.lang.String pname)
Given a program name, replace all folder names which have an associated 'source' folder,
and return the new path.
|
private static java.lang.String[] |
resolvePathAliases(java.lang.String pname)
Given a program name, replace all folder names which have an associated 'source' folder,
and return the new path.
|
private static void |
setSearchPath(java.lang.String searchPath)
Notification that the search path has changed - it updates the
SourceNameMapper.WorkArea.propath
value. |
private static void |
writeConvertedCache(java.lang.String[] propath,
java.lang.Long propathHash,
java.lang.String programName,
java.lang.String[] convertResult)
Writes an entry for the program name given into the propath cache, but only if one is
available.
|
public static final int NO_EXTENT
public static final int DYNAMIC_EXTENT
private static final java.lang.String NAME_MAP_FILE
private static final java.util.regex.Pattern OVERLOAD_SUFFIX
getOverloads(java.lang.Class<?>, java.lang.String).private static final CentralLogger LOG
private static final ContextLocal<SourceNameMapper.WorkArea> local
private static final java.util.Map<java.lang.String,java.lang.Boolean> CLASS_LOOKUPS
Class.forName(java.lang.String) lookups by convertName(java.lang.String, com.goldencode.p2j.util.SourceNameMapper.WorkArea, java.lang.String[]) which resolve (or not) to a Java class for
the given program name.private static final java.lang.String ELEM_REST_SERVICE
private static final java.lang.String ELEM_CMAP
private static final java.lang.String ELEM_MMAP
private static final java.lang.String ELEM_PMAP
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_PATHNAME
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 final java.lang.String WITH_SERVICES
private static final java.lang.String OONAME
private static final java.util.concurrent.atomic.AtomicInteger PATH_INIT_THREADS_COUNTER
initializationPaths.private static final java.util.concurrent.atomic.AtomicInteger MAPPING_COUNTER
initializationPaths.
The value is modified when reading the initial path-mapping nodes and whenever
a new entry is added to an existent cache.private static java.util.Map<java.lang.String,java.lang.String> pathAliases
private static java.util.Map<java.lang.String,java.lang.String> pathAliases_ci
private static volatile java.util.Map<java.lang.String,SourceNameMapper.ExternalProgram> p2jMap
private static volatile java.util.Map<java.lang.String,SourceNameMapper.ExternalProgram> p2jMap_ci
private static volatile java.util.Map<java.lang.String,java.util.List<SourceNameMapper.ExternalProgram>> p2jNonExtMap
private static volatile java.util.Map<java.lang.String,java.util.List<SourceNameMapper.ExternalProgram>> p2jNonExtMap_ci
private static java.util.Map<java.lang.String,SourceNameMapper.PathLookup> pathLookups
private static java.util.Map<java.lang.String,SourceNameMapper.ExternalProgram> j2pMap
private static LRUCache<java.lang.Long,SourceNameMapper.SourceNameMapperCache> sourceCache
private static volatile java.util.Map<java.lang.String,java.lang.Integer> initializationPaths
private static java.util.Set<java.lang.String> allowedLegacyExtensions
private static LRUCache<java.lang.String,java.lang.String[][]> searchPathCache
private static java.util.List<SourceNameMapper.ExternalProgram> servicePrograms
private static volatile java.util.Map<java.lang.Class<?>,SourceNameMapper.LegacyClass> classMap
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 volatile boolean mappingDataInitialized
private static volatile boolean mappingDataInitInProgess
private static java.lang.String fileSep
private static char fileSepChar
private static final java.util.regex.Pattern fileSepRegexp
private static final java.util.regex.Pattern dblBackslashRegexp
private static final java.lang.String altFileSep
fileSep and this.private static final java.util.concurrent.ExecutorService mappingExecutor
public static void initialize()
public static void registerServices()
public static java.lang.String[] resolvePathAliases(java.util.Map<java.lang.String,java.lang.String> pathAliases,
java.lang.String pname)
pname - The legacy program name.public static java.lang.String getLegacySourceName(java.lang.String javaClassName)
javaClassName - 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 getLegacyClassName(java.lang.String javaClassName)
javaClassName - The converted FWD class mapping a legacy 4GL class 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 getLegacySourceName(java.lang.String customRoot,
java.lang.String javaClassName)
javaClassName - 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)
SourceNameMapper.WorkArea.caseSens state.legacy - The legacy name to be normalizedpublic static java.lang.String convertNameToClass(java.lang.String legacy,
java.lang.String[] searchPaths)
convertName(String, WorkArea, String[]) worker for finding the name of the Java class name of
a converted P4GL procedure name.legacy - Progress file name.searchPaths - Paths where to search for the file instead of searching in the entire PROPATH.null is returned.public static java.lang.String convertNameToClass(java.lang.String legacy)
fastConvertName(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 convertNameToClass(java.lang.String legacy,
boolean fastConvert)
fastConvertName(String) or convertName(String, WorkArea, String[])
worker for finding the name of the Java class name of a converted P4GL procedure name.legacy - Progress file name.fastConvert - True if we should use the fastConvertName(String) worker.
False if we should use the convertName(String, WorkArea, String[]) worker.null is returned.public static java.lang.String convertOOToClass(java.lang.String legacyClsName)
legacyClsName - The qualified legacy class name.null is returned.public static java.lang.String lookupLegacyName(java.lang.String legacy)
fastConvertName(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 java.lang.String getPackageRoot()
package root.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.nullpublic 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.lang.String getParameterModes(java.lang.String pname,
InternalEntry ie,
java.lang.String ieName,
boolean function)
pname - Legacy 4GL program name.ie - If non-null, the already resolved internal entry.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, InternalEntry ie, java.lang.String ieName, boolean function)
pname - Legacy 4GL program name.ie - If non-null, the already resolved internal entry.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,
InternalEntry ie,
java.lang.String iename,
boolean func,
int param)
pname - Legacy 4GL program name.ie - If non-null, the already resolved internal entry.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,
InternalEntry ie,
java.lang.String iename,
boolean func,
int param)
pname - Legacy 4GL program name.ie - If non-null, the already resolved internal entry.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,
InternalEntry ie,
java.lang.String iename,
boolean function)
false.pname - Legacy 4GL program name.iename - ie - If non-null, the already resolved internal entry.
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.public static java.util.List<InternalEntry> getConstructors(java.lang.Class<? extends _BaseObject_> type)
type - The legacy class.public static InternalEntry getStaticConstructor(java.lang.Class<? extends _BaseObject_> type)
type - The legacy class.public static java.lang.reflect.Method[] getExecuteMethods(java.lang.Class<? extends _BaseObject_> type)
execute method names names for this legacy class and its hierarchy.type - The legacy class for which the method name must be resolved.public static java.util.List<InternalEntry> getDestructors(java.lang.Class<? extends _BaseObject_> type)
type - The legacy class.public static java.util.List<InternalEntry> getOverloads(java.lang.Class<?> type, java.lang.String iename)
type - The legacy _BaseObject_ sub-class.iename - The legacy name.public static java.util.List<InternalEntry> getOverrides(java.lang.Class<?> type, java.lang.String iename)
type - The legacy _BaseObject_ sub-class.iename - The legacy name.public static java.util.Map<java.lang.String,java.util.List<InternalEntry>> getGetters(java.lang.Class<? extends _BaseObject_> type)
type - The legacy _BaseObject_ sub-class.public static java.util.Map<java.lang.String,java.util.List<InternalEntry>> getSetters(java.lang.Class<? extends _BaseObject_> type)
type - The legacy _BaseObject_ sub-class.public static void registerLegacyClass(java.lang.Class<?> type)
This is used to register legacy builtin 4GL classes - these always need to be marked with
the LegacyResource annotation.
type - The class representing a builtin 4GL type.public static java.lang.Integer findLegacyPropertyExtent(java.lang.Class<?> type,
java.lang.String pname)
type - The legacy OO class.pname - The legacy OO property name.null if it does not apply.public static InternalEntry findLegacyAccessor(java.lang.Class<?> type, java.lang.String pname, boolean getter, boolean indexed)
type - The class matching the legacy OO type.pname - The legacy property name.getter - Flag indicating to retrieve a getter or setter.indexed - Flag indicating to retrieve the indexed getter or setter.InternalEntry or null if not found.public static boolean hasLegacyMethod(java.lang.Class<?> type,
java.lang.String pname)
pname - The legacy method name.true if there is a method defined with the given name.public static java.lang.String findLegacyEntryName(java.lang.Class<?> type,
java.lang.String mname)
type - The converted class name.mname - The Java method name.public static InternalEntry findLegacyMethod(java.lang.Class<?> type, java.lang.String pname, InternalEntry signature)
type - The class matching the legacy OO type.pname - The legacy method name.signature - The legacy signature to match.public static java.lang.String removeUpPath(java.lang.String relName)
.. entries from the given relative path name.relName - Relative file path.public static java.lang.String canonicalize(java.lang.String progName,
boolean caseSens)
. and .. are
processed. Empty path elements are removed.
If SourceNameMapper.WorkArea.caseSens is false, the program name is lower-cased.
progName - Input name.caseSens - Case sensitivity of the passed in input name.private static java.lang.reflect.Method[] resolveExecuteMethods(java.lang.Class<?> cls)
cls - The legacy class for which the method name must be resolved.private static java.lang.reflect.Method resolveExecuteMethod(java.lang.Class<?> cls)
cls - The legacy class for which the method name must be resolved.private static void createSourceCacheEntry(java.lang.String[] propath,
java.lang.Long propathHash)
name_map.xml
did not complete, the method is short-circuited.propath - The propath for which the cache will be created.propathHash - The hash code of the propath.private static void writeConvertedCache(java.lang.String[] propath,
java.lang.Long propathHash,
java.lang.String programName,
java.lang.String[] convertResult)
initializationPaths when writing the cache
so that other caches that will be created to directly use the available resource instead
of separately caching the value when searching. When a new value is added to the
initializationPaths map, it will not add the result of the search to other
existent caches, that's why it is necessary to check if the cache doesn't have the
path mapped instead of relying on the already available map.propath - The propath used to find the cache in which the new entry will be added.propathHash - The hash code of the propath.programName - The key for the map in the propath cache.convertResult - The value.private static java.lang.String[] fastConvertName(java.lang.String legacyProgName)
convertName(String, WorkArea)
by using pathLookups map of lookup instances. The lookup map contains
SinglePathLookup and MultiPathLookup instances.
SinglePathLookup looks up the program name based on the propath and the case sensitivity values of the WorkArea. If there are path aliases in use, then it will resolve the program name and redo the lookup process using each path alias available according to the propath and case sensitivity parameters.
MultiPathLookup stores a list of SinglePathLookup instances and will use their lookup method
to search for the program name. Multiple matches for the same program name will cause a conflict
and in this case, null will be returned.
If no match was found by SinglePathLookup/MultiPathLookup, or there is no entry for the unqualified program name in the lookup map, the search will fallback to the old implementation.
legacyProgName - Progress file name.String array with three components:
null is returned.private static java.lang.String[] fastConvertName(java.lang.String legacyProgName,
boolean avoidCache)
convertName(String, WorkArea)
by using pathLookups map of lookup instances. The lookup map contains
SinglePathLookup and MultiPathLookup instances.
SinglePathLookup looks up the program name based on the propath and the case sensitivity values of the WorkArea. If there are path aliases in use, then it will resolve the program name and redo the lookup process using each path alias available according to the propath and case sensitivity parameters.
MultiPathLookup stores a list of SinglePathLookup instances and will use their lookup method
to search for the program name. Multiple matches for the same program name will cause a conflict
and in this case, null will be returned.
If no match was found by SinglePathLookup/MultiPathLookup, or there is no entry for the unqualified program name in the lookup map, the search will fallback to the old implementation.
legacyProgName - Progress file name.avoidCache - false is the default value and allows reading from the cache or creating
new entries. true is only used by the thread creating the source cache
entry to avoid concurrent modification.String array with three components:
null is returned.private static java.lang.String[] convertName(java.lang.String legacyProgName,
SourceNameMapper.WorkArea wa,
java.lang.String[] searchPaths)
canonicalize(java.lang.String, boolean).
A simple lookup is tried first, taking into account if there is a .r, .p, or .w extension
which may have been left off the 4GL statement. 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 to match the structure from
name_map.xml.
If this mapping does not exist then each path segment of the list of directories is tried in order. The given program name is check to see if it is prefixed with the directory name, 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"
If no program name is explicitly found with a .r extension, R-code program
names are looked up using the p2jNonExtMap (the program name without the extension).
If pathAliases is specified, and the program can be found (as it is or after
removing the .r extension) using the directories list, the lookup falls back to resolving
the aliased folders in the program name, via resolvePathAliases(java.util.Map<java.lang.String, java.lang.String>, java.lang.String).
legacyProgName - Progress file name.wa - WorkArea of the current local context.searchPaths - Paths to use when searching for the Progress file. If null, will search in propath.String array with three components:
null is returned.private static java.lang.String[] convertName(java.lang.String legacyProgName,
SourceNameMapper.WorkArea wa)
convertName(String, WorkArea, String[]) with the PROPATH segments for the second parameter.
Consult the javadoc for the overloaded method with 3 parameters for more information.legacyProgName - Progress file name.wa - WorkArea of the current local context.String array with three components:
null is returned.public static java.lang.String getAbsolutePrefix(java.lang.String path)
path - The path for which we want to find the absolute prefix.public static java.lang.String removeAbsolutePrefix(java.lang.String absolutePath,
java.lang.String absolutePrefix)
absolutePath - The absolute path which we want to transform into a path relative to the root folder.absolutePrefix - The absolute prefix of the absolute path.canonicalize(String, boolean) method.public static java.lang.String getFileSep()
fileSep static data member.public static java.lang.String[] getPropath()
private static java.lang.String[] convertName(java.lang.String legacyProgName,
java.util.function.Function<java.lang.String,SourceNameMapper.ExternalProgram> lookup,
SourceNameMapper.WorkArea wa,
java.lang.String[] searchPaths)
canonicalize(java.lang.String, boolean).
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 to match the structure from
name_map.xml.
If this mapping does not exist then each path segment of the list of directories is tried in order. The given program name is check to see if it is prefixed with the directory name, 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.lookup - The lookup function used to resolve a program name to a SourceNameMapper.ExternalProgram.wa - WorkArea of the current local context.searchPaths - Paths to use when searching for the Progress file. If null, will search in propath.String array with three components:
null is returned.private static SourceNameMapper.ExternalProgram getExternalProgram(java.lang.String pname)
SourceNameMapper.ExternalProgram of the given Legacy 4GL program name.pname - Legacy 4GL program name.SourceNameMapper.ExternalProgram or null if not a valid pname.private static void setSearchPath(java.lang.String searchPath)
SourceNameMapper.WorkArea.propath
value.searchPath - The new PROPATH value.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 java.lang.String[] resolvePathAliases(java.lang.String pname)
pname - The legacy program name.private static void loadPathAliases()
pathAliases map. This map
contains as key the 'aliased' name which is an alias for a 'source' folder.
The directory contains these mappings in the /server/default/path-aliases or
/server/<server-id>/path-aliases node. The child nodes have as class
path-alias and this structure:
<node class="path-alias" name="alias1">
<node-attribute name="source" value="src1"/>
<node-attribute name="alias" value="obj1"/>
</node>
The alias1 name is just an unique ID for each child.
private static void registerServices(SourceNameMapper.ExternalProgram extProg, java.lang.String qname)
extProg - The external program specification.qname - Fully qualified, converted, Java class name.private static void initMappingData()
pkgroot and the NAME_MAP_FILE 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 void populateInMemoryMaps(java.net.URL mapUrl,
java.lang.String nameMappingXmlPath)
throws java.io.IOException,
javax.xml.parsers.ParserConfigurationException,
org.xml.sax.SAXException
mapUrl - The URL of the map name xml file (the file path inside the jar).nameMappingXmlPath - Only the name map xml file path.java.io.IOException - Map name xml file read exception.javax.xml.parsers.ParserConfigurationException - XML parser configuration exception.org.xml.sax.SAXException - XML parser general exception.private static void populateRestServices(org.w3c.dom.Element mapRootNode)
mapRootNode - The root node of the map name xml file.private static boolean populateClasses(org.w3c.dom.Element mapRootNode)
mapRootNode - The root node of the map name xml file.true if the node is successfully read, false otherwise.java.lang.IllegalStateException - On malformed class mapping entry.private static void populateInitPaths(org.w3c.dom.Element mapRootNode,
java.net.URL mapUrl)
mapRootNode - The root node of the map name xml file.mapUrl - The URL of the map name xml file (the file path inside the jar). Used for logging.private static boolean isPathMappingInitialized()
true if all path mapping initializer threads have completed work,
false otherwise.private static SourceNameMapper.ExternalProgram buildExternalProgram(java.lang.String pname, java.lang.String jname, java.lang.String ooname, org.w3c.dom.Element classMap)
SourceNameMapper.ExternalProgram info contained in the classMap
node.pname - The legacy 4GL program name.jname - The converted class name.ooname - The legacy OO 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.static void buildLegacyProgram(SourceNameMapper.ExternalProgram extprog)
Method, for the given external program.
Only methods marked with LegacySignature are included.
static SourceNameMapper.LegacyClass buildLegacyClass(java.lang.Class<?> cls)
LegacySignature annotation) and register them.
The InternalEntry will be linked with the defining Java method.
cls - The Java class associated with the legacy 4GL type.public static InternalEntry buildInternalEntry(LegacySignature ls, java.lang.reflect.Method jmeth)
InternalEntry matching the specified legacy signature.ls - The signature.jmeth - The converted Java method.static InternalEntry buildInternalEntry(LegacySignature ls, java.lang.String jname)
InternalEntry matching the specified legacy signature.ls - The signature.jname - The converted Java name.private static Parameter buildParameter(LegacyParameter lp)
Parameter instance from the specified LegacyParameter annotation.lp - The parameter signature.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.private static java.lang.String getLegacyPathSeparator()
SourceNameMapper.WorkArea.pathSepprivate static boolean getLegacyCaseSensitive()
SourceNameMapper.WorkArea.caseSens