APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.org.apache.xerces.internal.impl.xs.models

public Class XSDFACM

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

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

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[]
fElemMapCounter

Array of counters for all the for elements (or wildcards) of the form a{n,m} where n > 1 and m <= unbounded.

private int[]
fElemMapCounterLowerBound

Array of lower bounds for all the for elements (or wildcards) of the form a{n,m} where n > 1 and m <= unbounded.

private int[]
fElemMapCounterUpperBound

Array of upper bounds for all the for elements (or wildcards) of the form a{n,m} where n > 1 and m <= unbounded.

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 List<String>
checkMinMaxBounds()

Implements com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator.checkMinMaxBounds.

Used by constant space algorithm for a{n,m} for n > 1 and m <= unbounded.

public boolean

Returns:

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

Implements com.sun.org.apache.xerces.internal.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[] state)

Implements com.sun.org.apache.xerces.internal.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 termId)

Implements com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator.getTermName.

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

public boolean
isCompactedForUPA()

Implements com.sun.org.apache.xerces.internal.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[] state)

Implements com.sun.org.apache.xerces.internal.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 com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator.oneTransition.

one transition only

private void
postTreeBuildInit(CMNode nodeCur)

Post tree build initialization.

public int[]
startContentModel()

Implements com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator.startContentModel.

This methods to be called on entering a first element whose type has this content model.

public List<Object>

Returns:

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

Implements com.sun.org.apache.xerces.internal.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.

fElemMapCounterback to summary
private int[] fElemMapCounter

Array of counters for all the for elements (or wildcards) of the form a{n,m} where n > 1 and m <= unbounded. Used to count the a's to later check against n and m. Counter set to -1 if element (or wildcard) not optimized by constant space algorithm.

fElemMapCounterLowerBoundback to summary
private int[] fElemMapCounterLowerBound

Array of lower bounds for all the for elements (or wildcards) of the form a{n,m} where n > 1 and m <= unbounded. This array stores the n's for those elements (or wildcards) for which the constant space algorithm applies (or -1 otherwise).

fElemMapCounterUpperBoundback to summary
private int[] fElemMapCounterUpperBound

Array of upper bounds for all the for elements (or wildcards) of the form a{n,m} where n > 1 and m <= unbounded. This array stores the n's for those elements (or wildcards) for which the constant space algorithm applies, or -1 if algorithm does not apply or m = unbounded.

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.
checkMinMaxBoundsback to summary
public List<String> checkMinMaxBounds()

Implements com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator.checkMinMaxBounds.

Used by constant space algorithm for a{n,m} for n > 1 and m <= unbounded. Called by a validator if validation of countent model succeeds after subsuming a{n,m} to a* (or a+) to check the n and m bounds. Returns null if validation of bounds is successful. Returns a list of strings with error info if not. Even entries in list returned are error codes (used to look up properties) and odd entries are parameters to be passed when formatting error message. Each parameter is associated with the error code that preceeds it in the list.

checkUniqueParticleAttributionback to summary
public boolean checkUniqueParticleAttribution(SubstitutionGroupHandler subGroupHandler) throws XMLSchemaException

Implements com.sun.org.apache.xerces.internal.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 com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator.endContentModel.

Doc from com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator.endContentModel.

The method indicates the end of list of children

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 com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator.getTermName.

Doc from com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator.getTermName.

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

isCompactedForUPAback to summary
public boolean isCompactedForUPA()

Implements com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator.isCompactedForUPA.

Doc from com.sun.org.apache.xerces.internal.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

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 com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator.occurenceInfo.

Doc from com.sun.org.apache.xerces.internal.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

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

Implements com.sun.org.apache.xerces.internal.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 com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator.startContentModel.

Doc from com.sun.org.apache.xerces.internal.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

whatCanGoHereback to summary
public List<Object> whatCanGoHere(int[] state)

Implements com.sun.org.apache.xerces.internal.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:List<Object>

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

com.sun.org.apache.xerces.internal.impl.xs.models back to summary

pack-priv final Class XSDFACM.Occurence

extends Object
Class Inheritance
  • java.lang.Object
  • com.sun.org.apache.xerces.internal.impl.xs.models.XSDFACM.Occurence

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. Satisfying this method's contract implies a non-null result must be returned.