Ejemplo n.º 1
0
        /**
        * @param nameLiterals
        *      Name literals encoded into a string as
        *      "[stateId1][uri1]\u0000[local1]\u0000[stateid2][uri2]\u0000 ..."
        * @param defaultNameCode
        *      The name code assigned to literals that are not described in the above
        *      dictionary.
        * @param encStates
        *      encoded state information.
        * @param encATr, encDTr, encETr, encITr, encLTr, encNTr, encVTr
        *      encoded transition tables (per alphabet type.)
        * @param datatypes
        *      Datatype objects used in this schema.
        * @param values
        *      Values used by <value/> patterns.
        */
        public Schema(
            string nameLiterals,
            int defaultNameCode,
            string encStates,
            string encATr,
            string encDTr,
            string encETr,
            string encITr,
            string encLTr,
            string encNTr,
            string encVTr,
            Datatype[] datatypes,
            object[] values)
        {
            // decode name literals
            while(nameLiterals.Length!=0) {
                int code = decodeInt(nameLiterals,0);   // name code
                nameLiterals = nameLiterals.Substring(2);

                int idx;

                idx = nameLiterals.IndexOf('\u0000');
                string uri = nameLiterals.Substring(0,idx);
                nameLiterals = nameLiterals.Substring(idx+1);

                idx = nameLiterals.IndexOf('\u0000');
                string local = nameLiterals.Substring(0,idx);
                nameLiterals = nameLiterals.Substring(idx+1);

                this.nameLiterals.Add( new StringPair(uri,local), code );
            }

            this.defaultNameCode = defaultNameCode;

            {// decode state and transition table
                string es;
                State.Single[] states = new State.Single[ encStates.Length/sizeOfState ];

                // build basic state objects
                es=encStates;
                for( int idx=0; es.Length!=0; idx++,es=es.Substring(sizeOfState) ) {
                    char bitFlags = es[0];
                    states[idx] = new State.Single( (bitFlags&2)!=0, (bitFlags&1)!=0, idx );
                }

                bool[] decoded = new bool[states.Length];

                // bare stack.
                int[] stack = new int[16];
                int stackPtr=0;

                // decode transition table
                for( int idx=states.Length-1; idx>=0; idx-- ) {

                    int s = idx;
                    while( s!=65535 && !decoded[s] ) {
                        // this state needs to be decoded -- push this state
                        if( stack.Length==stackPtr ) {
                            // extend the stack
                            int[] newBuf = new int[stack.Length*2];
                            stack.CopyTo( newBuf,0 );
                            stack = newBuf;
                        }
                        stack[stackPtr++] = s;
                        decoded[s] = true;

                        // decode next state
                        s = encStates[ s*sizeOfState+1 ];
                    }

                    while( stackPtr!=0 ) {
                        // decode transitions from state 's'.
                        s = stack[--stackPtr];
                        State.Single current = states[s];

                        // next state
                        int nextStateIdx = encStates[ s*sizeOfState+1 ];
                        State.Single nextState = (nextStateIdx==65535)?null:states[nextStateIdx];

                        // decode transitions

                        current.aTr = decodeATr( encStates, encATr, states, s, nextState==null?null:nextState.aTr );
                        current.dTr = decodeDTr( encStates, encDTr, states, s, nextState==null?null:nextState.dTr, datatypes );
                        current.eTr = decodeETr( encStates, encETr, states, s, nextState==null?null:nextState.eTr );
                        current.iTr = decodeITr( encStates, encITr, states, s, nextState==null?null:nextState.iTr );
                        current.lTr = decodeLTr( encStates, encLTr, states, s, nextState==null?null:nextState.lTr );
                        current.nTr = decodeNTr( encStates, encNTr, states, s, nextState==null?null:nextState.nTr );
                        current.vTr = decodeVTr( encStates, encVTr, states, s, nextState==null?null:nextState.vTr, datatypes, values );
                    }
                }

                InitialState = states[0];
            }
        }