Permalink
Browse files

Refactored property validation to support validation extensions

  • Loading branch information...
benfortuna committed Sep 13, 2015
1 parent 0b196da commit 9754c11c1651b6cda154dad0709fdb7f08ba3cb8
@@ -34,7 +34,9 @@
import net.fortuna.ical4j.model.parameter.Value;
import net.fortuna.ical4j.model.property.XProperty;
import net.fortuna.ical4j.util.Strings;
+import net.fortuna.ical4j.validate.EmptyValidator;
import net.fortuna.ical4j.validate.ValidationException;
+import net.fortuna.ical4j.validate.Validator;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
@@ -352,9 +354,11 @@
*/
public static final String TEL = "TEL";
- private String name;
+ private final String name;
- private ParameterList parameters;
+ private final ParameterList parameters;
+
+ private final Validator<Property> validator;
private final PropertyFactoryImpl factory;
@@ -383,8 +387,13 @@ protected Property(final String aName, PropertyFactoryImpl factory) {
* @param factory the factory used to create the property instance
*/
protected Property(final String aName, final ParameterList aList, PropertyFactoryImpl factory) {
+ this(aName, aList, new EmptyValidator<Property>(), factory);
+ }
+
+ protected Property(final String aName, final ParameterList aList, Validator<Property> validator, PropertyFactoryImpl factory) {
this.name = aName;
this.parameters = aList;
+ this.validator = validator;
this.factory = factory;
}
@@ -485,7 +494,9 @@ public abstract void setValue(String aValue) throws IOException,
*
* @throws ValidationException where the property is not in a valid state
*/
- public abstract void validate() throws ValidationException;
+ public void validate() throws ValidationException {
+ validator.validate(this);
+ }
/**
* {@inheritDoc}
@@ -32,7 +32,6 @@
package net.fortuna.ical4j.model.property;
import net.fortuna.ical4j.model.*;
-import net.fortuna.ical4j.validate.ValidationException;
import java.io.IOException;
import java.net.URISyntaxException;
@@ -190,13 +189,6 @@ public void setMinVersion(final String minVersion) {
this.minVersion = minVersion;
}
- /**
- * {@inheritDoc}
- */
- public final void validate() throws ValidationException {
- // TODO: Auto-generated method stub
- }
-
public static class Factory extends Content.Factory implements PropertyFactory {
private static final long serialVersionUID = 1L;

0 comments on commit 9754c11

Please sign in to comment.