/
Activator.java
91 lines (80 loc) · 3.12 KB
/
Activator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*********************************************************************************************
*
*
* 'Activator.java', in plugin 'msi.gama.headless', is part of the source code of the GAMA modeling and simulation
* platform. (v. 1.8.1)
*
* (c) 2007-2020 UMI 209 UMMISCO IRD/UPMC & Partners
*
* Visit https://github.com/gama-platform/gama for license information and developers contact.
*
*
**********************************************************************************************/
package msi.gama.ext;
import javax.imageio.ImageIO;
import javax.media.jai.JAI;
import org.geotools.coverage.CoverageFactoryFinder;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.util.factory.GeoTools;
import org.geotools.util.factory.Hints;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import it.geosolutions.jaiext.ConcurrentOperationRegistry;
import one.util.streamex.StreamEx;
public class Activator implements BundleActivator {
private static BundleContext context;
static BundleContext getContext() {
return context;
}
/*
* (non-Javadoc)
*
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework. BundleContext)
*/
@Override
public void start(final BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
final JAI jaiDef = JAI.getDefaultInstance();
if (!(jaiDef.getOperationRegistry() instanceof ConcurrentOperationRegistry)) {
jaiDef.setOperationRegistry(ConcurrentOperationRegistry.initializeRegistry());
}
ImageIO.scanForPlugins();
Hints.putSystemDefault(Hints.FILTER_FACTORY, CommonFactoryFinder.getFilterFactory2(null));
Hints.putSystemDefault(Hints.STYLE_FACTORY, CommonFactoryFinder.getStyleFactory(null));
Hints.putSystemDefault(Hints.FEATURE_FACTORY, CommonFactoryFinder.getFeatureFactory(null));
Hints.putSystemDefault(Hints.USE_JAI_IMAGEREAD, true);
final Hints defHints = GeoTools.getDefaultHints();
//
// // Initialize GridCoverageFactory so that we don't make a lookup every time a factory is
// // needed
Hints.putSystemDefault(Hints.GRID_COVERAGE_FACTORY, CoverageFactoryFinder.getGridCoverageFactory(defHints));
// // Forces early initialisation of operation registry of JAI.
// // It fixes initialisation problems in some third party equinox
// // applications such as OpenMOLE.
//
// // final String os = System.getProperty("os.name");
// // if (!os.startsWith("Mac")) {
//
// // }
System.out.println(PAD("> JAI : ImageIO extensions", 45, ' ') + PAD(" loaded for", 15, '_') + " "
+ StreamEx.of(ImageIO.getReaderFileSuffixes()).joining("|"));
}
/*
* (non-Javadoc)
*
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(final BundleContext bundleContext) throws Exception {
Activator.context = null;
}
public static String PAD(final String string, final int minLength, final char pad) {
if (string.length() >= minLength) return string;
final StringBuilder sb = new StringBuilder(minLength);
sb.append(string);
for (int i = string.length(); i < minLength; i++) {
sb.append(pad);
}
return sb.toString();
}
}