001/* 002 * jDTAUS Core API 003 * Copyright (C) 2005 Christian Schulte 004 * <cs@schulte.it> 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License, or any later version. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 019 * 020 */ 021package org.jdtaus.core.container; 022 023import java.io.Serializable; 024 025/** 026 * Property meta-data. 027 * <p>A property consists of the properties {@code name}, {@code type} and 028 * {@code value}. Property {@code name} holds the name uniquely identifying the 029 * property in a collection of properties. Property {@code type} holds the type 030 * of the property. Property {@code value} holds the properties value which is 031 * of type {@code type}. The {@code api} flag indicates if the property is part 032 * of a public API.</p> 033 * 034 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 035 * @version $JDTAUS: Property.java 8743 2012-10-07 03:06:20Z schulte $ 036 */ 037public class Property extends ModelObject implements Cloneable, Serializable 038{ 039 //--Constants--------------------------------------------------------------- 040 041 /** Serial version UID for backwards compatibility with 1.0.x classes. */ 042 private static final long serialVersionUID = -5450366074586725711L; 043 044 //---------------------------------------------------------------Constants-- 045 //--Property---------------------------------------------------------------- 046 047 /** 048 * The name of the property. 049 * @serial 050 */ 051 private String name; 052 053 /** 054 * The type of the property. 055 * @serial 056 */ 057 private Class type; 058 059 /** 060 * The value of the property. 061 * @serial 062 */ 063 private Object value; 064 065 /** 066 * Flag indicating that the property is part of a public API. 067 * @serial 068 */ 069 private boolean api; 070 071 /** Creates a new {@code Property} instance. */ 072 public Property() 073 { 074 super(); 075 } 076 077 /** 078 * Gets the name of the property. 079 * 080 * @return the name of the property. 081 */ 082 public String getName() 083 { 084 if ( this.name == null ) 085 { 086 this.name = ""; 087 } 088 089 return this.name; 090 } 091 092 /** 093 * Setter for property {@code name}. 094 * 095 * @param value the new name of the property. 096 */ 097 public void setName( final String value ) 098 { 099 this.name = value; 100 } 101 102 /** 103 * Gets the type of the property. 104 * 105 * @return the type of the property. 106 */ 107 public Class getType() 108 { 109 if ( this.type == null ) 110 { 111 this.type = String.class; 112 } 113 114 return this.type; 115 } 116 117 /** 118 * Setter for property {@code type}. 119 * 120 * @param value the new type of the property. 121 */ 122 public void setType( final Class value ) 123 { 124 this.type = value; 125 } 126 127 /** 128 * Gets the value of the property. 129 * 130 * @return the value of the property or {@code null}. 131 */ 132 public Object getValue() 133 { 134 return this.value; 135 } 136 137 /** 138 * Setter for property {@code value}. 139 * 140 * @param value the new value of the property. 141 */ 142 public void setValue( final Object value ) 143 { 144 this.value = value; 145 } 146 147 /** 148 * Gets the flag indicating if the property is part of a public API. 149 * 150 * @return {@code true} if the property is part of a public API. 151 */ 152 public boolean isApi() 153 { 154 return this.api; 155 } 156 157 /** 158 * Setter for property {@code api}. 159 * 160 * @param value {@code true} if the property is part of a public API. 161 */ 162 public void setApi( final boolean value ) 163 { 164 this.api = value; 165 } 166 167 /** 168 * Creates a string representing the properties of the instance. 169 * 170 * @return a string representing the properties of the instance. 171 */ 172 private String internalString() 173 { 174 return new StringBuffer( 500 ).append( '{' ). 175 append( super.internalString( this ) ). 176 append( ", api=" ).append( this.api ). 177 append( ", name=" ).append( this.name ). 178 append( ", type=" ).append( this.type ). 179 append( ", value=" ).append( this.value ). 180 append( '}' ).toString(); 181 182 } 183 184 //----------------------------------------------------------------Property-- 185 //--Object------------------------------------------------------------------ 186 187 /** 188 * Returns a string representation of the object. 189 * 190 * @return a string representation of the object. 191 */ 192 public String toString() 193 { 194 return super.toString() + this.internalString(); 195 } 196 197 /** 198 * Indicates whether some other object is equal to this one by comparing 199 * the values of all properties. 200 * 201 * @param o the reference object with which to compare. 202 * 203 * @return {@code true} if this object is the same as {@code o}; 204 * {@code false} otherwise. 205 */ 206 public boolean equals( final Object o ) 207 { 208 boolean equal = this == o; 209 210 if ( !equal && o instanceof Property ) 211 { 212 final Property that = (Property) o; 213 equal = this.getName().equals( that.getName() ) && 214 this.getType().equals( that.getType() ) && 215 ( this.getValue() == null 216 ? that.getValue() == null 217 : this.getValue().equals( that.getValue() ) ); 218 219 } 220 221 return equal; 222 } 223 224 /** 225 * Returns a hash code value for this object. 226 * 227 * @return a hash code value for this object. 228 */ 229 public int hashCode() 230 { 231 return this.getName().hashCode() + 232 this.getType().hashCode() + 233 ( this.getValue() == null ? 0 : this.getValue().hashCode() ); 234 235 } 236 237 /** 238 * Creates and returns a copy of this object. This method performs a 239 * "shallow copy" of this object, not a "deep copy" operation. 240 * 241 * @return a clone of this instance. 242 */ 243 public Object clone() 244 { 245 try 246 { 247 return super.clone(); 248 } 249 catch ( final CloneNotSupportedException e ) 250 { 251 throw new AssertionError( e ); 252 } 253 } 254 255 //------------------------------------------------------------------Object-- 256}