Project

General

Profile

Download (1.2 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.remote.dto.assembler.converter;
11

    
12
import org.hibernate.Hibernate;
13
import org.hibernate.SessionException;
14
import org.hibernate.envers.entities.mapper.relation.lazy.proxy.CollectionProxy;
15

    
16
import net.sf.dozer.util.mapping.CustomFieldMapperIF;
17
import net.sf.dozer.util.mapping.classmap.ClassMap;
18
import net.sf.dozer.util.mapping.fieldmap.FieldMap;
19

    
20
public class HibernateProxyFieldMapper implements CustomFieldMapperIF {
21

    
22
	public boolean mapField(Object source, Object destination, Object sourceFieldValue, ClassMap classMap, FieldMap fieldMapping) {
23

    
24
		if(sourceFieldValue instanceof CollectionProxy) {
25
			try {
26
				((CollectionProxy)sourceFieldValue).hashCode();
27
			} catch(SessionException se) { // currently no way to tell if is initialized
28
				return true;
29
			}
30
		    return false;
31
		} else if(Hibernate.isInitialized(sourceFieldValue)) {
32
		    return false;
33
		}else {
34
			return true;
35
		}
36
		
37
	}
38
}
(3-3/9)