| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
package org.locationtech.jts.util; |
| 13 |
|
| 14 |
import java.lang.reflect.Method; |
| 15 |
|
| 16 |
import org.locationtech.jts.geom.Geometry; |
| 17 |
|
| 18 |
/** |
| 19 |
* A proxy to call TestBuilder functions dynamically. |
| 20 |
* If TestBuilder is not present, functions act as a no-op. |
| 21 |
* <p> |
| 22 |
* This class is somewhat experimental at the moment, so |
| 23 |
* is not recommended for production use. |
| 24 |
* |
| 25 |
* @author Martin Davis |
| 26 |
* |
| 27 |
*/ |
| 28 |
public class TestBuilderProxy { |
| 29 |
|
| 30 |
private static final String CLASS_FUNCTIONS_UTIL = "org.locationtech.jtstest.function.FunctionsUtil"; |
| 31 |
private static Class<?> tbClass; |
| 32 |
private static Method methodShowIndicator; |
| 33 |
|
| 34 |
private static void init() { |
| 35 |
if (tbClass != null) return; |
| 36 |
try { |
| 37 |
tbClass = TestBuilderProxy.class.getClassLoader().loadClass(CLASS_FUNCTIONS_UTIL); |
| 38 |
methodShowIndicator = tbClass.getMethod("showIndicator", Geometry.class); |
| 39 |
} |
| 40 |
catch (Exception ex) { |
| 41 |
|
| 42 |
|
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Tests whether the proxy is active (i.e. the TestBuilder is available). |
| 48 |
* This allows avoiding expensive geometry materialization if not needed. |
| 49 |
* |
| 50 |
* @return true if the proxy is active |
| 51 |
*/ |
| 52 |
public static boolean isActive() { |
| 53 |
init(); |
| 54 |
return tbClass != null; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public static void showIndicator(Geometry geom) { |
| 61 |
init(); |
| 62 |
if (methodShowIndicator == null) return; |
| 63 |
|
| 64 |
try { |
| 65 |
methodShowIndicator.invoke(null, geom); |
| 66 |
} catch (Exception e) { |
| 67 |
|
| 68 |
|
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
|