public void setVariable(final String name, final Object value) { ensureLevelInitialized(true); if (this.level > 0) { // We will only take care of new/old values if we are not on level 0 int levelIndex = searchNameInIndex(name,this.index); if (levelIndex >= 0) { // There already is a registered movement for this key - we should modify it instead of creating a new one this.newValues[this.index][levelIndex] = value; } else { if (this.names[this.index].length == this.levelSizes[this.index]) { // We need to grow the arrays for this level this.names[this.index] = Arrays.copyOf(this.names[this.index], this.names[this.index].length + DEFAULT_LEVELARRAYS_SIZE); this.newValues[this.index] = Arrays.copyOf(this.newValues[this.index], this.newValues[this.index].length + DEFAULT_LEVELARRAYS_SIZE); this.oldValues[this.index] = Arrays.copyOf(this.oldValues[this.index], this.oldValues[this.index].length + DEFAULT_LEVELARRAYS_SIZE); } levelIndex = this.levelSizes[this.index]; // We will add at the end this.names[this.index][levelIndex] = name; /* * Per construction, according to the Servlet API, an attribute set to null and a non-existing * attribute are exactly the same. So we don't really have a reason to worry about the attribute * already existing or not when it was set to null. */ this.oldValues[this.index][levelIndex] = this.request.getAttribute(name); this.newValues[this.index][levelIndex] = value; this.levelSizes[this.index]++; } } // No matter if value is null or not. Value null will be equivalent to .removeAttribute() this.request.setAttribute(name, value); }
public boolean isVariableLocal(final String name) { if (this.level == 0) { // We are at level 0, so we cannot have local variables at all return false; } int n = this.index + 1; while (n-- > 1) { // variables at n == 0 are not local! final int idx = searchNameInIndex(name, n); if (idx >= 0) { return this.newValues[n][idx] != null; } } return false; }