Project

General

Profile

Download (2.61 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.io.tcsrdf;
2

    
3
import org.apache.log4j.Logger;
4
import org.jdom.Element;
5

    
6
import com.hp.hpl.jena.rdf.model.Resource;
7
import com.hp.hpl.jena.rdf.model.Statement;
8

    
9
import eu.etaxonomy.cdm.io.common.mapping.CdmSingleAttributeMapperBase;
10
import eu.etaxonomy.cdm.io.common.mapping.IRdfMapper;
11
import eu.etaxonomy.cdm.io.tcsxml.CdmSingleAttributeXmlMapperBase;
12

    
13

    
14
public abstract class CdmSingleAttributeRDFMapperBase extends
15
		CdmSingleAttributeMapperBase implements IRdfMapper {
16

    
17
	
18
		@SuppressWarnings("unused")
19
		private static final Logger logger = Logger.getLogger(CdmSingleAttributeXmlMapperBase.class);
20
		
21
		protected String sourceNameSpace;
22

    
23
		
24
		/**
25
		 * @param sourceElementString
26
		 * @param sourceNamespace
27
		 * @param cdmAttributeString
28
		 */
29
		protected CdmSingleAttributeRDFMapperBase(String sourceElementString, String subject, String cdmAttributeString){
30
			super(sourceElementString, cdmAttributeString);
31
			this.sourceNameSpace = subject;
32
		}
33
		
34
		
35
		/**
36
		 * Uses the Namespace of the parent Element
37
		 * @param sourceElementString
38
		 * @param cdmAttributeString
39
		 */
40
		protected CdmSingleAttributeRDFMapperBase(String sourceElementString, String cdmAttributeString){
41
			super(sourceElementString, cdmAttributeString);
42
			
43
		}
44

    
45
		public String getSourceElement(){
46
			return super.getSourceAttribute();
47
		}
48

    
49
		public String getDestinationAttribute(){
50
			return super.getDestinationAttribute();
51
		}
52
		
53
		
54
		public String getSourceNamespace(){
55
			return sourceNameSpace;
56
		}
57
		
58
		/**
59
		 * Returns the namespace. If namespace is null, return parentElement namespace
60
		 * @param parentElement
61
		 * @return
62
		 */
63
		public String getSourceNameSpace(Statement resource){
64
			if (this.sourceNameSpace != null){
65
				return sourceNameSpace;
66
			}else if (resource != null){
67
				return resource.getPredicate().toString();
68
			}else{
69
				return null;
70
			}
71
		}
72
		
73
		public boolean mapsSource(Resource content, Statement statement){
74
			if (! (content instanceof Element)){
75
				return false;
76
			}
77
			//Element element = (Element)content;
78
			if (content == null){
79
				return false;
80
			}else if (! content.getNameSpace().equals(getSourceElement())){
81
				return false;
82
			}
83
			String thisSourceNameSpace= getSourceNameSpace(statement);
84
			if (thisSourceNameSpace == null){
85
				if (content.getNameSpace() == null){
86
					return true;
87
				}else{
88
					return false;
89
				}
90
			}
91
			if (! thisSourceNameSpace.equals(content.getNameSpace())){
92
				return false;
93
			}
94
			return true;
95
		}
96

    
97
		public String toString(){
98
			//TODO
99
			return this.getSourceElement();
100
		}	
101
	}
(2-2/13)