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 package org.exolab.castor.xml.schema; 36 37 import java.util.ArrayList; 38 import java.util.Enumeration; 39 import java.util.List; 40 41 42 /** 43 * A list for maintaining facets 44 * 45 * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a> 46 * @version $Revision$ $Date: 2006-04-14 04:14:43 -0600 (Fri, 14 Apr 2006) $ 47 **/ 48 public class FacetList implements java.io.Serializable { 49 /** SerialVersionUID */ 50 private static final long serialVersionUID = 3855871093270831240L; 51 52 /** 53 * The list of facets 54 **/ 55 private final List<Facet> facets = new ArrayList<Facet>(); 56 57 /** 58 * Adds the given Facet to this list 59 * 60 * @param facet the facet to add 61 **/ 62 public void add(Facet facet) { 63 if (facet != null) { 64 facets.add(facet); 65 } 66 } // -- add 67 68 /** 69 * Adds the facets from the given list into this FacetList 70 * 71 * @param facetList the FacetList to copy from 72 */ 73 public void add(FacetList facetList) { 74 if (facetList == null) { 75 return; 76 } 77 for (int i = 0; i < facetList.facets.size(); i++) { 78 facets.add(facetList.facets.get(i)); 79 } 80 } // -- add 81 82 83 /** 84 * Returns the facet at the given index 85 * 86 * @param index the index of the Facet to return 87 **/ 88 public Facet get(int index) { 89 return facets.get(index); 90 } // -- get 91 92 /** 93 * Removes the given Facet from this list 94 * 95 * @param facet the Facet to remove 96 **/ 97 public boolean remove(Facet facet) { 98 return facets.remove(facet); 99 } // -- remove 100 101 /** 102 * Removes the facet located at the given index 103 * 104 * @param index the index of the Facet to remove 105 * @return the removed facet 106 */ 107 public Facet remove(int index) { 108 return facets.remove(index); 109 } // -- remove 110 111 112 /** 113 * Returns the number of Facets in this list 114 * 115 * @return the number of Facets in this list 116 **/ 117 public int size() { 118 return facets.size(); 119 } // -- size 120 121 /** 122 * Returns an Enumeration of the Facets in this list 123 * 124 * @return an Enumeration of the Facets in this list 125 **/ 126 public Enumeration<Facet> enumerate() { 127 return new FacetListEnumerator(this); 128 } // -- enumerate 129 130 /** 131 * Returns the facet of the list with with the given name. In case of an ENUMERATION the first 132 * facet is returned. If none of the name of the facets of that list correspond to the given name, 133 * null is returned. 134 * 135 * @param name the facet name to look for. 136 * 137 * @return The facet of the list with the given name 138 */ 139 public Facet contains(String name) { 140 if (name == null) { 141 return null; 142 } 143 Enumeration<Facet> enumeration = enumerate(); 144 while (enumeration.hasMoreElements()) { 145 Facet temp = enumeration.nextElement(); 146 if (temp.getName().equals(name)) 147 return temp; 148 } 149 return null; 150 } 151 152 } // -- FacetList 153