Project

General

Profile

Download (2.32 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.IXmlMapper;
18
import eu.etaxonomy.cdm.io.common.mapping.berlinModel.CdmOneToManyMapper;
19
import eu.etaxonomy.cdm.io.tcsxml.CdmSingleAttributeXmlMapperBase;
20
import eu.etaxonomy.cdm.model.common.CdmBase;
21

    
22
/**
23
 * @author a.mueller
24
 * @since 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
	@Override
37
    public boolean mapsSource(Content content, Element parentElement) {
38
		if (! (content instanceof Element)){
39
			return false;
40
		}
41
		Element element = (Element)content;
42
		if (content == null){
43
			return false;
44
		}else if (! getSourceAttributes().contains(element.getName())){
45
			return false;
46
		}
47
		for (String sourceElement: getSourceAttributeList()){
48
			Namespace thisNamespace = getSourceNamespace(sourceElement, parentElement);
49
			if (thisNamespace == null){
50
				if (element.getNamespace() == null){
51
					return true;
52
				}
53
			}else if (thisNamespace.equals(element.getNamespace())){
54
				return true;
55
			}
56
		}
57
		return false;
58
	}
59

    
60

    
61
	/**
62
	 * Returns the namespace for the source element sourceElement. If not defined it returns the namespace
63
	 * of the parent element.
64
	 * @param sourceElement
65
	 * @param parentElement
66
	 * @return
67
	 */
68
	private Namespace getSourceNamespace(String sourceElement, Element parentElement){
69
		//TODO
70
		//namespaces for single attributes not yet implemented
71
		return parentElement.getNamespace();
72
	}
73

    
74
}
(1-1/13)