View Javadoc
1 /* 2 * Copyright (C) 2002 Carsten Krebs (Team-Konzept GmbH & Co.KG) 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 package com.teamkonzept.dom4jb.schema; 19 20 import java.util.Collection; 21 import java.util.Iterator; 22 import java.util.NoSuchElementException; 23 24 import com.teamkonzept.dom4jb.dom.Document; 25 import com.teamkonzept.dom4jb.dom.Node; 26 27 public class CollectionAdapterIterator implements ContentIterator { 28 protected final Document doc; 29 protected final Groupable adapter; 30 protected Iterator dataIter; 31 protected ContentIterator nextIter; 32 protected Node nextNode; 33 34 public CollectionAdapterIterator( final Collection data, final Document doc, 35 final Groupable adapter ) { 36 this.dataIter = data.iterator(); 37 this.adapter = adapter; 38 this.doc = doc; 39 40 this.nextIter = null; 41 this.nextNode = null; 42 } 43 44 public boolean hasNext() { 45 if ( nextNode != null ) { 46 return true; 47 } 48 if ( nextIter != null ) { 49 if ( nextIter.hasNext() ) { 50 nextNode = nextIter.next(); 51 return true; 52 } 53 nextIter = null; 54 } 55 if ( dataIter.hasNext() ) { 56 final Object obj = dataIter.next(); 57 58 nextIter = adapter.getContentIterator( doc, obj ); 59 if ( nextIter != null ) { 60 return hasNext(); 61 } 62 nextNode = adapter.getContent( doc, obj ); 63 } 64 return nextNode != null; 65 } 66 67 public Node next() { 68 if ( nextNode != null || hasNext() ) { 69 final Node node = nextNode; 70 nextNode = null; 71 return node; 72 } 73 throw new NoSuchElementException( "end of sequence reached!" ); 74 } 75 }

This page was automatically generated by Maven