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 @ 43925
History | View | Annotate | Download (3.96 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.ExportParameters; |
15 |
import org.gvsig.export.ExportParametersGeometry; |
16 |
import org.gvsig.export.Filter; |
17 |
import org.gvsig.export.impl.ExportGeometryUtils; |
18 |
import org.gvsig.export.spi.AttributeNamesTranslator; |
19 |
import org.gvsig.export.spi.ExportService; |
20 |
import org.gvsig.export.spi.ExportServiceFactory; |
21 |
import org.gvsig.export.spi.ExportServiceManager; |
22 |
import org.gvsig.fmap.dal.feature.FeatureType; |
23 |
import org.gvsig.fmap.geom.Geometry; |
24 |
import org.slf4j.Logger; |
25 |
import org.slf4j.LoggerFactory; |
26 |
|
27 |
/**
|
28 |
*
|
29 |
* @author jjdelcerro
|
30 |
*/
|
31 |
public class DefaultExportServiceManager implements ExportServiceManager { |
32 |
|
33 |
private static final Logger LOG = LoggerFactory.getLogger(DefaultExportServiceManager.class); |
34 |
|
35 |
private final Map<String,ExportServiceFactory> factories; |
36 |
|
37 |
public DefaultExportServiceManager() {
|
38 |
super();
|
39 |
this.factories = new HashMap<>(); |
40 |
} |
41 |
|
42 |
@Override
|
43 |
public AttributeNamesTranslator createAttributeNamesTranslator(FeatureType type, int maxNameLen) { |
44 |
return new DefaultAttributeNamesTranslator(type, maxNameLen); |
45 |
} |
46 |
|
47 |
@Override
|
48 |
public AttributeNamesTranslator createAttributeNamesTranslator() {
|
49 |
return new AttributeNamesTranslator() { |
50 |
@Override
|
51 |
public String getTargetName(String name) { |
52 |
return name;
|
53 |
} |
54 |
|
55 |
@Override
|
56 |
public String getSourceName(String name) { |
57 |
return name;
|
58 |
} |
59 |
|
60 |
@Override
|
61 |
public boolean hasTranslations() { |
62 |
return false; |
63 |
} |
64 |
|
65 |
@Override
|
66 |
public boolean hasTranslation(String name) { |
67 |
return false; |
68 |
} |
69 |
}; |
70 |
} |
71 |
|
72 |
@Override
|
73 |
public ExportServiceFactory getServiceFactory(String name) { |
74 |
ExportServiceFactory factory = this.factories.get(name);
|
75 |
if( factory == null ) { |
76 |
throw new IllegalArgumentException("Don't exists export factory '"+name+"'."); |
77 |
} |
78 |
return factory;
|
79 |
} |
80 |
|
81 |
@Override
|
82 |
public ExportService createService(ExportParameters parameters) {
|
83 |
return this.getServiceFactory(parameters.getServiceName()).createService(parameters); |
84 |
} |
85 |
|
86 |
@Override
|
87 |
public ExportParameters createServiceParameters(String name) { |
88 |
return this.getServiceFactory(name).createParameters(); |
89 |
} |
90 |
|
91 |
@Override
|
92 |
public void register(ExportServiceFactory factory) { |
93 |
this.factories.put(factory.getName(), factory);
|
94 |
} |
95 |
|
96 |
@Override
|
97 |
public List<ExportServiceFactory> getAllServiceFactories() { |
98 |
List<ExportServiceFactory> result = new ArrayList<>(); |
99 |
result.addAll(this.factories.values());
|
100 |
return Collections.unmodifiableList(result); |
101 |
} |
102 |
|
103 |
@Override
|
104 |
public List<ExportServiceFactory> getServiceFactories(Filter<ExportServiceFactory> filter) { |
105 |
List<ExportServiceFactory> result = new ArrayList<>(); |
106 |
if( filter == null ) { |
107 |
result.addAll(this.factories.values());
|
108 |
} else {
|
109 |
for (ExportServiceFactory factory : this.factories.values()) { |
110 |
if( factory.isEnabled() && filter.apply(factory) ) {
|
111 |
result.add(factory); |
112 |
} |
113 |
} |
114 |
} |
115 |
return Collections.unmodifiableList(result); |
116 |
} |
117 |
|
118 |
@Override
|
119 |
public FixGeometryStatus fixGeometry(
|
120 |
ExportParametersGeometry parmeters, |
121 |
ICoordTrans coord_trans, |
122 |
Geometry geometry |
123 |
) { |
124 |
return ExportGeometryUtils.fixGeometry(parmeters, coord_trans, geometry);
|
125 |
} |
126 |
} |