2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.common
.mapping
;
12 import java
.util
.ArrayList
;
13 import java
.util
.HashSet
;
14 import java
.util
.List
;
17 import org
.apache
.log4j
.Logger
;
19 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.out
.ObjectChangeMapper
;
28 public class CdmIoMapping
{
29 private static final Logger logger
= Logger
.getLogger(CdmIoMapping
.class);
31 //protected List<CdmAttributeMapperBase> mapperList = new ArrayList<CdmAttributeMapperBase>();
32 protected List
<CdmMapperBase
> mapperList
= new ArrayList
<CdmMapperBase
>();
33 Set
<String
> sourceAttributes
= new HashSet
<String
>();
34 Set
<String
> destinationAttributes
= new HashSet
<String
>();
35 List
<String
> sourceAttributeList
= new ArrayList
<String
>();
36 List
<String
> destinationAttributeList
= new ArrayList
<String
>();
39 public void addMapper(CdmAttributeMapperBase mapper
){
43 mapperList
.add(mapper
);
44 if (mapper
instanceof CdmSingleAttributeMapperBase
){
45 CdmSingleAttributeMapperBase singleMapper
= (CdmSingleAttributeMapperBase
)mapper
;
46 sourceAttributes
.addAll(singleMapper
.getSourceAttributes());
47 sourceAttributeList
.addAll(singleMapper
.getSourceAttributeList());
48 destinationAttributes
.addAll(singleMapper
.getDestinationAttributes());
49 destinationAttributeList
.addAll(singleMapper
.getDestinationAttributeList());
50 }else if (mapper
instanceof MultipleAttributeMapperBase
){
51 MultipleAttributeMapperBase
<?
> multipleMapper
= (MultipleAttributeMapperBase
<?
>)mapper
;
52 sourceAttributes
.addAll(multipleMapper
.getSourceAttributes());
53 sourceAttributeList
.addAll(multipleMapper
.getSourceAttributes());
54 destinationAttributes
.addAll(multipleMapper
.getDestinationAttributes());
55 destinationAttributeList
.addAll(multipleMapper
.getDestinationAttributeList());
56 }else if (mapper
instanceof ObjectChangeMapper
){
57 ObjectChangeMapper changeMapper
= (ObjectChangeMapper
)mapper
;
58 sourceAttributes
.addAll(changeMapper
.getSourceAttributes());
59 sourceAttributeList
.addAll(changeMapper
.getSourceAttributes());
60 destinationAttributes
.addAll(changeMapper
.getDestinationAttributes());
61 destinationAttributeList
.addAll(changeMapper
.getDestinationAttributeList());
64 logger
.error("Unknown mapper type: " + mapper
.getClass().getSimpleName());
65 throw new IllegalArgumentException("Unknown mapper type: " + mapper
.getClass().getSimpleName());
69 public Set
<String
> getSourceAttributes(){
70 Set
<String
> result
= new HashSet
<String
>();
71 result
.addAll(sourceAttributes
);
75 public Set
<String
> getSourceAttributesLowerCase(){
76 Set
<String
> result
= new HashSet
<String
>();
77 for(String attr
: sourceAttributes
){
79 result
.add(attr
.toLowerCase());
87 public Set
<String
> getDestinationAttributes(){
88 Set
<String
> result
= new HashSet
<String
>();
89 result
.addAll(destinationAttributes
);
93 public List
<String
> getDestinationAttributeList(){
94 List
<String
> result
= new ArrayList
<String
>();
95 result
.addAll(destinationAttributeList
);