1 /* 2 * Copyright 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.admin.domain.model; 17 18 import de.smartics.properties.api.config.domain.DescribedProperty; 19 import de.smartics.properties.api.config.domain.ValidatedProperty; 20 import de.smartics.properties.api.core.domain.PropertyDescriptor; 21 22 /** 23 * A property with its descriptor. 24 */ 25 public final class ConfigurationProperty 26 { 27 // ******************************** Fields ******************************** 28 29 // --- constants ---------------------------------------------------------- 30 31 // --- members ------------------------------------------------------------ 32 33 /** 34 * The unique identifier of the configuration. 35 */ 36 private final String configurationKey; 37 38 /** 39 * The unique identifier of the property within the configuration. 40 */ 41 private final String propertyKey; 42 43 /** 44 * The descriptor to the property. 45 */ 46 private final PropertyDescriptor descriptor; 47 48 /** 49 * The access to the property value. 50 */ 51 private final DescribedProperty property; 52 53 // ***************************** Initializer ****************************** 54 55 // ***************************** Constructors ***************************** 56 57 /** 58 * Default constructor. 59 * 60 * @param configurationKey the unique identifier of the configuration. 61 * @param propertyKey the unique identifier of the property within the 62 * configuration. 63 * @param descriptor the descriptor to the property. 64 * @param property the access to the property value. 65 */ 66 public ConfigurationProperty(final String configurationKey, 67 final String propertyKey, final PropertyDescriptor descriptor, 68 final DescribedProperty property) 69 { 70 this.configurationKey = configurationKey; 71 this.propertyKey = propertyKey; 72 this.descriptor = descriptor; 73 this.property = property; 74 } 75 76 // ***************************** Inner Classes **************************** 77 78 // ******************************** Methods ******************************* 79 80 // --- init --------------------------------------------------------------- 81 82 // --- get&set ------------------------------------------------------------ 83 84 /** 85 * Returns the unique identifier of the configuration. 86 * 87 * @return the unique identifier of the configuration. 88 */ 89 public String getConfigurationKey() 90 { 91 return configurationKey; 92 } 93 94 /** 95 * Returns the unique identifier of the property within the configuration. 96 * 97 * @return the unique identifier of the property within the configuration. 98 */ 99 public String getPropertyKey() 100 { 101 return propertyKey; 102 } 103 104 /** 105 * Returns the descriptor to the property. 106 * 107 * @return the descriptor to the property. 108 */ 109 public PropertyDescriptor getDescriptor() 110 { 111 return descriptor; 112 } 113 114 /** 115 * Returns the access to the property value. 116 * 117 * @return the access to the property value. 118 */ 119 public DescribedProperty getProperty() 120 { 121 return property; 122 } 123 124 /** 125 * Returns the value of the property. If the property cannot be converted or 126 * validated, the simple string property value is returned. 127 * 128 * @return the value of the property. 129 */ 130 public Object getPropertyValue() 131 { 132 if (property instanceof ValidatedProperty) 133 { 134 return ((ValidatedProperty) property).getValidatedValue(); 135 } 136 else 137 { 138 return property.getValue(); 139 } 140 } 141 142 // --- business ----------------------------------------------------------- 143 144 // --- object basics ------------------------------------------------------ 145 }