Exemplo n.º 1
0
		private int process_child(VTDNav vn)
		{
			int result;
			bool b = false, b1 = false;
			//int contextSize;
			Predicate t = null;
			
			switch (state)
			{
				
				case START: 
					if (currentStep.nt.testType != NodeTest.TEXT)
					{
						// first search for any predicate that 
						// requires contextSize
						// if so, compute its context size
						// if size > 0
						// set context
						// if size ==0 
						// immediately set the state to backward or end
						t = currentStep.p;
						while (t != null)
						{
							if (t.requireContextSize())
							{
								int i = computeContextSize(t, vn);
								if (i == 0)
								{
									b1 = true;
									break;
								}
								else
									t.ContextSize = i;
							}
							t = t.nextP;
						}
						if (b1)
						{
							state = END;
							break;
						}
						
						b = vn.toElement(VTDNav.FIRST_CHILD);
						state = END;
						if (b == true)
						{
							do 
							{
								if (currentStep.eval(vn))
								{
									if (currentStep.NextStep != null)
									{
										//currentStep.position++;
										state = FORWARD;
										currentStep = currentStep.NextStep;
									}
									else
									{
										state = TERMINAL;
										result = vn.getCurrentIndex();
										if (isUnique(result))
										{
											return result;
										}
									}
									break;
								}
							}
							while (vn.toElement(VTDNav.NS));
							if (state == END)
								vn.toElement(VTDNav.PARENT);
						}
					}
					else
					{
                        if (vn.AtTerminal == true)
                        {
                            state = END;
                        }
                        else
                        {
                            // compute context size;
                            t = currentStep.p;
                            while (t != null)
                            {
                                if (t.requireContextSize())
                                {
                                    int i = computeContextSize(t, vn);
                                    if (i == 0)
                                    {
                                        b1 = true;
                                        break;
                                    }
                                    else
                                        t.ContextSize=i;
                                }
                                t = t.nextP;
                            }
                            // b1 false indicate context size is zero. no need to go any further...
                            if (b1)
                            {
                                state = END;
                                break;
                            }
                            // get textIter
                            TextIter ti = null;
                            if (currentStep.o != null)
                            {
                                ti = (TextIter)currentStep.o;
                            }
                            else
                            {
                                ti = new TextIter();
                                currentStep.o = ti;
                            }
                            ti.touch(vn);
                            state = END;
                            while ((result = ti.getNext()) != -1)
                            {
                                if (currentStep.evalPredicates(vn))
                                {
                                    break;
                                }
                            }
                            // old code
                            //result = vn.getText();
                            if (result != -1)
                            {
                                vn.AtTerminal=true;
                                //currentStep.resetP(vn);
                                vn.LN = result;
                                if (currentStep.NextStep != null)
                                {
                                    vn.LN = result;
                                    state = FORWARD;
                                    currentStep = currentStep.NextStep;
                                }
                                else
                                {
                                    //vn.pop();
                                    state = TERMINAL;
                                    if (isUnique(result))
                                    {
                                        vn.LN = result;
                                        return result;
                                    }
                                }
                            }
                            else
                            {
                                //currentStep.set_ft(true);
                                currentStep.resetP(vn);
                                vn.AtTerminal=false;
                            }
                        }		    
					}
					break;
				
				case END: 
					currentStep = null;
					// reset();
					return - 1;
				
				
				case FORWARD: 
					if (currentStep.nt.testType != NodeTest.TEXT)
					{
						t = currentStep.p;
						while (t != null)
						{
							if (t.requireContextSize())
							{
								int i = computeContextSize(t, vn);
								if (i == 0)
								{
									b1 = true;
									break;
								}
								else
									t.ContextSize = i;
							}
							t = t.nextP;
						}
						if (b1)
						{
							currentStep = currentStep.PrevStep;
							state = BACKWARD;
							break;
						}
						
						state = BACKWARD;
						if (vn.toElement(VTDNav.FC))
						{
							do 
							{
								if (currentStep.eval(vn))
								{
									if (currentStep.NextStep != null)
									{
										state = FORWARD;
										currentStep = currentStep.NextStep;
									}
									else
									{
										state = TERMINAL;
										result = vn.getCurrentIndex();
										if (isUnique(result))
											return result;
									}
									//UPGRADE_NOTE: Labeled break statement was changed to a goto statement. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1012'"
									goto forward_brk;
								}
							}
							while (vn.toElement(VTDNav.NS));
							vn.toElement(VTDNav.P);
							currentStep.resetP(vn);
							currentStep = currentStep.PrevStep;
						}
						else
						{
							//vn.toElement(VTDNav.P);
							currentStep = currentStep.PrevStep;
						}
						//UPGRADE_NOTE: Label 'forward_brk' was added. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1011'"

forward_brk: ;
						
					}
					else
					{
                        // predicate at an attribute is not evaled
                        if (vn.AtTerminal == true)
                        {
                            state = BACKWARD;
                            currentStep = currentStep.PrevStep;
                        }
                        else
                        {
                            // compute context size;
                            t = currentStep.p;
                            while (t != null)
                            {
                                if (t.requireContextSize())
                                {
                                    int i = computeContextSize(t, vn);
                                    if (i == 0)
                                    {
                                        b1 = true;
                                        break;
                                    }
                                    else
                                        t.ContextSize=i;
                                }
                                t = t.nextP;
                            }
                            // b1 false indicate context size is zero. no need to go any further...
                            if (b1)
                            {
                                state = BACKWARD;
                                break;
                            }
                            // get textIter
                            TextIter ti = null;
                            if (currentStep.o != null)
                            {
                                ti = (TextIter)currentStep.o;
                            }
                            else
                            {
                                ti = new TextIter();
                                currentStep.o = ti;
                            }
                            ti.touch(vn);
                            //result = ti.getNext();

                            while ((result = ti.getNext()) != -1)
                            {
                                if (currentStep.evalPredicates(vn))
                                {
                                    break;
                                }
                            }

                            if (result == -1)
                            {
                                //currentStep.set_ft(true);
                                //currentStep.resetP(vn);
                                vn.AtTerminal=false;
                                if (state == FORWARD)
                                {
                                    state = BACKWARD;
                                    currentStep = currentStep.PrevStep;
                                }
                            }
                            else
                            {
                                vn.AtTerminal=true;
                                if (currentStep.NextStep != null)
                                {
                                    vn.LN = result;
                                    state = FORWARD;
                                    currentStep = currentStep.NextStep;
                                }
                                else
                                {
                                    //vn.pop();
                                    state = TERMINAL;
                                    if (isUnique(result))
                                    {
                                        vn.LN = result;
                                        return result;
                                    }
                                }
                            }
                        }				
					}
					
					break;
				
				
				case BACKWARD: 
					if (currentStep.nt.testType != NodeTest.TEXT)
					{
						//currentStep = currentStep.getPrevStep();
						b = false;
						while (vn.toElement(VTDNav.NS))
						{
							if (currentStep.eval(vn))
							{
								b = true;
								break;
							}
						}
						if (b == true)
						{
							state = FORWARD;
							currentStep = currentStep.NextStep;
						}
						else if (currentStep.PrevStep == null)
						{
							currentStep.resetP(vn);
							vn.toElement(VTDNav.P);
							state = END;
						}
						else
						{
							currentStep.resetP(vn);
							state = BACKWARD;
							vn.toElement(VTDNav.P);
							currentStep = currentStep.PrevStep;
						}
					}
					else
					{
						vn.AtTerminal = false;
						if (currentStep.PrevStep == null)
							state = END;
						else
						{
							state = BACKWARD;
							//vn.setAtTerminal(false);
							currentStep = currentStep.PrevStep;
						}
					}
					break;
				
				
				case TERMINAL: 
					if (currentStep.nt.testType != NodeTest.TEXT)
					{
						while (vn.toElement(VTDNav.NS))
						{
							if (currentStep.eval(vn))
							{
								// state =  TERMINAL;
								result = vn.getCurrentIndex();
								if (isUnique(result))
									return result;
							}
						}
						currentStep.resetP(vn);
						if (currentStep.PrevStep == null)
						{
							state = END;
							vn.toElement(VTDNav.P);
						}
						else
						{
							vn.toElement(VTDNav.P);
							
							state = BACKWARD;
							currentStep = currentStep.PrevStep;
						}
					}
					else
					{
                        TextIter ti = (TextIter)currentStep.o;
                        while ((result = ti.getNext()) != -1)
                        {
                            if (currentStep.evalPredicates(vn))
                            {
                                if (isUnique(result))
                                    return result;
                            }
                        }
                        currentStep.resetP(vn);
                        vn.AtTerminal=false;
                        if (currentStep.PrevStep == null)
                            state = END;
                        else
                        {
                            state = BACKWARD;
                            currentStep = currentStep.PrevStep;
                        }
					}
					break;
				
				
				default: 
					throw new XPathEvalException("unknown state");
				
			}
			return - 2;
		}
