1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package net.fortuna.ical4j.model;
35
36 import java.util.Iterator;
37
38 /***
39 * Defines an iCalendar component. Subclasses of this class provide additional
40 * validation and typed values for specific iCalendar components.
41 *
42 * @author benf
43 */
44 public abstract class Component {
45
46 public static final String BEGIN = "BEGIN";
47
48 public static final String END = "END";
49
50 public static final String VEVENT = "VEVENT";
51
52 public static final String VTODO = "VTODO";
53
54 public static final String VJOURNAL = "VJOURNAL";
55
56 public static final String VFREEBUSY = "VFREEBUSY";
57
58 public static final String VTIMEZONE = "VTIMEZONE";
59
60 public static final String VALARM = "VALARM";
61
62 private String name;
63
64 private PropertyList properties;
65
66 /***
67 * Constructor made protected to enforce the use of
68 * <code>ComponentFactory</code> for component instantiation.
69 * @param s component name
70 * @param p a list of properties
71 */
72 protected Component(final String s, final PropertyList p) {
73
74 this.name = s;
75 this.properties = p;
76 }
77
78 /***
79 * @see java.lang.Object#toString()
80 */
81 public String toString() {
82
83 return BEGIN + ":" + name + "\r\n" + properties + END + ":" + name
84 + "\r\n";
85 }
86
87 /***
88 * @return Returns the name.
89 */
90 public final String getName() {
91 return name;
92 }
93
94 /***
95 * Indicates whether this component is a top-level
96 * calendar component.
97 * @return a boolean value
98 */
99 public final boolean isCalendarComponent() {
100 return VALARM.equals(getName())
101 || VEVENT.equals(getName())
102 || VFREEBUSY.equals(getName())
103 || VJOURNAL.equals(getName())
104 || VTIMEZONE.equals(getName())
105 || VTODO.equals(getName());
106 }
107
108 /***
109 * @return Returns the properties.
110 */
111 public final PropertyList getProperties() {
112 return properties;
113 }
114
115 /***
116 * Perform validation on a component and its properties.
117 * @throws ValidationException
118 * where the component is not in a valid state
119 */
120 public final void validate() throws ValidationException {
121 validate(true);
122 }
123
124 /***
125 * Perform validation on a component.
126 * @param recurse indicates whether to validate the component's
127 * properties
128 * @throws ValidationException
129 * where the component is not in a valid state
130 */
131 public abstract void validate(final boolean recurse) throws ValidationException;
132
133 /***
134 * Invoke validation on the component properties in its current state.
135 * @throws ValidationException
136 * where any of the component properties is not in a valid state
137 */
138 protected void validateProperties() throws ValidationException {
139 for (Iterator i = getProperties().iterator(); i.hasNext();) {
140 Property property = (Property) i.next();
141 property.validate();
142 }
143 }
144 }