Project

General

Profile

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

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

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

    
17
import eu.etaxonomy.cdm.io.common.mapping.berlinModel.CdmOneToManyMapper;
18
import eu.etaxonomy.cdm.io.common.mapping.IXmlMapper;
19
import eu.etaxonomy.cdm.io.tcsxml.CdmSingleAttributeXmlMapperBase;
20
import eu.etaxonomy.cdm.model.common.CdmBase;
21

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

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

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