Top Description Inners Fields Constructors Methods
org.apache.xerces.impl.xs.models

public Class XSDFACM

extends Object
implements XSCMValidator
Class Inheritance
All Implemented Interfaces
org.apache.xerces.impl.xs.models.XSCMValidator
Imports
java.util.HashMap, .Vector, org.apache.xerces.impl.dtd.models.CMNode, .CMStateSet, org.apache.xerces.impl.xs.SchemaSymbols, .SubstitutionGroupHandler, .XMLSchemaException, .XSConstraints, .XSElementDecl, .XSModelGroupImpl, .XSParticleDecl, .XSWildcardDecl, org.apache.xerces.xni.QName

DFAContentModel is the implementation of XSCMValidator that does all of the non-trivial element content validation. This class does the conversion from the regular expression to the DFA that it then uses in its validation algorithm.
Author
Neil Graham, IBM
Version
$Id: XSDFACM.java 806363 2009-08-20 21:18:48Z mrglavas $

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final boolean
private static final boolean
DEBUG_VALIDATE_CONTENT

Set to true to debug content model validation.

private XSDFACM.Occurence[]
fCountingStates

Array containing occurence information for looping states which use counters to check minOccurs/maxOccurs.

private Object[]
fElemMap

This is the map of unique input symbol elements to indices into each state's per-input symbol transition table entry.

private int[]
fElemMapId

id of the unique input symbol

private int
fElemMapSize

The element map size.

private int[]
fElemMapType

This is a map of whether the element map contains information related to ANY models.

private boolean[]
fFinalStateFlags

This is an array of booleans, one per state (there are fTransTableSize states in the DFA) that indicates whether that state is a final state.

private CMStateSet[]
fFollowList

The list of follow positions for each NFA position (i.e. for each non-epsilon leaf node.) This is only used during the building of the DFA, and is let go afterwards.

private CMNode
fHeadNode

This is the head node of our intermediate representation.

private boolean
private int
fLeafCount

The count of leaf nodes.

private XSCMLeaf[]
fLeafList

An array of non-epsilon leaf nodes, which is used during the DFA build operation, then dropped.

private int[]
fLeafListType

Array mapping ANY types to the leaf list.

private int[][]
fTransTable

This is the transition table that is the main by product of all of the effort here.

private int
fTransTableSize

The number of valid entries in the transition table, and in the other related tables such as fFinalStateFlags.

private static long

Constructor Summary

AccessConstructor and Description
public
XSDFACM(CMNode
The syntax tree of the content model.
syntaxTree
,
int
The number of leaves.
leafCount
)

Constructs a DFA content model.

Method Summary

Modifier and TypeMethod and Description
private void
buildDFA(CMNode
The syntax tree.
syntaxTree
)

Builds the internal DFA transition table from the given syntax tree.

private void
calcFollowList(CMNode
The curent node.
nodeCur
)

Calculates the follow list of the current node.

public boolean

Returns:

true if this content model contains other or list wildcard
checkUniqueParticleAttribution
(SubstitutionGroupHandler
the substitution group handler
subGroupHandler
)

Implements org.apache.xerces.impl.xs.models.XSCMValidator.checkUniqueParticleAttribution.

check whether this content violates UPA constraint.
private void
dumpTree(CMNode
The current node.
nodeCur
,
int
The maximum levels to output.
level
)

Dumps the tree of the current node to standard output.

public boolean
endContentModel(int[]
Current state of the content model
state
)

Implements org.apache.xerces.impl.xs.models.XSCMValidator.endContentModel.

The method indicates the end of list of children
pack-priv Object
pack-priv Object
findMatchingDecl(QName curElem, int[] state, SubstitutionGroupHandler subGroupHandler, int elemIndex)

public String
getTermName(int
identifier for the element declaration or wildcard
termId
)

Implements org.apache.xerces.impl.xs.models.XSCMValidator.getTermName.

Returns the name of the term (element or wildcard) for the given identifier.
public boolean
isCompactedForUPA()

Implements org.apache.xerces.impl.xs.models.XSCMValidator.isCompactedForUPA.

Checks if this content model has had its min/maxOccurs values reduced for purposes of speeding up UPA.
public boolean

Returns:

whether it's a final state
isFinalState
(int
the state to check
state
)

check whether the given state is one of the final states

private int[]
makeDefStateList()

-1 is used to represent bad transitions in the transition table entry for each state.

public int[]
occurenceInfo(int[]
the current state
state
)

Implements org.apache.xerces.impl.xs.models.XSCMValidator.occurenceInfo.

Returns an array containing information about the current repeating term or null if no occurrence counting was being performed at the current state.

public Object

Returns:

null if transition is invalid; otherwise the Object corresponding to the XSElementDecl or XSWildcardDecl identified. Also, the state array will be modified to include the new state; this so that the validator can store it away.
oneTransition
(QName
The current element's QName
curElem
,
int[]
stack to store the previous state
state
,
SubstitutionGroupHandler
the substitution group handler
subGroupHandler
)

