public class DataAccess
extends java.lang.Object
Assert
and TreeNodeBase
. The last one is checked whether it is used as container.
It is not necessary to work with.
#getDataFromField(String, Object, boolean)
: Data from one instance, also from super and enclosing.
Enhances Class.getField(String)
and Field.get(Object)
#getData(String, Object, boolean, boolean)
: Data from one instance. If the instance is a Map
it accessed to an element of this container. Elsewhere it tries to get from a field.
Invokes #getDataFromField(String, Object, boolean)
.
invokeNew(DatapathElement)
creates an instance by symbolic name maybe with parameters, maybe with
another ClassLoader (from additional jar files etc.).
Enhances Class.newInstance()
and Constructor.newInstance(java.lang.Object...)
.
#invokeMethod(DatapathElement, Class, Object, boolean, boolean)
invokes a static method by symbolic name
maybe with parameters, maybe with another ClassLoader (from additional jar files etc.).
Enhances Class.getMethod(String, Class...)
and Method.invoke(Object, Object...)
.
#access(List, Object, Map, boolean, boolean, boolean, Dst)
Data from a complex referenced instance
maybe with method invocations and creation of instances.
It uses a List< DataAccess.DatapathElement
>
to access,
it uses method arguments. Static methods and creation of instances can invoked too. See DataAccess.DatapathElement
.
#access(CharSequence, Object, Map, boolean, boolean, boolean, Dst)
: Path String given.
#storeValue(List, Map, Object, boolean)
stores instead accesses
#setVariable(Map, String, Object)
, getVariable(Map, String, boolean)
: Deal with variables.
getEnclosingInstance(Object)
: Gets the enclosing instance
getStringFromObject(Object, String)
, getInt(Object)
, getFloat(Object)
: access to simple data,
conversions.
setBit(int, int, boolean)
Helper to deal with bits
getInt(Object)
, getFloat(Object)
etc.
add_datapathElement(DatapathElement)
and can access with this path
using the non-static method #access(Map, boolean, boolean)
.
DataAccess.DatapathElement
and DataAccess.DatapathElementClass
.
DataAccess.Variable
is a wrapper for any Object which is used and regarded. Sometimes the Variable is returned
which's content can be changed: DataAccess.Variable.setValue(Object)
. A Variable is helpfully if the content
of referenced instances should be changed without changing all references:
any_instance---------------->| other_instance-------------->| Variable |--value------->references_somewhat ^ \ | ------>other_reference is changed:
Modifier and Type | Class and Description |
---|---|
private static interface |
DataAccess.Conversion
Interface to convert between data.
|
private static class |
DataAccess.Conversions
This inner class contains all possible automatic special conversions.
|
static class |
DataAccess.DataAccessSet
This class extends its outer class and provides the capability to set the data path
especially from a ZBNF parser result.
|
static class |
DataAccess.DatapathElement
Class holds one element for access to data.
|
static class |
DataAccess.DatapathElementClass
Variant of a DatapathElement which can contain a ClassLoader for a new Java class or a static method invocation
or a Class which's field, method or constructor should access.
|
static class |
DataAccess.Dst
Result of an
DataAccess#access(List, Object, Map, boolean, boolean, boolean, Dst)
to store a value. |
static class |
DataAccess.IntegerIx
Wrapper around the index as integer.
|
static class |
DataAccess.ObjMethod |
static class |
DataAccess.SetDatapathElement
This class extends a
DataAccess.DatapathElement and provides the capability to set the data path
especially from a ZBNF parser result, see ZbnfJavaOutput . |
static class |
DataAccess.Test |
static class |
DataAccess.Variable<T>
This class wraps any Object which is used for a variable.
|
Modifier and Type | Field and Description |
---|---|
protected java.util.List<DataAccess.DatapathElement> |
datapath
The description of the path to any data if the script-element refers data.
|
private static java.lang.String |
debugIdent
Can be set immediately for debug approach.
|
private static java.lang.String |
debugMethod |
private static java.util.Map<java.lang.String,DataAccess.Conversion> |
idxConversions |
static java.lang.String |
sVersion
Version, history and license.
|
Constructor and Description |
---|
DataAccess()
Empty constructor.
|
DataAccess(java.lang.String path)
Creates a Datapath with given String.
|
DataAccess(java.lang.String path,
char cTypeNewVariable)
Creates a Datapath with given String.
|
DataAccess(StringPartScan sp,
java.util.Map<java.lang.String,DataAccess.IntegerIx> nameVariables,
java.lang.Class<?> reflData,
char cTypeNewVariable)
Creates a Datapath with given StringPartScan.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
access(java.lang.CharSequence datapathArg,
java.lang.Object dataRoot,
boolean accessPrivate,
boolean bContainer,
boolean bVariable,
DataAccess.Dst dst)
Accesses data with a String given path.
|
static java.lang.Object |
access(DataAccess.DatapathElement element,
java.lang.Object data1,
boolean accessPrivate,
boolean bContainer,
java.util.Map<java.lang.String,DataAccess.IntegerIx> nameVariables,
java.lang.Object[] varValues,
boolean bVariable,
DataAccess.Dst dst)
Access to the given element, used internally, also able to use for one element form extern.
|
static java.lang.Object |
access(java.util.List<DataAccess.DatapathElement> datapathArg,
java.lang.Object dataRoot,
boolean accessPrivate,
boolean bContainer,
java.util.Map<java.lang.String,DataAccess.IntegerIx> nameVariables,
java.lang.Object[] varValues,
boolean bVariable,
DataAccess.Dst dst)
Universal method to accesses data.
|
java.lang.Object |
access(java.lang.Object dataRoot,
boolean accessPrivate,
boolean bContainer,
java.util.Map<java.lang.String,DataAccess.IntegerIx> nameVariables,
java.lang.Object[] varValues)
Searches the Object maybe invoking some methods which is referred with this instances,
datapath . |
void |
add_datapathElement(DataAccess.DatapathElement item)
Sets the datapath while adding one element after another.
|
protected static java.lang.Object[] |
checkAndConvertArgTypes(java.lang.Object[] providedArgs,
java.lang.Class<?>[] argTypes)
Checks whether the given arguments matches to the necessary arguments of a method or constructor invocation.
|
static DataAccess.Conversion |
checkArgTypes(java.lang.Class<?> argType,
java.lang.Class<?> actType,
java.lang.Object arg)
Checks whether the given actType with its value arg matches to the given argType.
|
private static DataAccess.Conversion |
checkIfcTypes(java.lang.Class<?> argType,
java.lang.Class<?> ifcType,
java.lang.Object arg) |
static DataAccess.Conversion |
checkTypes(java.lang.Class<?> argType,
java.lang.Class<?> actType,
java.lang.Object arg)
Checks whether a given type with its value can be converted to a destination type.
|
static DataAccess.Variable<java.lang.Object> |
createOrReplaceVariable(java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> map,
java.lang.String name,
char type,
java.lang.Object content,
boolean isConst)
Creates or replaces a variable with a simple name in the given container.
|
java.util.List<DataAccess.DatapathElement> |
datapath()
Returns the datapath of this access to check details.
|
protected static void |
debug()
Set a breakpoint here to edit a
debugIdent(String) |
static void |
debugIdent(java.lang.String ident)
A debug helper: Set this ident to any String, which is expected for access.
|
static void |
debugMethod(java.lang.String ident)
A debug helper: Set this identifier to any String, which is expected for invocation of a method.
|
static java.util.List<DataAccess.DatapathElement> |
expandElements(java.lang.CharSequence path,
char whatisit)
Splits a String given path to elements.
|
static java.lang.Object |
getArrayElement(java.lang.Object data,
int... ixArray)
Gets the indexed element of the given array.
|
private static java.lang.Class<?> |
getClass(java.lang.String name) |
private static java.lang.ClassLoader |
getClassLoader(DataAccess.DatapathElement element) |
static java.lang.Object |
getData(java.lang.String name,
java.lang.Object instance,
boolean accessPrivate,
boolean bContainer,
boolean bVariable,
DataAccess.Dst dst)
Gets data from a field or from an indexed container.
|
private static java.lang.Object |
getDataFromField(java.lang.String name,
java.lang.Object obj,
boolean accessPrivate,
java.lang.Class<?> clazz,
DataAccess.Dst dst,
int recursiveCt)
Core method to get data from a field, static or non static
|
static java.lang.Object |
getDataFromField(java.lang.String name,
java.lang.Object obj,
boolean accessPrivate,
DataAccess.Dst dst)
Returns the data which are stored in the named field of the given instance.
|
private static java.lang.Object |
getDataPriv(java.lang.String name,
java.lang.Object instance,
boolean accessPrivate,
boolean bContainer,
boolean bVariable,
DataAccess.Dst dst)
It does not resolve the instance if it is a Variable
|
private static java.lang.Object |
getEnclosingInstance(int recurs,
java.lang.Object obj) |
static java.lang.Object |
getEnclosingInstance(java.lang.Object obj)
Returns the enclosing instance (outer class) of an instance which is type of any inner non-static class.
|
static float |
getFloat(java.lang.Object val)
Gets the float value from any Object.
|
static int |
getInt(java.lang.Object val)
Gets the int value from any Object.
|
static int |
getLengthOfArray(java.lang.Object data)
Checks whether data is an array and returns the current number of elements.
|
protected static java.lang.Object |
getStaticValue(DataAccess.DatapathElement element)
Invokes the static method which is described with the element.
|
static java.lang.String |
getStringFromObject(java.lang.Object content,
java.lang.String format)
Returns a string representation of the object.
|
static DataAccess.Variable<java.lang.Object> |
getVariable(java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> map,
java.lang.String name,
boolean strict)
Searches the variale in the container and returns it.
|
java.lang.CharSequence |
idents()
Returns a CharSequence with the idents of the path separated with "."
|
(package private) static java.util.Map<java.lang.String,DataAccess.Conversion> |
initConversion()
This method initializes the internal conversion index.
|
int |
intFromUnsignedShort(short val)
Converts a value in a short to a unsigned value, which can be stored in a int in Java.
|
static java.lang.Object |
invokeMethod(DataAccess.DatapathElement element,
java.lang.Class<?> clazz,
java.lang.Object obj,
boolean accessPrivate,
boolean bNoExceptionifNotFound,
java.lang.Object[] args)
Invokes the method which is described with the element with given immediately calling arguments.
|
static java.lang.Object |
invokeMethod(DataAccess.DatapathElement element,
java.lang.Class<?> clazz,
java.lang.Object obj,
boolean accessPrivate,
java.lang.Object[] varValues,
boolean bNoExceptionifNotFound)
Prepares firstly the arguments of the method and invokes the method.
|
protected static java.lang.Object |
invokeNew(DataAccess.DatapathElement element)
Invokes the static method which is described with the element.
|
protected static java.lang.Object |
invokeStaticMethod(DataAccess.DatapathElement element)
Invokes the static method which is described with the element.
|
static boolean |
isOrExtends(java.lang.Class<?> thisclazz,
java.lang.Class<?> cmpclazz)
Check whether a given class is type of another class.
|
static boolean |
isReferenceToEnclosing(java.lang.reflect.Field ref)
Checks whether a given Field is the reference to the enclosing respectively outer class.
|
static boolean |
istypeof(java.lang.Object obj,
java.lang.Class type)
Checks whether the given obj is type of the given type.
|
static boolean |
istypeof(java.lang.Object obj,
java.lang.String sType)
Checks whether the given obj is type of the given type.
|
static int |
setBit(int value,
int mask,
boolean set)
Sets a bit in a int word
|
static void |
setVariable(java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> map,
DataAccess.Variable<java.lang.Object> ref)
Set or replaces a variable with a simple name in the given container.
|
short |
shortFromUnsignedByte(byte val)
Converts a value in a byte to a unsigned value, which can be stored in a short in Java.
|
static void |
storeValue(DataAccess.DatapathElement path,
java.lang.Object data,
java.lang.Object value,
boolean bAccessPrivate)
Stores a value in the given field or with the given method into the data instance.
|
static void |
storeValue(java.util.List<DataAccess.DatapathElement> path,
java.lang.Object dataRoot,
java.lang.Object value,
boolean bAccessPrivate)
Stores the given value in the element determined by the data path, maybe create a new Variable therewith.
|
void |
storeValue(java.lang.Object dataRoot,
java.lang.Object value,
boolean bAccessPrivate)
Stores the value in the given path.
|
java.lang.String |
toString()
Should be used only for debug to view what is it.
|
void |
writeStruct(java.lang.Appendable out) |
public static final java.lang.String sVersion
istypeof(Object, Class)
now also can detect the class Object itself. More universal.
invokeMethod(DatapathElement, Class, Object, boolean, boolean, Object[])
access(CharSequence, Object, boolean, boolean, boolean, Dst)
now regards a "%..." path for static access.
ParseException
on syntax errors.
access(Object, boolean, boolean, Map, Object[])
etc. needs the variableNames.
DataAccess(StringPartScan, Map, Class, char)
has a new 2. and 3. argument nameVariables and , as well as
DataAccess.DatapathElement#DatapathElement(StringPartScan, Map, Class)
. If given this map is used
to search the first identifier there. If found
#access(Object, boolean, boolean, Object[])
,
#access(List, Object, boolean, boolean, Object[], boolean, Dst)
,
#access(DatapathElement, Object, boolean, boolean, Object[], boolean, Dst)
invokeMethod(DatapathElement, Class, Object, boolean, Object[], boolean)
gets a new argument varValues
to access the variable given on ctor and set operations.
invokeMethod(DatapathElement, Class, Object, boolean, Object[], boolean)
calculates the arguments of the method with the given calculation rule in DataAccess.DatapathElement.args
. This approach is used in, see next
invokeMethod(DatapathElement, Class, Object, boolean, Object[], boolean)
calculates the arguments
due to given algorithm in DataAccess.DatapathElement.args
using the varValues which corresponds to the nameVariables argument on setting the expression.
DataAccess.DatapathElement
has the new field args, instead argNames and argExpr are removed.
ParseException
on parsing errors. Hence the request to handle it is forced.
#DataAccess(StringPartScan, char)
and DatapathElement#set(StringPartScan)
used in parsing pattern in CalculatorExpr
.
DatapathElement#XXXargExpr
to calculate more complex arguments with given expression outside JZtxtcmd
Conversion#key()
may be a better documentation for the conversion classes. It is experience, not used yet.
DataAccess.DatapathElement.operation_
, private and setter and getter. The JzTxtCmd invokes the set_operation() without changes.
It is set now on any operation. Used via DataAccess.DatapathElement.isOperation()
in the org.vishia.xmlReader.XmlZzReader
DatapathElement#operation
. If that is not set and there are no fnArgs
then a field (static) is accessed. That were missing. Used for JzTxtCmd.
initConversion()
accepts boolean from Boolean, important for JzTxtCmd
#invokeMethod(DatapathElement, Class, Object, boolean, boolean)
: Show used class on error.
istypeof(Object, String)
with String argument, based on istypeof(Object, Class)
.
debugMethod(String)
can be invoked with "". Then it invokes debug()
on the next found method
and removes the settings after them. It is usual in a JZtxtcmd Script to stop on the next method.
storeValue(DatapathElement, Object, Object, boolean)
and #access(DatapathElement, Object, boolean, boolean, boolean, Dst)
only with an datapath element, more simple.
invokeMethod(DatapathElement, Class, Object, boolean, boolean, Object[])
with the arguments of the method.
The DatapathElement#argNames
contains names of the arguments which are given with DataAccess.DatapathElement.set(String)
.
With that concept it is possible to define a method call in a script with control which values in the script are used as parameters.
It is used for the XmlJzReader
.
DataAccess.SetDatapathElement.set_index(int)
and DataAccess.DatapathElement.indices
. Syntax for JZcmd adapted (JZtxtcmdSyntax
).
access(CharSequence, Object, boolean, boolean, boolean, Dst)
has dissolved a DataAccess.Variable
twice,
problem if a variable contains a Variable as value. The access <&myVariable.name> was faulty. Not it works.
shortFromUnsignedByte(byte)
and intFromUnsignedShort(short)
.
invokeStaticMethod(DatapathElement)
with variable argument list but only 1 argument
has not worked. TODO okay if no argument?
isReferenceToEnclosing(Field)
and isOrExtends(Class, Class)
#access(List, Object, boolean, boolean, boolean, Dst)
and access(CharSequence, Object, boolean, boolean, boolean, Dst)
now with only one dataRoot.
Not differenced between a MapDataAccess.Variable.type()
to check whether the type of value is correct.
It is not ready yet. Idea: Parameter Class> on creation of variables. JZcmd feature.
DataAccess.Conversions.list2array
: If a List is provided as argument
and an array is expected and the first element matches, it is used. It is assumed that all arguments matches.
TODO special handling for main(String[]) with List argument is not necessary then.
DataAccess.DatapathElementClass.clazz
with a given class. Used on
invokeNew(DatapathElement)
and invokeStaticMethod(DatapathElement)
DataAccess.DatapathElementClass.loader
: static Methods
and #invokeMethod(DatapathElement, Class, Object, boolean, boolean)
with an special ClassLoader
.
#expandElements(String, char)
for String-given elements. The first only one element
of #access(List, Object, Map, boolean, boolean, boolean, Dst)
can contain "path.subpath..."
#access(CharSequence, Object, Map, boolean, boolean, boolean, Dst)
for String given elements.
DataAccess.ObjMethod
for invocation of an method described with reflection,
not used yet but prepared.
#invokeMethod(DatapathElement, Class, Object, boolean, boolean)
with Class as parameter.
#access(List, Object, Map, boolean, boolean, boolean, Dst)
checks whether the obj is stored in an DataAccess.Variable
with type 'C' and value instanceof Class. Then the static method of this Class type is searched and invoked.
That feature is used in conclusion with JZcmd Class myClass = package.path.Class;
debugIdent(String)
sets an identifier on which debug() was called, to set manual breakpoint while debugging.
fnArgsExpr
of DataAccess.DatapathElement
is removed from here.
It is now located in JZtxtcmdScript.JZcmdDatapathElement
because it is necessary
only for the JZcmd usage. This class is more simple in its functionality.
DataAccess.DataAccessSet
are final now. Nobody overrides.
createOrReplaceVariable(Map, String, char, Object, boolean)
instead setVariable(...)
with type argument.
getData(String, Object, boolean, boolean, boolean, Dst)
returns the variable
if the argument bVariable is set.
#access(List, Object, Map, boolean, boolean, boolean, Dst)
,
return value Dst for setting. The #storeValue(List, Map, Object, boolean)
may be obsolte now.
#getData(List, Object, Map, boolean, boolean, boolean)
DataAccess#storeValue(List, Map, Object, boolean)
with special designation in DataAccess.DatapathElement.whatisit
with 'new Variable' designation.
DataAccess.Variable
up to now. This concept is changed
in JZtxtcmdExecuter
originally. Any other application of this class have to wrapped its data
in such an instance DataAccess.Variable
, it is a low-cost effort.
#storeValue(List, Map, Object, boolean)
put in a map, replaces the value.
datapath
as only one attribute.
Now this class can be used instead a List
as bundled instance.
DataAccess.DataAccessSet
is moved from the org.vishia.zbatch.ZbatchGenScript
because it is more universal.
#checkAndConvertArgTypes(List, Class[])
now checks super classes and interfaces,
invokeNew(DatapathElement)
.
#getData(String, DataAccess.Variable, boolean, boolean)
Now accesses to all elements,
also to enclosing and super classes.
#getDataFromField(String, DataAccess.Variable, boolean)
getEnclosingInstance(Object)
#getData(String, DataAccess.Variable, boolean, boolean)
has thrown an Exception if a existing
element has a null-value. Instead it should return null. Exception only if the field is not found.
#checkAndConvertArgTypes(List, Class[])
: Now supports a (String[]) arg which is
typical for a main(String[]) routine. General: The last formal argument can be an array, then all further
non-array arguments are tried to build the element of it.
#getData(List, Object, Map, boolean, boolean)
can be invoked with null for dataPool
to invoke new or static methods.
#checkAndConvertArgTypes(List, Class[])
improved,
new #invokeStaticMethod(DatapathElement, Object, boolean, boolean)
DataAccess.DatapathElement.fnArgs
and #getData(List, Object, Map, boolean, boolean)
.
getStringFromObject(Object, String)
now uses a format string.
DatapathElement#constValue
as general possibility, usual for the first element of a path.
#getData(String, Object, boolean)
as subroutine in #getData(List, Object, Map, boolean, boolean)
and able to use to get with non treed path, only direct but with all facilities to get from Map etc..
DataAccess.DatapathElement
for describing more complex path for access.
setBit(int, int, boolean)
as little universal routine.
getInt(Object)
, getFloat(Object)
from ObjectValue
, last one is deprecated now.
org.vishia.zbatch.ZbatchExecuter
in this class.
That algorithm are able to use independent in some applications.
private static java.util.Map<java.lang.String,DataAccess.Conversion> idxConversions
private static java.lang.String debugIdent
private static java.lang.String debugMethod
protected java.util.List<DataAccess.DatapathElement> datapath
ZbnfDataPathElement
.
If it is used in DataAccess
, its base class DataAccess.DatapathElement
are used. The difference
are the handling of actual values for method calls. See ZbnfDataPathElement#actualArguments
.public DataAccess(java.lang.String path) throws java.text.ParseException
DataAccess.DatapathElement.set(String)
.
path
- java.text.ParseException
public DataAccess(java.lang.String path, char cTypeNewVariable) throws java.text.ParseException
DataAccess.DatapathElement.set(String)
.
path
- cTypeNewVariable
- if A...Z then the last element will be designated with it.
Then a new variable should be created in the parent's container with the access.java.text.ParseException
public DataAccess(StringPartScan sp, java.util.Map<java.lang.String,DataAccess.IntegerIx> nameVariables, java.lang.Class<?> reflData, char cTypeNewVariable) throws java.text.ParseException
DataAccess.DatapathElement.set(String)
.
path
- nameVariables
- if not null then the argument names can start with this given names. The first identifier is searched here.
If it is not found, firstly reflData are used to find it as static variable.
If it is not possible then the identifier is added to the nameVariables map. Hence used names are documented
to outside and can be evaluate on invocation before #access(Object, boolean, boolean, Object[])
.
This feature is introduced with OutTextPreparer
to support simple expressions in a fast way.
If null then the arguments are parsed as DataAccess.reflData
- type wich can contain a static member with the required name in sDatapath if the name is not found in variables
If nameVariables are given and this argument is not null, then an identifier will be searched in this
reflData to get its Access routine.
This feature is introduced with OutTextPreparer
to support simple expressions in a fast way.cTypeNewVariable
- if A...Z then the last element will be designated with it.
Then a new variable should be created in the parent's container with the access.java.text.ParseException
- on errors on sp, on not found variables too.public DataAccess()
add_datapathElement(DatapathElement)
to determine the datapath.public final java.util.List<DataAccess.DatapathElement> datapath()
public void add_datapathElement(DataAccess.DatapathElement item)
item
- DatapathElement}
public java.lang.Object access(java.lang.Object dataRoot, boolean accessPrivate, boolean bContainer, java.util.Map<java.lang.String,DataAccess.IntegerIx> nameVariables, java.lang.Object[] varValues) throws java.lang.Exception
datapath
.dataRoot
- Either a MapbContainer
- true then returns a found container or build one.varValues
- maybe null or array of some variables which are sorted by parameter idxVariables
in DataAccess(StringPartScan, Map, Class, char)
java.lang.Exception
- on any not found or etc.public static void storeValue(java.util.List<DataAccess.DatapathElement> path, java.lang.Object dataRoot, java.lang.Object value, boolean bAccessPrivate) throws java.lang.Exception
DataAccess.DatapathElement.whatisit
DataAccess.Variable.type()
, this variable is created newly.
The destination before, that is either the param variables or the result of the path before,
have to be a Map< String, DataAccess.Variables>
.
DataAccess.Variable
then the value of the variable is replaced.
List
or
a Appendable
, then the value is added respectively appended to it.
Map
with a String as key.
path
- dataRoot
- Either a Mapvalue
- java.lang.IllegalAccessException
java.io.IOException
- if append fails.java.lang.IllegalAccessException
- if a field exists but can't access. Note that private members can be accessed.java.lang.Exception
public static void storeValue(DataAccess.DatapathElement path, java.lang.Object data, java.lang.Object value, boolean bAccessPrivate) throws java.lang.Exception
DataAccess.Variable
its value will be changed.
path
- describes a field or method of data. It is the 'destination'.data
- instance where path is found.value
- valuebAccessPrivate
- java.lang.Exception
- any exception is possible because faulty path, faulty data types etc.public void storeValue(java.lang.Object dataRoot, java.lang.Object value, boolean bAccessPrivate) throws java.lang.Exception
#storeValue(List, Map, Object, boolean)
.dataRoot
- Either a Mapvalue
- bAccessPrivate
- java.lang.Exception
static java.util.Map<java.lang.String,DataAccess.Conversion> initConversion()
fromType:toType
.private static final java.lang.Class<?> getClass(java.lang.String name)
public static java.util.List<DataAccess.DatapathElement> expandElements(java.lang.CharSequence path, char whatisit) throws java.text.ParseException
path
- If starts with "&@$" it is the type.whatisit
- only used if path does not start with type.java.text.ParseException
public static java.lang.Object access(java.lang.CharSequence datapathArg, java.lang.Object dataRoot, boolean accessPrivate, boolean bContainer, boolean bVariable, DataAccess.Dst dst) throws java.lang.Exception
datapathArg
- dataRoot
- Either a MapaccessPrivate
- bContainer
- bVariable
- dst
- java.lang.Exception
public static java.lang.Object access(java.util.List<DataAccess.DatapathElement> datapathArg, java.lang.Object dataRoot, boolean accessPrivate, boolean bContainer, java.util.Map<java.lang.String,DataAccess.IntegerIx> nameVariables, java.lang.Object[] varValues, boolean bVariable, DataAccess.Dst dst) throws java.lang.Exception
DataAccess.DatapathElement.whatisit
is used like:
$
: The datapath can start with an element designated with DataAccess.DatapathElement.whatisit
== '$'.
It describes an access to an environment variable.
The the variable is searched first in the given dataPool with an additional '$' on start of identifier.
Note that the name of the variable (DataAccess.DatapathElement.ident
) does not start with that '$' itself.
If it is found, the dataPool contains this environment variable, it is prior.
If the environment variable is not found in the datapool (a normal case), then the
variable is searched in the environment variables of the operation system. Its String representation is returned.
If the environment variable is not found, null is returned.
The datapath should contain only this one element. Only this first element of the datapath is used.
@
or .
: A variable, DataAccess.DatapathElement.ident
contains the name of the field. It is searched as a
Field
in the given instance of the parent level, firstly in dataRoot.
@
or .
: and DataAccess.DatapathElement.ident
== "[]" It should be the last element of the path.
Then the length of the array of the path before is returned, or the size of a container.
A..Z a..z
: If the only one first element or the last element is designated with DataAccess.DatapathElement.whatisit
== 'A' .. 'Z'
or 'a' ...'z' a new Variable will be created in the given datapool.
The character 'A'...'Z' describes the type. If lower case is written then the variable is created as const.
+
: The only one first element with DataAccess.DatapathElement.whatisit
== '+' is the creation of instance maybe with or without arguments
in DataAccess.DatapathElement.fnArgs
%
: The only one first element with DataAccess.DatapathElement.whatisit
== '%' is a call of a static routine maybe with or without arguments
in DataAccess.DatapathElement.fnArgs
(
: An element with DataAccess.DatapathElement.whatisit
== '(' is a method invocation maybe with or without arguments.
in DataAccess.DatapathElement.fnArgs
Map
then the element is searched by name
as member of this map. The key of the map should be instanceof String.
NoSuchFieldException
or NoSuchMethodException
is returned.
InvocationTargetException
is thrown.
[myField:.]
: The content respectively referenced instance of the field
myField
inside the dataRoot instance is returned.
[myReference:., myField:.]
: The content respectively referenced instance
of the field myReference
inside the dataRoot instance is read. From that instance the
myField
content of referenced instance is returned.
DataAccess.Variable
are designated especially for referencing from one or more MapDataAccess.Variable.value()
. Therewith all references
sees the new value. This method can deal especially with Variable in Map-container additionally to any other accesses.
DataAccess.DatapathElement.whatisit
= 'A' .. 'Z', then
a new variable is created in the context. The context should be a MapDataAccess.DatapathElement.whatisit
== '.':DataAccess.DatapathElement.ident
may determine a field of the current data reference or it may be a key for a indexed container.
The #getData(String, DataAccess.Variable, boolean, boolean)
is invoked, see there for further explanation.
DatapathElement#addArgumentExpression(CalculatorExpr)
.
before the method is called. The expression to calculate is stored in
DatapathElement#fnArgsExpr
whereby the calculated results is stored in DataAccess.DatapathElement.fnArgs
.
DataAccess.DatapathElement.fnArgs
. The number of args should match and the types should be compatibel.
See #checkAndConvertArgTypes(List, Class[])
.dataRoot
- Either a MapaccessPrivate
- if true then private data are accessed too. The accessing of private data may be helpfully
for debugging. It is not recommended for general purpose! The access mechanism is given with
AccessibleObject.setAccessible(boolean)
.bVariable
- if true then return the found DataAccess.Variable
and not its content. If false then return
the DataAccess.Variable.value()
if a variable is the last element.bContainer
- If the element is a container, returns it. Elsewhere build a List
to return a container for iteration with only the found element.
A container is any object implementing java.util.Map or java.util.Iterable or an Array.nameVariables
- necessary on indirect access to variable via String, construct such as <&&(path)>
can be null if not used, should be null especially if varValues == nullvarValues
- maybe null or array of some variables which are sorted by parameter idxVariables
in DataAccess(StringPartScan, Map, Class, char)
dst
- If not null then fill the last Field
and the associated Object in the dst.
It can be used to set the field with a new value.DataAccess.Variable.value()
, then the other rules.
List
with this Object as member.
NoSuchFieldException
or NoSuchMethodException
java.lang.ReflectiveOperationException
java.lang.Throwable
java.lang.IllegalArgumentException
- if the datapath does not address an element. The exception message contains a String
as hint which part does not match.java.lang.Exception
public static java.lang.Object access(DataAccess.DatapathElement element, java.lang.Object data1, boolean accessPrivate, boolean bContainer, java.util.Map<java.lang.String,DataAccess.IntegerIx> nameVariables, java.lang.Object[] varValues, boolean bVariable, DataAccess.Dst dst) throws java.lang.Exception
element
- describes the access, can be a field, operation, environment variable or all possibilitiesdata1
- If it is instanceof Class, then static access. Can be null for instance access, then output null.accessPrivate
- bContainer
- nameVariables
- varValues
- bVariable
- dst
- java.lang.Exception
protected static java.lang.Object invokeNew(DataAccess.DatapathElement element) throws java.lang.Exception
element
- its DataAccess.DatapathElement.whatisit
== '%'.
The DatapathElement#identArgJbat
should contain the full qualified "packagepath.Class.methodname" separated by dot.java.lang.NoSuchMethodException
java.lang.Exception
public static java.lang.Object invokeMethod(DataAccess.DatapathElement element, java.lang.Class<?> clazz, java.lang.Object obj, boolean accessPrivate, java.lang.Object[] varValues, boolean bNoExceptionifNotFound) throws java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.Exception
DataAccess.DatapathElement.args
which contains the access algorithm.
The association to the arguments of the operation in argument 'args' is done here
before invokeMethod(DatapathElement, Class, Object, boolean, boolean, Object[])
is called.element
- its DataAccess.DatapathElement.whatisit
== '('.
The DataAccess.DatapathElement.ident
is the "methodname".clazz
- the Class instance where the method should be found.
For non-static methods the relation obj instanceof clazz should be valid,
elsewhere an exception is thrown.obj
- The instance which is the instance of the method. The obj
is used as first argument of Method.invoke(Object, Object...)
.
For static methods obj is not used. It may be null.accessPrivate
- true then uses private methods toovarValues
- maybe null or array of some variables which are sorted by parameter idxVariables
in DataAccess(StringPartScan, Map, Class, char)
bNoExceptionifNotFound
- if the then does not a NochSuchMethodException if the method was not found.
This is a special flag if the method is optional.java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.Exception
public static java.lang.Object invokeMethod(DataAccess.DatapathElement element, java.lang.Class<?> clazz, java.lang.Object obj, boolean accessPrivate, boolean bNoExceptionifNotFound, java.lang.Object[] args) throws java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.Exception
element
- its DataAccess.DatapathElement.whatisit
== '('.
The DataAccess.DatapathElement.ident
is the "methodname".clazz
- the Class instance where the method should be found.
For non-static methods the relation obj instanceof clazz should be valid,
elsewhere an exception is thrown.obj
- The instance which is the instance of the method. The obj
is used as first argument of Method.invoke(Object, Object...)
.
For static methods obj is not used. It may be null.accessPrivate
- bNoExceptionifNotFound
- args
- if not null then this arguments are used prior to element DataAccess.DatapathElement.fnArgs
.#invokeMethod(DatapathElement, Class, Object, boolean, boolean)
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.Exception
protected static java.lang.Object invokeStaticMethod(DataAccess.DatapathElement element) throws java.lang.Exception
element
- its DataAccess.DatapathElement.whatisit
== '%'.
The DatapathElement#identArgJbat
should contain the full qualified "packagepath.Class.methodname" separated by dot.java.lang.Throwable
java.lang.Exception
protected static java.lang.Object getStaticValue(DataAccess.DatapathElement element) throws java.lang.Exception
element
- its DataAccess.DatapathElement.whatisit
== '%'.
The DatapathElement#identArgJbat
should contain the full qualified "packagepath.Class.methodname" separated by dot.java.lang.Throwable
java.lang.Exception
private static java.lang.ClassLoader getClassLoader(DataAccess.DatapathElement element)
protected static java.lang.Object[] checkAndConvertArgTypes(java.lang.Object[] providedArgs, java.lang.Class<?>[] argTypes)
CharSequence
-> CharSequence
: arg
CharSequence
-> String
: arg.toString()
CharSequence
-> File
: new File(arg)
providedArgs
- Given argumentsargTypes
- requested argument typespublic static DataAccess.Conversion checkArgTypes(java.lang.Class<?> argType, java.lang.Class<?> actType, java.lang.Object arg)
initConversion()
.
If actType is an interface, all super interfaces are checked after them.
If actType is a class, all interfaces are checked but not the superclass.
This routine will be called recursively for the interfaces.
To get the interfaces of a class and all super interfaces of an interface,
the routine Class.getInterfaces()
is called.
Last not least the checkTypes(Class, Class, Object)
is called
for a possible conversion.argType
- Requested typeactType
- Given type, it may be a super class, an interface or a conversion may exists.arg
- The argument itself to check value ranges for conversion using Conversion#canConvert(Object)
.private static DataAccess.Conversion checkIfcTypes(java.lang.Class<?> argType, java.lang.Class<?> ifcType, java.lang.Object arg)
public static DataAccess.Conversion checkTypes(java.lang.Class<?> argType, java.lang.Class<?> actType, java.lang.Object arg)
argType
- The destination type.actType
- The given type.arg
- The valuepublic static final boolean istypeof(java.lang.Object obj, java.lang.String sType) throws java.lang.ClassNotFoundException
Class.forName(sType)
and invokes istypeof(Object, Class)
obj
- any instancetype
- String given typejava.lang.ClassNotFoundException
public static final boolean istypeof(java.lang.Object obj, java.lang.Class type)
obj
- any instancetype
- can be a base type or an interface typepublic static java.lang.Object getData(java.lang.String name, java.lang.Object instance, boolean accessPrivate, boolean bContainer, boolean bVariable, DataAccess.Dst dst) throws java.lang.NoSuchFieldException, java.lang.IllegalAccessException
DataAccess.Variable
then its value is used.
"[]"
and the instance is an array, its length is gotten and returned.
If the instance is instance of an Container or Map, then the size() is returned. This property can be used especially
for #access(Object, boolean, boolean)
as last element.
TreeNodeBase
and the field identifier is not found in this instance,
a child node with the given name is searched.
The TreeNodeBase is the super class of XmlNodeSimple
which is used to present a ZBNF parse result. Therewith the ZbnfParser.getResultTree()
can be used as data input. The tag names of that result tree follow the semantic in the string given Syntax script.
DataAccess.Variable
and bContainer = false, then the value of the Variable is returned.
name
- Name of the field or key in the containerinstance
- The instance where the field or element is searched.accessPrivate
- true than accesses also private data.bContainer
- only used for a TreeNodeBase: If true then returns the List of children as container, If false returns the first child with that name.bVariable
- returns the variable if it is found. if false then returns the value inside a variable.java.lang.NoSuchFieldException
- If not found.java.lang.IllegalAccessException
private static java.lang.Object getDataPriv(java.lang.String name, java.lang.Object instance, boolean accessPrivate, boolean bContainer, boolean bVariable, DataAccess.Dst dst) throws java.lang.NoSuchFieldException, java.lang.IllegalAccessException
name
- instance
- accessPrivate
- bContainer
- bVariable
- dst
- java.lang.NoSuchFieldException
java.lang.IllegalAccessException
public static java.lang.Object getDataFromField(java.lang.String name, java.lang.Object obj, boolean accessPrivate, DataAccess.Dst dst) throws java.lang.NoSuchFieldException, java.lang.IllegalAccessException
name
- The name of the field.obj
- The instance where the field are searched.accessPrivate
- true then read from private or protected fields, false then the access to such fields
throws the IllegalAccessExceptionjava.lang.NoSuchFieldException
- If the field does not exist in the objjava.lang.IllegalAccessException
- if the field exists but is not accessible.private static java.lang.Object getDataFromField(java.lang.String name, java.lang.Object obj, boolean accessPrivate, java.lang.Class<?> clazz, DataAccess.Dst dst, int recursiveCt) throws java.lang.NoSuchFieldException, java.lang.IllegalAccessException
name
- of the fieldobj
- null if static fields should be accessed.accessPrivate
- also search private fieldsclazz
- Should be match to obj if obj !=nulldst
- recursiveCt
- 0 on user call, max. 100 recursions for sub classes and outer classesjava.lang.NoSuchFieldException
- If the field was not found in clazzjava.lang.IllegalAccessException
- If the field cannot be accessed in objpublic static java.lang.Object getEnclosingInstance(java.lang.Object obj)
obj
- The instanceprivate static java.lang.Object getEnclosingInstance(int recurs, java.lang.Object obj)
public static boolean isReferenceToEnclosing(java.lang.reflect.Field ref)
EnclosingType.thisbut it can be omitted. The internal name of the field is
this$99whereby 99 is a number,
this$0 for the immediate enclosing instance.
Note that a enclosing instance is accessible immediately, but it is a referenced object.
ref
- the Fieldthis$
public static boolean isOrExtends(java.lang.Class<?> thisclazz, java.lang.Class<?> cmpclazz)
MyClass myInstance = new MyClass(); //MyClass extends MySuperclass. ... if(DataAcess.isOrExtends(myInstance.getClass(), MySuperclass.class)) { ...This method is similar like
myInstance instanceof MySuperclass. The difference is: It checks classes.
thisclazz
- Class to test, usual build with myInstance.getClass()
cmpclazz
- A Class to check, usual build with Classtype.class
public static java.lang.String getStringFromObject(java.lang.Object content, java.lang.String format)
content
- any objectformat
- may be null, if not null it is used with String.format(String, Object...)
.public static int getInt(java.lang.Object val)
val
- The Object. An int value is returned from all numerical wrappers: Byte, ... Float, Double.public static float getFloat(java.lang.Object val)
val
- The Object. An float value is returned from all numerical wrappers: Byte, ... Float, Double.public static int getLengthOfArray(java.lang.Object data)
Class.isArray()
to check whether it is an arraydata
- any datapublic static java.lang.Object getArrayElement(java.lang.Object data, int... ixArray)
data
- Should be an array with the expected number of dimensions, elsewhere see throwsixArray
- The indices, maybe missed or lesser than array depth, then data or an element as array is returned.
if ixArray contains more indices than necessary, there are ignored.java.lang.IndexOutOfBoundsException
- on faulty ixArraypublic static int setBit(int value, int mask, boolean set)
value
- The actual value of the wordmask
- Designation of bits to change. Usual only one bit. Tip: Use symbolic names.set
- true: set this bits to 1, false: reset the bits to 0.public static DataAccess.Variable<java.lang.Object> createOrReplaceVariable(java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> map, java.lang.String name, char type, java.lang.Object content, boolean isConst) throws java.lang.IllegalAccessException
map
- The container for variables.name
- The name of the variable in the container.type
- one of A O Q J S U L M V E C = Appendable, Object, Boolean, Long,
String, StringBuilder, ListContainer, Map, VariableTree, EnvironmentVariable, Classcontent
- The new valueisConst
- true then create a const variable, or change content of a constant variable.
A const variable is designated by DataAccess.Variable.isConst
boolean element. A const variable can change its content
by setting another const value with this param, but not by assign without this const param flag.java.lang.IllegalAccessException
- if a const variable is attempt to modify without isConst argument.public static void setVariable(java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> map, DataAccess.Variable<java.lang.Object> ref)
createOrReplaceVariable(Map, String, char, Object, boolean)
the container will contain the original given ref.map
- The container for variables.ref
- Initialized variable with or without value.public static DataAccess.Variable<java.lang.Object> getVariable(java.util.Map<java.lang.String,DataAccess.Variable<java.lang.Object>> map, java.lang.String name, boolean strict) throws java.lang.NoSuchFieldException
map
- The containername
- name of the variable in the containerstrict
- true then throws an NoSuchFieldException
if not found.java.lang.NoSuchFieldException
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public java.lang.CharSequence idents()
public static void debugIdent(java.lang.String ident)
debug()
in any IDE (Eclipse...)ident
- The ident to break;public static void debugMethod(java.lang.String ident)
debug()
in any IDE (Eclipse...)ident
- The identifier to break;protected static void debug()
debugIdent(String)
public void writeStruct(java.lang.Appendable out) throws java.io.IOException
java.io.IOException
public short shortFromUnsignedByte(byte val)
val
- a byte value in range -128..0..127public int intFromUnsignedShort(short val)
val
- a short value in range -32768..0..32767