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 @ 44270
History | View | Annotate | Download (4.08 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.slf4j.Logger; |
27 |
import org.slf4j.LoggerFactory; |
28 |
|
29 |
/**
|
30 |
*
|
31 |
* @author jjdelcerro
|
32 |
*/
|
33 |
public class DefaultExportServiceManager implements ExportServiceManager { |
34 |
|
35 |
private static final Logger LOG = LoggerFactory.getLogger(DefaultExportServiceManager.class); |
36 |
|
37 |
private final Map<String,ExportServiceFactory> factories; |
38 |
|
39 |
public DefaultExportServiceManager() {
|
40 |
super();
|
41 |
this.factories = new HashMap<>(); |
42 |
} |
43 |
|
44 |
@Override
|
45 |
public AttributeNamesTranslator createAttributeNamesTranslator(int maxNameLen) { |
46 |
return new DefaultAttributeNamesTranslator(maxNameLen); |
47 |
} |
48 |
|
49 |
@Override
|
50 |
public AttributeNamesTranslator createAttributeNamesTranslator() {
|
51 |
return new DefaultAttributeNamesTranslator(10); |
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(FeatureType featureType) {
|
122 |
DefaultExportAttributes exp = new DefaultExportAttributes(featureType);
|
123 |
return exp;
|
124 |
} |
125 |
} |