All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax.faces.component.SelectItemsIterator Maven / Gradle / Ivy

Go to download

This is the master POM file for Oracle's Implementation of the JSF 2.1 Specification.

There is a newer version: 2.1
Show newest version
/*
 * $Id: SelectItemsIterator.java,v 1.16 2007/01/29 07:56:05 rlubke Exp $
 */

/*
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the License). You may not use this file except in
 * compliance with the License.
 * 
 * You can obtain a copy of the License at
 * https://javaserverfaces.dev.java.net/CDDL.html or
 * legal/CDDLv1.0.txt. 
 * See the License for the specific language governing
 * permission and limitations under the License.
 * 
 * When distributing Covered Code, include this CDDL
 * Header Notice in each file and include the License file
 * at legal/CDDLv1.0.txt.    
 * If applicable, add the following below the CDDL Header,
 * with the fields enclosed by brackets [] replaced by
 * your own identifying information:
 * "Portions Copyrighted [year] [name of copyright owner]"
 * 
 * [Name of File] [ver.__] [Date]
 * 
 * Copyright 2005 Sun Microsystems Inc. All Rights Reserved
 */

package javax.faces.component;


import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Map;
import java.util.ArrayList;
import java.util.ListIterator;

import javax.faces.model.SelectItem;


/**
 * 

Package private class for iterating over the set of {@link SelectItem}s * for a parent {@link UISelectMany} or {@link UISelectOne}.

*/ final class SelectItemsIterator implements Iterator { // ------------------------------------------------------------ Constructors /** *

Construct an iterator instance for the specified parent component.

* * @param parent The parent {@link UIComponent} whose children will be * processed */ public SelectItemsIterator(UIComponent parent) { kids = parent.getChildren().listIterator(); } // ------------------------------------------------------ Instance Variables /** *

Iterator over the SelectItem elements pointed at by a * UISelectItems component, or null.

*/ private Iterator items = null; /** *

Iterator over the children of the parent component.

*/ private ListIterator kids = null; // -------------------------------------------------------- Iterator Methods /** *

Return true if the iteration has more elements.

*/ public boolean hasNext() { if (items != null) { if (items.hasNext()) { return (true); } else { items = null; } } Object next = findNextValidChild(); if (next != null) { kids.previous(); return true; } return false; } /** *

Return the next element in the iteration.

* * @throws NoSuchElementException if there are no more elements */ public SelectItem next() { if (!hasNext()) { throw new NoSuchElementException(); } if (items != null) { return (items.next()); } UIComponent kid = (UIComponent) findNextValidChild(); if (kid instanceof UISelectItem) { UISelectItem ui = (UISelectItem) kid; SelectItem item = (SelectItem) ui.getValue(); if (item == null) { item = new SelectItem(ui.getItemValue(), ui.getItemLabel(), ui.getItemDescription(), ui.isItemDisabled(), ui.isItemEscaped()); } return (item); } else if (kid instanceof UISelectItems) { UISelectItems ui = (UISelectItems) kid; Object value = ui.getValue(); if (value instanceof SelectItem) { return ((SelectItem)value); } else if (value instanceof SelectItem[]) { items = Arrays.asList((SelectItem[]) value).iterator(); return (next()); } else if (value instanceof List) { items = TypedCollections.dynamicallyCastList((List) value, SelectItem.class).iterator(); return (next()); } else if (value instanceof Map) { List list = new ArrayList(((Map) value).size()); for (Iterator keys = ((Map) value).keySet().iterator(); keys.hasNext(); ) { Object key = keys.next(); if (key == null) { continue; } Object val = ((Map) value).get(key); if (val == null) { continue; } list.add(new SelectItem(val, key.toString(), null)); } items = list.iterator(); return (next()); } else { throw new IllegalArgumentException(); } } else { throw new NoSuchElementException(); } } /** *

Throw UnsupportedOperationException.

*/ public void remove() { throw new UnsupportedOperationException(); } private Object findNextValidChild() { if (kids.hasNext()) { Object next = kids.next(); while (kids.hasNext() && !(next instanceof UISelectItem || next instanceof UISelectItems)) { next = kids.next(); } if (next instanceof UISelectItem || next instanceof UISelectItems) { return next; } } return null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy