public class TypeAnalyzer
extends java.lang.Object
Title: Framework Support Library
Description: This class can be used to analyze Java types using reflection mechanism.
class Test { private HashMap<String, Test> map = new HashMap<String, Test>(); private String str = "string"; private ArrayList<Object> list = new ArrayList<Object>(); }The graph for this type (using the default creation strategy) will be the following:
Test | +-- map (HashMap<String, Test>) | | | +-- key (String) | | | +-- value (Test) | +-- str (String) | +-- list (ArrayList<Object>) | +-- element (Object)For this type the following SDR paths are possible:
//map[key='some_key'] ~ //map/value //map[8] ~ //map/value //map[value='some_value'] ~ //map/key //array[7] ~ //array/element
Copyright: Copyright (c) 2011
Company: StreamScape Technologies
Modifier and Type | Class and Description |
---|---|
static class |
TypeAnalyzer.ParameterizedTypeImplicitMap |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ELEMENT |
static java.lang.String |
KEY |
static java.lang.String |
VALUE |
Modifier and Type | Method and Description |
---|---|
boolean |
assertPath(java.lang.String path)
Returns true if the specified SDR path is correct: it starts from "//<{root type}>", and
the syntax is correct, and no path's class casts fail, and the root type is resolved
successfully, and the corresponding Class is successfully loaded, and all the path parts point
to existing class fields.
|
boolean |
assertPath(java.lang.reflect.Type type,
java.lang.String path)
Returns true if the specified SDR path in the specified Java type is correct: its syntax is
correct, and no path's class casts fail, and all the path parts point to existing class
fields.
|
java.lang.Class |
getClassBySemanticType(java.lang.String semanticType)
Looks up for the specified semantic type in the semantic type cache, gets its full Java class
name, loads this class and returns it.
|
java.lang.ClassLoader |
getClassLoader()
Returns the class loader used for class loading, when class casts are
present in an SDR path.
|
java.lang.reflect.Field |
getField(java.lang.reflect.Type type,
java.lang.String path)
Returns the Java field referenced by the specified SDRPath.
|
java.lang.Class |
getFieldClass(java.lang.String path)
Returns the Java class of the field located by the specified SDR path.
|
java.lang.Class |
getFieldClass(java.lang.String typeName,
java.lang.String path)
Returns the Java type of the field located by the specified SDR path in the specified
semantic type.
|
java.lang.Class |
getFieldClass(java.lang.reflect.Type type,
java.lang.String path)
Returns the Java class of the field located by the specified SDR path in the specified Java
type.
|
java.lang.reflect.Type |
getFieldType(java.lang.String path)
Returns the Java type of the field located by the specified SDR path.
|
java.lang.reflect.Type |
getFieldType(java.lang.reflect.Type type,
java.lang.String path)
Returns the Java type of the field located by the specified SDR path in the specified
type.
|
java.lang.String |
getFieldTypeAsString(java.lang.String path)
Returns the class name of the field located by the specified SDR path.
|
java.lang.String |
getFieldTypeAsString(java.lang.reflect.Type type,
java.lang.String path)
Returns the class name of the field located by the specified SDR path in the specified Java
type.
|
static java.lang.Class |
getRawClass(java.lang.reflect.Type type)
Returns the raw Java class for the specified Java type.
|
SemanticTypeCache |
getSemanticTypeCache()
Returns the semantic type cache used for types lookup, when type casts are
present in an SDR path.
|
TypeGraphCreationStrategy |
getStrategy()
Returns the strategy used during building of type graphs.
|
TypeGraph |
getTypeGraph(java.lang.String path)
Creates a type graph (a tree) for the Java type located by the specified SDR path.
|
TypeGraph |
getTypeGraph(java.lang.reflect.Type type)
Creates a type graph (a tree) for the specified Java type.
|
TypeGraph |
getTypeGraph(java.lang.reflect.Type type,
java.lang.String path)
Creates a type graph (a tree) for the Java type, which is a child of the specified type,
located by the specified SDR path in this type.
|
void |
setClassLoader(java.lang.ClassLoader loader)
Sets the specified class loader to be used for class loading, when class casts are
present in an SDR path.
|
void |
setSemanticTypeCache(SemanticTypeCache cache)
Sets the specified semantic type cache to be used for types lookup, when type casts are
present in an SDR path.
|
void |
setStrategy(TypeGraphCreationStrategy graphStrategy)
Sets the specified strategy to be used during building of a type graph.
|
public static final java.lang.String KEY
public static final java.lang.String VALUE
public static final java.lang.String ELEMENT
public void setStrategy(TypeGraphCreationStrategy graphStrategy)
graphStrategy
- the strategy to be used during building of a type graph.public TypeGraphCreationStrategy getStrategy()
public void setSemanticTypeCache(SemanticTypeCache cache)
TypeAnalyzer
for a description of SDR path.cache
- The semantic type cache to be set for types lookup.public SemanticTypeCache getSemanticTypeCache()
TypeAnalyzer
for a description of SDR path.public void setClassLoader(java.lang.ClassLoader loader)
TypeAnalyzer
for a description of SDR path.loader
- the class loader to be set.public java.lang.ClassLoader getClassLoader()
TypeAnalyzer
for a description of SDR path.public TypeGraph getTypeGraph(java.lang.String path) throws TypeAnalyzerException
"//{}"
to specify in what root type
the necessary Java type is located by this path.
See TypeAnalyzer
for a description of type graphs and SDR paths.path
- the SDR path of the Java type, which graph should be created.TypeAnalyzerException
- if the path doesn't start from "//<{root type}>", or the
path has bad syntax, or one of the path's class casts fails, or the root type can't be
resolved, or the corresponding Class can't be loaded, or there are no such class field
pointed to by one of the path parts.public TypeGraph getTypeGraph(java.lang.reflect.Type type, java.lang.String path) throws TypeAnalyzerException
TypeAnalyzer
for
a description of type graphs and SDR paths.type
- the type, for which child the graph should be createdpath
- the SDR path of the child type, which graph should be createdTypeAnalyzerException
- if the path has bad syntax, or one of the path's class casts
fails, or there are no such class field pointed to by one of the path parts.public TypeGraph getTypeGraph(java.lang.reflect.Type type) throws TypeAnalyzerException
TypeAnalyzer
for
a description of type graphs.type
- the type for which the graph should be created.TypeAnalyzerException
- if some error occurs during processing of the graph nodes by the
the current creation strategy.public java.lang.String getFieldTypeAsString(java.lang.String path) throws TypeAnalyzerException
"//{<root type>}"
to specify in what root type the necessary field is
located by this path. See TypeAnalyzer
for a description of SDR paths.HashMap<String, Test>
it returns
java.util.HashMap
. To get the fully-qualified parametrized type use
getFieldType(String)
method.path
- the SDR path of the field, which Java class name should be returned.TypeAnalyzerException
- If the path doesn't start from "//<{root type}>", or the
path has bad syntax, or one of the path's class casts fails, or the root type can't be
resolved, or the corresponding Class can't be loaded, or there are no such class field
pointed to by one of the path parts.public java.lang.Class getFieldClass(java.lang.String path) throws TypeAnalyzerException
"//{<root type>}"
to specify in what root type the necessary field is
located by this path. See TypeAnalyzer
for a description of SDR paths.HashMap<String, Test>
it returns
java.util.HashMap
class.path
- the SDR path of the field, which Java class should be returned.TypeAnalyzerException
- if the path doesn't start from "//<{root type}>", or the
path has bad syntax, or one of the path's class casts fails, or the root type can't be
resolved, or the corresponding Class can't be loaded, or there are no such class field
pointed to by one of the path parts.public java.lang.reflect.Type getFieldType(java.lang.String path) throws TypeAnalyzerException
"//{<root type>}"
to specify in what root type the necessary field is
located by this path. See TypeAnalyzer
for a description of SDR paths.path
- the SDR path of the field, which Java class should be returned.TypeAnalyzerException
- if the path doesn't start from "//<{root type}>", or the
path has bad syntax, or one of the path's class casts fails, or the root type can't be
resolved, or the corresponding Class can't be loaded, or there are no such class field
pointed to by one of the path parts.public java.lang.String getFieldTypeAsString(java.lang.reflect.Type type, java.lang.String path) throws TypeAnalyzerException
TypeAnalyzer
for a description of SDR paths.HashMap<String, Test>
it returns
java.util.HashMap
. To get the fully-qualified parametrized type use
getFieldType(Type, String)
method.type
- the type, for which field the class name should be returned.path
- the SDR path of the field, which Java class name should be returned.TypeAnalyzerException
- if the path has bad syntax, or one of the path's class casts
fails, or the root type can't be resolved, or the corresponding Class can't be loaded,
or there are no such class field pointed to by one of the path parts.public java.lang.Class getFieldClass(java.lang.reflect.Type type, java.lang.String path) throws TypeAnalyzerException
TypeAnalyzer
for a description of SDR paths.HashMap<String, Test>
it returns
java.util.HashMap
class. To get the fully-qualified parametrized type use
getFieldType(Type, String)
method.type
- the type, for which field the Java class should be returned.path
- the SDR path of the field, which Java class should be returned.TypeAnalyzerException
- If the path has bad syntax, or one of the path's class casts
fails, or the root type can't be resolved, or the corresponding Class can't be loaded,
or there are no such class field pointed to by one of the path parts.public java.lang.reflect.Type getFieldType(java.lang.reflect.Type type, java.lang.String path) throws TypeAnalyzerException
TypeAnalyzer
for a description of SDR paths.type
- the type, for which field the Java type should be returned.path
- the SDR path of the field, which Java type should be returned.TypeAnalyzerException
- If the path has bad syntax, or one of the path's class casts
fails, or the root type can't be resolved, or the corresponding Class can't be loaded,
or there are no such class field pointed to by one of the path parts.public java.lang.reflect.Field getField(java.lang.reflect.Type type, java.lang.String path) throws TypeAnalyzerException
TypeAnalyzer
for a description of SDR paths.type
- the type, which should contain specified field.path
- the SDR path of the field.TypeAnalyzerException
- if the path has bad syntax, or one of the path's class casts
fails, or the root type can't be resolved, or the corresponding Class can't be loaded,
or there are no such class field pointed to by one of the path parts.public java.lang.Class getFieldClass(java.lang.String typeName, java.lang.String path) throws TypeAnalyzerException
TypeAnalyzer
for a description of SDR paths.typeName
- the semantic type name, for which field the Java type should be returned.path
- the SDR path of the field, which Java type should be returned.TypeAnalyzerException
- if the path has bad syntax, or one of the path's class casts
fails, or the root type can't be resolved, or the corresponding Class can't be loaded,
or there are no such class field pointed to by one of the path parts.public boolean assertPath(java.lang.String path)
TypeAnalyzer
for a description of SDR
paths.path
- the SDR path to be checked.true
if the specified path is correct, false
otherwise.public boolean assertPath(java.lang.reflect.Type type, java.lang.String path)
TypeAnalyzer
for a description of SDR paths.path
- the SDR path to be checked.true
if the specified path is correct, false
otherwise.public java.lang.Class getClassBySemanticType(java.lang.String semanticType) throws TypeAnalyzerException
semanticType
- Semantic type, which Java class should be returned.TypeAnalyzerException
- if the specified semantic type is not found in the cache or the
corresponding class can't be loaded.public static java.lang.Class getRawClass(java.lang.reflect.Type type)
HashMap<String, Test>
or HashMap<String, Test>[]
the
method returns java.util.HashMap
class.type
- the Java type for which the raw Java class should be returned.Copyright © 2015-2024 StreamScape Technologies. All rights reserved.