svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.lib / org.gvsig.exportto.lib.impl / src / main / java / org / gvsig / export / impl / service / DefaultExportServiceManager.java @ 44386
History | View | Annotate | Download (4.43 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.export.impl.service; |
7 |
|
8 |
import java.util.ArrayList; |
9 |
import java.util.Collections; |
10 |
import java.util.HashMap; |
11 |
import java.util.List; |
12 |
import java.util.Map; |
13 |
import org.cresques.cts.ICoordTrans; |
14 |
import org.gvsig.export.ExportAttributes; |
15 |
import org.gvsig.export.ExportParameters; |
16 |
import org.gvsig.export.ExportParametersGeometry; |
17 |
import org.gvsig.export.Filter; |
18 |
import org.gvsig.export.impl.ExportGeometryUtils; |
19 |
import org.gvsig.export.spi.AttributeNamesTranslator; |
20 |
import org.gvsig.export.spi.ExportGeometryHelper; |
21 |
import org.gvsig.export.spi.ExportService; |
22 |
import org.gvsig.export.spi.ExportServiceFactory; |
23 |
import org.gvsig.export.spi.ExportServiceManager; |
24 |
import org.gvsig.fmap.dal.feature.FeatureType; |
25 |
import org.gvsig.fmap.geom.Geometry; |
26 |
import org.gvsig.tools.bookmarksandhistory.Bookmark; |
27 |
import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
28 |
import org.gvsig.tools.bookmarksandhistory.History; |
29 |
import org.gvsig.tools.bookmarksandhistory.impl.BaseBookmarks; |
30 |
import org.gvsig.tools.bookmarksandhistory.impl.BaseHistory; |
31 |
import org.slf4j.Logger; |
32 |
import org.slf4j.LoggerFactory; |
33 |
|
34 |
/**
|
35 |
*
|
36 |
* @author jjdelcerro
|
37 |
*/
|
38 |
public class DefaultExportServiceManager implements ExportServiceManager { |
39 |
|
40 |
private static final Logger LOG = LoggerFactory.getLogger(DefaultExportServiceManager.class); |
41 |
|
42 |
private final Map<String, ExportServiceFactory> factories; |
43 |
|
44 |
private final History<ExportParameters> history; |
45 |
private final Bookmarks<ExportParameters> bookmarks; |
46 |
|
47 |
public DefaultExportServiceManager() {
|
48 |
super();
|
49 |
this.factories = new HashMap<>(); |
50 |
this.history = new BaseHistory<ExportParameters>(10); |
51 |
this.bookmarks = new BaseBookmarks<ExportParameters>(); |
52 |
} |
53 |
|
54 |
@Override
|
55 |
public ExportServiceFactory getServiceFactory(String name) { |
56 |
ExportServiceFactory factory = this.factories.get(name);
|
57 |
if (factory == null) { |
58 |
throw new IllegalArgumentException("Don't exists export factory '" + name + "'."); |
59 |
} |
60 |
return factory;
|
61 |
} |
62 |
|
63 |
@Override
|
64 |
public ExportService createService(ExportParameters parameters) {
|
65 |
return this.getServiceFactory(parameters.getServiceName()).createService(parameters); |
66 |
} |
67 |
|
68 |
@Override
|
69 |
public ExportParameters createServiceParameters(String name) { |
70 |
return this.getServiceFactory(name).createParameters(); |
71 |
} |
72 |
|
73 |
@Override
|
74 |
public void register(ExportServiceFactory factory) { |
75 |
this.factories.put(factory.getName(), factory);
|
76 |
} |
77 |
|
78 |
@Override
|
79 |
public List<ExportServiceFactory> getAllServiceFactories() { |
80 |
List<ExportServiceFactory> result = new ArrayList<>(); |
81 |
result.addAll(this.factories.values());
|
82 |
return Collections.unmodifiableList(result); |
83 |
} |
84 |
|
85 |
@Override
|
86 |
public List<ExportServiceFactory> getServiceFactories(Filter<ExportServiceFactory> filter) { |
87 |
List<ExportServiceFactory> result = new ArrayList<>(); |
88 |
if (filter == null) { |
89 |
result.addAll(this.factories.values());
|
90 |
} else {
|
91 |
for (ExportServiceFactory factory : this.factories.values()) { |
92 |
if (factory.isEnabled() && filter.apply(factory)) {
|
93 |
result.add(factory); |
94 |
} |
95 |
} |
96 |
} |
97 |
return Collections.unmodifiableList(result); |
98 |
} |
99 |
|
100 |
@Override
|
101 |
public FixGeometryStatus fixGeometry(
|
102 |
ExportParametersGeometry parmeters, |
103 |
ICoordTrans coord_trans, |
104 |
Geometry geometry |
105 |
) { |
106 |
return ExportGeometryUtils.fixGeometry(parmeters, coord_trans, geometry);
|
107 |
} |
108 |
|
109 |
@Override
|
110 |
public ExportGeometryHelper createGeometryHelper(ExportParametersGeometry parameters, FeatureType theTargetFeatureType, FeatureType theSourceFeatureType) {
|
111 |
DefaultExportGeometryHelper helper = new DefaultExportGeometryHelper(
|
112 |
parameters, |
113 |
theTargetFeatureType, |
114 |
theSourceFeatureType |
115 |
); |
116 |
return helper;
|
117 |
|
118 |
} |
119 |
|
120 |
@Override
|
121 |
public ExportAttributes createExportAttributes() {
|
122 |
DefaultExportAttributes exp = new DefaultExportAttributes();
|
123 |
return exp;
|
124 |
} |
125 |
|
126 |
@Override
|
127 |
public History<ExportParameters> getHistory() {
|
128 |
return this.history; |
129 |
} |
130 |
|
131 |
@Override
|
132 |
public Bookmarks<ExportParameters> getBookmarks() {
|
133 |
return this.bookmarks; |
134 |
} |
135 |
} |