001: /*
002: * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.es;
030:
031: import com.caucho.util.IntMap;
032:
033: import java.util.Iterator;
034:
035: class PropertyEnumeration implements Iterator {
036: IntMap completed = new IntMap();
037: ESObject object;
038: int index;
039:
040: public Object next() {
041: if (object == null)
042: return null;
043:
044: if (object.propNames != null) {
045: for (; index < object.propNames.length; index++) {
046: if (object.propValues[index] != null
047: && (object.propFlags[index] & ESObject.DONT_ENUM) == 0
048: && completed.get(object.propNames[index]) != 1) {
049: index++;
050: completed.put(object.propNames[index - 1], 1);
051:
052: return object.propNames[index - 1];
053: }
054: }
055: }
056:
057: if (object.prototype instanceof ESObject) {
058: object = (ESObject) object.prototype;
059: index = 0;
060:
061: return next();
062: }
063:
064: object = null;
065:
066: return null;
067: }
068:
069: public boolean hasNext() {
070: if (object == null)
071: return false;
072:
073: if (object.propNames != null) {
074: for (; index < object.propNames.length; index++) {
075: if (object.propValues[index] != null
076: && (object.propFlags[index] & ESObject.DONT_ENUM) == 0
077: && completed.get(object.propNames[index]) != 1) {
078: break;
079: }
080: }
081:
082: if (index < object.propNames.length)
083: return true;
084: }
085:
086: if (object.prototype instanceof ESObject) {
087: object = (ESObject) object.prototype;
088: index = 0;
089:
090: return hasNext();
091: }
092:
093: object = null;
094:
095: return false;
096: }
097:
098: public void remove() {
099: throw new RuntimeException();
100: }
101:
102: PropertyEnumeration(ESObject object) {
103: this .object = object;
104: index = 0;
105: }
106: }
|