View Javadoc

1   /*
2    ORG Usurper is a random value object generator library 
3    Copyright (C) 2007  Pierre-Antoine Grégoire
4    
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9    
10   This library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14   
15   You should have received a copy of the GNU Lesser General Public
16   License along with this library; if not, write to the Free Software
17   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18   */
19  package org.org.usurper.model;
20  
21  import org.org.usurper.setup.IUsurperGeneratorSetup;
22  
23  /**
24   * The Class HandledBeanProperty is an immutable value object containing all the necessary elements for the handling of a precise attribute of an usurped object.
25   */
26  public class HandledBeanProperty implements IHandledEntity {
27  
28      private final Object targetObject;
29  
30      private final Class<?> propertyClass;
31  
32      private final String propertyName;
33  
34      private final IUsurperGeneratorSetup usurperGeneratorSetup;
35  
36      /**
37       * This constructor creates the HandledBeanProperty
38       * 
39       * @param targetObject
40       *            the object where the property will be set as a context (can be useful to handle relations between attributes).
41       * @param propertyClass
42       *            the class of the property to generate.
43       * @param propertyName
44       *            the name of the property to generate.
45       * @param usurperGeneratorSetup the usurper generator setup
46       * @return an Object of the type defined by the propertyClass parameter.
47       */
48      public HandledBeanProperty(final Object targetObject, final Class<?> propertyClass, final String propertyName, final IUsurperGeneratorSetup usurperGeneratorSetup) {
49          super();
50          this.targetObject = targetObject;
51          this.propertyClass = propertyClass;
52          this.propertyName = propertyName;
53          this.usurperGeneratorSetup = usurperGeneratorSetup;
54      }
55  
56    
57      /**
58       * Gets the class of the property to be handled.
59       * 
60       * @return the property class
61       */
62      public Class<?> getPropertyClass() {
63          return propertyClass;
64      }
65  
66      /**
67       * Gets the property name.
68       * 
69       * @return the property name
70       */
71      public String getPropertyName() {
72          return propertyName;
73      }
74  
75      /**
76       * Gets the object where the property will be set.
77       * 
78       * @return the target object
79       */
80      public Object getTargetObject() {
81          return targetObject;
82      }
83  
84      /**
85       * Gets the usurper generator setup.
86       * 
87       * @return the usurper generator setup
88       */
89      public IUsurperGeneratorSetup getUsurperGeneratorSetup() {
90          return usurperGeneratorSetup;
91      }
92  
93      @Override
94      public String toString() {
95          StringBuilder stringBuilder = new StringBuilder();
96          stringBuilder.append("Target object: " + targetObject.getClass().getName() + targetObject.getClass().hashCode());
97          stringBuilder.append("property name: " + propertyName);
98          stringBuilder.append("property class: " + propertyClass.getName());
99          return stringBuilder.toString();
100     }
101 
102     @Override
103     public boolean equals(Object obj) {
104         if (this == obj)
105             return true;
106         if ((obj == null) || (obj.getClass() != this.getClass()))
107             return false;
108         // object must be Test at this point
109         HandledBeanProperty other = (HandledBeanProperty) obj;
110         return targetObject.equals(other.targetObject) && propertyName.equals(other.propertyName);
111     }
112 
113     @Override
114     public int hashCode() {
115         int hash = 7;
116         hash = 31 * hash + (null == targetObject ? 0 : targetObject.hashCode());
117         hash = 31 * hash + (null == propertyName ? 0 : propertyName.hashCode());
118         return hash;
119     }
120 }