You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by ta...@apache.org on 2008/10/22 22:30:38 UTC
svn commit: r707189 - in /portals/pluto/branches/2.0-spi-refactoring:
pluto-container-api/src/main/java/org/apache/pluto/spi/optional/
pluto-container/src/main/java/org/apache/pluto/core/
pluto-container/src/main/java/org/apache/pluto/internal/impl/
Author: taylor
Date: Wed Oct 22 13:30:38 2008
New Revision: 707189
URL: http://svn.apache.org/viewvc?rev=707189&view=rev
Log:
https://issues.apache.org/jira/browse/PLUTO-481
remove static PreferencesValidatorRegistry service and implement its one service on the Portlet Preferences service
Removed:
portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/core/PreferencesValidatorRegistry.java
Modified:
portals/pluto/branches/2.0-spi-refactoring/pluto-container-api/src/main/java/org/apache/pluto/spi/optional/PortletPreferencesService.java
portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/core/DefaultPortletPreferencesService.java
portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletEntityImpl.java
portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletPreferencesImpl.java
Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-container-api/src/main/java/org/apache/pluto/spi/optional/PortletPreferencesService.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-container-api/src/main/java/org/apache/pluto/spi/optional/PortletPreferencesService.java?rev=707189&r1=707188&r2=707189&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-container-api/src/main/java/org/apache/pluto/spi/optional/PortletPreferencesService.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-container-api/src/main/java/org/apache/pluto/spi/optional/PortletPreferencesService.java Wed Oct 22 13:30:38 2008
@@ -19,10 +19,13 @@
import java.util.Map;
import javax.portlet.PortletRequest;
+import javax.portlet.PreferencesValidator;
+import javax.portlet.ValidatorException;
import org.apache.pluto.PortletContainerException;
import org.apache.pluto.PortletWindow;
import org.apache.pluto.internal.InternalPortletPreference;
+import org.apache.pluto.om.portlet.PortletDefinition;
import org.apache.pluto.spi.ContainerService;
/**
@@ -68,4 +71,17 @@
Map<String, InternalPortletPreference> preferences)
throws PortletContainerException;
+ /**
+ * Returns the preferences validator instance for the given portlet
+ * definition. If no preferences validator class is defined for the portlet
+ * definition, null is returned. This method caches the validator instances
+ * in the cache to ensure that only one validator instance is created per
+ * portlet definition.
+ * @param portletDefinition the portlet definition.
+ * @return the preferences validator if defined for the portlet definition.
+ * @throw ValidatorException if fail to instantiate validator instance.
+ */
+ public PreferencesValidator getPreferencesValidator(PortletDefinition portletDefinition)
+ throws ValidatorException;
+
}
Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/core/DefaultPortletPreferencesService.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/core/DefaultPortletPreferencesService.java?rev=707189&r1=707188&r2=707189&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/core/DefaultPortletPreferencesService.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/core/DefaultPortletPreferencesService.java Wed Oct 22 13:30:38 2008
@@ -21,6 +21,8 @@
import java.util.Map;
import javax.portlet.PortletRequest;
+import javax.portlet.PreferencesValidator;
+import javax.portlet.ValidatorException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -58,6 +60,12 @@
*/
private Map<String,Map<String,InternalPortletPreference>> storage = new HashMap<String,Map<String,InternalPortletPreference>>();
+ /**
+ * The preferences validator cache: key is the portlet definition, value is
+ * the portlet preferences validator instance.
+ */
+ private Map<PortletDefinition, PreferencesValidator> cache = new HashMap<PortletDefinition, PreferencesValidator>();
+
// Constructor -------------------------------------------------------------
@@ -207,4 +215,47 @@
}
return copy;
}
+
+ public PreferencesValidator getPreferencesValidator(PortletDefinition portletDD)
+ throws ValidatorException {
+
+ // Try to retrieve the validator from cache.
+ PreferencesValidator validator = (PreferencesValidator)
+ cache.get(portletDD);
+ if (validator != null) {
+ return validator;
+ }
+
+ // Try to construct the validator instance for the portlet definition.
+ Preferences portletPreferencesDD = portletDD.getPortletPreferences();
+
+ if (portletPreferencesDD != null) {
+ String className = portletPreferencesDD.getPreferencesValidator();
+ if (className != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Creating preferences validator: " + className);
+ }
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ try {
+ Class clazz = loader.loadClass(className);
+ validator = (PreferencesValidator) clazz.newInstance();
+ cache.put(portletDD, validator);
+ } catch (InstantiationException ex) {
+ LOG.error("Error instantiating validator.", ex);
+ throw new ValidatorException(ex, null);
+ } catch (IllegalAccessException ex) {
+ LOG.error("Error instantiating validator.", ex);
+ throw new ValidatorException(ex, null);
+ } catch (ClassNotFoundException ex) {
+ LOG.error("Error instantiating validator.", ex);
+ throw new ValidatorException(ex, null);
+ } catch (ClassCastException ex) {
+ LOG.error("Error casting instance to PreferencesValidator.", ex);
+ throw new ValidatorException(ex, null);
+ }
+ }
+ }
+ return validator;
+ }
+
}
\ No newline at end of file
Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletEntityImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletEntityImpl.java?rev=707189&r1=707188&r2=707189&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletEntityImpl.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletEntityImpl.java Wed Oct 22 13:30:38 2008
@@ -16,11 +16,7 @@
*/
package org.apache.pluto.internal.impl;
-import javax.portlet.PreferencesValidator;
-import javax.portlet.ValidatorException;
-
import org.apache.pluto.PortletEntity;
-import org.apache.pluto.core.PreferencesValidatorRegistry;
import org.apache.pluto.om.portlet.PortletDefinition;
/**
Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletPreferencesImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletPreferencesImpl.java?rev=707189&r1=707188&r2=707189&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletPreferencesImpl.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletPreferencesImpl.java Wed Oct 22 13:30:38 2008
@@ -24,7 +24,6 @@
import java.util.Vector;
import javax.portlet.PortletPreferences;
-import javax.portlet.PreferencesValidator;
import javax.portlet.ReadOnlyException;
import javax.portlet.ValidatorException;
@@ -34,7 +33,6 @@
import org.apache.pluto.PortletContainer;
import org.apache.pluto.PortletContainerException;
import org.apache.pluto.PortletWindow;
-import org.apache.pluto.core.PreferencesValidatorRegistry;
import org.apache.pluto.internal.InternalPortletPreference;
import org.apache.pluto.internal.InternalPortletRequest;
import org.apache.pluto.om.portlet.PortletDefinition;
@@ -276,11 +274,7 @@
// If the preferences cannot pass the validation,
// an ValidatorException will be thrown out.
PortletDefinition portletD = window.getPortletEntity().getPortletDefinition();
- PreferencesValidator validator = PreferencesValidatorRegistry.getRegistry()
- .getPreferencesValidator(portletD);
- if (validator != null) {
- validator.validate(this);
- }
+ preferencesService.getPreferencesValidator(portletD).validate(this);
// Store the portlet preferences.
try {
preferencesService.store(window, request, preferences);