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.common.mapping.berlinModel.CdmOneToManyMapper;
|
19
|
import eu.etaxonomy.cdm.io.common.mapping.IXmlMapper;
|
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
|
}
|