Exemplo n.º 2
0
 private void selectNodeType(TextIter ti)
 {
     if (currentStep.nt.testType == NodeTest.TEXT)
         ti.selectText();
     else if (currentStep.nt.testType == NodeTest.COMMENT)
         ti.selectComment();
     else if (currentStep.nt.testType == NodeTest.PI0)
         ti.selectPI0();
     else
     {
         ti.selectPI1(currentStep.nt.nodeName);
     }
 }
Exemplo n.º 3
0
		public int computeContextSize(Predicate p, VTDNav vn){
	    
	    bool b = false;
	    Predicate tp = null;
	    int i = 0;
	    AutoPilot ap;
	    switch(currentStep.axis_type){
	    	case AxisType.CHILD:
	    	    if (currentStep.nt.testType != NodeTest.TEXT){
	    	    b = vn.toElement(VTDNav.FIRST_CHILD);
	    		if (b) {
	    		    do {
	    		        if (currentStep.eval(vn, p)) {
                        	i++;
	    		        }
	    		    } while (vn.toElement(VTDNav.NS));	    		    
	    		    vn.toElement(VTDNav.PARENT);
	    		    currentStep.resetP(vn,p);
	    		    return i;
	    		} else
	    		    return 0;
	    	    }else {	    
	    	        TextIter ti = new TextIter();
	    	        ti.touch(vn);
	    	        while((ti.getNext())!=-1){
	    	            if (currentStep.evalPredicates(vn,p)){
	    	                i++;
	    	            }
	    	        }
	    	        currentStep.resetP(vn,p);
	    	        return i;
	    	    }
	    		   
			case AxisType.DESCENDANT_OR_SELF:
			case AxisType.DESCENDANT:
			case AxisType.PRECEDING:								
			case AxisType.FOLLOWING:
			    
			    String helper = null;
				if (currentStep.nt.testType == NodeTest.NODE){
				    helper = "*";
				}else {
				    helper = currentStep.nt.nodeName;
				}
				ap = new AutoPilot(vn);
				if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF )
					if (currentStep.nt.testType == NodeTest.NODE)
                        ap.Special = true;
					else
						ap.Special = false;
				//currentStep.o = ap = new AutoPilot(vn);
			    if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF)
			        if (currentStep.nt.localName!=null)
			            ap.selectElementNS(currentStep.nt.URL,currentStep.nt.localName);
			        else 
			            ap.selectElement(helper);
				else if (currentStep.axis_type == AxisType.DESCENDANT)
				    if (currentStep.nt.localName!=null)
				        ap.selectElementNS_D(currentStep.nt.URL,currentStep.nt.localName);
				    else 
				        ap.selectElement_D(helper);
				else if (currentStep.axis_type == AxisType.PRECEDING)
				    if (currentStep.nt.localName!=null)
				        ap.selectElementNS_P(currentStep.nt.URL,currentStep.nt.localName);
				    else 
				        ap.selectElement_P(helper);
				else 
				    if (currentStep.nt.localName!=null)
				        ap.selectElementNS_F(currentStep.nt.URL,currentStep.nt.localName);
				    else 
				        ap.selectElement_F(helper);
			    vn.push2();
    			while(ap.iterate()){
    				if (currentStep.evalPredicates(vn,p)){
    					i++;
    				}
    			}
    			vn.pop2();
    			currentStep.resetP(vn,p);
    			return i;
			  
			case AxisType.PARENT:
			    vn.push2();
				i = 0;
				if (vn.toElement(VTDNav.PARENT)){
				    if (currentStep.eval(vn,p)){
				        i++;
				    }
				}			    
				vn.pop2();
				currentStep.resetP(vn,p);
				return i;
				
			case AxisType.ANCESTOR:
			    vn.push2();
				i = 0;
				while (vn.toElement(VTDNav.PARENT)) {
				    if (currentStep.eval(vn, p)) {
                    	i++;
    		        }
				}				
				vn.pop2();
				currentStep.resetP(vn,p);
				return i;
				
			case AxisType.ANCESTOR_OR_SELF:
			    vn.push2();
				i = 0;
				do {
				    if (currentStep.eval(vn, p)) {
                    	i++;
    		        }
				}while(vn.toElement(VTDNav.PARENT));
				vn.pop2();
				currentStep.resetP(vn,p);
				return i;
				
			case AxisType.SELF:
			    i = 0;
				if (vn.toElement(VTDNav.PARENT)){
				    if (currentStep.eval(vn,p)){
				        i++;
				    }
				}			    
				currentStep.resetP(vn,p);
				return i;
			    
			case AxisType.FOLLOWING_SIBLING:
			    vn.push2();
				while(vn.toElement(VTDNav.NEXT_SIBLING)){
				    if (currentStep.eval(vn,p)){
				        i++;
				    }
				}			    
			    vn.pop2();
				currentStep.resetP(vn,p);
				return i;
			    
			case AxisType.PRECEDING_SIBLING:
			    vn.push2();
				while(vn.toElement(VTDNav.PREV_SIBLING)){
				    if (currentStep.eval(vn,p)){
				        i++;
				    }
				}			    
				vn.pop2();
				currentStep.resetP(vn,p);
				return i;
				
			case AxisType.ATTRIBUTE:
			    ap = new AutoPilot(vn);
				if (currentStep.nt.localName!=null)
				    ap.selectAttrNS(currentStep.nt.URL,
			            currentStep.nt.localName);
				else 
				    ap.selectAttr(currentStep.nt.nodeName);
				i = 0;
				while(ap.iterateAttr()!=-1){
				    if (currentStep.evalPredicates(vn,p)){
				        i++;
				    }
				}
          		currentStep.resetP(vn,p);
				return i;
			    
	    	default:
	    	    throw new XPathEvalException("axis not supported");
	    }
	    //return 8;
	}