Clover Coverage Report - SmartWeb
Coverage timestamp: Sun Jun 8 2008 21:20:12 CEST
../../../img/srcFileCovDistChart0.png 29% of files have more coverage
23   216   19   1,53
4   74   0,83   15
15     1,27  
1    
2,3% of code in this file is excluded from these metrics.
 
  Enumeration       Line # 44 23 19 0% 0.0
 
No Tests
 
1    /*
2    * The SmartWeb Framework
3    * Copyright (C) 2004-2006
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    * For further informations on the SmartWeb Framework please visit
20    *
21    * http://smartweb.sourceforge.net
22    */
23    package net.smartlab.web;
24   
25    import java.io.Serializable;
26    import java.sql.PreparedStatement;
27    import java.sql.ResultSet;
28    import java.sql.SQLException;
29    import java.sql.Types;
30   
31    import org.hibernate.Hibernate;
32    import org.hibernate.HibernateException;
33    import org.hibernate.usertype.UserType;
34   
35    /**
36    * Represents a meta type used to constraint a property to accept only
37    * pre-defined admitted values. Whenever a property needs some sort of
38    * constraint on assignable values, like person gender or process status, a
39    * subclass of <code>Enumeration</code> can be used to enumerate all possible
40    * values.
41    *
42    * @author rlogiacco
43    */
 
44    public abstract class Enumeration implements UserType, Serializable {
45   
46    private final static long serialVersionUID = 8849967605617496075L;
47   
48    /**
49    * Type of the persisted field reference.
50    */
51    private final static int[] TYPES = new int[] {Types.SMALLINT};
52   
53    /**
54    * The unique identifier used to represent the choice onto the persisted
55    * field.
56    *
57    * @uml.property name="id"
58    */
59    private final int id;
60   
61    /**
62    * A brief, human understandable, description of the choice.
63    *
64    * @uml.property name="display"
65    */
66    private final String display;
67   
68   
69    /**
70    * Default constructor used for internal purposes only.
71    */
 
72  0 toggle protected Enumeration() {
73    // Default constructor
74  0 this.id = -1;
75  0 this.display = null;
76    }
77   
78    /**
79    * Constructs an available choice on a unique identifier and a brief, human
80    * understandable, description.
81    *
82    * @param id the unique identifier for this choice.
83    * @param display a short, human understandable, description of the choice.
84    */
 
85  0 toggle protected Enumeration(int id, String display) {
86  0 this.id = id;
87  0 this.display = display;
88    }
89   
90    /**
91    * Returns the unique identifier for the choice.
92    *
93    * @return the unique identifier for the choice.
94    * @uml.property name="id"
95    */
 
96  0 toggle public int getId() {
97  0 return id;
98    }
99   
100    /**
101    * Returns the brief description of the choice.
102    *
103    * @return the brief description of the choice.
104    * @uml.property name="display"
105    */
 
106  0 toggle public String getDisplay() {
107  0 return display;
108    }
109   
110    /**
111    * Decodes a unique identifier into an instance of this class. This method
112    * <b>can not</b> return <code>null</code> values, instead it should
113    * define a <i>default</i> value.
114    *
115    * @param id the identifier to decode.
116    * @return an instance of this class.
117    */
118    public abstract Enumeration decode(int id);
119   
120    /**
121    * @see org.hibernate.usertype.UserType#deepCopy(java.lang.Object)
122    */
 
123  0 toggle public Object deepCopy(Object value) throws HibernateException {
124  0 return value;
125    }
126   
127    /**
128    * @see org.hibernate.usertype.UserType#equals(java.lang.Object,
129    * java.lang.Object)
130    */
 
131  0 toggle public boolean equals(Object src, Object dst) throws HibernateException {
132  0 if (src == dst) {
133  0 return true;
134    }
135  0 if (src == null || dst == null) {
136  0 return false;
137    }
138  0 return Hibernate.INTEGER.isEqual(src, dst);
139    }
140   
141    /**
142    * @see org.hibernate.usertype.UserType#isMutable()
143    */
 
144  0 toggle public boolean isMutable() {
145  0 return false;
146    }
147   
148    /**
149    * @see org.hibernate.usertype.UserType#nullSafeGet(java.sql.ResultSet,
150    * java.lang.String[], java.lang.Object)
151    */
 
152  0 toggle public Object nullSafeGet(ResultSet rows, String[] names, Object value) throws HibernateException, SQLException {
153  0 int id = ((Integer)Hibernate.INTEGER.nullSafeGet(rows, names[0])).intValue();
154  0 return this.decode(id);
155    }
156   
157    /**
158    * @see org.hibernate.usertype.UserType#nullSafeSet(java.sql.PreparedStatement,
159    * java.lang.Object, int)
160    */
 
161  0 toggle public void nullSafeSet(PreparedStatement statement, Object value, int index) throws HibernateException,
162    SQLException {
163  0 try {
164  0 statement.setInt(index, ((Enumeration)value).getId());
165    } catch (ClassCastException cce) {
166    throw new HibernateException(cce);
167    }
168    }
169   
170    /**
171    * @see org.hibernate.usertype.UserType#returnedClass()
172    */
 
173  0 toggle public Class returnedClass() {
174  0 return this.getClass();
175    }
176   
177    /**
178    * @see org.hibernate.usertype.UserType#sqlTypes()
179    */
 
180  0 toggle public int[] sqlTypes() {
181  0 return TYPES;
182    }
183   
184    /**
185    * @see org.hibernate.usertype.UserType#assemble(java.io.Serializable,
186    * java.lang.Object)
187    */
 
188  0 toggle public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
189  0 return null;
190    // FIXME: may be an HibernateException is better
191    }
192   
193    /**
194    * @see org.hibernate.usertype.UserType#disassemble(java.lang.Object)
195    */
 
196  0 toggle public Serializable disassemble(Object arg0) throws HibernateException {
197  0 return null;
198    // FIXME: may be an HibernateException is better
199    }
200   
201    /**
202    * @see org.hibernate.usertype.UserType#hashCode(java.lang.Object)
203    */
 
204  0 toggle public int hashCode(Object obj) throws HibernateException {
205  0 return ((Enumeration)obj).getId();
206    }
207   
208    /**
209    * @see org.hibernate.usertype.UserType#replace(java.lang.Object,
210    * java.lang.Object, java.lang.Object)
211    */
 
212  0 toggle public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException {
213  0 return null;
214    // FIXME: may be an HibernateException is better
215    }
216    }