You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2009/07/12 10:52:45 UTC
svn commit: r793297 - in
/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval:
./ validation/ validation/message/interpolator/
Author: gpetracek
Date: Sun Jul 12 08:52:45 2009
New Revision: 793297
URL: http://svn.apache.org/viewvc?rev=793297&view=rev
Log:
EXTVAL-33 refactoring of ebv-context
Modified:
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/ExtValBeanValidationContext.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/message/interpolator/ExtValMessageInterpolatorAdapter.java
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/ExtValBeanValidationContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/ExtValBeanValidationContext.java?rev=793297&r1=793296&r2=793297&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/ExtValBeanValidationContext.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/ExtValBeanValidationContext.java Sun Jul 12 08:52:45 2009
@@ -21,9 +21,9 @@
import org.apache.myfaces.extensions.validator.beanval.validation.message.interpolator.DefaultMessageInterpolator;
import org.apache.myfaces.extensions.validator.beanval.validation.message.interpolator.ExtValMessageInterpolatorAdapter;
import org.apache.myfaces.extensions.validator.beanval.validation.ModelValidationEntry;
-import org.apache.myfaces.extensions.validator.internal.ToDo;
-import org.apache.myfaces.extensions.validator.internal.Priority;
+import org.apache.myfaces.extensions.validator.beanval.validation.strategy.BeanValidationStrategyAdapter;
import org.apache.myfaces.extensions.validator.core.validation.message.resolver.MessageResolver;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -47,26 +47,35 @@
private static final String KEY = ExtValBeanValidationContext.class.getName() + ":KEY";
- private static MessageInterpolator defaultMessageInterpolator = new DefaultMessageInterpolator(
- Validation.buildDefaultValidatorFactory().getMessageInterpolator());
+ private MessageInterpolator defaultMessageInterpolator;
- private static MessageResolver messageResolver;
+ private MessageResolver messageResolver;
- @ToDo(value = Priority.HIGH, description = "refactor to a pluggable Storage")
private Map<String, List<Class>> addedGroups = new HashMap<String, List<Class>>();
- @ToDo(value = Priority.HIGH, description = "refactor to a pluggable Storage")
private Map<String, List<Class>> restrictedGroups = new HashMap<String, List<Class>>();
- @ToDo(value = Priority.HIGH, description = "refactor to a pluggable Storage")
private Map<String, List<ModelValidationEntry>> modelValidationEntries =
new HashMap<String, List<ModelValidationEntry>>();
- @ToDo(value = Priority.HIGH, description = "refactor to a pluggable Storage")
private List<String> componentsOfRequest = new ArrayList<String>();
private ExtValBeanValidationContext()
{
+ this.messageResolver = ExtValUtils
+ .getMessageResolverForValidationStrategy(new BeanValidationStrategyAdapter(null));
+
+ Object foundBean = ExtValUtils.getELHelper().getBean(MessageInterpolator.class.getName().replace(".", "_"));
+
+ if(foundBean instanceof MessageInterpolator)
+ {
+ this.defaultMessageInterpolator = (MessageInterpolator)foundBean;
+ }
+ else
+ {
+ this.defaultMessageInterpolator = new DefaultMessageInterpolator(
+ Validation.buildDefaultValidatorFactory().getMessageInterpolator());
+ }
}
@SuppressWarnings({"unchecked"})
@@ -87,36 +96,11 @@
return currentContext;
}
- private String getGroupKey(String viewId, String componentId)
- {
- return componentId == null ? viewId : viewId + "@" + componentId;
- }
-
- public void addGroup(Class groupClass)
- {
- addGroup(groupClass, FacesContext.getCurrentInstance().getViewRoot().getViewId());
- }
-
- public void addGroup(Class groupClass, String viewId)
- {
- addGroup(groupClass, viewId, null);
- }
-
public void addGroup(Class groupClass, String viewId, String componentId)
{
addGroupToGroupStorage(groupClass, viewId, componentId, this.addedGroups);
}
- public void addModelValidationEntry(ModelValidationEntry modelValidationEntry)
- {
- addModelValidationEntry(modelValidationEntry, FacesContext.getCurrentInstance().getViewRoot().getViewId());
- }
-
- public void addModelValidationEntry(ModelValidationEntry modelValidationEntry, String viewId)
- {
- addModelValidationEntry(modelValidationEntry, viewId, null);
- }
-
public void addModelValidationEntry(
ModelValidationEntry modelValidationEntry, String viewId, UIComponent component)
{
@@ -145,78 +129,11 @@
}
}
- public void restrictGroup(Class groupClass)
- {
- restrictGroup(groupClass, FacesContext.getCurrentInstance().getViewRoot().getViewId());
- }
-
- public void restrictGroup(Class groupClass, String viewId)
- {
- restrictGroup(groupClass, viewId, null);
- }
-
public void restrictGroup(Class groupClass, String viewId, String componentId)
{
addGroupToGroupStorage(groupClass, viewId, componentId, this.restrictedGroups);
}
- private void addGroupToGroupStorage(Class groupClass, String viewId, String componentId,
- Map<String, List<Class>> groupStorage)
- {
- List<Class> groupList = groupStorage.get(getGroupKey(viewId, componentId));
-
- if(groupList == null)
- {
- groupList = new ArrayList<Class>();
- groupStorage.put(getGroupKey(viewId, componentId), groupList);
- }
-
- if(!groupList.contains(groupClass))
- {
- groupList.add(groupClass);
- }
- }
-
- public void resetGroup(String viewId)
- {
- resetGroups(viewId, null);
- }
-
- public void resetGroups(String viewId, String componentId)
- {
- this.addedGroups.put(getGroupKey(viewId, componentId), new ArrayList<Class>());
- }
-
- /*
- public Class[] getGroups()
- {
- if(this.addedGroups.size() < 1)
- {
- return new Class[] {Default.class};
- }
-
- List<Class> fullGroupList = new ArrayList<Class>();
-
- for(Map.Entry<String, List<Class>> currentGroupEntry : this.addedGroups.entrySet())
- {
- fullGroupList.addAll(currentGroupEntry.getValue());
-
- }
- return (Class[]) fullGroupList.toArray();
- }
- */
-
- public Class[] getGroups(String viewId)
- {
- return getGroups(viewId, null);
- }
-
- public Class[] getAllGroups(String viewId)
- {
- return getGroups(viewId, "*");
- }
-
- @ToDo(value = Priority.HIGH, description = "change impl. for #getAllGroups - see getModelValidationEntries")
public Class[] getGroups(String viewId, String componentId)
{
if(this.addedGroups.size() < 1)
@@ -260,66 +177,56 @@
return mergeResults(resultsForPage, resultsForComponent);
}
- public List<ModelValidationEntry> getModelValidationEntries(String viewId)
- {
- return getModelValidationEntries(viewId, null);
- }
-
- public List<ModelValidationEntry> getAllModelValidationEntries(String viewId)
- {
- return getModelValidationEntries(viewId, "*");
- }
-
- public List<ModelValidationEntry> getModelValidationEntriesOfCurrentRequest(String viewId)
+ public List<ModelValidationEntry> getModelValidationEntriesToValidate()
{
+ String viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
List<ModelValidationEntry> result = new ArrayList<ModelValidationEntry>();
+ //add entries for specific components
for(String currentClientId : this.componentsOfRequest)
{
result.addAll(getModelValidationEntries(viewId, currentClientId));
}
+ //add entries for the whole page
result.addAll(getModelValidationEntries(viewId));
return result;
}
- public List<ModelValidationEntry> getModelValidationEntries(String viewId, String componentId)
+ public MessageInterpolator getMessageInterpolator()
{
- if(this.modelValidationEntries.size() < 1)
+ if(this.messageResolver != null)
{
- return new ArrayList<ModelValidationEntry>();
+ return new ExtValMessageInterpolatorAdapter(this.defaultMessageInterpolator, this.messageResolver);
}
- //add found groups
- String key;
- List<ModelValidationEntry> resultListForPage = null;
+ return this.defaultMessageInterpolator;
+ }
- if(!"*".equals(componentId))
- {
- key = getGroupKey(viewId, null);
- resultListForPage =
- buildModelValidationEntryList(key, this.modelValidationEntries);
- }
+ /*
+ * private methods
+ */
+ private String getGroupKey(String viewId, String componentId)
+ {
+ return componentId == null ? viewId : viewId + "@" + componentId;
+ }
- key = getGroupKey(viewId, componentId);
- List<ModelValidationEntry> resultListForComponent =
- buildModelValidationEntryList(key, this.modelValidationEntries);
+ private void addGroupToGroupStorage(Class groupClass, String viewId, String componentId,
+ Map<String, List<Class>> groupStorage)
+ {
+ List<Class> groupList = groupStorage.get(getGroupKey(viewId, componentId));
- if(resultListForPage == null || resultListForPage.isEmpty())
+ if(groupList == null)
{
- return resultListForComponent;
+ groupList = new ArrayList<Class>();
+ groupStorage.put(getGroupKey(viewId, componentId), groupList);
}
- else if(resultListForComponent.isEmpty())
+
+ if(!groupList.contains(groupClass))
{
- return resultListForPage;
+ groupList.add(groupClass);
}
-
- //merge results
- List<ModelValidationEntry> mergedResult = new ArrayList<ModelValidationEntry>();
- mergedResult.addAll(resultListForPage);
- mergedResult.addAll(resultListForComponent);
- return mergedResult;
}
private List<Class> buildGroupList(String key, Map<String, List<Class>> groupStorage)
@@ -377,35 +284,46 @@
return mergedResult;
}
- public void removeGroup(Class groupClass)
+ private List<ModelValidationEntry> getModelValidationEntries(String viewId)
{
- removeGroup(groupClass, FacesContext.getCurrentInstance().getViewRoot().getViewId());
+ return getModelValidationEntries(viewId, null);
}
- public void removeGroup(Class groupClass, String viewId)
+ private List<ModelValidationEntry> getModelValidationEntries(String viewId, String componentId)
{
- removeGroup(groupClass, viewId, null);
- }
+ if(this.modelValidationEntries.size() < 1)
+ {
+ return new ArrayList<ModelValidationEntry>();
+ }
- @ToDo(Priority.HIGH)
- public void removeGroup(Class groupClass, String viewId, String componentId)
- {
- this.addedGroups.remove(getGroupKey(viewId, componentId));
- }
+ //add found groups
+ String key;
+ List<ModelValidationEntry> resultListForPage = null;
- public MessageInterpolator getMessageInterpolator()
- {
- if(messageResolver != null)
+ if(!"*".equals(componentId))
{
- return new ExtValMessageInterpolatorAdapter(defaultMessageInterpolator, messageResolver);
+ key = getGroupKey(viewId, null);
+ resultListForPage =
+ buildModelValidationEntryList(key, this.modelValidationEntries);
}
- return defaultMessageInterpolator;
- }
+ key = getGroupKey(viewId, componentId);
+ List<ModelValidationEntry> resultListForComponent =
+ buildModelValidationEntryList(key, this.modelValidationEntries);
- @ToDo(Priority.HIGH)
- public static void setMessageResolver(MessageResolver customMessageResolver)
- {
- messageResolver = customMessageResolver;
+ if(resultListForPage == null || resultListForPage.isEmpty())
+ {
+ return resultListForComponent;
+ }
+ else if(resultListForComponent.isEmpty())
+ {
+ return resultListForPage;
+ }
+
+ //merge results
+ List<ModelValidationEntry> mergedResult = new ArrayList<ModelValidationEntry>();
+ mergedResult.addAll(resultListForPage);
+ mergedResult.addAll(resultListForComponent);
+ return mergedResult;
}
}
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java?rev=793297&r1=793296&r2=793297&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java Sun Jul 12 08:52:45 2009
@@ -62,7 +62,7 @@
}
List<ModelValidationEntry> modelValidationEntries = ExtValBeanValidationContext.getCurrentInstance()
- .getModelValidationEntriesOfCurrentRequest(FacesContext.getCurrentInstance().getViewRoot().getViewId());
+ .getModelValidationEntriesToValidate();
List processedValidationTargets = new ArrayList();
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/message/interpolator/ExtValMessageInterpolatorAdapter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/message/interpolator/ExtValMessageInterpolatorAdapter.java?rev=793297&r1=793296&r2=793297&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/message/interpolator/ExtValMessageInterpolatorAdapter.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/message/interpolator/ExtValMessageInterpolatorAdapter.java Sun Jul 12 08:52:45 2009
@@ -19,6 +19,7 @@
package org.apache.myfaces.extensions.validator.beanval.validation.message.interpolator;
import org.apache.myfaces.extensions.validator.core.validation.message.resolver.MessageResolver;
+import org.apache.myfaces.extensions.validator.core.validation.message.resolver.AbstractValidationErrorMessageResolver;
import javax.validation.MessageInterpolator;
import java.util.Locale;
@@ -50,8 +51,14 @@
{
if(messageOrKey.startsWith("{") && messageOrKey.endsWith("}"))
{
- messageOrKey = this.messageResolver
+ String newMessageOrKey = this.messageResolver
.getMessage(messageOrKey.substring(1, messageOrKey.length() - 1), getCurrentLocale());
+
+ if(!(newMessageOrKey.startsWith(AbstractValidationErrorMessageResolver.MISSING_RESOURCE_MARKER) &&
+ newMessageOrKey.endsWith(AbstractValidationErrorMessageResolver.MISSING_RESOURCE_MARKER)))
+ {
+ messageOrKey = newMessageOrKey;
+ }
}
else
{