Implements org.apache.xerces.impl.xs.models.XSCMValidator.oneTransition.

one transition only
private void
postTreeBuildInit(CMNode nodeCur)

Post tree build initialization.

public int[]
startContentModel()

Implements org.apache.xerces.impl.xs.models.XSCMValidator.startContentModel.

This methods to be called on entering a first element whose type has this content model.
public Vector<E>

Returns:

a Vector whose entries are instances of either XSWildcardDecl or XSElementDecl.
whatCanGoHere
(int[]
the current state
state
)

Implements org.apache.xerces.impl.xs.models.XSCMValidator.whatCanGoHere.

Check which elements are valid to appear at this point.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEBUGback to summary
private static final boolean DEBUG
DEBUG_VALIDATE_CONTENTback to summary
private static final boolean DEBUG_VALIDATE_CONTENT

Set to true to debug content model validation.

fCountingStatesback to summary
private XSDFACM.Occurence[] fCountingStates

Array containing occurence information for looping states which use counters to check minOccurs/maxOccurs.

fElemMapback to summary
private Object[] fElemMap

This is the map of unique input symbol elements to indices into each state's per-input symbol transition table entry. This is part of the built DFA information that must be kept around to do the actual validation. Note tat since either XSElementDecl or XSParticleDecl object can live here, we've got to use an Object.

fElemMapIdback to summary
private int[] fElemMapId

id of the unique input symbol

fElemMapSizeback to summary
private int fElemMapSize

The element map size.

fElemMapTypeback to summary
private int[] fElemMapType

This is a map of whether the element map contains information related to ANY models.

fFinalStateFlagsback to summary
private boolean[] fFinalStateFlags

This is an array of booleans, one per state (there are fTransTableSize states in the DFA) that indicates whether that state is a final state.

fFollowListback to summary
private CMStateSet[] fFollowList

The list of follow positions for each NFA position (i.e. for each non-epsilon leaf node.) This is only used during the building of the DFA, and is let go afterwards.

fHeadNodeback to summary
private CMNode fHeadNode

This is the head node of our intermediate representation. It is only non-null during the building of the DFA (just so that it does not have to be passed all around.) Once the DFA is built, this is no longer required so its nulled out.

fIsCompactedForUPAback to summary
private boolean fIsCompactedForUPA
fLeafCountback to summary
private int fLeafCount

The count of leaf nodes. This is an important number that set some limits on the sizes of data structures in the DFA process.

fLeafListback to summary
private XSCMLeaf[] fLeafList

An array of non-epsilon leaf nodes, which is used during the DFA build operation, then dropped.

fLeafListTypeback to summary
private int[] fLeafListType

Array mapping ANY types to the leaf list.

fTransTableback to summary
private int[][] fTransTable

This is the transition table that is the main by product of all of the effort here. It is an array of arrays of ints. The first dimension is the number of states we end up with in the DFA. The second dimensions is the number of unique elements in the content model (fElemMapSize). Each entry in the second dimension indicates the new state given that input for the first dimension's start state.

The fElemMap array handles mapping from element indexes to positions in the second dimension of the transition table.

fTransTableSizeback to summary
private int fTransTableSize

The number of valid entries in the transition table, and in the other related tables such as fFinalStateFlags.

timeback to summary
private static long time

Constructor Detail

XSDFACMback to summary
public XSDFACM(CMNode syntaxTree, int leafCount)

Constructs a DFA content model.

Parameters
syntaxTree:CMNode

The syntax tree of the content model.

leafCount:int

The number of leaves.

Exceptions
RuntimeException:
Thrown if DFA can't be built.

Method Detail

buildDFAback to summary
private void buildDFA(CMNode syntaxTree)

Builds the internal DFA transition table from the given syntax tree.

Parameters
syntaxTree:CMNode

The syntax tree.

Exceptions
RuntimeException:
Thrown if DFA cannot be built.
calcFollowListback to summary
private void calcFollowList(CMNode nodeCur)

Calculates the follow list of the current node.

Parameters
nodeCur:CMNode

The curent node.

Exceptions
RuntimeException:
Thrown if follow list cannot be calculated.
checkUniqueParticleAttributionback to summary
public boolean checkUniqueParticleAttribution(SubstitutionGroupHandler subGroupHandler) throws XMLSchemaException

Implements org.apache.xerces.impl.xs.models.XSCMValidator.checkUniqueParticleAttribution.

check whether this content violates UPA constraint.

Parameters
subGroupHandler:SubstitutionGroupHandler

the substitution group handler

Returns:boolean

true if this content model contains other or list wildcard

dumpTreeback to summary
private void dumpTree(CMNode nodeCur, int level)

Dumps the tree of the current node to standard output.

