Author: jcompagner
Date: Wed May 14 01:15:44 2008
New Revision: 656145
URL: http://svn.apache.org/viewvc?rev=656145&view=rev
Log:
a bit better generics en some java doc for visitChildren
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java?rev=656145&r1=656144&r2=656145&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
(original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
Wed May 14 01:15:44 2008
@@ -125,9 +125,9 @@
* Thrown if a child with the same id is replaced by the
add operation.
* @return This
*/
- public final MarkupContainer<T> add(final Component< ? >... childs)
+ public final MarkupContainer<T> add(final Component<?>... childs)
{
- for (Component< ? > child : childs)
+ for (Component<?> child : childs)
{
checkHierarchyChange(child);
@@ -162,9 +162,9 @@
* The child(s) to be added or replaced
* @return This
*/
- public final MarkupContainer<T> addOrReplace(final Component< ? >...
childs)
+ public final MarkupContainer<T> addOrReplace(final Component<?>...
childs)
{
- for (Component< ? > child : childs)
+ for (Component<?> child : childs)
{
checkHierarchyChange(child);
@@ -206,7 +206,7 @@
* stream to be used to render the component.
* @return True, if component has been added
*/
- public final boolean autoAdd(final Component< ? > component, final
MarkupStream markupStream)
+ public final boolean autoAdd(final Component<?> component, final
MarkupStream markupStream)
{
if (component == null)
{
@@ -250,7 +250,7 @@
* @deprecated since 1.3 Please use [EMAIL PROTECTED]
#autoAdd(Component, MarkupStream)} instead
*/
@Deprecated
- public final boolean autoAdd(final Component< ? > component)
+ public final boolean autoAdd(final Component<?> component)
{
return autoAdd(component, null);
}
@@ -262,7 +262,7 @@
* True if all descendents should be considered
* @return True if the component is contained in this container
*/
- public final boolean contains(final Component< ? > component, final
boolean recurse)
+ public final boolean contains(final Component<?> component, final
boolean recurse)
{
if (component == null)
{
@@ -272,10 +272,10 @@
if (recurse)
{
// Start at component and continue while we're not out
of parents
- for (Component< ? > current = component; current !=
null;)
+ for (Component<?> current = component; current != null;)
{
// Get parent
- final MarkupContainer< ? > parent =
current.getParent();
+ final MarkupContainer<?> parent =
current.getParent();
// If this container is the parent, then the
component is
// recursively contained by this container
@@ -307,7 +307,7 @@
* @return The component at the path
*/
@Override
- public final Component< ? > get(final String path)
+ public final Component<?> get(final String path)
{
// Reference to this container
if (path == null || path.trim().equals(""))
@@ -319,7 +319,7 @@
final String id = Strings.firstPathComponent(path,
Component.PATH_SEPARATOR);
// Get child by id
- Component< ? > child = children_get(id);
+ Component<?> child = children_get(id);
// If the container is transparent, than ask its parent.
// ParentResolver does something quite similar, but because of
<head>,
@@ -409,7 +409,7 @@
* @throws IllegalArgumentException
* Thrown if a child with the same id is replaced by the
add operation.
*/
- public void internalAdd(final Component< ? > child)
+ public void internalAdd(final Component<?> child)
{
if (log.isDebugEnabled())
{
@@ -438,9 +438,9 @@
/**
* @return Iterator that iterates through children in the order they
were added
*/
- public final Iterator<Component< ? >> iterator()
+ public final Iterator<Component<?>> iterator()
{
- return new Iterator<Component< ? >>()
+ return new Iterator<Component<?>>()
{
int index = 0;
@@ -449,14 +449,14 @@
return index < children_size();
}
- public Component< ? > next()
+ public Component<?> next()
{
return children_get(index++);
}
public void remove()
{
- final Component< ? > removed =
children_remove(--index);
+ final Component<?> removed =
children_remove(--index);
checkHierarchyChange(removed);
removedComponent(removed);
}
@@ -469,9 +469,9 @@
* @return Iterator that iterates over children in the order specified
by comparator
*/
@SuppressWarnings("unchecked")
- public final Iterator<Component< ? >> iterator(Comparator<Component< ?
>> comparator)
+ public final Iterator<Component<?>> iterator(Comparator<Component<?>>
comparator)
{
- final List<Component< ? >> sorted;
+ final List<Component<?>> sorted;
if (children == null)
{
sorted = Collections.emptyList();
@@ -480,8 +480,8 @@
{
if (children instanceof Component)
{
- sorted = new ArrayList<Component< ? >>(1);
- sorted.add((Component< ? >)children);
+ sorted = new ArrayList<Component<?>>(1);
+ sorted.add((Component<?>)children);
}
else if (children instanceof ChildList)
{
@@ -489,7 +489,7 @@
}
else
{
- sorted = Arrays.asList((Component< ?
>[])children);
+ sorted =
Arrays.asList((Component<?>[])children);
}
}
Collections.sort(sorted, comparator);
@@ -506,7 +506,7 @@
*/
// TODO remove after release 1.3.0
public final IResourceStream newMarkupResourceStream(
- Class< ? extends Component< ? >> containerClass)
+ Class<? extends Component<?>> containerClass)
{
throw new IllegalStateException(
"this method is not used any more (and shouldn't be
called by clients anyway)");
@@ -516,7 +516,7 @@
* @param component
* Component to remove from this container
*/
- public void remove(final Component< ? > component)
+ public void remove(final Component<?> component)
{
checkHierarchyChange(component);
@@ -542,7 +542,7 @@
throw new IllegalArgumentException("argument id may not
be null");
}
- final Component< ? > component = get(id);
+ final Component<?> component = get(id);
if (component != null)
{
remove(component);
@@ -585,7 +585,7 @@
for (int i = 0; i < size; i++)
{
// Get next child
- final Component< ? > child =
children_get(i);
+ final Component<?> child =
children_get(i);
child.setParent(MarkupContainer.this);
}
}
@@ -599,7 +599,7 @@
if (childObject instanceof Component)
{
// Get next child
- final Component< ? > child =
(Component< ? >)childObject;
+ final Component<?> child =
(Component<?>)childObject;
// Do not call remove() because the
state change would than be
// recorded twice.
@@ -680,7 +680,7 @@
* Thrown if there was no child with the same id.
* @return This
*/
- public final MarkupContainer<T> replace(final Component< ? > child)
+ public final MarkupContainer<T> replace(final Component<?> child)
{
checkHierarchyChange(child);
@@ -697,7 +697,7 @@
if (child.getParent() != this)
{
// Add to map
- final Component< ? > replaced = put(child);
+ final Component<?> replaced = put(child);
// Look up to make sure it was already in the map
if (replaced == null)
@@ -729,18 +729,18 @@
@Override
public MarkupContainer<T> setModel(final IModel<T> model)
{
- final IModel< ? > previous = getModelImpl();
+ final IModel<?> previous = getModelImpl();
super.setModel(model);
if (previous instanceof IComponentInheritedModel)
{
- visitChildren(new IVisitor<Component< ? >>()
+ visitChildren(new IVisitor<Component<?>>()
{
- public Object component(Component< ? >
component)
+ public Object component(Component<?> component)
{
- IModel< ? > compModel =
component.getModel();
+ IModel<?> compModel =
component.getModel();
if (compModel instanceof IWrapModel)
{
- compModel = ((IWrapModel< ?
>)compModel).getWrappedModel();
+ compModel =
((IWrapModel<?>)compModel).getWrappedModel();
}
if (compModel == previous)
{
@@ -804,7 +804,7 @@
for (int i = 0; i < size; i++)
{
// Get next child
- final Component< ? > child =
children_get(i);
+ final Component<?> child =
children_get(i);
if (i != 0)
{
buffer.append(' ');
@@ -821,6 +821,12 @@
* Traverses all child components of the given class in this container,
calling the visitor's
* visit method at each one.
*
+ * Make sure that if you give a type S that the clazz parameter will
only resolve to those
+ * types. Else a class cast exception will occur.
+ *
+ * @param <S>
+ * The type that goes into the Visitor.component() method.
+ *
* @param clazz
* The class of child to visit, or null to visit all children
* @param visitor
@@ -828,8 +834,9 @@
* @return The return value from a visitor which halted the traversal,
or null if the entire
* traversal occurred
*/
- public final Object visitChildren(final Class< ? > clazz,
- final IVisitor< ? extends Component< ? >> visitor)
+ public final <S extends Component<?>> Object visitChildren(final
Class<?> clazz,
+ final IVisitor<S> visitor)
+
{
if (visitor == null)
{
@@ -840,16 +847,16 @@
for (int i = 0; i < children_size(); i++)
{
// Get next child component
- final Component< ? > child = children_get(i);
+ final Component<?> child = children_get(i);
Object value = null;
- IVisitor vis = visitor;
-
// Is the child of the correct class (or was no class
specified)?
if (clazz == null || clazz.isInstance(child))
{
// Call visitor
- value = vis.component(child);
+ @SuppressWarnings("unchecked")
+ S s = (S)child;
+ value = visitor.component(s);
// If visitor returns a non-null value, it
halts the traversal
if ((value != IVisitor.CONTINUE_TRAVERSAL) &&
@@ -864,7 +871,7 @@
(value !=
IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER))
{
// visit the children in the container
- value = ((MarkupContainer< ?
>)child).visitChildren(clazz, visitor);
+ value =
((MarkupContainer<?>)child).visitChildren(clazz, visitor);
// If visitor returns a non-null value, it
halts the traversal
if ((value != IVisitor.CONTINUE_TRAVERSAL) &&
@@ -887,7 +894,7 @@
* @return The return value from a visitor which halted the traversal,
or null if the entire
* traversal occurred
*/
- public final Object visitChildren(final IVisitor<Component< ? >>
visitor)
+ public final Object visitChildren(final IVisitor<Component<?>> visitor)
{
return visitChildren(null, visitor);
}
@@ -896,7 +903,7 @@
* @param component
* Component being added
*/
- private final void addedComponent(final Component< ? > component)
+ private final void addedComponent(final Component<?> component)
{
// Check for degenerate case
if (component == this)
@@ -904,7 +911,7 @@
throw new IllegalArgumentException("Component can't be
added to itself");
}
- MarkupContainer< ? > parent = component.getParent();
+ MarkupContainer<?> parent = component.getParent();
if (parent != null)
{
parent.remove(component);
@@ -913,7 +920,7 @@
// Set child's parent
component.setParent(this);
- final Page< ? > page = findPage();
+ final Page<?> page = findPage();
final IDebugSettings debugSettings =
Application.get().getDebugSettings();
if (debugSettings.isLinePreciseReportingOnAddComponentEnabled())
@@ -940,7 +947,7 @@
* @param child
* Child to add
*/
- private final void children_add(final Component< ? > child)
+ private final void children_add(final Component<?> child)
{
if (children == null)
{
@@ -962,9 +969,9 @@
* @param index
* @return The child component
*/
- private final Component< ? > children_get(int index)
+ private final Component<?> children_get(int index)
{
- return (Component< ? >)children_get(index, true);
+ return (Component<?>)children_get(index, true);
}
/**
@@ -978,8 +985,8 @@
* @param index
* @return The object directly or the reconstructed component
*/
- private final Object postprocess(Object object, boolean reconstruct,
- MarkupContainer< ? > parent, int index)
+ private final Object postprocess(Object object, boolean reconstruct,
MarkupContainer<?> parent,
+ int index)
{
if (reconstruct && object instanceof ComponentSourceEntry)
{
@@ -1044,7 +1051,7 @@
{
if (object instanceof Component)
{
- return ((Component< ? >)object).getId();
+ return ((Component<?>)object).getId();
}
else if (object instanceof ComponentSourceEntry)
{
@@ -1061,18 +1068,18 @@
* @param id
* @return The child component
*/
- private final Component< ? > children_get(final String id)
+ private final Component<?> children_get(final String id)
{
if (children == null)
{
return null;
}
- Component< ? > component = null;
+ Component<?> component = null;
if ((children instanceof Object[] == false) && (children
instanceof List == false))
{
if (getId(children).equals(id))
{
- component = (Component< ?
>)postprocess(children, true, this, 0);
+ component = (Component<?>)postprocess(children,
true, this, 0);
if (children != component)
{
children = component;
@@ -1097,7 +1104,7 @@
{
if (getId(children[i]).equals(id))
{
- component = (Component< ?
>)postprocess(children[i], true, this, i);
+ component =
(Component<?>)postprocess(children[i], true, this, i);
if (children[i] != component)
{
children[i] = component;
@@ -1114,7 +1121,7 @@
* @param child
* @return The index of the given child component
*/
- private final int children_indexOf(Component< ? > child)
+ private final int children_indexOf(Component<?> child)
{
if (children == null)
{
@@ -1158,7 +1165,7 @@
* @param component
* @return The component that is removed.
*/
- private final Component< ? > children_remove(Component< ? > component)
+ private final Component<?> children_remove(Component<?> component)
{
int index = children_indexOf(component);
if (index != -1)
@@ -1173,7 +1180,7 @@
* @param index
* @return The component that is removed
*/
- private final Component< ? > children_remove(int index)
+ private final Component<?> children_remove(int index)
{
if (children == null)
return null;
@@ -1182,7 +1189,7 @@
{
if (index == 0)
{
- final Component< ? > removed = (Component< ?
>)postprocess(children, true, null, -1);
+ final Component<?> removed =
(Component<?>)postprocess(children, true, null, -1);
children = null;
return removed;
}
@@ -1211,7 +1218,7 @@
{
throw new
IndexOutOfBoundsException();
}
- return (Component< ?
>)postprocess(removed, true, null, -1);
+ return
(Component<?>)postprocess(removed, true, null, -1);
}
children = new ChildList(children);
}
@@ -1222,7 +1229,7 @@
{
children = lst.get(0);
}
- return (Component< ? >)postprocess(removed, true, null,
-1);
+ return (Component<?>)postprocess(removed, true, null,
-1);
}
}
@@ -1270,9 +1277,9 @@
* @param child
* @return The component that is replaced
*/
- private final Component< ? > children_set(int index, Component< ? >
child)
+ private final Component<?> children_set(int index, Component<?> child)
{
- return (Component< ? >)children_set(index, child, true);
+ return (Component<?>)children_set(index, child, true);
}
/**
@@ -1306,7 +1313,7 @@
* The child to put into the map
* @return Any component that was replaced
*/
- private final Component< ? > put(final Component< ? > child)
+ private final Component<?> put(final Component<?> child)
{
int index = children_indexOf(child);
if (index == -1)
@@ -1324,10 +1331,10 @@
* @param component
* Component being removed
*/
- private final void removedComponent(final Component< ? > component)
+ private final void removedComponent(final Component<?> component)
{
// Notify Page that component is being removed
- final Page< ? > page = component.findPage();
+ final Page<?> page = component.findPage();
if (page != null)
{
page.componentRemoved(component);
@@ -1360,7 +1367,7 @@
final String id = tag.getId();
// Get the component for the id from the given container
- final Component< ? > component = get(id);
+ final Component<?> component = get(id);
// Failed to find it?
if (component != null)
@@ -1371,7 +1378,7 @@
{
// 2rd try: Components like Border and Panel
might implement
// the ComponentResolver interface as well.
- MarkupContainer< ? > container = this;
+ MarkupContainer<?> container = this;
while (container != null)
{
if (container instanceof
IComponentResolver)
@@ -1440,7 +1447,7 @@
protected final MarkupStream findMarkupStream()
{
// Start here
- MarkupContainer< ? > c = this;
+ MarkupContainer<?> c = this;
// Walk up hierarchy until markup found
while (c.getMarkupStream() == null)
@@ -1574,7 +1581,7 @@
*/
private static class ComponentSourceEntry extends
org.apache.wicket.ComponentSourceEntry
{
- private ComponentSourceEntry(MarkupContainer< ? > container,
Component< ? > component,
+ private ComponentSourceEntry(MarkupContainer<?> container,
Component<?> component,
IComponentSource componentSource)
{
super(container, component, componentSource);
@@ -1583,7 +1590,7 @@
private static final long serialVersionUID = 1L;
@Override
- protected void setChild(MarkupContainer< ? > parent, int index,
Component< ? > child)
+ protected void setChild(MarkupContainer<?> parent, int index,
Component<?> child)
{
parent.children_set(index, child, false);
}
@@ -1603,7 +1610,7 @@
Object child = children_get(i, false);
if (child instanceof Component)
{
- Component< ? > component = (Component< ?
>)child;
+ Component<?> component = (Component<?>)child;
component.detach();
if (child instanceof IComponentSourceProvider)
@@ -1638,7 +1645,7 @@
final int size = children_size();
for (int i = 0; i < size; i++)
{
- final Component< ? > child = children_get(i);
+ final Component<?> child = children_get(i);
child.internalMarkRendering();
}
}
@@ -1646,10 +1653,10 @@
/**
* @return a copy of the children array.
*/
- private Component< ? >[] copyChildren()
+ private Component<?>[] copyChildren()
{
int size = children_size();
- Component< ? > result[] = new Component[size];
+ Component<?> result[] = new Component[size];
for (int i = 0; i < size; ++i)
{
result[i] = children_get(i);
@@ -1668,14 +1675,14 @@
// We need to copy the children list because the children
components can
// modify the hierarchy in their onBeforeRender.
- Component< ? >[] children = copyChildren();
+ Component<?>[] children = copyChildren();
try
{
// Loop through child components
for (int i = 0; i < children.length; i++)
{
// Get next child
- final Component< ? > child = children[i];
+ final Component<?> child = children[i];
// Call begin request on the child
// We need to check whether the child's wasn't
removed from the
@@ -1709,11 +1716,11 @@
void onAfterRenderChildren()
{
// Loop through child components
- final Iterator<Component< ? >> iter = iterator();
+ final Iterator<Component<?>> iter = iterator();
while (iter.hasNext())
{
// Get next child
- final Component< ? > child = iter.next();
+ final Component<?> child = iter.next();
// Call end request on the child
child.afterRender();
@@ -1737,9 +1744,9 @@
{
super.setRenderAllowed();
- visitChildren(new IVisitor<Component< ? >>()
+ visitChildren(new IVisitor<Component<?>>()
{
- public Object component(final Component< ? > component)
+ public Object component(final Component<?> component)
{
// Find out if this component can be rendered
final boolean renderAllowed =
component.isActionAuthorized(RENDER);