3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.io
.dwca
.in
;
13 import java
.util
.ArrayList
;
14 import java
.util
.HashMap
;
15 import java
.util
.List
;
19 import org
.apache
.log4j
.Logger
;
21 import eu
.etaxonomy
.cdm
.api
.service
.IIdentifiableEntityService
;
22 import eu
.etaxonomy
.cdm
.io
.common
.ImportStateBase
;
23 import eu
.etaxonomy
.cdm
.io
.dwca
.in
.InMemoryMapping
.CdmKey
;
24 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
25 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
32 public class DwcaImportState
extends ImportStateBase
<DwcaImportConfigurator
, DwcaImport
>{
33 @SuppressWarnings("unused")
34 private static final Logger logger
= Logger
.getLogger(DwcaImportState
.class);
38 private IImportMapping mapping
= new InMemoryMapping();
40 public DwcaImportState(DwcaImportConfigurator config
) {
45 * True, if taxa have been fully created.
48 public boolean isTaxaCreated() {
54 * @param taxaCreated the taxaCreated to set
56 public void setTaxaCreated(boolean taxaCreated
) {
57 this.taxaCreated
= taxaCreated
;
60 public void putMapping(String namespace
, Integer sourceKey
, IdentifiableEntity
<?
> destinationObject
){
61 mapping
.putMapping(namespace
, sourceKey
, destinationObject
);
64 public void putMapping(String namespace
, String sourceKey
, IdentifiableEntity
<?
> destinationObject
){
65 mapping
.putMapping(namespace
, sourceKey
, destinationObject
);
69 public List
<IdentifiableEntity
> get(String namespace
, String sourceKey
){
70 return get(namespace
, sourceKey
, null);
73 public <CLASS
extends IdentifiableEntity
> List
<CLASS
> get(String namespace
, String sourceKey
,Class
<CLASS
> destinationClass
){
74 List
<CLASS
> result
= new ArrayList
<CLASS
>();
75 Set
<CdmKey
> keySet
= mapping
.get(namespace
, sourceKey
);
76 for (CdmKey
<CLASS
> key
: keySet
){
77 if (destinationClass
== null || destinationClass
.isAssignableFrom(key
.clazz
)){
78 IIdentifiableEntityService
<CLASS
> service
= getCurrentIO().getServiceByClass(key
.clazz
);
79 CLASS entity
= CdmBase
.deproxy(service
.find(key
.id
), key
.clazz
);
86 public boolean exists(String namespace
, String sourceKey
,Class
<?
> destinationClass
){
87 return mapping
.exists(namespace
, sourceKey
, destinationClass
);