1 61 62 63 64 package org.jaxen.expr; 65 66 import org.jaxen.Context; 67 import org.jaxen.UnresolvableException; 68 69 class DefaultVariableReferenceExpr extends DefaultExpr implements VariableReferenceExpr 70 { 71 private String prefix; 72 private String variableName; 73 74 DefaultVariableReferenceExpr(String prefix, 75 String variableName) 76 { 77 this.prefix = prefix; 78 this.variableName = variableName; 79 } 80 81 public String getPrefix() 82 { 83 return this.prefix; 84 } 85 86 public String getVariableName() 87 { 88 return this.variableName; 89 } 90 91 public String toString() 92 { 93 String prefix = getPrefix(); 94 95 if ( prefix == null ) 96 { 97 return "[(DefaultVariableReferenceExpr): " + getVariableName() + "]"; 98 } 99 100 return "[(DefaultVariableReferenceExpr): " + getPrefix() + ":" + getVariableName() + "]"; 101 } 102 103 public String getText() 104 { 105 String prefix = getPrefix(); 106 107 if ( prefix == null ) 108 { 109 return "$" + getVariableName(); 110 } 111 112 return "$" + prefix + ":" + getVariableName(); 113 } 114 115 public Object evaluate(Context context) 116 throws UnresolvableException 117 { 118 String namespaceURI = 119 context.translateNamespacePrefixToUri( getPrefix() ); 120 121 return context.getVariableValue( namespaceURI, 122 getPrefix(), 123 getVariableName() ); 124 } 125 126 public void accept(Visitor visitor) 127 { 128 visitor.visit(this); 129 } 130 } 131 | Popular Tags |