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