1 /*******************************************************************************
2 * Copyright 2013 Universidad Politécnica de Madrid
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
17 package org.universAAL.middleware.ui.rdf;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.universAAL.middleware.rdf.FinalizedResource;
23 import org.universAAL.middleware.ui.owl.Recommendation;
24
25 /**
26 * @author amedrano
27 *
28 */
29 public abstract class FormElement extends FinalizedResource {
30
31 /**
32 * FormElements may have Recommendations.
33 */
34 public static final String PROP_APPEARANCE = Form.uAAL_DIALOG_NAMESPACE
35 + "appearance";
36
37 /**
38 *
39 */
40 public FormElement() {
41 super();
42 }
43
44 /**
45 * @param isXMLLiteral
46 */
47 public FormElement(boolean isXMLLiteral) {
48 super(isXMLLiteral);
49 }
50
51 /**
52 * @param uri
53 * @param isXMLLiteral
54 */
55 public FormElement(String uri, boolean isXMLLiteral) {
56 super(uri, isXMLLiteral);
57 }
58
59 /**
60 * @param uriPrefix
61 * @param numProps
62 */
63 public FormElement(String uriPrefix, int numProps) {
64 super(uriPrefix, numProps);
65 }
66
67 /**
68 * @param uri
69 */
70 public FormElement(String uri) {
71 super(uri);
72 }
73
74 /**
75 * Convenience method to add an Appearance recommendation,
76 * see ont.recommendation for the definition of possible recommendations.
77 * It is not granted that the recommendation will be followed when rendered.
78 * @param recommendation the {@link Recommendation} instance to add.
79 */
80 public void addAppearanceRecommendation(Recommendation recommendation){
81 if (recommendation == null){
82 return;
83 }
84
85 List recommendations = (List) getProperty(PROP_APPEARANCE);
86 if (recommendations == null){
87 recommendations = new ArrayList();
88 }
89 recommendations.add(recommendation);
90 changeProperty(PROP_APPEARANCE, recommendations);
91 }
92
93 /**
94 * Intended to be used by handlers, to iterate over the recommendations added to the FormElement.
95 * @return the List of {@link Recommendation}s, that is empty if none are present.
96 */
97 public List getAppearanceRecommendations(){
98 List recommendations = (List) getProperty(PROP_APPEARANCE);
99 if (recommendations == null){
100 recommendations = new ArrayList();
101 }
102 return recommendations;
103 }
104 }