1 10 package com.hp.hpl.jena.reasoner.rulesys; 11 12 import com.hp.hpl.jena.graph.Node; 13 import com.hp.hpl.jena.graph.Node_Variable; 14 15 28 public class Node_RuleVariable extends Node_Variable { 29 30 protected int index; 31 32 34 protected Node value; 35 36 37 protected boolean isRef = true; 38 39 40 public static final Node_RuleVariable WILD = new Node_RuleVariable("*", -1); 41 42 47 public Node_RuleVariable(String label, int index) { 48 super(new VarLabel(label)); 49 this.index = index; 50 this.value = this; 51 } 52 53 58 private Node_RuleVariable(VarLabel label, int index) { 59 super(label); 60 this.index = index; 61 this.value = this; 62 } 63 64 68 public int getIndex() { 69 return index; 70 } 71 72 76 public void setIndex(int index) { 77 this.index = index; 78 } 79 80 86 90 96 public void simpleBind(Node node) { 97 value = node; 98 isRef = node instanceof Node_RuleVariable; 99 } 100 101 106 public Node deref() { 107 Node_RuleVariable var = this; 108 while (var.isRef) { 109 if (var.value == var) { 110 return var; 111 } 112 var = (Node_RuleVariable)var.value; 113 } 114 return var.value; 115 } 116 117 121 public Node getRawBoundValue() { 122 return value; 123 } 124 125 128 public void unbind() { 129 isRef = true; 130 value = this; 131 } 132 133 136 public boolean isUnbound() { 137 return (isRef && (value == this)); 138 } 139 140 143 public Node_RuleVariable cloneNode() { 144 return new Node_RuleVariable((VarLabel)label, index); 145 } 146 147 148 public String toString() { 149 String l = ((VarLabel)label).getLabel(); 150 return (l == null) ? "*" : l; 151 } 152 153 155 167 170 public boolean sameValueAs(Object o) { 171 return o instanceof Node_RuleVariable; 172 } 173 174 177 public static boolean sameNodeAs(Node n, Node m) { 178 if (n instanceof Node_RuleVariable) { 179 if (m instanceof Node_RuleVariable) { 180 return ((Node_RuleVariable)n).getIndex() == ((Node_RuleVariable)m).getIndex(); 181 } else { 182 return false; 183 } 184 } else { 185 return n.sameValueAs(m); 186 } 187 } 188 189 190 static class VarLabel { 191 192 193 String label; 194 195 VarLabel(String label ) { 196 this.label = label; 197 } 198 199 public String getLabel() { 200 return label; 201 } 202 } 203 204 } 205 206 232 | Popular Tags |