1 61 62 package org.jaxen.expr; 63 64 65 import org.jaxen.Context; 66 import org.jaxen.JaxenException; 67 68 69 class DefaultPathExpr extends DefaultExpr implements PathExpr { 70 71 private Expr filterExpr; 72 private LocationPath locationPath; 73 74 DefaultPathExpr(Expr filterExpr, 75 LocationPath locationPath) { 76 this.filterExpr = filterExpr; 77 this.locationPath = locationPath; 78 } 79 80 public Expr getFilterExpr() { 81 return this.filterExpr; 82 } 83 84 85 public void setFilterExpr(Expr filterExpr) { 86 this.filterExpr = filterExpr; 87 } 88 89 90 public LocationPath getLocationPath() { 91 return this.locationPath; 92 } 93 94 95 public String toString() { 96 if (getLocationPath() != null) { 97 return "[(DefaultPathExpr): " + getFilterExpr() + ", " + getLocationPath() + "]"; 98 } 99 100 return "[(DefaultPathExpr): " + getFilterExpr() + "]"; 101 } 102 103 104 public String getText() { 105 StringBuffer buf = new StringBuffer (); 106 107 if (getFilterExpr() != null) { 108 buf.append(getFilterExpr().getText()); 109 } 110 111 if (getLocationPath() != null) { 112 buf.append(getLocationPath().getText()); 113 } 114 115 return buf.toString(); 116 } 117 118 119 public Expr simplify() { 120 if (getFilterExpr() != null) { 121 setFilterExpr(getFilterExpr().simplify()); 122 } 123 124 if (getLocationPath() != null) { 125 getLocationPath().simplify(); 126 } 127 128 if (getFilterExpr() == null && getLocationPath() == null) { 129 return null; 130 } 131 132 133 if (getLocationPath() == null) { 134 return getFilterExpr(); 135 } 136 137 if (getFilterExpr() == null) { 138 return getLocationPath(); 139 } 140 141 return this; 142 } 143 144 public Object evaluate(Context context) throws JaxenException { 145 Object results = null; 146 Context pathContext = null; 147 if (getFilterExpr() != null) { 148 results = getFilterExpr().evaluate(context); 149 pathContext = new Context(context.getContextSupport()); 150 pathContext.setNodeSet(convertToList(results)); 151 } 152 if (getLocationPath() != null) { 153 return getLocationPath().evaluate(pathContext); 154 } 155 return results; 156 } 157 158 public void accept(Visitor visitor) { 159 visitor.visit(this); 160 } 161 } 162 163 | Popular Tags |