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.api.config.domain; 17 18 import javax.annotation.CheckForNull; 19 20 import de.smartics.properties.api.config.domain.key.ConfigurationKey; 21 import de.smartics.properties.api.core.domain.PropertyDescriptor; 22 import de.smartics.util.lang.Arg; 23 24 /** 25 * Extends the {@link Property} with metadata concerning the property and the 26 * configuration. 27 */ 28 public class DescribedProperty extends Property 29 { 30 // ********************************* Fields ********************************* 31 32 // --- constants ------------------------------------------------------------ 33 34 /** 35 * The class version identifier. 36 * <p> 37 * The value of this constant is {@value}. 38 */ 39 private static final long serialVersionUID = 1L; 40 41 // --- members -------------------------------------------------------------- 42 43 /** 44 * The identifier of the configuration this property is part of. The value is 45 * set to <code>null</code>, if the property has not been found in a 46 * configuration. With other words, the property has a default or no value. 47 * 48 * @serial 49 */ 50 private final ConfigurationKey<?> configurationKey; 51 52 /** 53 * The descriptor to the property to access property metadata. 54 * 55 * @serial 56 */ 57 private final PropertyDescriptor descriptor; 58 59 // ****************************** Initializer ******************************* 60 61 // ****************************** Constructors ****************************** 62 63 /** 64 * Default constructor. 65 * 66 * @param configurationKey the identifier of the configuration this property 67 * is part of. 68 * @param descriptor the descriptor to the property to access property 69 * metadata. 70 * @param property the referenced property to copy. 71 * @throws NullPointerException if {@code descriptor} or {@code property} is 72 * <code>null</code>. 73 */ 74 public DescribedProperty(final ConfigurationKey<?> configurationKey, 75 final PropertyDescriptor descriptor, final Property property) 76 throws NullPointerException 77 { 78 super(property); 79 80 this.configurationKey = 81 Arg.checkNotNull("configurationKey", configurationKey); 82 this.descriptor = descriptor; 83 } 84 85 /** 86 * Copy-constructor. 87 * 88 * @param property the property to copy. 89 * @throws NullPointerException if {@code property} is <code>null</code>. 90 */ 91 public DescribedProperty(final DescribedProperty property) 92 throws NullPointerException 93 { 94 this(property.getConfigurationKey(), property.getDescriptor(), property); 95 } 96 97 // ****************************** Inner Classes ***************************** 98 99 // ********************************* Methods ******************************** 100 101 // --- init ----------------------------------------------------------------- 102 103 // --- get&set -------------------------------------------------------------- 104 105 /** 106 * Returns the identifier of the configuration this property is part of. The 107 * value is set to <code>null</code>, if the property has not been found in a 108 * configuration. With other words, the property has a default or no value. 109 * 110 * @return the identifier of the configuration this property is part of. 111 */ 112 @CheckForNull 113 public final ConfigurationKey<?> getConfigurationKey() 114 { 115 return configurationKey; 116 } 117 118 /** 119 * Returns the descriptor to the property to access property metadata. 120 * 121 * @return the descriptor to the property to access property metadata. 122 */ 123 public final PropertyDescriptor getDescriptor() 124 { 125 return descriptor; 126 } 127 128 // --- business ------------------------------------------------------------- 129 130 // --- object basics -------------------------------------------------------- 131 132 /** 133 * Returns the string representation of the object. 134 * 135 * @return the string representation of the object. 136 */ 137 @Override 138 public String toString() 139 { 140 final StringBuilder buffer = new StringBuilder(); 141 142 if (configurationKey != null) 143 { 144 buffer.append(configurationKey); 145 } 146 else 147 { 148 buffer.append("Default value."); 149 } 150 buffer.append(' ').append(super.toString()); 151 buffer.append(' ').append(descriptor); 152 153 return buffer.toString(); 154 } 155 }