Parameters
nodeCur:CMNode

The current node.

level:int

The maximum levels to output.

Exceptions
RuntimeException:
Thrown on error.
endContentModelback to summary
public boolean endContentModel(int[] state)

Implements org.apache.xerces.impl.xs.models.XSCMValidator.endContentModel.

Doc from org.apache.xerces.impl.xs.models.XSCMValidator.endContentModel.

The method indicates the end of list of children

Parameters
state:int[]

Current state of the content model

Returns:boolean

true if the last state was a valid final state

findMatchingDeclback to summary
pack-priv Object findMatchingDecl(QName curElem, SubstitutionGroupHandler subGroupHandler)
findMatchingDeclback to summary
pack-priv Object findMatchingDecl(QName curElem, int[] state, SubstitutionGroupHandler subGroupHandler, int elemIndex)
getTermNameback to summary
public String getTermName(int termId)

Implements org.apache.xerces.impl.xs.models.XSCMValidator.getTermName.

Doc from org.apache.xerces.impl.xs.models.XSCMValidator.getTermName.

Returns the name of the term (element or wildcard) for the given identifier.

Parameters
termId:int

identifier for the element declaration or wildcard

Returns:String

the name of the element declaration or wildcard

isCompactedForUPAback to summary
public boolean isCompactedForUPA()

Implements org.apache.xerces.impl.xs.models.XSCMValidator.isCompactedForUPA.

Doc from org.apache.xerces.impl.xs.models.XSCMValidator.isCompactedForUPA.

Checks if this content model has had its min/maxOccurs values reduced for purposes of speeding up UPA. If so, this content model should not be used for any purpose other than checking unique particle attribution

Returns:boolean

a boolean that says whether this content has been compacted for UPA

isFinalStateback to summary
public boolean isFinalState(int state)

check whether the given state is one of the final states

Parameters
state:int

the state to check

Returns:boolean

whether it's a final state

makeDefStateListback to summary
private int[] makeDefStateList()

-1 is used to represent bad transitions in the transition table entry for each state. So each entry is initialized to an all -1 array. This method creates a new entry and initializes it.

occurenceInfoback to summary
public int[] occurenceInfo(int[] state)

Implements org.apache.xerces.impl.xs.models.XSCMValidator.occurenceInfo.

Doc from org.apache.xerces.impl.xs.models.XSCMValidator.occurenceInfo.

Returns an array containing information about the current repeating term or null if no occurrence counting was being performed at the current state.

If an array is returned it will have a length == 4 and will contain:

  • a[0] :: min occurs
  • a[1] :: max occurs
  • a[2] :: current value of the counter
  • a[3] :: identifier for the repeating term

Parameters
state:int[]

the current state

Returns:int[]

an array containing information about the current repeating term

oneTransitionback to summary
public Object oneTransition(QName curElem, int[] state, SubstitutionGroupHandler subGroupHandler)

Implements org.apache.xerces.impl.xs.models.XSCMValidator.oneTransition.

one transition only

Parameters
curElem:QName

The current element's QName

state:int[]

stack to store the previous state

subGroupHandler:SubstitutionGroupHandler

the substitution group handler

Returns:Object

null if transition is invalid; otherwise the Object corresponding to the XSElementDecl or XSWildcardDecl identified. Also, the state array will be modified to include the new state; this so that the validator can store it away.

Exceptions
RuntimeException:
thrown on error
postTreeBuildInitback to summary
private void postTreeBuildInit(CMNode nodeCur) throws RuntimeException

Post tree build initialization.

startContentModelback to summary
public int[] startContentModel()

Implements org.apache.xerces.impl.xs.models.XSCMValidator.startContentModel.

Doc from org.apache.xerces.impl.xs.models.XSCMValidator.startContentModel.

This methods to be called on entering a first element whose type has this content model. It will return the initial state of the content model

Returns:int[]

Start state of the content model

whatCanGoHereback to summary
public Vector<E> whatCanGoHere(int[] state)

Implements org.apache.xerces.impl.xs.models.XSCMValidator.whatCanGoHere.

Check which elements are valid to appear at this point. This method also works if the state is in error, in which case it returns what should have been seen.

Parameters
state:int[]

the current state

Returns:Vector<E>

a Vector whose entries are instances of either XSWildcardDecl or XSElementDecl.

org.apache.xerces.impl.xs.models back to summary

pack-priv final Class XSDFACM.Occurence

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final int
pack-priv final int
pack-priv final int

Constructor Summary

AccessConstructor and Description
public
Occurence(XSCMRepeatingLeaf leaf, int elemIndex)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

elemIndexback to summary
pack-priv final int elemIndex
maxOccursback to summary
pack-priv final int maxOccurs
minOccursback to summary
pack-priv final int minOccurs

Constructor Detail

Occurenceback to summary
public Occurence(XSCMRepeatingLeaf leaf, int elemIndex)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.