implement tree index update
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / berlinModel / CdmOneToManyMapper.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
10 package eu.etaxonomy.cdm.io.berlinModel;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import org.apache.log4j.Logger;
16
17 import eu.etaxonomy.cdm.io.common.mapping.CdmSingleAttributeMapperBase;
18 import eu.etaxonomy.cdm.io.common.mapping.MultipleAttributeMapperBase;
19 import eu.etaxonomy.cdm.model.common.CdmBase;
20
21 /**
22 * @author a.mueller
23 * @created 20.03.2008
24 * @version 1.0
25 */
26 public class CdmOneToManyMapper<ONE extends CdmBase, MANY extends CdmBase, SINGLE_MAPPER extends CdmSingleAttributeMapperBase> extends MultipleAttributeMapperBase<SINGLE_MAPPER> {
27 @SuppressWarnings("unused")
28 private static Logger logger = Logger.getLogger(CdmOneToManyMapper.class);
29
30 private Class<MANY> manyClass;
31 private Class<ONE> oneClass;
32 private String singleAttributeName;
33
34 public CdmOneToManyMapper(Class<ONE> oneClass, Class<MANY> manyClass, String singleAttributeName, SINGLE_MAPPER[] singleAttributesMappers) {
35 if (singleAttributesMappers == null){
36 throw new NullPointerException("singleAttributesMapper and cdmAttributeStrings must not be null");
37 }
38 for (SINGLE_MAPPER singleMapper : singleAttributesMappers){
39 singleMappers.add(singleMapper);
40 }
41 this.manyClass = manyClass;
42 this.oneClass = oneClass;
43 this.singleAttributeName = singleAttributeName;
44 }
45
46 // @Override
47 // public Set<String> getSourceAttributes(){
48 // Set<String> result = new HashSet<String>();
49 // result.addAll(getSourceAttributeList());
50 // return result;
51 // }
52
53 @Override
54 public List<String> getSourceAttributeList(){
55 List<String> result = new ArrayList<String>();
56 for (SINGLE_MAPPER singleMapper : singleMappers){
57 result.add(singleMapper.getSourceAttribute());
58 }
59 return result;
60 }
61
62 // @Override
63 // public Set<String> getDestinationAttributes(){
64 // Set<String> result = new HashSet<String>();
65 // result.addAll(getDestinationAttributeList());
66 // return result;
67 // }
68
69 @Override
70 public List<String> getDestinationAttributeList(){
71 List<String> result = new ArrayList<String>();
72 for (SINGLE_MAPPER singleMapper : singleMappers){
73 result.add(singleMapper.getDestinationAttribute());
74 }
75 return result;
76 }
77
78
79 public Class<MANY> getManyClass(){
80 return manyClass;
81 }
82
83 public Class<ONE> getOneClass(){
84 return oneClass;
85 }
86
87 public String getDestinationAttribute(String sourceAttribute){
88 if (sourceAttribute == null){
89 return null;
90 }
91 for (SINGLE_MAPPER singleMapper : singleMappers){
92 if (sourceAttribute.equals(singleMapper.getSourceAttribute())){
93 return singleMapper.getDestinationAttribute();
94 }
95 }
96 return null;
97 }
98
99 public List<SINGLE_MAPPER> getSingleMappers(){
100 return singleMappers;
101 }
102
103 /**
104 * @return the singleAttributeName
105 */
106 public String getSingleAttributeName() {
107 return singleAttributeName;
108 }
109
110 }