Revision: 430
http://svn.sourceforge.net/stripes/?rev=430&view=rev
Author: tfenne
Date: 2006-10-05 19:16:47 -0700 (Thu, 05 Oct 2006)
Log Message:
-----------
Merge of r:427:429, fixed for memory leak in dispatcher helper and NPE in
options-collection tag.
Modified Paths:
--------------
branches/1.4.x/stripes/src/net/sourceforge/stripes/controller/DispatcherHelper.java
branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java
Modified:
branches/1.4.x/stripes/src/net/sourceforge/stripes/controller/DispatcherHelper.java
===================================================================
---
branches/1.4.x/stripes/src/net/sourceforge/stripes/controller/DispatcherHelper.java
2006-10-06 02:12:39 UTC (rev 429)
+++
branches/1.4.x/stripes/src/net/sourceforge/stripes/controller/DispatcherHelper.java
2006-10-06 02:16:47 UTC (rev 430)
@@ -1,3 +1,17 @@
+/* Copyright 2005-2006 Tim Fennell
+ *
+ * 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 net.sourceforge.stripes.controller;
import net.sourceforge.stripes.action.ActionBean;
@@ -6,8 +20,8 @@
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.config.Configuration;
import net.sourceforge.stripes.exception.StripesServletException;
+import net.sourceforge.stripes.util.HtmlUtil;
import net.sourceforge.stripes.util.Log;
-import net.sourceforge.stripes.util.HtmlUtil;
import net.sourceforge.stripes.validation.Validatable;
import net.sourceforge.stripes.validation.ValidationError;
import net.sourceforge.stripes.validation.ValidationErrorHandler;
@@ -18,16 +32,21 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.PageContext;
import java.lang.reflect.Method;
+import java.lang.ref.WeakReference;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
-import java.util.concurrent.ConcurrentHashMap;
+import java.util.WeakHashMap;
/**
- *
+ * Helper class that contains much of the logic used when dispatching requests
in Stripes.
+ * Used primarily by the DispatcherSerlvet, but also by the UseActionBean tag.
+ *
+ * @author Tim Fennell
*/
public class DispatcherHelper {
private static final Log log = Log.getInstance(DispatcherHelper.class);
@@ -38,15 +57,29 @@
* to a particular ActionBean. The Map will contain a zero length array
for ActionBeans
* that do not have any valiation methods.
*/
- private static final Map<Class,Method[]> customValidations = new
ConcurrentHashMap<Class, Method[]>();
+ private static final Map<Class, WeakReference<Method[]>> customValidations
=
+ Collections.synchronizedMap(new WeakHashMap<Class,
WeakReference<Method[]>>());
/** A place to hide a page context object so that we can get access to EL
classes. */
private static ThreadLocal<PageContext> pageContextStash = new
ThreadLocal<PageContext>();
+ /**
+ * Should be called prior to invoking validation related methods to
provide the helper
+ * with access to a PageContext object that can be used to manufacture
expression
+ * evaluator instances.
+ *
+ * @param ctx a page context object supplied by the container
+ */
public static void setPageContext(PageContext ctx) {
pageContextStash.set(ctx);
}
+ /**
+ * Used by the validation subsystem to access a page context that can be
used to
+ * create an expression evaluator for use in the expression validation
code.
+ *
+ * @return a page context object if one was set with setPageContext()
+ */
public static PageContext getPageContext() {
return pageContextStash.get();
}
@@ -272,7 +305,9 @@
* an empty array, but never null.
*/
public static Method[] findCustomValidationMethods(Class<? extends
ActionBean> type) throws Exception {
- Method[] validations = customValidations.get(type);
+ Method[] validations = null;
+ WeakReference<Method[]> ref = customValidations.get(type);
+ if (ref != null) validations = ref.get();
// Lazily examine the ActionBean and collect this information
if (validations == null) {
@@ -310,7 +345,7 @@
}
validations = validationMethods.toArray(new
Method[validationMethods.size()]);
- customValidations.put(type, validations);
+ customValidations.put(type, new WeakReference(validations));
}
return validations;
Modified:
branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
===================================================================
---
branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
2006-10-06 02:12:39 UTC (rev 429)
+++
branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
2006-10-06 02:16:47 UTC (rev 430)
@@ -142,16 +142,17 @@
// Lookup the bean properties for the label and value
Object label = (labelProperty == null) ? item :
BeanUtil.getPropertyValue(labelProperty, item);
Object value = (valueProperty == null) ? item :
BeanUtil.getPropertyValue(valueProperty, item);
+ String packageName = clazz.getPackage() == null
? "" : clazz.getPackage().getName();
// Try to localize the label
String localizedLabel = null;
if (label != null) {
localizedLabel = LocalizationUtility.getLocalizedFieldName
- (clazz.getSimpleName() + "." + label,
clazz.getPackage().getName(), locale);
+ (clazz.getSimpleName() + "." + label, packageName,
locale);
}
if (localizedLabel == null && value != null) {
localizedLabel = LocalizationUtility.getLocalizedFieldName
- (clazz.getSimpleName() + "." + value,
clazz.getPackage().getName(), locale);
+ (clazz.getSimpleName() + "." + value, packageName,
locale);
}
if (localizedLabel != null) label = localizedLabel;
Modified:
branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java
===================================================================
---
branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java
2006-10-06 02:12:39 UTC (rev 429)
+++
branches/1.4.x/stripes/src/net/sourceforge/stripes/tag/InputOptionsEnumerationTag.java
2006-10-06 02:16:47 UTC (rev 430)
@@ -134,10 +134,11 @@
for (Enum item : enums) {
Object value = item.name();
Object label = null;
+ String packageName = clazz.getPackage() == null
? "" : clazz.getPackage().getName();
// Check for a localized label using class.ENUM_VALUE and
package.class.ENUM_VALUE
label =
LocalizationUtility.getLocalizedFieldName(clazz.getSimpleName() + "." +
item.name(),
-
clazz.getPackage().getName(),
+ packageName,
locale);
if (label == null) {
if (this.label != null) {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development