1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/net/fortuna/ical4j/model/component/CalendarComponent.java Tue Feb 10 18:12:00 2015 +0100 1.3 @@ -0,0 +1,177 @@ 1.4 +/** 1.5 + * Copyright (c) 2012, Ben Fortuna 1.6 + * All rights reserved. 1.7 + * 1.8 + * Redistribution and use in source and binary forms, with or without 1.9 + * modification, are permitted provided that the following conditions 1.10 + * are met: 1.11 + * 1.12 + * o Redistributions of source code must retain the above copyright 1.13 + * notice, this list of conditions and the following disclaimer. 1.14 + * 1.15 + * o Redistributions in binary form must reproduce the above copyright 1.16 + * notice, this list of conditions and the following disclaimer in the 1.17 + * documentation and/or other materials provided with the distribution. 1.18 + * 1.19 + * o Neither the name of Ben Fortuna nor the names of any other contributors 1.20 + * may be used to endorse or promote products derived from this software 1.21 + * without specific prior written permission. 1.22 + * 1.23 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.24 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.25 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.26 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 1.27 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.28 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.29 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.30 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1.31 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 1.32 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 1.33 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.34 + */ 1.35 +package net.fortuna.ical4j.model.component; 1.36 + 1.37 +import net.fortuna.ical4j.model.Component; 1.38 +import net.fortuna.ical4j.model.PropertyList; 1.39 +import net.fortuna.ical4j.model.ValidationException; 1.40 +import net.fortuna.ical4j.model.Validator; 1.41 +import net.fortuna.ical4j.model.property.Method; 1.42 + 1.43 +/** 1.44 + * $Id$ 1.45 + * 1.46 + * Created on 26/02/2006 1.47 + * 1.48 + * Base class for components that may be added to a calendar. 1.49 + * @author Ben Fortuna 1.50 + */ 1.51 +public abstract class CalendarComponent extends Component { 1.52 + 1.53 + /** 1.54 + * 1.55 + */ 1.56 + private static final long serialVersionUID = -5832972592377720592L; 1.57 + 1.58 + /** 1.59 + * Validator instance that does nothing. 1.60 + */ 1.61 + protected static final Validator EMPTY_VALIDATOR = new EmptyValidator(); 1.62 + 1.63 + /** 1.64 + * @param name component name 1.65 + */ 1.66 + public CalendarComponent(final String name) { 1.67 + super(name); 1.68 + } 1.69 + 1.70 + /** 1.71 + * @param name component name 1.72 + * @param properties component properties 1.73 + */ 1.74 + public CalendarComponent(final String name, final PropertyList properties) { 1.75 + super(name, properties); 1.76 + } 1.77 + 1.78 + /** 1.79 + * Performs method-specific ITIP validation. 1.80 + * @param method the applicable method 1.81 + * @throws ValidationException where the component does not comply with RFC2446 1.82 + */ 1.83 + public final void validate(Method method) throws ValidationException { 1.84 + final Validator validator = getValidator(method); 1.85 + if (validator != null) { 1.86 + validator.validate(); 1.87 + } 1.88 + else { 1.89 + throw new ValidationException("Unsupported method: " + method); 1.90 + } 1.91 + } 1.92 + 1.93 + /** 1.94 + * @param method a method to validate on 1.95 + * @return a validator for the specified method or null if the method is not supported 1.96 + */ 1.97 + protected abstract Validator getValidator(Method method); 1.98 + 1.99 + /** 1.100 + * Apply validation for METHOD=PUBLISH. 1.101 + * @throws ValidationException where the component does not comply with RFC2446 1.102 + * @deprecated 1.103 + */ 1.104 + public final void validatePublish() throws ValidationException { 1.105 + validate(Method.PUBLISH); 1.106 + } 1.107 + 1.108 + /** 1.109 + * Apply validation for METHOD=REQUEST. 1.110 + * @throws ValidationException where the component does not comply with RFC2446 1.111 + * @deprecated 1.112 + */ 1.113 + public final void validateRequest() throws ValidationException { 1.114 + validate(Method.REQUEST); 1.115 + } 1.116 + 1.117 + /** 1.118 + * Apply validation for METHOD=REPLY. 1.119 + * @throws ValidationException where the component does not comply with RFC2446 1.120 + * @deprecated 1.121 + */ 1.122 + public final void validateReply() throws ValidationException { 1.123 + validate(Method.REPLY); 1.124 + } 1.125 + 1.126 + /** 1.127 + * Apply validation for METHOD=ADD. 1.128 + * @throws ValidationException where the component does not comply with RFC2446 1.129 + * @deprecated 1.130 + */ 1.131 + public final void validateAdd() throws ValidationException { 1.132 + validate(Method.ADD); 1.133 + } 1.134 + 1.135 + /** 1.136 + * Apply validation for METHOD=CANCEL. 1.137 + * @throws ValidationException where the component does not comply with RFC2446 1.138 + * @deprecated 1.139 + */ 1.140 + public final void validateCancel() throws ValidationException { 1.141 + validate(Method.CANCEL); 1.142 + } 1.143 + 1.144 + /** 1.145 + * Apply validation for METHOD=REFRESH. 1.146 + * @throws ValidationException where the component does not comply with RFC2446 1.147 + * @deprecated 1.148 + */ 1.149 + public final void validateRefresh() throws ValidationException { 1.150 + validate(Method.REFRESH); 1.151 + } 1.152 + 1.153 + /** 1.154 + * Apply validation for METHOD=COUNTER. 1.155 + * @throws ValidationException where the component does not comply with RFC2446 1.156 + * @deprecated 1.157 + */ 1.158 + public final void validateCounter() throws ValidationException { 1.159 + validate(Method.COUNTER); 1.160 + } 1.161 + 1.162 + /** 1.163 + * Apply validation for METHOD=DECLINE-COUNTER. 1.164 + * @throws ValidationException where the component does not comply with RFC2446 1.165 + * @deprecated 1.166 + */ 1.167 + public final void validateDeclineCounter() throws ValidationException { 1.168 + validate(Method.DECLINE_COUNTER); 1.169 + } 1.170 + 1.171 + private static class EmptyValidator implements Validator { 1.172 + 1.173 + private static final long serialVersionUID = 1L; 1.174 + 1.175 + public void validate() throws ValidationException { 1.176 + // TODO Auto-generated method stub 1.177 + 1.178 + } 1.179 + } 1.180 +}