-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scan classpath for EDD subclasses/dataset types
This change uses reflection, specifically the ClassGraph classpath scanner, to discover concrete EDD subclasses and associated class metadata (fromXml methods and Sax handlers for XML deseralization) at runtime. The scan is performed once and stored in a static map for use in XML deserialization methods. In addition to eliminating the need to register various EDD implementations in the ERDDAP codebase in EDD.fromXml and HandlerFactory.getHandlerFor, this change also allows loading of third party EDD implementations at runtime. In local testing classpath scanning took about 1 second. This scan occurs only once at startup. Scanning is confined to EDD's package (gov.noaa.pfel.erddap.dataset) for performance reasons; scanning all packages took around 12 seconds. For this reason, all EDD implementations need to belong to the gov.noaa.pfel.erddap.dataset package to be detected. This adds a dependency on classgraph, which is very small (~560k).
- Loading branch information
1 parent
5a0d0c8
commit e672ee3
Showing
27 changed files
with
294 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDFromXmlMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package gov.noaa.pfel.erddap.dataset; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Indicates that the annotated method should be used to create an EDD object from an XML string | ||
* (non-Sax parser approach) | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface EDDFromXmlMethod {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
import gov.noaa.pfel.coastwatch.util.SSR; | ||
import gov.noaa.pfel.coastwatch.util.SimpleXMLReader; | ||
import gov.noaa.pfel.erddap.Erddap; | ||
import gov.noaa.pfel.erddap.handlers.EDDGridAggregateExistingDimensionHandler; | ||
import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; | ||
import gov.noaa.pfel.erddap.util.EDStatic; | ||
import gov.noaa.pfel.erddap.variable.*; | ||
import java.text.MessageFormat; | ||
|
@@ -31,6 +33,7 @@ | |
* | ||
* @author Bob Simons (was [email protected], now [email protected]) 2008-02-04 | ||
*/ | ||
@SaxHandlerClass(EDDGridAggregateExistingDimensionHandler.class) | ||
public class EDDGridAggregateExistingDimension extends EDDGrid { | ||
|
||
protected EDDGrid childDatasets[]; | ||
|
@@ -53,6 +56,7 @@ public class EDDGridAggregateExistingDimension extends EDDGrid { | |
* <erddapDatasets></dataset> . | ||
* @throws Throwable if trouble | ||
*/ | ||
@EDDFromXmlMethod | ||
public static EDDGridAggregateExistingDimension fromXml(Erddap erddap, SimpleXMLReader xmlReader) | ||
throws Throwable { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
import gov.noaa.pfel.coastwatch.util.SSR; | ||
import gov.noaa.pfel.coastwatch.util.SimpleXMLReader; | ||
import gov.noaa.pfel.erddap.Erddap; | ||
import gov.noaa.pfel.erddap.handlers.EDDGridCopyHandler; | ||
import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; | ||
import gov.noaa.pfel.erddap.util.EDStatic; | ||
import gov.noaa.pfel.erddap.util.TaskThread; | ||
import gov.noaa.pfel.erddap.variable.*; | ||
|
@@ -33,6 +35,7 @@ | |
* | ||
* @author Bob Simons (was [email protected], now [email protected]) 2009-05-25 | ||
*/ | ||
@SaxHandlerClass(EDDGridCopyHandler.class) | ||
public class EDDGridCopy extends EDDGrid { | ||
|
||
protected EDDGrid sourceEdd; | ||
|
@@ -61,6 +64,7 @@ public class EDDGridCopy extends EDDGrid { | |
* <erddapDatasets></dataset> . | ||
* @throws Throwable if trouble | ||
*/ | ||
@EDDFromXmlMethod | ||
public static EDDGridCopy fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { | ||
|
||
// data to be obtained (or not) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ | |
import gov.noaa.pfel.coastwatch.util.SSR; | ||
import gov.noaa.pfel.coastwatch.util.SimpleXMLReader; | ||
import gov.noaa.pfel.erddap.Erddap; | ||
import gov.noaa.pfel.erddap.handlers.EDDGridFromDapHandler; | ||
import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; | ||
import gov.noaa.pfel.erddap.util.EDStatic; | ||
import gov.noaa.pfel.erddap.variable.*; | ||
import java.io.ByteArrayInputStream; | ||
|
@@ -56,6 +58,7 @@ | |
* | ||
* @author Bob Simons (was [email protected], now [email protected]) 2007-06-04 | ||
*/ | ||
@SaxHandlerClass(EDDGridFromDapHandler.class) | ||
public class EDDGridFromDap extends EDDGrid { | ||
|
||
/** | ||
|
@@ -74,6 +77,7 @@ public class EDDGridFromDap extends EDDGrid { | |
* <erddapDatasets></dataset> . | ||
* @throws Throwable if trouble | ||
*/ | ||
@EDDFromXmlMethod | ||
public static EDDGridFromDap fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { | ||
|
||
// data to be obtained (or not) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
import gov.noaa.pfel.coastwatch.pointdata.Table; | ||
import gov.noaa.pfel.coastwatch.util.SimpleXMLReader; | ||
import gov.noaa.pfel.erddap.Erddap; | ||
import gov.noaa.pfel.erddap.handlers.EDDGridFromEDDTableHandler; | ||
import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; | ||
import gov.noaa.pfel.erddap.util.EDStatic; | ||
import gov.noaa.pfel.erddap.variable.*; | ||
import java.io.DataInputStream; | ||
|
@@ -33,6 +35,7 @@ | |
* | ||
* @author Bob Simons (was [email protected], now [email protected]) 2015-01-27 | ||
*/ | ||
@SaxHandlerClass(EDDGridFromEDDTableHandler.class) | ||
public class EDDGridFromEDDTable extends EDDGrid { | ||
|
||
protected EDDTable eddTable; | ||
|
@@ -55,6 +58,7 @@ public class EDDGridFromEDDTable extends EDDGrid { | |
* <erddapDatasets></dataset> . | ||
* @throws Throwable if trouble | ||
*/ | ||
@EDDFromXmlMethod | ||
public static EDDGridFromEDDTable fromXml(Erddap erddap, SimpleXMLReader xmlReader) | ||
throws Throwable { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ | |
import gov.noaa.pfel.coastwatch.util.SSR; | ||
import gov.noaa.pfel.coastwatch.util.SimpleXMLReader; | ||
import gov.noaa.pfel.erddap.Erddap; | ||
import gov.noaa.pfel.erddap.handlers.EDDGridFromErddapHandler; | ||
import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; | ||
import gov.noaa.pfel.erddap.util.EDStatic; | ||
import gov.noaa.pfel.erddap.variable.*; | ||
import java.io.BufferedReader; | ||
|
@@ -42,6 +44,7 @@ | |
* | ||
* @author Bob Simons ([email protected]) 2007-06-04 | ||
*/ | ||
@SaxHandlerClass(EDDGridFromErddapHandler.class) | ||
public class EDDGridFromErddap extends EDDGrid implements FromErddap { | ||
|
||
protected double sourceErddapVersion = | ||
|
@@ -67,6 +70,7 @@ public class EDDGridFromErddap extends EDDGrid implements FromErddap { | |
* <erddapDatasets></dataset> . | ||
* @throws Throwable if trouble | ||
*/ | ||
@EDDFromXmlMethod | ||
public static EDDGridFromErddap fromXml(Erddap erddap, SimpleXMLReader xmlReader) | ||
throws Throwable { | ||
|
||
|
Oops, something went wrong.