1 16 package org.directwebremoting.extend; 17 18 import org.directwebremoting.dwrp.ProtocolConstants; 19 import org.directwebremoting.util.Logger; 20 import org.directwebremoting.util.Messages; 21 22 26 public final class InboundVariable 27 { 28 35 public InboundVariable(InboundContext context, String key, String type, String value) 36 { 37 this.context = context; 38 this.type = type; 39 this.value = value; 40 this.key = key; 41 this.dereferenced = attemptDereference(); 42 } 43 44 52 private boolean attemptDereference() 53 { 54 int maxDepth = 0; 55 56 if (ProtocolConstants.TYPE_REFERENCE.equals(type)) 57 { 58 while (ProtocolConstants.TYPE_REFERENCE.equals(type)) 59 { 60 InboundVariable cd = context.getInboundVariable(value); 61 if (cd == null) 62 { 63 return false; 64 } 65 66 type = cd.type; 67 value = cd.value; 68 69 maxDepth++; 70 if (maxDepth > 20) 71 { 72 throw new IllegalStateException ("Max depth exceeded when dereferencing " + value); 73 } 74 } 75 76 if (key == null) 79 { 80 key = value; 81 } 82 } 83 84 return true; 85 } 86 87 91 private void forceDereference() 92 { 93 if (!dereferenced) 94 { 95 dereferenced = attemptDereference(); 96 if (!dereferenced) 97 { 98 log.error(Messages.getString("InboundVariable.MissingVariable", value)); 99 } 100 } 101 } 102 103 106 public InboundContext getLookup() 107 { 108 forceDereference(); 109 return context; 110 } 111 112 115 public String getType() 116 { 117 forceDereference(); 118 return type; 119 } 120 121 125 public boolean isNull() 126 { 127 forceDereference(); 128 return type.equals(ProtocolConstants.INBOUND_NULL); 129 } 130 131 134 public String getValue() 135 { 136 forceDereference(); 137 return value; 138 } 139 140 143 public String toString() 144 { 145 forceDereference(); 146 return type + ProtocolConstants.INBOUND_TYPE_SEPARATOR + value; 147 } 148 149 152 public boolean equals(Object obj) 153 { 154 if (this == obj) 155 { 156 return true; 157 } 158 159 if (!(obj instanceof InboundVariable)) 160 { 161 return false; 162 } 163 164 InboundVariable that = (InboundVariable) obj; 165 166 forceDereference(); 167 168 if (!this.type.equals(that.type)) 169 { 170 return false; 171 } 172 173 if (!this.value.equals(that.value)) 174 { 175 return false; 176 } 177 178 if (this.key == null || that.key == null) 179 { 180 return false; 181 } 182 183 return this.key.equals(that.key); 184 } 185 186 189 public int hashCode() 190 { 191 return value.hashCode() + type.hashCode(); 192 } 193 194 197 private InboundContext context; 198 199 202 private String key; 203 204 207 private String type; 208 209 212 private String value; 213 214 217 private boolean dereferenced; 218 219 222 private static final Logger log = Logger.getLogger(InboundVariable.class); 223 } 224 | Popular Tags |