1 /*
2 * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package de.smartics.properties.tutorial.property.list;
17
18 import java.util.List;
19
20 import javax.validation.constraints.Max;
21 import javax.validation.constraints.Min;
22 import javax.validation.constraints.NotNull;
23 import javax.validation.constraints.Size;
24
25 import de.smartics.properties.api.core.annotations.AccessType;
26 import de.smartics.properties.api.core.annotations.PropertyElementType;
27 import de.smartics.properties.api.core.annotations.PropertyLifecycle;
28 import de.smartics.properties.api.core.annotations.PropertyListElementConstraints;
29 import de.smartics.properties.api.core.annotations.PropertySet;
30 import de.smartics.properties.api.core.domain.PropertyKey;
31
32 /**
33 * This example shows how to add constraints to lists and list elements.
34 */
35 @PropertySet("tutorial.property.list")
36 public interface ListPropertiesWithConstraints
37 {
38 /**
39 * A simple list of Integers with two to four elements. The constraints added
40 * to the list are applied to the list as a whole.
41 * <p>
42 * The {@link PropertyElementType} annotation provides the type of the
43 * elements to the runtime.
44 * </p>
45 */
46 @PropertyElementType(Integer.class)
47 @NotNull
48 @Size(min = 2, max = 4)
49 @PropertyLifecycle(access = AccessType.READ_WRITE)
50 List<Integer> intList();
51
52 PropertyKey intListPropertyKey();
53
54 /**
55 * The annotation at the nested interface that extends the interface that
56 * declares the list property, signals: Here are constraints on the list
57 * elements.
58 * <p>
59 * Each element is between 2 and 5.
60 * </p>
61 */
62 @PropertyListElementConstraints
63 interface ElementConstraints extends ListPropertiesWithConstraints
64 {
65 @Min(2)
66 @Max(5)
67 @Override
68 List<Integer> intList();
69 }
70 }