KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > tuple > Tuplizer


1 // $Id: Tuplizer.java,v 1.6 2005/07/11 21:47:03 steveebersole Exp $
2
package org.hibernate.tuple;
3
4 import org.hibernate.HibernateException;
5
6 /**
7  * A tuplizer defines the contract for things which know how to manage
8  * a particular representation of a piece of data, given that
9  * representation's {@link org.hibernate.EntityMode} (the entity-mode
10  * essentially defining which representation).
11  * </p>
12  * If that given piece of data is thought of as a data structure, then a tuplizer
13  * is the thing which knows how to<ul>
14  * <li>create such a data structure appropriately
15  * <li>extract values from and inject values into such a data structure
16  * </ul>
17  * </p>
18  * For example, a given piece of data might be represented as a POJO class.
19  * Here, it's representation and entity-mode is POJO. Well a tuplizer for POJO
20  * entity-modes would know how to<ul>
21  * <li>create the data structure by calling the POJO's constructor
22  * <li>extract and inject values through getters/setter, or by direct field access, etc
23  * </ul>
24  * </p>
25  * That same piece of data might also be represented as a DOM structure, using
26  * the tuplizer associated with the DOM4J entity-mode, which would generate instances
27  * of {@link org.dom4j.Element} as the data structure and know how to access the
28  * values as either nested {@link org.dom4j.Element}s or as {@link org.dom4j.Attribute}s.
29  *
30  * @see EntityTuplizer
31  * @see ComponentTuplizer
32  *
33  * @author Steve Ebersole
34  */

35 public interface Tuplizer {
36
37     /**
38      * Extract the current values contained on the given entity.
39      *
40      * @param entity The entity from which to extract values.
41      * @return The current property values.
42      * @throws HibernateException
43      */

44     public Object JavaDoc[] getPropertyValues(Object JavaDoc entity) throws HibernateException;
45
46     /**
47      * Inject the given values into the given entity.
48      *
49      * @param entity The entity.
50      * @param values The values to be injected.
51      * @throws HibernateException
52      */

53     public void setPropertyValues(Object JavaDoc entity, Object JavaDoc[] values) throws HibernateException;
54
55     /**
56      * Extract the value of a particular property from the given entity.
57      *
58      * @param entity The entity from which to extract the property value.
59      * @param i The index of the property for which to extract the value.
60      * @return The current value of the given property on the given entity.
61      * @throws HibernateException
62      */

63     public Object JavaDoc getPropertyValue(Object JavaDoc entity, int i) throws HibernateException;
64
65     /**
66      * Generate a new, empty entity.
67      *
68      * @return The new, empty entity instance.
69      * @throws HibernateException
70      */

71     public Object JavaDoc instantiate() throws HibernateException;
72     
73     /**
74      * Is the given object considered an instance of the the entity (acconting
75      * for entity-mode) managed by this tuplizer.
76      *
77      * @param object The object to be checked.
78      * @return True if the object is considered as an instance of this entity
79      * within the given mode.
80      */

81     public boolean isInstance(Object JavaDoc object);
82
83     /**
84      * Return the pojo class managed by this tuplizer.
85      * </p>
86      * Need to determine how to best handle this for the Tuplizers for EntityModes
87      * other than POJO.
88      * </p>
89      * todo : be really nice to not have this here since it is essentially pojo specific...
90      *
91      * @return The persistent class.
92      */

93     public Class JavaDoc getMappedClass();
94
95 }
96
Popular Tags