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.common;
|
11
|
|
12
|
import java.util.HashMap;
|
13
|
import java.util.Map;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
18
|
|
19
|
/**
|
20
|
* This class is a helper class for all IOStates implementing IPartionedState to hold and retrieve the
|
21
|
* related objects for a partition. If once all import states implement IPartitionedState this class
|
22
|
* can be integrated into ImportStateBase
|
23
|
* @author a.mueller
|
24
|
* @since 02.03.2010
|
25
|
*/
|
26
|
public class RelatedObjectsHelper {
|
27
|
@SuppressWarnings("unused")
|
28
|
private static final Logger logger = Logger.getLogger(RelatedObjectsHelper.class);
|
29
|
|
30
|
private Map<Object, Map<String, ? extends CdmBase>> relatedObjects;
|
31
|
|
32
|
/**
|
33
|
* @param relatedObjects the relatedObjects to set
|
34
|
*/
|
35
|
public void setRelatedObjects(Map<Object, Map<String, ? extends CdmBase>> relatedObjects) {
|
36
|
this.relatedObjects = relatedObjects;
|
37
|
}
|
38
|
|
39
|
/**
|
40
|
* Returns the cdmbase object for the key pair (namespace, id).
|
41
|
* @param namespace
|
42
|
* @param id
|
43
|
*/
|
44
|
public CdmBase getRelatedObject(Object namespace, String id) {
|
45
|
CdmBase cdmBase = null;
|
46
|
Map<String, ? extends CdmBase> idMap = relatedObjects.get(namespace);
|
47
|
if (idMap != null){
|
48
|
cdmBase = idMap.get(id);
|
49
|
}
|
50
|
return cdmBase;
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* Adds a related object to the underlying map.
|
55
|
* @param namespace
|
56
|
* @param id
|
57
|
* @param relatedObject
|
58
|
*/
|
59
|
public void addRelatedObjet(Object namespace, String id, CdmBase relatedObject){
|
60
|
Map idMap = relatedObjects.get(namespace);
|
61
|
if (idMap == null){
|
62
|
idMap = new HashMap<String, CdmBase>();
|
63
|
relatedObjects.put(namespace, idMap);
|
64
|
}
|
65
|
idMap.put(id, relatedObject);
|
66
|
|
67
|
}
|
68
|
}
|