3 * Copyright (C) 2009 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.
10 package eu
.etaxonomy
.cdm
.ext
.geo
;
12 import javax
.xml
.stream
.XMLStreamException
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
16 import org
.springframework
.stereotype
.Component
;
18 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
19 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
20 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
21 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
22 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
25 * This class implements {@link IGeoServiceAreaMapping}. The mapping
26 * is stored as a technical annotation of the area.
27 * The area is saved while the mapping is set.
33 public class GeoServiceAreaAnnotatedMapping
implements IGeoServiceAreaMapping
{
34 @SuppressWarnings("unused")
35 private static final Logger logger
= Logger
.getLogger(GeoServiceAreaAnnotatedMapping
.class);
38 private ITermService termService
;
41 * @see eu.etaxonomy.cdm.ext.geo.IGeoServiceAreaMapping#valueOf(eu.etaxonomy.cdm.model.location.NamedArea)
44 public GeoServiceArea
valueOf(NamedArea area
) {
45 for (Annotation annotation
: area
.getAnnotations()){
46 if (AnnotationType
.TECHNICAL().equals(annotation
.getAnnotationType())){
47 GeoServiceArea areas
= GeoServiceArea
.valueOf(annotation
.getText());
58 * @see eu.etaxonomy.cdm.ext.geo.IGeoServiceAreaMapping#set(eu.etaxonomy.cdm.model.location.NamedArea, eu.etaxonomy.cdm.ext.geo.GeoServiceArea)
61 public void set(NamedArea area
, GeoServiceArea geoServiceArea
) {
64 xml
= geoServiceArea
.toXml();
65 } catch (XMLStreamException e
) {
66 throw new RuntimeException(e
);
68 Annotation annotation
=null;
69 for (Annotation existingAnnotation
: area
.getAnnotations()){
70 if (AnnotationType
.TECHNICAL().equals(existingAnnotation
.getAnnotationType())){
71 if (GeoServiceArea
.isAreaMapping(existingAnnotation
.getText())){
72 //FIXME test mapping type. There may be a mapping for each map service
73 annotation
= existingAnnotation
;
77 if (annotation
== null){
78 AnnotationType type
= AnnotationType
.TECHNICAL();
79 annotation
= Annotation
.NewInstance(xml
, type
, Language
.DEFAULT());
81 area
.addAnnotation(annotation
);
83 termService
.saveOrUpdate(area
);