public class NameNode extends java.lang.Object implements java.lang.Comparable<NameNode>
Namespace
object, which may contain children nodes (only for nodes which represent
databases and tables; field nodes have no children).
Nodes representing fields have a parent table node; those representing
tables have a parent database node; database nodes represent the top of
the hierarchy and as such, have no parent node. Thus, any node will be
able to reconstruct its own fully qualified name by walking up the chain
of its ancestors (toQualifiedName()
does this).
This class defines two comparators as inner classes (NameNode.ExactMatchComparator
and NameNode.AbbreviationComparator
)
which are used by Namespace
for name lookups. The former is also
used to define the natural order of NameNode
instances for
sorting purposes.
NameNode is backed by an AST which is stored internally, and which is accessible via accessor methods. The token type of the backing AST defines the data type of the name node. The text of the AST defines the name of the name node.
Note: instances of this object are used as keys in a
WeakHashMap
mapping
in the
SchemaDictionary
. That mapping relies on this object using
==
as its implementation of the equals
method
(inherited from java.lang.Object
). Any other implementation
of equals
will break that mapping!
Modifier and Type | Class and Description |
---|---|
private static class |
NameNode.AbbreviationComparator
Comparator which will report two
NameNode objects as
equivalent if the second node's name represents an abbreviation for the
first node's name. |
private static class |
NameNode.ExactMatchComparator
Comparator which requires the name portion of the
NameNode s
being compared lexically to match exactly for the nodes to be reported
as equivalent (return value of 0 from compare method). |
Modifier and Type | Field and Description |
---|---|
static NameNode.AbbreviationComparator |
ABBREVIATION_COMPARATOR
Comparator which allows abbreviations of node names
|
private Aast |
ast
AST node associated with this name node
|
private Namespace |
children
Namespace containing child nodes, if any
|
static NameNode.ExactMatchComparator |
EXACT_COMPARATOR
Comparator which requires exact lexical match of node names
|
private NameNode |
parent
Optional parent associated with this name node
|
Constructor and Description |
---|
NameNode(NameNode parent,
Aast ast)
Constructor which specifies node's parent, AST, and name.
|
NameNode(java.lang.String name)
Convenience constructor to create a temporary name node.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(NameNode o)
Compares this name node with the specified name node to determine the
natural order of name nodes.
|
Aast |
getAst()
Get the AST which backs this name node.
|
java.lang.String |
getName()
Get the name associated with this node.
|
Namespace |
getNamespace()
Get the namespace which contains this node's children, if any.
|
(package private) long |
getOrder()
Must be called only for fields.
|
NameNode |
getParent()
Get the parent, if any, associated with this node.
|
int |
getType()
Get the data type associated with this node.
|
boolean |
isPreferred()
Reports if this node is to be preferred in ambiguous name conflicts
over other name nodes that do not have this flag set.
|
void |
setAst(Aast ast)
Set the AST which backs this name node.
|
void |
setParent(NameNode parent)
Set the parent name node of this node.
|
(package private) java.lang.String |
toAliasedName(int type,
EntityName entityName)
Get the fully qualified, unabbreviated name which corresponds with this
node.
|
java.lang.String |
toQualifiedName()
Get the fully qualified, unabbreviated name which corresponds with this
node.
|
java.lang.String |
toString()
Returns a string representation of this name node, primarily for debug
purposes.
|
public static final NameNode.ExactMatchComparator EXACT_COMPARATOR
public static final NameNode.AbbreviationComparator ABBREVIATION_COMPARATOR
private NameNode parent
private Namespace children
private Aast ast
public NameNode(NameNode parent, Aast ast)
parent
- Optional parent name node. If not null
this node
will be added to parent
's namespace.ast
- AST node to be associated with this name node.java.lang.NullPointerException
- if name
is null
.NameNode(java.lang.String name)
name
- Name assigned to the name node. May not be null
.public NameNode getParent()
null
.public void setParent(NameNode parent)
parent
is
not null
, add this node to its private namespace.parent
- New parent name node.public Aast getAst()
public void setAst(Aast ast)
ast
- Backing AST. Should not be null
.public java.lang.String getName()
public int getType()
public boolean isPreferred()
public Namespace getNamespace()
public java.lang.String toQualifiedName()
[[grandparent_name.]parent_name.]name
.
Note that this node might not have a grandparent or even a parent, in
which case the missing ancestor names are omitted.public int compareTo(NameNode o)
NameNode.ExactMatchComparator
.compareTo
in interface java.lang.Comparable<NameNode>
o
- NameNode
for comparison. If null
or
not of type NameNode
, 1
is returned.0
if objects are considered equal by the rules
of the NameNode.ExactMatchComparator
; -1
if this
is considered less than o
;
1
if this
is considered greater than
o
.public java.lang.String toString()
toString
in class java.lang.Object
java.lang.String toAliasedName(int type, EntityName entityName)
entityName
, if any, for the
database name portion of the qualified nametype
- Entity type, using EntityName
constants.entityName
- If this object specifies a database qualifier, it is used in
preference to the qualifier discovered by inspection of this
node's internal state or lineage. May be null
; if
so, no database alias substitution is performed.database[.table[.field]]
for regular schema entities, or table[.field]
for temp
or work tables (or their fields).long getOrder()