View Javadoc

1   /*
2    * Copyright 2004-2005 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package net.sf.morph.reflect;
17  
18  import java.util.Iterator;
19  
20  /**
21   * Exposes information available in 'container-like' structures. A
22   * 'container-like' structure contains a certain number of objects, each of
23   * which has a particular type. Examples of 'container-like' objects include
24   * arrays and java.util.Collections.
25   * 
26   * @author Matt Sgarlata
27   * @since Nov 26, 2004
28   */
29  public interface ContainerReflector extends Reflector {
30  
31  	/**
32  	 * Returns the type of the elements that are contained in objects of the
33  	 * given class. For example, if <code>indexedClass</code> represents an
34  	 * array of <code>int</code>s,<code>Integer.TYPE</code> should be
35  	 * returned. This method should only be called if
36  	 * {@link Reflector#isReflectable(Class)}returns <code>true</code>.
37  	 * 
38  	 * @param clazz
39  	 *            the container's type
40  	 * @return the type of the elements that are container by the given object
41  	 * @throws ReflectionException
42  	 *             if <code>container</code> is null or <br>
43  	 *             the type of the elements that are container could not be
44  	 *             determined
45  	 */
46  	public Class getContainedType(Class clazz) throws ReflectionException;
47  
48  	/**
49  	 * Exposes an iterator over the contents of the container. Note that in many
50  	 * cases, an Iterator may only be used once and is then considered invalid.
51  	 * If you need to loop through the contents of the iterator multiple times,
52  	 * you will have to copy the contents of the iterator to some other
53  	 * structure, such as a java.util.List.
54  	 * 
55  	 * @param container
56  	 *            the container to iterate over
57  	 * @return an Iterator over the elements in the container
58  	 * @throws ReflectionException
59  	 *             if <code>container</code> is <code>null</code> or <br>
60  	 *             the Iterator could not be created for some reason
61  	 */
62  	public Iterator getIterator(Object container) throws ReflectionException;
63  
64  }