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  /**
22   * The Class PropertyTypeDefinition is an immutable value object describing a target property type.
23   */
24  public class PropertyTypeDefinition implements ITargetDefinition {
25  
26      private final Class<?> targetClass;
27  
28      /**
29       * Instantiates a new PropertyTypeDefinition from a Class object.
30       * 
31       * @param targetClass the target class
32       */
33      public PropertyTypeDefinition(final Class<?> targetClass) {
34          super();
35          this.targetClass = targetClass;
36      }
37  
38      /**
39       * Instantiates a new PropertyTypeDefinition from the name of a Class.
40       * 
41       * @param targetDescription the target description
42       */
43      public PropertyTypeDefinition(final String targetDescription) {
44          super();
45          String targetClassName = targetDescription;
46          try {
47              this.targetClass = Class.forName(targetClassName);
48          } catch (ClassNotFoundException e) {
49              throw new IllegalArgumentException("Impossible to resolve class in: " + targetDescription, e);
50          }
51      }
52  
53      /**
54       * Gets the target class.
55       * 
56       * @return the target class
57       */
58      public Class<?> getTargetClass() {
59          return targetClass;
60      }
61  
62      @Override
63      public String toString() {
64          return targetClass.getName();
65      }
66  
67      @Override
68      public boolean equals(Object obj) {
69          if (this == obj)
70              return true;
71          if ((obj == null) || (obj.getClass() != this.getClass()))
72              return false;
73          // object must be Test at this point
74          PropertyTypeDefinition other = (PropertyTypeDefinition) obj;
75          return targetClass.equals(other.targetClass);
76      }
77  
78      @Override
79      public int hashCode() {
80          int hash = 7;
81          hash = 31 * hash + (null == targetClass ? 0 : targetClass.hashCode());
82          return hash;
83      }
84  }