1 /* 2 Copyright 2007-2014 Fraunhofer IGD, http://www.igd.fraunhofer.de 3 Fraunhofer-Gesellschaft - Institute for Computer Graphics Research 4 5 See the NOTICE file distributed with this work for additional 6 information regarding copyright ownership 7 8 Licensed under the Apache License, Version 2.0 (the "License"); 9 you may not use this file except in compliance with the License. 10 You may obtain a copy of the License at 11 12 http://www.apache.org/licenses/LICENSE-2.0 13 14 Unless required by applicable law or agreed to in writing, software 15 distributed under the License is distributed on an "AS IS" BASIS, 16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 See the License for the specific language governing permissions and 18 limitations under the License. 19 */ 20 package org.universAAL.middleware.ui.rdf; 21 22 import org.universAAL.middleware.rdf.PropertyPath; 23 import org.universAAL.middleware.rdf.TypeMapper; 24 25 /** 26 * The default {@link Output} control containing info in form of plain text or 27 * another simple type supported by 28 * {@link org.universAAL.middleware.rdf.TypeMapper}. 29 * 30 * @author mtazari 31 * @author Carsten Stockloew 32 */ 33 public class SimpleOutput extends Output { 34 public static final String MY_URI = Form.uAAL_DIALOG_NAMESPACE 35 + "SimpleOutput"; 36 37 /** 38 * For local storage of the contained info if this info is not accessible 39 * from the form data. 40 */ 41 public static final String PROP_CONTENT = Form.uAAL_DIALOG_NAMESPACE 42 + "theContent"; 43 44 /** 45 * For exclusive use by de-serializers. 46 */ 47 public SimpleOutput() { 48 super(); 49 } 50 51 /** 52 * For exclusive use by applications. 53 * 54 * @param parent 55 * The mandatory parent group as the direct container of this 56 * input field. See {@link FormControl#PROP_PARENT_CONTROL}. 57 * @param label 58 * The optional {@link Label} to be associated with this input 59 * field. See {@link FormControl#PROP_CONTROL_LABEL}. 60 * @param ref 61 * See {@link FormControl#PROP_REFERENCED_PPATH}; optional. 62 * @param content 63 * The contained info. If the previous parameter ( 64 * <code>ref</code>) is not null, it will be stored as part of 65 * the form data, otherwise locally using {@link #PROP_CONTENT}. 66 */ 67 public SimpleOutput(Group parent, Label label, PropertyPath ref, 68 Object content) { 69 super(MY_URI, parent, label, ref, (ref == null) ? null : content); 70 boolean hasValue = hasValue(); 71 if (!isRepeatable() && content == null && !hasValue) 72 throw new IllegalArgumentException("Null content not allowed!"); 73 Object value = hasValue ? super.getValue() : null; 74 if (TypeMapper.getDatatypeURI(content) == null) { 75 if (content != null 76 || (value != null && TypeMapper.getDatatypeURI(value) == null)) 77 throw new IllegalArgumentException("Given content not allowed!"); 78 } else if (!content.equals(value)) 79 props.put(PROP_CONTENT, content); 80 } 81 82 /** 83 * Returns the contained info as an instance of one of the classes supported 84 * by {@link org.universAAL.middleware.rdf.TypeMapper}. 85 */ 86 public Object getContent() { 87 Object res = props.get(PROP_CONTENT); 88 return (res == null) ? super.getValue() : res; 89 } 90 91 /** 92 * Overrides {@link FormControl#getValue()} in order to additionally 93 * consider the local storage using {@link #PROP_CONTENT}. 94 */ 95 public Object getValue() { 96 return getContent(); 97 } 98 99 /** 100 * For usage by de-serializers. 101 */ 102 public boolean setProperty(String propURI, Object value) { 103 if (PROP_CONTENT.equals(propURI)) { 104 if (!props.containsKey(propURI) && value != null) { 105 props.put(propURI, value); 106 return true; 107 } 108 } else 109 return super.setProperty(propURI, value); 110 return false; 111 } 112 }