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/11/02 23:44:37 UTC
svn commit: r832168 - in /myfaces/extensions/validator/trunk:
core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/
validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/
validation...
Author: gpetracek
Date: Mon Nov 2 22:44:37 2009
New Revision: 832168
URL: http://svn.apache.org/viewvc?rev=832168&view=rev
Log:
small refactorings
Modified:
myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java
myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/AbstractCompareStrategy.java
myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java
myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/RequiredIfStrategy.java
Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java?rev=832168&r1=832167&r2=832168&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java (original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java Mon Nov 2 22:44:37 2009
@@ -52,13 +52,18 @@
ValidatorException validatorException,
ValidationStrategy validatorExceptionSource)
{
- if(metaDataEntry.getValue() instanceof Annotation)
+ if(isExtValMetaData(metaDataEntry))
{
tryToPlaceSeverity(validatorException, metaDataEntry.getValue(Annotation.class));
}
return true;
}
+ private boolean isExtValMetaData(MetaDataEntry metaDataEntry)
+ {
+ return metaDataEntry.getValue() instanceof Annotation;
+ }
+
private void tryToPlaceSeverity(ValidatorException validatorException, Annotation annotation)
{
for(FacesMessage.Severity severity : ExtValUtils.getValidationParameterExtractor()
Modified: myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java?rev=832168&r1=832167&r2=832168&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java Mon Nov 2 22:44:37 2009
@@ -409,8 +409,7 @@
if (elHelper.isELTermWellFormed(condition) &&
elHelper.isELTermValid(FacesContext.getCurrentInstance(), condition))
{
- if (Boolean.TRUE.equals(
- elHelper.getValueOfExpression(
+ if (Boolean.TRUE.equals(elHelper.getValueOfExpression(
FacesContext.getCurrentInstance(), new ValueBindingExpression(condition))))
{
return true;
Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/AbstractCompareStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/AbstractCompareStrategy.java?rev=832168&r1=832167&r2=832168&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/AbstractCompareStrategy.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/AbstractCompareStrategy.java Mon Nov 2 22:44:37 2009
@@ -18,15 +18,14 @@
*/
package org.apache.myfaces.extensions.validator.crossval.strategy;
-import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.MissingResourceException;
+import java.lang.annotation.Annotation;
import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;
import org.apache.myfaces.extensions.validator.crossval.storage.CrossValidationStorage;
@@ -42,8 +41,9 @@
* @author Gerhard Petracek
* @since 1.x.1
*/
+@SuppressWarnings({"unchecked"})
@UsageInformation(UsageCategory.INTERNAL)
-public abstract class AbstractCompareStrategy extends AbstractCrossValidationStrategy
+public abstract class AbstractCompareStrategy<A extends Annotation> extends AbstractCrossValidationStrategy
{
protected static List<ReferencingStrategy> referencingStrategies;
protected Map<Object, Object> violationResultStorage = new HashMap<Object, Object>();
@@ -84,8 +84,8 @@
{
//initCrossValidation is done in the CrossValidationPhaseListener
- String[] validationTargets = getValidationTargets(
- crossValidationStorageEntry.getMetaDataEntry().getValue(Annotation.class));
+ String[] validationTargets = getValidationTargets((A)
+ crossValidationStorageEntry.getMetaDataEntry().getValue());
for (String validationTarget : validationTargets)
{
@@ -130,11 +130,9 @@
return;
}
- FacesContext facesContext = FacesContext.getCurrentInstance();
-
//get validation error messages for the target component
- String summary = getErrorMessageSummary(entryOfSource.getMetaDataEntry().getValue(Annotation.class), true);
- String details = getErrorMessageDetail(entryOfSource.getMetaDataEntry().getValue(Annotation.class), true);
+ String summary = getErrorMessageSummary((A)entryOfSource.getMetaDataEntry().getValue(), true);
+ String details = getErrorMessageDetail((A)entryOfSource.getMetaDataEntry().getValue(), true);
//validation target isn't bound to a component withing the current page
//(see validateFoundEntry, tryToValidateLocally and tryToValidateBindingOnly)
@@ -146,15 +144,13 @@
FacesMessage message;
if (entryOfTarget.getMetaDataEntry() != null)
{
- message = getTargetComponentErrorMessage(
- entryOfTarget.getMetaDataEntry().getValue(Annotation.class), summary, details);
+ message = getTargetComponentErrorMessage((A)entryOfTarget.getMetaDataEntry().getValue(), summary, details);
}
else
{
//TODO document possible side effects
//due to a missing target annotation (see: tryToValidateLocally)
- message = getTargetComponentErrorMessage(
- entryOfSource.getMetaDataEntry().getValue(Annotation.class), summary, details);
+ message = getTargetComponentErrorMessage((A)entryOfSource.getMetaDataEntry().getValue(), summary, details);
}
if ((message.getSummary() != null || message.getDetail() != null) &&
@@ -175,11 +171,11 @@
private void processTargetComponentAsSourceComponentAfterViolation(CrossValidationStorageEntry entryOfSource)
{
//get validation error messages for the current component
- String summary = getReverseErrorMessageSummary(entryOfSource.getMetaDataEntry().getValue(Annotation.class));
- String details = getReverseErrorMessageDetail(entryOfSource.getMetaDataEntry().getValue(Annotation.class));
+ String summary = getReverseErrorMessageSummary((A)entryOfSource.getMetaDataEntry().getValue());
+ String details = getReverseErrorMessageDetail((A)entryOfSource.getMetaDataEntry().getValue());
FacesMessage message = getSourceComponentErrorMessage(
- entryOfSource.getMetaDataEntry().getValue(Annotation.class), summary, details);
+ (A)entryOfSource.getMetaDataEntry().getValue(), summary, details);
if (message.getSummary() != null || message.getDetail() != null)
{
@@ -197,11 +193,11 @@
if (handleSourceViolation(entryOfSource))
{
//get validation error messages for the current component
- String summary = getErrorMessageSummary(entryOfSource.getMetaDataEntry().getValue(Annotation.class), false);
- String details = getErrorMessageDetail(entryOfSource.getMetaDataEntry().getValue(Annotation.class), false);
+ String summary = getErrorMessageSummary((A)entryOfSource.getMetaDataEntry().getValue(), false);
+ String details = getErrorMessageDetail((A)entryOfSource.getMetaDataEntry().getValue(), false);
FacesMessage message = getSourceComponentErrorMessage(
- entryOfSource.getMetaDataEntry().getValue(Annotation.class), summary, details);
+ (A)entryOfSource.getMetaDataEntry().getValue(), summary, details);
if (message.getSummary() != null || message.getDetail() != null)
{
@@ -215,22 +211,22 @@
entryOfSource.getComponent(), new FacesMessage(FacesMessage.SEVERITY_ERROR, null, null), null);
}
- protected FacesMessage getSourceComponentErrorMessage(Annotation annotation, String summary, String detail)
+ protected FacesMessage getSourceComponentErrorMessage(A annotation, String summary, String detail)
{
return ExtValUtils.createFacesMessage(summary, detail);
}
- protected FacesMessage getTargetComponentErrorMessage(Annotation foundAnnotation, String summary, String detail)
+ protected FacesMessage getTargetComponentErrorMessage(A foundAnnotation, String summary, String detail)
{
return ExtValUtils.createFacesMessage(summary, detail);
}
- protected String getErrorMessageSummary(Annotation annotation, boolean isTargetComponent)
+ protected String getErrorMessageSummary(A annotation, boolean isTargetComponent)
{
return resolveMessage(getValidationErrorMsgKey(annotation, isTargetComponent));
}
- protected String getErrorMessageDetail(Annotation annotation, boolean isTargetComponent)
+ protected String getErrorMessageDetail(A annotation, boolean isTargetComponent)
{
try
{
@@ -248,9 +244,9 @@
return null;
}
- protected String getValidationErrorMsgKey(Annotation annotation)
+ protected final String getValidationErrorMsgKey(Annotation annotation)
{
- return getValidationErrorMsgKey(annotation, false);
+ return getValidationErrorMsgKey((A)annotation, false);
}
protected boolean handleTargetViolation(
@@ -273,7 +269,7 @@
/*
* no target component (validation against the model) -> get reverse message for source component
*/
- protected String getReverseErrorMessageSummary(Annotation annotation)
+ protected String getReverseErrorMessageSummary(A annotation)
{
//if the message is neutral
return getErrorMessageSummary(annotation, true);
@@ -282,7 +278,7 @@
/*
* no target component (validation against the model) -> get reverse message for source component
*/
- protected String getReverseErrorMessageDetail(Annotation annotation)
+ protected String getReverseErrorMessageDetail(A annotation)
{
//if the message is neutral
return getErrorMessageDetail(annotation, true);
@@ -292,18 +288,18 @@
* abstract methods
*/
- protected abstract String getValidationErrorMsgKey(Annotation annotation, boolean isTargetComponent);
+ protected abstract String getValidationErrorMsgKey(A annotation, boolean isTargetComponent);
/*
* implements the specific validation logic
*/
- public abstract boolean isViolation(Object object1, Object object2, Annotation annotation);
+ public abstract boolean isViolation(Object object1, Object object2, A annotation);
/*
* returns the referenced validation targets of the annotation
* e.g. @DateIs(type = DateIsType.before, value = "finalExam")
* -> method returns an array with one value ("finalExam")
*/
- public abstract String[] getValidationTargets(Annotation annotation);
+ public abstract String[] getValidationTargets(A annotation);
}
Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java?rev=832168&r1=832167&r2=832168&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/DateIsStrategy.java Mon Nov 2 22:44:37 2009
@@ -26,7 +26,6 @@
import org.apache.myfaces.extensions.validator.internal.UsageCategory;
import javax.faces.context.FacesContext;
-import java.lang.annotation.Annotation;
import java.text.DateFormat;
import java.util.Date;
import java.util.MissingResourceException;
@@ -37,7 +36,7 @@
*/
@SkipValidationSupport
@UsageInformation(UsageCategory.INTERNAL)
-public class DateIsStrategy extends AbstractCompareStrategy
+public class DateIsStrategy extends AbstractCompareStrategy<DateIs>
{
protected static final String TOO_EARLY = "early";
protected static final String TOO_LATE = "late";
@@ -60,11 +59,11 @@
return false;
}
- public boolean isViolation(Object object1, Object object2, Annotation annotation)
+ public boolean isViolation(Object object1, Object object2, DateIs annotation)
{
boolean violationFound;
- if (((DateIs) annotation).type().equals(DateIsType.same))
+ if (annotation.type().equals(DateIsType.same))
{
violationFound = object1 != null && !object1.equals(object2);
@@ -73,7 +72,7 @@
this.violationResultStorage.put(RESULT_KEY, NOT_EQUAL_DATE_TIME);
}
}
- else if (((DateIs) annotation).type().equals(DateIsType.before))
+ else if (annotation.type().equals(DateIsType.before))
{
violationFound = object1 != null && object2 != null &&
(!new Date(((Date) object1).getTime()).before((Date) object2) || object1.equals(object2));
@@ -103,15 +102,15 @@
return violationFound;
}
- public String[] getValidationTargets(Annotation annotation)
+ public String[] getValidationTargets(DateIs annotation)
{
- return ((DateIs) annotation).valueOf();
+ return annotation.valueOf();
}
/*
* protected
*/
- protected String getValidationErrorMsgKey(Annotation annotation, boolean isTargetComponent)
+ protected String getValidationErrorMsgKey(DateIs annotation, boolean isTargetComponent)
{
String result = (String) this.violationResultStorage.get(RESULT_KEY);
@@ -122,15 +121,15 @@
if (TOO_EARLY.equals(result))
{
- return getNotAfterErrorMsgKey((DateIs) annotation);
+ return getNotAfterErrorMsgKey(annotation);
}
else if (TOO_LATE.equals(result))
{
- return getNotBeforeErrorMsgKey((DateIs) annotation);
+ return getNotBeforeErrorMsgKey(annotation);
}
else
{
- return getNotEqualErrorMsgKey((DateIs) annotation);
+ return getNotEqualErrorMsgKey(annotation);
}
}
@@ -147,7 +146,7 @@
}
@Override
- protected String getErrorMessageSummary(Annotation annotation, boolean isTargetComponent)
+ protected String getErrorMessageSummary(DateIs annotation, boolean isTargetComponent)
{
if (!isTargetComponent)
{
@@ -158,7 +157,7 @@
}
@Override
- protected String getErrorMessageDetail(Annotation annotation, boolean isTargetComponent)
+ protected String getErrorMessageDetail(DateIs annotation, boolean isTargetComponent)
{
if (!isTargetComponent)
{
@@ -182,13 +181,13 @@
}
@Override
- protected String getReverseErrorMessageSummary(Annotation annotation)
+ protected String getReverseErrorMessageSummary(DateIs annotation)
{
return getErrorMessage(getValidationErrorMsgKey(annotation, false), annotation, false);
}
@Override
- protected String getReverseErrorMessageDetail(Annotation annotation)
+ protected String getReverseErrorMessageDetail(DateIs annotation)
{
try
{
@@ -206,11 +205,11 @@
return null;
}
- protected String getErrorMessage(String key, Annotation annotation, boolean isTargetComponent)
+ protected String getErrorMessage(String key, DateIs annotation, boolean isTargetComponent)
{
String message = resolveMessage(key);
- DateFormat dateFormat = DateFormat.getDateInstance(((DateIs) annotation).errorMessageDateStyle(),
+ DateFormat dateFormat = DateFormat.getDateInstance(annotation.errorMessageDateStyle(),
FacesContext.getCurrentInstance().getViewRoot().getLocale());
String result;
Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/RequiredIfStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/RequiredIfStrategy.java?rev=832168&r1=832167&r2=832168&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/RequiredIfStrategy.java (original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/RequiredIfStrategy.java Mon Nov 2 22:44:37 2009
@@ -28,7 +28,6 @@
import org.apache.myfaces.extensions.validator.util.ExtValUtils;
import javax.faces.validator.ValidatorException;
-import java.lang.annotation.Annotation;
/**
* @author Gerhard Petracek
@@ -36,7 +35,7 @@
*/
@SkipValidationSupport
@UsageInformation(UsageCategory.INTERNAL)
-public class RequiredIfStrategy extends AbstractCompareStrategy
+public class RequiredIfStrategy extends AbstractCompareStrategy<RequiredIf>
{
private boolean useFacesBundle = false;
@@ -60,20 +59,20 @@
return result;
}
- protected String getValidationErrorMsgKey(Annotation annotation, boolean isTargetComponent)
+ protected String getValidationErrorMsgKey(RequiredIf annotation, boolean isTargetComponent)
{
- return ((RequiredIf) annotation).validationErrorMsgKey();
+ return annotation.validationErrorMsgKey();
}
- public boolean isViolation(Object object1, Object object2, Annotation annotation)
+ public boolean isViolation(Object object1, Object object2, RequiredIf annotation)
{
boolean violationFound = false;
- if (((RequiredIf) annotation).is().equals(RequiredIfType.empty))
+ if (annotation.is().equals(RequiredIfType.empty))
{
violationFound = (object2 == null || object2.equals("")) && (object1 == null || object1.equals(""));
}
- else if (((RequiredIf) annotation).is().equals(RequiredIfType.not_empty))
+ else if (annotation.is().equals(RequiredIfType.not_empty))
{
violationFound = (object2 != null && !object2.equals("")) && (object1 == null || object1.equals(""));
}
@@ -81,9 +80,9 @@
return violationFound;
}
- public String[] getValidationTargets(Annotation annotation)
+ public String[] getValidationTargets(RequiredIf annotation)
{
- return ((RequiredIf) annotation).valueOf();
+ return annotation.valueOf();
}
@Override
@@ -97,4 +96,4 @@
return super.processAfterCrossValidatorException(crossValidationStorageEntry, validatorException);
}
-}
\ No newline at end of file
+}