public class HandleOps
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.String,java.lang.String> |
GETTERS_TO_JAVA
Mapping of the 4GL attributes to their Java getter method names.
|
private static java.util.Map<java.lang.String,java.util.Set<java.lang.String>> |
LEGACY_GETTERS
A map holding the set of all gettable attribute names, per each resource class.
|
private static java.util.Map<java.lang.String,java.util.Set<java.lang.String>> |
LEGACY_METHODS
A map holding the set of all method names, per each resource class.
|
private static java.util.Map<java.lang.String,java.util.Set<java.lang.String>> |
LEGACY_SETTERS
A map holding the set of all settable attribute names, per each resource class.
|
private static java.util.logging.Logger |
LOG
Logger
|
private static java.util.Map<java.lang.String,java.lang.String> |
METHODS_TO_JAVA
Mapping of the 4GL method to their Java method names.
|
private static java.util.Map<java.lang.Class<?>,java.lang.String> |
QUERY_ATTRIBUTES
A map holding the string-representation of all queryable attributes and methods, per each
resource class.
|
private static java.util.Map<java.lang.Class<?>,java.lang.String> |
SET_ATTRIBUTES
A map holding the string-representation of all settable attributes, per each resource class.
|
private static java.util.Map<java.lang.String,java.lang.String> |
SETTERS_TO_JAVA
Mapping of the 4GL attributes to their Java setter method names.
|
Constructor and Description |
---|
HandleOps() |
Modifier and Type | Method and Description |
---|---|
static logical |
canQuery(handle h,
character attr)
Reports if the given attribute or method can be read from the given handle.
|
static logical |
canQuery(handle h,
java.lang.String attributeOrMethodName)
Reports if the given attribute or method can be read from the given handle.
|
static logical |
canSet(handle h,
character attr)
Reports if the given attribute can be written to the given handle.
|
static logical |
canSet(handle h,
java.lang.String attributeName)
Reports if the given attribute can be written to the given handle.
|
static void |
delete(handle... handles)
Deletes the given handles.
|
static void |
delete(handle h)
Deletes the given handle.
|
(package private) static java.lang.String |
findLegacy(handle h,
java.lang.String attrOrMethod,
boolean attr,
boolean setter)
Find if the legacy attribute or method can be used with the resource referenced by the
given handle.
|
private static boolean |
invalidChainAttribute(HandleChain chain,
java.lang.String name,
boolean query)
Check if the specified chain attribute is invalid with the given resource, in query or
settable mode.
|
private static void |
invalidDelete()
Invoked when the handle is invalid or a system (non-procedure) handle.
|
private static void |
invalidDelete(handle h)
Invoked when the handle is invalid or a system (non-procedure) handle.
|
private static boolean |
isHandleAttribute(java.lang.String attrName)
Checks if the given attribute name is HANDLE.
|
private static boolean |
isLegacyResourceOperationAllowed(java.lang.Object resource,
java.lang.String key,
java.util.Map<java.lang.String,java.util.Set<java.lang.String>> table,
java.util.function.Function<java.lang.reflect.Method,java.lang.annotation.Annotation> resolver)
Test if a legacy operation is allowed for a given resource based on method annotations.
|
static boolean |
isSystemHandle(handle h)
Check if the given resource represents a system handle.
|
static boolean |
isSystemHandle(WrappedResource res)
Check if the given resource represents a system handle.
|
private static java.util.Set<java.lang.String> |
legacyResourceAllowedOperations(java.lang.Class<?> fromClass,
java.util.Map<java.lang.String,java.util.Set<java.lang.String>> table,
java.util.function.Function<java.lang.reflect.Method,java.lang.annotation.Annotation> resolver)
Get the set of operations of given type allowed for a class instances.
|
private static void |
legacyResourceAllowedUpdateFromMethods(java.lang.Iterable<java.lang.reflect.Method> methods,
java.util.Set<java.lang.String> allowSet,
java.util.function.Function<java.lang.reflect.Method,java.lang.annotation.Annotation> resolver)
Update the set of allowed names based on methods annotations.
|
private static java.util.List<java.lang.reflect.Method> |
listAllMethods(java.lang.Class<?> cls)
List all methods declared in this class and all its super-classes and interfaces.
|
static character |
listEvents(handle h)
Get the list of valid events for the specified resource.
|
static character |
listEvents(handle h,
character platform)
Get the list of valid events for the specified resource.
|
static character |
listEvents(handle h,
java.lang.String platform)
Get the list of valid events for the specified resource.
|
private static java.lang.String |
listLegacyResource(java.lang.Object res,
java.util.function.Function<java.lang.reflect.Method,java.lang.String> resolver,
boolean query)
Get a listing of the specified resource, of all its attributes/methods (in 'query' mode)
or all its setable attributes (in non-query mode).
|
static character |
listQueryAttributes(handle h)
Get the list of queryable attributes and methods for the specified resource.
|
static character |
listSetAttributes(handle h)
Get the list of settable attributes for the specified resource.
|
private static final java.util.logging.Logger LOG
private static final java.util.Map<java.lang.Class<?>,java.lang.String> QUERY_ATTRIBUTES
private static final java.util.Map<java.lang.Class<?>,java.lang.String> SET_ATTRIBUTES
private static final java.util.Map<java.lang.String,java.lang.String> SETTERS_TO_JAVA
private static final java.util.Map<java.lang.String,java.lang.String> GETTERS_TO_JAVA
private static final java.util.Map<java.lang.String,java.lang.String> METHODS_TO_JAVA
private static final java.util.Map<java.lang.String,java.util.Set<java.lang.String>> LEGACY_GETTERS
private static final java.util.Map<java.lang.String,java.util.Set<java.lang.String>> LEGACY_SETTERS
private static final java.util.Map<java.lang.String,java.util.Set<java.lang.String>> LEGACY_METHODS
public static boolean isSystemHandle(WrappedResource res)
res
- The resource to check.true
if the resource represents a system handle as defined above.public static character listEvents(handle h)
The order in which these are returned by 4GL has no meaning; in FWD, these are returned sorted alphabetically.
h
- The handle referencing the resource.public static character listEvents(handle h, java.lang.String platform)
The order in which these are returned by 4GL has no meaning; in FWD, these are returned sorted alphabetically.
h
- The handle referencing the resource.platform
- The display type (GUI or TTY are valid).public static character listEvents(handle h, character platform)
The order in which these are returned by 4GL has no meaning; in FWD, these are returned sorted alphabetically.
h
- The handle referencing the resource.platform
- The display type (GUI or TTY are valid).public static character listQueryAttributes(handle h)
The order in which these are returned by 4GL has no meaning; in FWD, these are returned sorted alphabetically.
h
- The handle referencing the resource.public static character listSetAttributes(handle h)
The order in which these are returned by 4GL has no meaning; in FWD, these are returned sorted alphabetically.
h
- The handle referencing the resource.public static boolean isSystemHandle(handle h)
h
- The handle to check.true
if the handle references a system handle.public static void delete(handle... handles)
In cases when the handle is a system handle, an invalidDelete()
is called (to raise an error).
handles
- The list of handles to be deleted.public static void delete(handle h)
In cases when the handle is a system handle, an invalidDelete()
is called (to raise
an error).
h
- The handle to be deleted.public static logical canQuery(handle h, character attr)
CAN-QUERY()
built-in function.h
- The handle to be tested.attr
- The name of the attribute to be checked.true
if the resource in this handle supports reading the named
attribute or method, false
if the resource is valid but doesn't
support the named attribute and unknown
if either input is
unknown
.public static logical canQuery(handle h, java.lang.String attributeOrMethodName)
CAN-QUERY()
built-in function.h
- The handle to be tested.attributeOrMethodName
- The name of the attribute or method to be checked.true
if the resource in this handle supports reading the named
attribute or method, false
if the resource is valid but doesn't
support the named attribute and unknown
if either input is
unknown
.public static logical canSet(handle h, character attr)
CAN-SET()
built-in function.h
- The handle to be tested.attr
- The name of the attribute to be checked.true
if the resource in this handle supports writing the named
attribute, false
if the resource is valid but doesn't support
the named attribute and unknown
if either input is
unknown
.public static logical canSet(handle h, java.lang.String attributeName)
CAN-SET()
built-in function.h
- The handle to be tested.attributeName
- The name of the attribute to be checked.true
if the resource in this handle supports writing the named
attribute, false
if the resource is valid but doesn't support
the named attribute and unknown
if either input is
unknown
.static java.lang.String findLegacy(handle h, java.lang.String attrOrMethod, boolean attr, boolean setter)
This will use the global SETTERS_TO_JAVA
, GETTERS_TO_JAVA
and
METHODS_TO_JAVA
maps - if the cached values do not exist for the given resource
type, this will be initialized via a listQueryAttributes(com.goldencode.p2j.util.handle)
call.
h
- The resource.attrOrMethod
- The attribute or method name.attr
- Flag indicating if looking for attributes only.setter
- Flag indicating if looking for attribute setters only.private static boolean isHandleAttribute(java.lang.String attrName)
attrName
- The name of the attribute to be checked.true
if the attribute name is HANDLE, false
otherwise.private static void invalidDelete()
invalidDelete(null)
.private static void invalidDelete(handle h)
h
- The handle for which the delete failed. May be
null
if it was decide this is a non-procedure
handle.private static java.lang.String listLegacyResource(java.lang.Object res, java.util.function.Function<java.lang.reflect.Method,java.lang.String> resolver, boolean query)
res
- The resource for which to resolve the attributes/methods.resolver
- Function which checks if a method can be used by this call.query
- Flag indicating if we are looking for queryable attributes/methods (when true) or
only settable attributes (when false).private static java.util.List<java.lang.reflect.Method> listAllMethods(java.lang.Class<?> cls)
cls
- The class which requires its methods listed.private static boolean invalidChainAttribute(HandleChain chain, java.lang.String name, boolean query)
chain
- The chainable resource.name
- The attribute name.query
- Check for reading (when true
) or writing (when false
).true
if the attribute is invalid in this resource.private static final java.util.Set<java.lang.String> legacyResourceAllowedOperations(java.lang.Class<?> fromClass, java.util.Map<java.lang.String,java.util.Set<java.lang.String>> table, java.util.function.Function<java.lang.reflect.Method,java.lang.annotation.Annotation> resolver)
fromClass
- the class or interface in questiontable
- resolver
- a function which takes a method as the only arguments and
returns a method annotation, matching some condiotions,
or null
if no method annotation matches.private static boolean isLegacyResourceOperationAllowed(java.lang.Object resource, java.lang.String key, java.util.Map<java.lang.String,java.util.Set<java.lang.String>> table, java.util.function.Function<java.lang.reflect.Method,java.lang.annotation.Annotation> resolver)
Obtain the legacy attribute annotation instance for the given handle object and given legacy attribute name.
The search algorithm for this method uses reflection to read annotations from various sources in the following precedence order:
The search is repeated recursively for the superclass and interfaces.
Where possible, we put annotations on the interface, not the class for the resource. But there are some attributes where the configuration is not universal for all resources implementing the same attribute. For example, the following attributes are readable for certain resources even though for most other resources the same attribute is writable:
Keeping the above precedence order is critical to allow attribute configurations of more-specific resources to properly override the more general configuration in the parent hierarchy or the interface hierarchy.
resource
- the resource jbject to testkey
- the operation name, must be in upper casetable
- the map holding sets of allowed operations for an operation type, this map
is updated lazily in this callresolver
- a function which takes a method as the only arguments and
returns a method annotation, matching some condiotions,
or null
if no method annotation matches.private static void legacyResourceAllowedUpdateFromMethods(java.lang.Iterable<java.lang.reflect.Method> methods, java.util.Set<java.lang.String> allowSet, java.util.function.Function<java.lang.reflect.Method,java.lang.annotation.Annotation> resolver)
methods
- the methods to scan for annotations.allowSet
- the set of allowed names to updateresolver
- a function which takes a method as the only arguments and
returns a method annotation, matching some condiotions,
or null
if no method annotation matches.