@Override
    public void validateElementStart(String localName, String uri, String prefix)
        throws XMLStreamException
    {
        /* Ok, need to find the element definition; if not found (or
         * only implicitly defined), need to throw the exception.
         */
        mTmpKey.reset(prefix, localName);

        DTDElement elem = mElemSpecs.get(mTmpKey);

        /* Let's add the entry in (even if it's a null); this is necessary
         * to keep things in-sync if allowing graceful handling of validity
         * errors
         */
        int elemCount = mElemCount++;
        if (elemCount >= mElems.length) {
            mElems = (DTDElement[]) DataUtil.growArrayBy50Pct(mElems);
            mValidators = (StructValidator[]) DataUtil.growArrayBy50Pct(mValidators);
        }
        mElems[elemCount] = mCurrElem = elem;
        if (elem == null || !elem.isDefined()) {
            reportValidationProblem(ErrorConsts.ERR_VLD_UNKNOWN_ELEM, mTmpKey.toString());
        }

        // Is this element legal under the parent element?
        StructValidator pv = (elemCount > 0) ? mValidators[elemCount-1] : null;

        if (pv != null && elem != null) {
            String msg = pv.tryToValidate(elem.getName());
            if (msg != null) {
                int ix = msg.indexOf("$END");
                String pname = mElems[elemCount-1].toString();
                if (ix >= 0) {
                    msg = msg.substring(0, ix) + "</"+pname+">"
                        +msg.substring(ix+4);
                }
                reportValidationProblem("Validation error, encountered element <"
                                        +elem.getName()+"> as a child of <"
                                        +pname+">: "+msg);
            }
        }

        mAttrCount = 0;
        mIdAttrIndex = -2; // -2 as a "don't know yet" marker

        // Ok, need to get the child validator, then:
        if (elem == null) {
            mValidators[elemCount] = null;
            mCurrAttrDefs = NO_ATTRS;
            mCurrHasAnyFixed = false;
            mCurrSpecialAttrs = null;
        } else {
            mValidators[elemCount] = elem.getValidator();
            mCurrAttrDefs = elem.getAttributes();
            if (mCurrAttrDefs == null) {
                mCurrAttrDefs = NO_ATTRS;
            }
            mCurrHasAnyFixed = elem.hasFixedAttrs();
            int specCount = elem.getSpecialCount();
            if (specCount == 0) {
                mCurrSpecialAttrs = null;
            } else {
                BitSet bs = mTmpSpecialAttrs;
                if (bs == null) {
                    mTmpSpecialAttrs = bs = new BitSet(specCount);
                } else {
                    bs.clear();
                }
                mCurrSpecialAttrs = bs;
            }
        }
    }
@ Override public void validateElementStart ( String localName , String uri , String prefix ) throws XMLStreamException { mTmpKey . reset ( prefix , localName ) ; DTDElement elem = mElemSpecs . get ( mTmpKey ) ; int elemCount = mElemCount ++ ; if ( elemCount >= mElems . length ) { mElems = ( DTDElement [ ] ) DataUtil . growArrayBy50Pct ( mElems ) ; mValidators = ( StructValidator [ ] ) DataUtil . growArrayBy50Pct ( mValidators ) ; } mElems [ elemCount ] = mCurrElem = elem ; if ( elem == null || ! elem . isDefined ( ) ) { reportValidationProblem ( ErrorConsts . ERR_VLD_UNKNOWN_ELEM , mTmpKey . toString ( ) ) ; } StructValidator pv = ( elemCount > 0 ) ? mValidators [ elemCount - 1 ] : null ; if ( pv != null && elem != null ) { String msg = pv . tryToValidate ( elem . getName ( ) ) ; if ( msg != null ) { int ix = msg . indexOf ( "$END" ) ; String pname = mElems [ elemCount - 1 ] . toString ( ) ; if ( ix >= 0 ) { msg = msg . substring ( 0 , ix ) + "</" + pname + ">" + msg . substring ( ix + 4 ) ; } reportValidationProblem ( "Validation error, encountered element <" + elem . getName ( ) + "> as a child of <" + pname + ">: " + msg ) ; } } mAttrCount = 0 ; mIdAttrIndex = - 2 ; if ( elem == null ) { mValidators [ elemCount ] = null ; mCurrAttrDefs = NO_ATTRS ; mCurrHasAnyFixed = false ; mCurrSpecialAttrs = null ; } else { mValidators [ elemCount ] = elem . getValidator ( ) ; mCurrAttrDefs = elem . getAttributes ( ) ; if ( mCurrAttrDefs == null ) { mCurrAttrDefs = NO_ATTRS ; } mCurrHasAnyFixed = elem . hasFixedAttrs ( ) ; int specCount = elem . getSpecialCount ( ) ; if ( specCount == 0 ) { mCurrSpecialAttrs = null ; } else { BitSet bs = mTmpSpecialAttrs ; if ( bs == null ) { mTmpSpecialAttrs = bs = new BitSet ( specCount ) ; } else { bs . clear ( ) ; } mCurrSpecialAttrs = bs ; } } }
Method called to update information about the newly encountered (start)
element. At this point namespace information has been resolved, but
no DTD validation has been done. Validator is to do these validations,
including checking for attribute value (and existence) compatibility.