Permalink
Browse files

Removed calendar property interface to allow overriding valid calenda…

…r properties
  • Loading branch information...
benfortuna committed Sep 13, 2015
1 parent 689896b commit 65d61f69c2b037255906cef7fb08c20acdf1518c
@@ -48,7 +48,7 @@
*
* @author benf
*/
-public class CalScale extends Property implements CalendarProperty {
+public class CalScale extends Property {
private static final long serialVersionUID = 7446184786984981423L;
@@ -1,8 +0,0 @@
-package net.fortuna.ical4j.model.property;
-
-/**
- * An interface used to tag a {@link net.fortuna.ical4j.model.Property} instance as applicable to a
- * {@link net.fortuna.ical4j.model.Calendar} object.
- */
-public interface CalendarProperty {
-}
@@ -47,7 +47,7 @@
*
* @author benf
*/
-public class Method extends Property implements CalendarProperty {
+public class Method extends Property {
private static final long serialVersionUID = 7220956532685378719L;
@@ -47,7 +47,7 @@
*
* @author benf
*/
-public class ProdId extends Property implements Escapable, CalendarProperty {
+public class ProdId extends Property implements Escapable {
private static final long serialVersionUID = -2433059917714523286L;
@@ -50,7 +50,7 @@
*
* @author Ben Fortuna
*/
-public class Version extends Property implements CalendarProperty {
+public class Version extends Property {
private static final long serialVersionUID = 8872508067309087704L;
@@ -4,16 +4,25 @@
import net.fortuna.ical4j.model.Component;
import net.fortuna.ical4j.model.Property;
import net.fortuna.ical4j.model.component.CalendarComponent;
-import net.fortuna.ical4j.model.property.CalendarProperty;
-import net.fortuna.ical4j.model.property.Method;
-import net.fortuna.ical4j.model.property.Version;
-import net.fortuna.ical4j.model.property.XProperty;
+import net.fortuna.ical4j.model.property.*;
import net.fortuna.ical4j.util.CompatibilityHints;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.Predicate;
+
+import java.util.Arrays;
+import java.util.List;
/**
* Created by fortuna on 13/09/15.
*/
public class CalendarValidatorImpl implements Validator<Calendar> {
+
+ protected final List<Class<? extends Property>> calendarProperties;
+
+ public CalendarValidatorImpl() {
+ calendarProperties = Arrays.asList(CalScale.class, Method.class, ProdId.class, Version.class);
+ }
+
@Override
public void validate(Calendar target) throws ValidationException {
// 'prodid' and 'version' are both REQUIRED,
@@ -43,10 +52,15 @@ public void validate(Calendar target) throws ValidationException {
// validate properties..
for (final Property property : target.getProperties()) {
- if (!(property instanceof XProperty)
- && !(property instanceof CalendarProperty)) {
- throw new ValidationException("Invalid property: "
- + property.getName());
+ boolean isCalendarProperty = CollectionUtils.find(calendarProperties, new Predicate<Class<? extends Property>>() {
+ @Override
+ public boolean evaluate(Class<? extends Property> object) {
+ return object.isInstance(property);
+ }
+ }) != null;
+
+ if (!(property instanceof XProperty) && !isCalendarProperty) {
+ throw new ValidationException("Invalid property: " + property.getName());
}
}

0 comments on commit 65d61f6

Please sign in to comment.