1 61 package org.jaxen.expr; 62 63 import java.util.ArrayList ; 64 import java.util.Iterator ; 65 import java.util.List ; 66 67 import org.jaxen.Context; 68 import org.jaxen.ContextSupport; 69 import org.jaxen.JaxenException; 70 import org.jaxen.UnsupportedAxisException; 71 import org.jaxen.expr.iter.IterableAxis; 72 import org.jaxen.saxpath.Axis; 73 74 public abstract class DefaultStep implements Step 75 { 76 private IterableAxis axis; 77 private PredicateSet predicates; 78 79 public DefaultStep(IterableAxis axis, PredicateSet predicates) 80 { 81 this.axis = axis; 82 this.predicates = predicates; 83 } 84 85 public void addPredicate(Predicate predicate) 86 { 87 this.predicates.addPredicate(predicate); 88 } 89 90 public List getPredicates() 91 { 92 return this.predicates.getPredicates(); 93 } 94 95 public PredicateSet getPredicateSet() 96 { 97 return this.predicates; 98 } 99 100 public int getAxis() 101 { 102 return this.axis.value(); 103 } 104 105 public IterableAxis getIterableAxis() 106 { 107 return this.axis; 108 } 109 110 public String getAxisName() 111 { 112 return Axis.lookup(getAxis()); 113 } 114 115 public String getText() 116 { 117 return this.predicates.getText(); 118 } 119 120 public String toString() 121 { 122 return getIterableAxis() + " " + super.toString(); 123 } 124 125 public void simplify() 126 { 127 this.predicates.simplify(); 128 } 129 130 public Iterator axisIterator(Object contextNode, ContextSupport support) 131 throws UnsupportedAxisException 132 { 133 return getIterableAxis().iterator(contextNode, support); 134 } 135 136 public List evaluate(final Context context) throws JaxenException 137 { 138 final List contextNodeSet = context.getNodeSet(); 139 final IdentitySet unique = new IdentitySet(); 140 final int contextSize = contextNodeSet.size(); 141 142 final ArrayList interimSet = new ArrayList (); 145 final ArrayList newNodeSet = new ArrayList (); 146 final ContextSupport support = context.getContextSupport(); 147 148 for ( int i = 0 ; i < contextSize ; ++i ) 150 { 151 Object eachContextNode = contextNodeSet.get( i ); 152 153 154 161 Iterator axisNodeIter = axis.iterator(eachContextNode, support); 162 while ( axisNodeIter.hasNext() ) 163 { 164 Object eachAxisNode = axisNodeIter.next(); 165 if ( ! unique.contains( eachAxisNode ) ) 166 { 167 if ( matches( eachAxisNode, support ) ) 168 { 169 unique.add( eachAxisNode ); 170 interimSet.add( eachAxisNode ); 171 } 172 } 173 } 174 newNodeSet.addAll(getPredicateSet().evaluatePredicates( 175 interimSet, support )); 176 interimSet.clear(); 177 } 178 return newNodeSet; 179 } 180 181 } 182 | Popular Tags |