Project

General

Profile

Download (2.45 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

    
11
package eu.etaxonomy.cdm.io.tcsrdf;
12

    
13
import org.apache.log4j.Logger;
14
import org.jdom.Content;
15
import org.jdom.Element;
16
import org.jdom.Namespace;
17

    
18
import eu.etaxonomy.cdm.io.berlinModel.CdmOneToManyMapper;
19
import eu.etaxonomy.cdm.io.common.mapping.IXmlMapper;
20
import eu.etaxonomy.cdm.io.common.mapping.CdmSingleAttributeMapperBase;
21
import eu.etaxonomy.cdm.model.common.CdmBase;
22

    
23
/**
24
 * @author a.mueller
25
 * @created 24.03.2009
26
 * @version 1.0
27
 */
28
public class CdmOneToManyXmlMapper<ONE extends CdmBase, MANY extends CdmBase, SINGLE_MAPPER extends CdmSingleAttributeXmlMapperBase> extends
29
		CdmOneToManyMapper<ONE, MANY, SINGLE_MAPPER> implements IXmlMapper{
30
	@SuppressWarnings("unused")
31
	private static final Logger logger = Logger.getLogger(CdmOneToManyXmlMapper.class);
32

    
33
	public CdmOneToManyXmlMapper(Class<ONE> oneClass, Class<MANY> manyClass, String singleAttributeName, SINGLE_MAPPER[] singleAttributesMappers) {
34
		super(oneClass, manyClass, singleAttributeName, singleAttributesMappers);
35
	}
36

    
37
	
38
	/* (non-Javadoc)
39
	 * @see eu.etaxonomy.cdm.io.common.IXmlMapper#mapsSource(org.jdom.Content, org.jdom.Element)
40
	 */
41
	public boolean mapsSource(Content content, Element parentElement) {
42
		if (! (content instanceof Element)){
43
			return false;
44
		}
45
		Element element = (Element)content;
46
		if (content == null){
47
			return false;
48
		}else if (! getSourceAttributes().contains(element.getName())){
49
			return false;
50
		}
51
		for (String sourceElement: getSourceAttributeList()){
52
			Namespace thisNamespace = getSourceNamespace(sourceElement, parentElement);
53
			if (thisNamespace == null){
54
				if (element.getNamespace() == null){
55
					return true;
56
				}
57
			}else if (thisNamespace.equals(element.getNamespace())){
58
				return true;
59
			}	
60
		}
61
		return false;
62
	}
63
	
64
	
65
	/**
66
	 * Returns the namespace for the source element sourceElement. If not defined it returns the namespace
67
	 * of the parent element.
68
	 * @param sourceElement
69
	 * @param parentElement
70
	 * @return
71
	 */
72
	private Namespace getSourceNamespace(String sourceElement, Element parentElement){
73
		//TODO 
74
		//namespaces for single attributes not yet implemented
75
		return parentElement.getNamespace();
76
	}
77
	
78
}
(1-1/13)