1 /** 2 * Redistribution and use of this software and associated documentation ("Software"), with or 3 * without modification, are permitted provided that the following conditions are met: 4 * 5 * 1. Redistributions of source code must retain copyright statements and notices. Redistributions 6 * must also contain a copy of this document. 7 * 8 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of 9 * conditions and the following disclaimer in the documentation and/or other materials provided with 10 * the distribution. 11 * 12 * 3. The name "Exolab" must not be used to endorse or promote products derived from this Software 13 * without prior written permission of Intalio, Inc. For written permission, please contact 14 * info@exolab.org. 15 * 16 * 4. Products derived from this Software may not be called "Exolab" nor may "Exolab" appear in 17 * their names without prior written permission of Intalio, Inc. Exolab is a registered trademark of 18 * Intalio, Inc. 19 * 20 * 5. Due credit should be given to the Exolab Project (http://www.exolab.org/). 21 * 22 * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 24 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTALIO, INC. OR ITS 25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 29 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. 32 * 33 * $Id$ 34 */ 35 36 package org.exolab.castor.xml.schema; 37 38 import java.util.Enumeration; 39 40 /** 41 * A list for maintaining facets 42 * 43 * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a> 44 * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ 45 **/ 46 class FacetListEnumerator implements Enumeration<Facet> { 47 48 private int currentIdx = 0; 49 private FacetList facets = null; 50 private FacetListEnumerator inherited = null; 51 private String mask = null; 52 53 /** 54 * Creates a new FacetList for the given FacetList 55 **/ 56 FacetListEnumerator(FacetList facets) { 57 this.facets = facets; 58 } // -- FacetListEnumerator 59 60 /** 61 * Creates a new FacetList enumerator 62 **/ 63 FacetListEnumerator(FacetList facets, FacetListEnumerator inheritedFacets) { 64 this.facets = facets; 65 inherited = inheritedFacets; 66 67 } // -- FacetListEnumerator 68 69 /** 70 * Sets the mask for this enumerator. The mask is the name of the facets to enumerate. 71 * 72 * @param name the name of the facets to enumerate 73 **/ 74 void setMask(String name) { 75 this.mask = name; 76 if (inherited != null) 77 inherited.setMask(name); 78 } // -- setMask 79 80 // -------------------------------------------/ 81 // - implementation of java.util.Enumeration -/ 82 // -------------------------------------------/ 83 84 public boolean hasMoreElements() { 85 86 if (inherited != null) { 87 if (inherited.hasMoreElements()) 88 return true; 89 } 90 91 if (facets == null) 92 return false; 93 if (mask == null) 94 return (currentIdx < facets.size()); 95 96 for (; currentIdx < facets.size(); currentIdx++) { 97 Facet facet = facets.get(currentIdx); 98 if (mask.equals(facet.getName())) 99 return true; 100 } 101 return false; 102 } // -- hasMoreElements 103 104 public Facet nextElement() { 105 if (inherited != null) { 106 if (inherited.hasMoreElements()) 107 return inherited.nextElement(); 108 } 109 if (facets == null) 110 return null; 111 112 if (mask == null) { 113 if (currentIdx < facets.size()) 114 return facets.get(currentIdx++); 115 } else { 116 for (; currentIdx < facets.size(); currentIdx++) { 117 Facet facet = facets.get(currentIdx); 118 if (mask.equals(facet.getName())) { 119 ++currentIdx; 120 return facet; 121 } 122 } 123 } 124 return null; 125 } // -- nextElement 126 127 } // -- FacetListEnumerator