Author: ivaynberg
Date: Thu Nov 9 23:28:14 2006
New Revision: 473222
URL: http://svn.apache.org/viewvc?view=rev&rev=473222
Log:
factoring out debug type data and logic into a separate class in preparation
for adding more checks for attach/detach super() calls enforcement
Added:
incubator/wicket/trunk/wicket/src/main/java/wicket/DebugHelper.java
Modified:
incubator/wicket/trunk/wicket/src/main/java/wicket/Page.java
incubator/wicket/trunk/wicket/src/main/java/wicket/RequestCycle.java
Added: incubator/wicket/trunk/wicket/src/main/java/wicket/DebugHelper.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/DebugHelper.java?view=auto&rev=473222
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/DebugHelper.java (added)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/DebugHelper.java Thu Nov
9 23:28:14 2006
@@ -0,0 +1,179 @@
+/*
+ * $Id: org.eclipse.jdt.ui.prefs 5004 2006-03-17 20:47:08 -0800 (Fri, 17 Mar
2006) eelco12 $
+ * $Revision: 5004 $
+ * $Date: 2006-03-17 20:47:08 -0800 (Fri, 17 Mar 2006) $
+ *
+ *
==============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package wicket;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import wicket.Component.IVisitor;
+import wicket.markup.MarkupException;
+import wicket.settings.IDebugSettings;
+import wicket.util.value.Count;
+
+/**
+ * Class that consolidates and helps the debugging process for applications in
+ * development mode.
+ *
+ * @author ivaynberg
+ */
+public class DebugHelper
+{
+ private static Log log = LogFactory.getLog(DebugHelper.class);
+
+ private Set<Component> renderedComponents;
+
+ /**
+ * Resets the set of rendered components kept for component-use check.
+ *
+ * @see IDebugSettings#setComponentUseCheck(boolean)
+ *
+ */
+ public void resetRenderedComponentsSet()
+ {
+ this.renderedComponents = null;
+ }
+
+ /**
+ * Listener method invoked by the framework when a component render is
began
+ *
+ * @param component
+ * component being rendered
+ */
+ public void onBeginComponentRender(Component component)
+ {
+ if (renderedComponents == null)
+ {
+ renderedComponents = new HashSet<Component>();
+ }
+ if (renderedComponents.add(component) == false)
+ {
+ throw new MarkupException(
+ "The component "
+ + component
+ + " has the same
wicket:id as another component already rendered at the same level");
+ }
+ if (log.isDebugEnabled())
+ {
+ log.debug("Rendered " + component);
+ }
+ }
+
+ /**
+ * Listener method invoked by the framework when a component render is
+ * finished
+ *
+ * @param component
+ * component being rendered
+ */
+ public void onEndComponentRender(Component component)
+ {
+ if (component instanceof MarkupContainer)
+ {
+ checkRendering((MarkupContainer)component);
+ }
+ else
+ {
+ renderedComponents = null;
+ }
+ }
+
+ /**
+ * Throw an exception if not all components rendered.
+ *
+ * @param container
+ * The page itself if it was a full page render or the
container
+ * that was rendered standalone
+ */
+ private void checkRendering(MarkupContainer container)
+ {
+ // If the application wants component uses checked and
+ // the response is not a redirect
+ final IDebugSettings debugSettings =
Application.get().getDebugSettings();
+ if (debugSettings.getComponentUseCheck() &&
!RequestCycle.get().getResponse().isRedirect())
+ {
+ final Count unrenderedComponents = new Count();
+ final List<Component> unrenderedAutoComponents = new
ArrayList<Component>();
+ final StringBuffer buffer = new StringBuffer();
+ container.visitChildren(new IVisitor()
+ {
+ public Object component(final Component
component)
+ {
+ // If component never rendered
+ if (renderedComponents == null ||
!renderedComponents.contains(component))
+ {
+ // If auto component ...
+ if (component.isAuto())
+ {
+ // Add to list of
unrendered auto components to
+ // delete below
+
unrenderedAutoComponents.add(component);
+ }
+ else if
(component.isVisibleInHierarchy())
+ {
+ // Increase number of
unrendered components
+
unrenderedComponents.increment();
+
+ // Add to explanatory
string to buffer
+
buffer.append(Integer.toString(unrenderedComponents.getCount()) + ". "
+ +
component + "\n");
+ }
+ else
+ {
+ // if the component is
not visible in hierarchy we
+ // should not visit its
children since they are also
+ // not visible
+ return
CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
+ }
+ }
+ return CONTINUE_TRAVERSAL;
+ }
+ });
+
+ // Remove any unrendered auto components since
versioning couldn't
+ // do it. We can't remove the component in the above
visitChildren
+ // callback because we're traversing the list at that
time.
+ for (int i = 0; i < unrenderedAutoComponents.size();
i++)
+ {
+ unrenderedAutoComponents.get(i).remove();
+ }
+
+ // Throw exception if any errors were found
+ if (unrenderedComponents.getCount() > 0)
+ {
+ // Get rid of set
+ renderedComponents = null;
+
+ // Throw exception
+ throw new WicketRuntimeException(
+ "The component(s) below failed
to render. A common problem is that you have added a component in code but
forgot to reference it in the markup (thus the component will never be
rendered).\n\n"
+ +
buffer.toString());
+ }
+ }
+
+ // Get rid of set
+ renderedComponents = null;
+
+ }
+
+}
Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/Page.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/Page.java?view=diff&rev=473222&r1=473221&r2=473222
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/Page.java (original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/Page.java Thu Nov 9
23:28:14 2006
@@ -182,9 +182,6 @@
/** Name of PageMap that this page is stored in */
private String pageMapName;
- /** Set of components that rendered if component use checking is
enabled */
- private transient Set<Component> renderedComponents;
-
/**
* Boolean if the page is stateless, so it doesn't have to be in the
page
* map, will be set in urlFor.
@@ -353,24 +350,9 @@
*/
final void componentRendered(final Component component)
{
- // Inform the page that this component rendered
if (Application.get().getDebugSettings().getComponentUseCheck())
{
- if (renderedComponents == null)
- {
- renderedComponents = new HashSet<Component>();
- }
- if (renderedComponents.add(component) == false)
- {
- throw new MarkupException(
- "The component "
- + component
- + " has the
same wicket:id as another component already rendered at the same level");
- }
- if (log.isDebugEnabled())
- {
- log.debug("Rendered " + component);
- }
+
RequestCycle.get().getDebugHelper().onBeginComponentRender(component);
}
}
@@ -475,13 +457,9 @@
*/
public final void endComponentRender(Component component)
{
- if (component instanceof MarkupContainer)
- {
- checkRendering((MarkupContainer)component);
- }
- else
+ if (Application.get().getDebugSettings().getComponentUseCheck())
{
- renderedComponents = null;
+
RequestCycle.get().getDebugHelper().onEndComponentRender(component);
}
}
@@ -745,83 +723,6 @@
}
/**
- * Throw an exception if not all components rendered.
- *
- * @param renderedContainer
- * The page itself if it was a full page render or the
container
- * that was rendered standalone
- */
- private final void checkRendering(final MarkupContainer<?>
renderedContainer)
- {
- // If the application wants component uses checked and
- // the response is not a redirect
- final IDebugSettings debugSettings =
Application.get().getDebugSettings();
- if (debugSettings.getComponentUseCheck() &&
!getResponse().isRedirect())
- {
- final Count unrenderedComponents = new Count();
- final List<Component> unrenderedAutoComponents = new
ArrayList<Component>();
- final StringBuffer buffer = new StringBuffer();
- renderedContainer.visitChildren(new IVisitor()
- {
- public Object component(final Component
component)
- {
- // If component never rendered
- if (renderedComponents == null ||
!renderedComponents.contains(component))
- {
- // If auto component ...
- if (component.isAuto())
- {
- // Add to list of
unrendered auto components to
- // delete below
-
unrenderedAutoComponents.add(component);
- }
- else if
(component.isVisibleInHierarchy())
- {
- // Increase number of
unrendered components
-
unrenderedComponents.increment();
-
- // Add to explanatory
string to buffer
-
buffer.append(Integer.toString(unrenderedComponents.getCount()) + ". "
- +
component + "\n");
- }
- else
- {
- // if the component is
not visible in hierarchy we
- // should not visit its
children since they are also
- // not visible
- return
CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
- }
- }
- return CONTINUE_TRAVERSAL;
- }
- });
-
- // Remove any unrendered auto components since
versioning couldn't
- // do it. We can't remove the component in the above
visitChildren
- // callback because we're traversing the list at that
time.
- for (int i = 0; i < unrenderedAutoComponents.size();
i++)
- {
- unrenderedAutoComponents.get(i).remove();
- }
-
- // Throw exception if any errors were found
- if (unrenderedComponents.getCount() > 0)
- {
- // Get rid of set
- renderedComponents = null;
-
- // Throw exception
- throw new WicketRuntimeException(
- "The component(s) below failed
to render. A common problem is that you have added a component in code but
forgot to reference it in the markup (thus the component will never be
rendered).\n\n"
- +
buffer.toString());
- }
- }
-
- // Get rid of set
- renderedComponents = null;
- }
-
- /**
* Initializes Page by adding it to the Session and initializing it.
*/
private final void init()
@@ -1205,7 +1106,10 @@
}
// Make sure it is really empty
- renderedComponents = null;
+ if (Application.get().getDebugSettings().getComponentUseCheck())
+ {
+
RequestCycle.get().getDebugHelper().resetRenderedComponentsSet();
+ }
// Reset it to stateless so that it can be tested again
this.stateless = null;
@@ -1264,7 +1168,10 @@
render(null);
// Check rendering if it happened fully
- checkRendering(this);
+ if (Application.get().getDebugSettings().getComponentUseCheck())
+ {
+
RequestCycle.get().getDebugHelper().onEndComponentRender(this);
+ }
if (!isPageStateless())
{
@@ -1351,7 +1258,10 @@
*/
public final void startComponentRender(Component component)
{
- renderedComponents = null;
+ if (Application.get().getDebugSettings().getComponentUseCheck())
+ {
+
RequestCycle.get().getDebugHelper().resetRenderedComponentsSet();
+ }
}
/**
Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/RequestCycle.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/RequestCycle.java?view=diff&rev=473222&r1=473221&r2=473222
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/RequestCycle.java
(original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/RequestCycle.java Thu
Nov 9 23:28:14 2006
@@ -240,7 +240,8 @@
private boolean redirect;
/** holds the stack of set [EMAIL PROTECTED] IRequestTarget}, the last
set op top. */
- private transient ArrayListStack<IRequestTarget> requestTargets = new
ArrayListStack<IRequestTarget>(3);
+ private transient ArrayListStack<IRequestTarget> requestTargets = new
ArrayListStack<IRequestTarget>(
+ 3);
/** the time that this request cycle object was created. */
private final long startTime = System.currentTimeMillis();
@@ -248,6 +249,9 @@
/** True if the session should be updated (for clusterf purposes). */
private boolean updateSession;
+ /** debug data */
+ private DebugHelper debugHelper;
+
/**
* Constructor.
*
@@ -282,6 +286,20 @@
}
/**
+ * Returns debug helper for this request
+ *
+ * @return debug helper for this request
+ */
+ public final DebugHelper getDebugHelper()
+ {
+ if (debugHelper == null)
+ {
+ debugHelper = new DebugHelper();
+ }
+ return debugHelper;
+ }
+
+ /**
* Gets the new agent info object for this session. This method calls
* [EMAIL PROTECTED] Session#getClientInfo()}, which may or may not
cache the client
* info object and typically calls [EMAIL PROTECTED] #newClientInfo()}
when no client
@@ -851,7 +869,7 @@
log.error("there was an error cleaning up feedback
messages for session " + session
+ ".", re);
}
-
+
if (updateSession)
{
// At the end of our response, we need to set any
session
@@ -859,14 +877,14 @@
try
{
session.update();
- }
- catch(RuntimeException re)
+ }
+ catch (RuntimeException re)
{
log.error("there was an error updating the
session " + session + ".", re);
}
}
- // clear the used pagemap for this thread,
+ // clear the used pagemap for this thread,
// maybe we can move this a few lines above to have a but more
// concurrency (session.update)
try
@@ -884,7 +902,7 @@
{
((BufferedWebResponse)getResponse()).filter();
}
- catch(RuntimeException re)
+ catch (RuntimeException re)
{
log.error("there was an error filtering the
response.", re);
}