01: //$Id: EmbeddedComponentType.java 10119 2006-07-14 00:09:19Z steve.ebersole@jboss.com $
02: package org.hibernate.type;
03:
04: import java.lang.reflect.Method;
05:
06: import org.hibernate.EntityMode;
07: import org.hibernate.HibernateException;
08: import org.hibernate.engine.SessionImplementor;
09: import org.hibernate.tuple.component.ComponentTuplizer;
10: import org.hibernate.tuple.component.ComponentMetamodel;
11:
12: /**
13: * @author Gavin King
14: */
15: public class EmbeddedComponentType extends ComponentType {
16:
17: public boolean isEmbedded() {
18: return true;
19: }
20:
21: public EmbeddedComponentType(ComponentMetamodel metamodel) {
22: super (metamodel);
23: }
24:
25: public boolean isMethodOf(Method method) {
26: return ((ComponentTuplizer) tuplizerMapping
27: .getTuplizer(EntityMode.POJO)).isMethodOf(method);
28: }
29:
30: public Object instantiate(Object parent, SessionImplementor session)
31: throws HibernateException {
32: final boolean useParent = parent != null &&
33: //TODO: Yuck! This is not quite good enough, it's a quick
34: //hack around the problem of having a to-one association
35: //that refers to an embedded component:
36: super.getReturnedClass().isInstance(parent);
37:
38: return useParent ? parent : super.instantiate(parent, session);
39: }
40: }
|