Project

General

Profile

Download (1.97 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2009 EDIT European Distributed Institute of Taxonomy
3
 * http://www.e-taxonomy.eu
4
 *
5
 * The contents of this file are subject to the Mozilla Public License Version
6
 * 1.1 See LICENSE.TXT at the top of this package for the full license terms.
7
 */
8

    
9
package eu.etaxonomy.cdm.remote.json.processor.value;
10

    
11
import org.apache.logging.log4j.LogManager;
12
import org.apache.logging.log4j.Logger;
13

    
14
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
15
import eu.etaxonomy.cdm.remote.json.processor.matcher.HibernateJSONValueProcessorMatcher;
16
import net.sf.json.JSONArray;
17
import net.sf.json.JsonConfig;
18
import net.sf.json.processors.JsonValueProcessor;
19

    
20
/**
21
 * Used in conjunction with the {@link HibernateJSONValueProcessorMatcher} to unwrap
22
 * beans from hibernate proxies. Using this Value processor is essential for
23
 * properly detecting @Transient annotations which are not inherited by subclasses
24
 * like the proxies
25
 *
26
 * @author a.kohlbecker
27
 */
28
public class HibernateJSONValueProcessor implements JsonValueProcessor {
29

    
30
	public static final Logger logger = LogManager.getLogger(HibernateJSONValueProcessor.class);
31

    
32
//	public Object processArrayValue(Object object, JsonConfig jsonConfig) {
33
//		if(Hibernate.isInitialized(object)) {
34
//			log.debug("Processing array value " + object);
35
//			return JSONArray.fromObject(object,jsonConfig);
36
//		} else{
37
//		    log.debug("Collection is uninitialized, returning null");
38
//		    return JSONNull.getInstance();
39
//		}
40
//	}
41

    
42
	@Override
43
    public Object processArrayValue(Object object, JsonConfig jsonConfig) {
44
		// usage of the InitializedHibernatePropertyFiler is expected !!!
45
		// retain default processing
46
		return JSONArray.fromObject(object,jsonConfig);
47
	}
48

    
49
	@Override
50
    public Object processObjectValue(String propertyName, Object object, JsonConfig jsonConfig) {
51
		// deproxy
52
		Object target = HibernateProxyHelper.deproxy(object, Object.class);
53
		if(logger.isDebugEnabled()){
54
			logger.debug("deproxying object " + target);
55
		}
56
		return target;
57

    
58
	}
59
}
(5-5/10)