Merge branch 'develop' of ssh://dev.e-taxonomy.eu/var/git/cdmlib into develop
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / tcsxml / CdmSingleAttributeXmlMapperBase.java
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 package eu.etaxonomy.cdm.io.tcsxml;
10
11 import org.apache.log4j.Logger;
12 import org.jdom.Content;
13 import org.jdom.Element;
14 import org.jdom.Namespace;
15
16 import eu.etaxonomy.cdm.io.common.mapping.IXmlMapper;
17 import eu.etaxonomy.cdm.io.common.mapping.CdmSingleAttributeMapperBase;
18
19
20 /**
21 * @author a.mueller
22 * @created 29.07.2008
23 * @version 1.0
24 */
25
26 public abstract class CdmSingleAttributeXmlMapperBase extends CdmSingleAttributeMapperBase implements IXmlMapper{
27 @SuppressWarnings("unused")
28 private static final Logger logger = Logger.getLogger(CdmSingleAttributeXmlMapperBase.class);
29
30 protected Namespace sourceNamespace;
31
32
33 /**
34 * @param sourceElementString
35 * @param sourceNamespace
36 * @param cdmAttributeString
37 */
38 protected CdmSingleAttributeXmlMapperBase(String sourceElementString,Namespace sourceNamespace, String cdmAttributeString){
39 super(sourceElementString, cdmAttributeString);
40
41 }
42
43
44 /**
45 * Uses the Namespace of the parent Element
46 * @param sourceElementString
47 * @param cdmAttributeString
48 */
49 protected CdmSingleAttributeXmlMapperBase(String sourceElementString, String cdmAttributeString){
50 super(sourceElementString, cdmAttributeString);
51
52 }
53
54 public String getSourceElement(){
55 return super.getSourceAttribute();
56 }
57
58 public String getDestinationAttribute(){
59 return super.getDestinationAttribute();
60 }
61
62
63 public Namespace getSourceNamespace(){
64 return sourceNamespace;
65 }
66
67 /**
68 * Returns the namespace. If namespace is null, return parentElement namespace
69 * @param parentElement
70 * @return
71 */
72 public Namespace getSourceNamespace(Element parentElement){
73 if (this.sourceNamespace != null){
74 return sourceNamespace;
75 }else if (parentElement != null){
76 return parentElement.getNamespace();
77 }else{
78 return null;
79 }
80 }
81
82 public boolean mapsSource(Content content, Element parentElement){
83 if (! (content instanceof Element)){
84 return false;
85 }
86 Element element = (Element)content;
87 if (content == null){
88 return false;
89 }else if (! element.getName().equals(getSourceElement())){
90 return false;
91 }
92 Namespace thisNamespace = getSourceNamespace(parentElement);
93 if (thisNamespace == null){
94 if (element.getNamespace() == null){
95 return true;
96 }else{
97 return false;
98 }
99 }
100 if (! thisNamespace.equals(element.getNamespace())){
101 return false;
102 }
103 return true;
104 }
105
106 public String toString(){
107 //TODO
108 return this.getSourceElement();
109 }
110 }