diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDD.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDD.java index 0ee6ba4c..f5542db4 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDD.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDD.java @@ -37,8 +37,20 @@ import gov.noaa.pfel.coastwatch.util.Tally; import gov.noaa.pfel.erddap.Erddap; import gov.noaa.pfel.erddap.handlers.SaxHandler; -import gov.noaa.pfel.erddap.util.*; -import gov.noaa.pfel.erddap.variable.*; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; +import gov.noaa.pfel.erddap.handlers.State; +import gov.noaa.pfel.erddap.util.CfToFromGcmd; +import gov.noaa.pfel.erddap.util.EDStatic; +import gov.noaa.pfel.erddap.util.EmailThread; +import gov.noaa.pfel.erddap.util.Subscriptions; +import gov.noaa.pfel.erddap.util.TaskThread; +import gov.noaa.pfel.erddap.util.TouchThread; +import gov.noaa.pfel.erddap.variable.EDV; +import io.github.classgraph.AnnotationClassRef; +import io.github.classgraph.AnnotationInfo; +import io.github.classgraph.ClassGraph; +import io.github.classgraph.ClassInfo; +import io.github.classgraph.ScanResult; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.BufferedOutputStream; @@ -47,6 +59,8 @@ import java.io.OutputStream; import java.io.StringWriter; import java.io.Writer; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; @@ -54,10 +68,15 @@ import java.util.GregorianCalendar; import java.util.HashMap; import java.util.HashSet; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.ReentrantLock; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; @@ -405,6 +424,103 @@ public boolean filesInPrivateS3Bucket() { return filesInPrivateS3Bucket; } + /** Internal class for storing conrete EDD subclass information. */ + public static final class EDDClassInfo { + private Class eddClass; + private Optional fromXmlMethod; + private Optional> saxHandlerClass; + + public EDDClassInfo( + Class eddClass, + Optional fromXmlMethod, + Optional> saxHandlerClass) { + this.eddClass = eddClass; + this.fromXmlMethod = fromXmlMethod; + this.saxHandlerClass = saxHandlerClass; + } + + public Class getEddClass() { + return eddClass; + } + + public boolean hasFromXmlMethod() { + return fromXmlMethod.isPresent(); + } + + public Optional getFromXmlMethod() { + return fromXmlMethod; + } + + public boolean hasSaxHandlerClass() { + return saxHandlerClass.isPresent(); + } + + public Optional> getSaxHandlerClass() { + return saxHandlerClass; + } + } + + /** List of all concrete/non-abstact EDD subclass EDDClassInfo */ + public static final Map EDD_CLASS_INFO_MAP = initEddClassInfoMap(); + + /** + * Scan classpath for concrete/non-abstract EDD subclasses in package gov.noaa.pfel.erddap.dataset + * and store metadata for each discovered subclass in map of EDDClassInfo objects. + */ + private static final Map initEddClassInfoMap() { + String2.log("Scanning EDD classes in package " + EDD.class.getPackageName()); + try (ScanResult scanResult = + new ClassGraph() + .enableAnnotationInfo() + .enableClassInfo() + .enableMethodInfo() + .acceptPackages(EDD.class.getPackageName()) + .scan()) { + return scanResult.getSubclasses(EDD.class).stream() + .filter(c -> !c.isAbstract()) + .collect( + Collectors.toUnmodifiableMap( + ClassInfo::getSimpleName, + classInfo -> + new EDDClassInfo( + (Class) classInfo.loadClass(), + getFromXmlMethod(classInfo), + getSaxHandler(classInfo)))); + } + } + + /** + * Get State (Sax handler) class for EDD class from annotation if it exists + * + * @param eddClassInfo the ClassInfo object to check + * @return Optional of the State class + */ + private static final Optional> getSaxHandler(ClassInfo classInfo) { + return Stream.of(classInfo.getAnnotationInfo(SaxHandlerClass.class)) + .filter(Objects::nonNull) + .map(AnnotationInfo::getParameterValues) + .map(parameterValues -> parameterValues.get("value")) + .filter(Objects::nonNull) + .map(annotationParameterValue -> (AnnotationClassRef) annotationParameterValue.getValue()) + .filter(annotationClassRef -> annotationClassRef != null) + .map(annotationClassRef -> (Class) annotationClassRef.loadClass()) + .filter(Objects::nonNull) + .findFirst(); + } + + /** + * Get fromXml method annotated with EDDFromXmlMethod from EDD class if it exists + * + * @param eddClassInfo the ClassInfo object to check + * @return Optional of the fromXml method + */ + private static final Optional getFromXmlMethod(ClassInfo classInfo) { + return classInfo.getMethodInfo("fromXml").stream() + .filter(mi -> mi.hasAnnotation(EDDFromXmlMethod.class)) + .map(mi -> mi.loadClassAndGetMethod()) + .findFirst(); + } + /** * This constructs an EDDXxx based on the information in an .xml file. This ignores the * <dataset active=.... > setting. All of the subclasses fromXml() methods ignore the @@ -422,94 +538,24 @@ public static EDD fromXml(Erddap erddap, String type, SimpleXMLReader xmlReader) String startStartError = "datasets.xml error on"; // does the error message already start with this? String startError = "datasets.xml error on or before line #"; - if (type == null) - throw new SimpleException( + EDDClassInfo eddClassInfo = EDD_CLASS_INFO_MAP.get(type); + if (eddClassInfo == null || !eddClassInfo.hasFromXmlMethod()) { + throw new RuntimeException( startError + xmlReader.lineNumber() + ": Unexpected type=" + type + "."); + } + try { - // FUTURE: classes could be added at runtime if I used reflection - if (type.equals("EDDGridAggregateExistingDimension")) - return EDDGridAggregateExistingDimension.fromXml(erddap, xmlReader); - if (type.equals("EDDGridCopy")) return EDDGridCopy.fromXml(erddap, xmlReader); - if (type.equals("EDDGridFromAudioFiles")) - return EDDGridFromAudioFiles.fromXml(erddap, xmlReader); - if (type.equals("EDDGridFromDap")) return EDDGridFromDap.fromXml(erddap, xmlReader); - if (type.equals("EDDGridFromEDDTable")) return EDDGridFromEDDTable.fromXml(erddap, xmlReader); - if (type.equals("EDDGridFromErddap")) return EDDGridFromErddap.fromXml(erddap, xmlReader); - if (type.equals("EDDGridFromEtopo")) return EDDGridFromEtopo.fromXml(erddap, xmlReader); - if (type.equals("EDDGridFromMergeIRFiles")) - return EDDGridFromMergeIRFiles.fromXml(erddap, xmlReader); - if (type.equals("EDDGridFromNcFiles")) return EDDGridFromNcFiles.fromXml(erddap, xmlReader); - if (type.equals("EDDGridFromNcFilesUnpacked")) - return EDDGridFromNcFilesUnpacked.fromXml(erddap, xmlReader); - if (type.equals("EDDGridLonPM180")) return EDDGridLonPM180.fromXml(erddap, xmlReader); - if (type.equals("EDDGridLon0360")) return EDDGridLon0360.fromXml(erddap, xmlReader); - if (type.equals("EDDGridSideBySide")) return EDDGridSideBySide.fromXml(erddap, xmlReader); - - if (type.equals("EDDTableAggregateRows")) - return EDDTableAggregateRows.fromXml(erddap, xmlReader); - if (type.equals("EDDTableCopy")) return EDDTableCopy.fromXml(erddap, xmlReader); - // if (type.equals("EDDTableCopyPost")) return EDDTableCopyPost.fromXml(erddap, - // xmlReader); //inactive - if (type.equals("EDDTableFromAsciiServiceNOS")) - return EDDTableFromAsciiServiceNOS.fromXml(erddap, xmlReader); - // if (type.equals("EDDTableFromBMDE")) return EDDTableFromBMDE.fromXml(erddap, - // xmlReader); //inactive - if (type.equals("EDDTableFromCassandra")) - return EDDTableFromCassandra.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromDapSequence")) - return EDDTableFromDapSequence.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromDatabase")) - return EDDTableFromDatabase.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromEDDGrid")) return EDDTableFromEDDGrid.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromErddap")) return EDDTableFromErddap.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromFileNames")) - return EDDTableFromFileNames.fromXml(erddap, xmlReader); - // if (type.equals("EDDTableFromMWFS")) return EDDTableFromMWFS.fromXml(erddap, - // xmlReader); //inactive as of 2009-01-14 - if (type.equals("EDDTableFromAsciiFiles")) - return EDDTableFromAsciiFiles.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromAudioFiles")) - return EDDTableFromAudioFiles.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromAwsXmlFiles")) - return EDDTableFromAwsXmlFiles.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromColumnarAsciiFiles")) - return EDDTableFromColumnarAsciiFiles.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromHttpGet")) return EDDTableFromHttpGet.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromInvalidCRAFiles")) - return EDDTableFromInvalidCRAFiles.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromJsonlCSVFiles")) - return EDDTableFromJsonlCSVFiles.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromHyraxFiles")) - return EDDTableFromHyraxFiles.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromMultidimNcFiles")) - return EDDTableFromMultidimNcFiles.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromNcFiles")) return EDDTableFromNcFiles.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromNcCFFiles")) - return EDDTableFromNcCFFiles.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromNccsvFiles")) - return EDDTableFromNccsvFiles.fromXml(erddap, xmlReader); - // if (type.equals("EDDTableFromNOS")) return EDDTableFromNOS.fromXml(erddap, - // xmlReader); //inactive 2010-09-08 - // if (type.equals("EDDTableFromNWISDV")) return EDDTableFromNWISDV.fromXml(erddap, - // xmlReader); //inactive 2011-12-16 - if (type.equals("EDDTableFromOBIS")) return EDDTableFromOBIS.fromXml(erddap, xmlReader); - // if (type.equals("EDDTableFromPostDatabase"))return EDDTableFromPostDatabase.fromXml(erddap, - // xmlReader); - // if (type.equals("EDDTableFromPostNcFiles")) return EDDTableFromPostNcFiles.fromXml(erddap, - // xmlReader); - if (type.equals("EDDTableFromSOS")) return EDDTableFromSOS.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromThreddsFiles")) - return EDDTableFromThreddsFiles.fromXml(erddap, xmlReader); - if (type.equals("EDDTableFromWFSFiles")) - return EDDTableFromWFSFiles.fromXml(erddap, xmlReader); + return (EDD) eddClassInfo.getFromXmlMethod().get().invoke(null, erddap, xmlReader); } catch (Throwable t) { + // unwrap InvocationTargetExceptions + if (t instanceof InvocationTargetException && t.getCause() != null) { + t = t.getCause(); + } String msg = MustBe.getShortErrorMessage(t); throw new RuntimeException( (msg.startsWith(startStartError) ? "" : startError + xmlReader.lineNumber() + ": ") + msg, t); } - throw new RuntimeException( - startError + xmlReader.lineNumber() + ": Unexpected type=" + type + "."); } /** diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDFromXmlMethod.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDFromXmlMethod.java new file mode 100644 index 00000000..0fe909d0 --- /dev/null +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDFromXmlMethod.java @@ -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 {} diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridAggregateExistingDimension.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridAggregateExistingDimension.java index b1a15acb..3b54a705 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridAggregateExistingDimension.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridAggregateExistingDimension.java @@ -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 bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 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 { diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridCopy.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridCopy.java index 55c51ace..88076e4d 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridCopy.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridCopy.java @@ -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 bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 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) diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromDap.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromDap.java index 76b75d64..4d768349 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromDap.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromDap.java @@ -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 bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 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) diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromEDDTable.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromEDDTable.java index d399d5d8..a0dea856 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromEDDTable.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromEDDTable.java @@ -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 bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 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 { diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromErddap.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromErddap.java index 9496a6d5..394eef69 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromErddap.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromErddap.java @@ -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 (bob.simons@noaa.gov) 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 { diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromEtopo.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromEtopo.java index fbc1d1a2..3530f211 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromEtopo.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromEtopo.java @@ -23,6 +23,8 @@ import gov.noaa.pfel.coastwatch.sgt.SgtMap; import gov.noaa.pfel.coastwatch.util.SimpleXMLReader; import gov.noaa.pfel.erddap.Erddap; +import gov.noaa.pfel.erddap.handlers.EDDGridFromEtopoHandler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.variable.*; import java.io.BufferedOutputStream; @@ -41,6 +43,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2008-02-20 */ +@SaxHandlerClass(EDDGridFromEtopoHandler.class) public class EDDGridFromEtopo extends EDDGrid { /** Properties of the datafile */ @@ -73,6 +76,7 @@ public class EDDGridFromEtopo extends EDDGrid { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDGridFromEtopo fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { // data to be obtained (or not) diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromFiles.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromFiles.java index 61fc7f28..5b1612b1 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromFiles.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridFromFiles.java @@ -31,6 +31,8 @@ import gov.noaa.pfel.coastwatch.util.WatchDirectory; import gov.noaa.pfel.coastwatch.util.WatchUpdateHandler; import gov.noaa.pfel.erddap.Erddap; +import gov.noaa.pfel.erddap.handlers.EDDGridFromFilesHandler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.util.ThreadedWorkManager; import gov.noaa.pfel.erddap.variable.*; @@ -64,6 +66,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2008-11-26 */ +@SaxHandlerClass(EDDGridFromFilesHandler.class) public abstract class EDDGridFromFiles extends EDDGrid implements WatchUpdateHandler { public static final String MF_FIRST = "first", MF_LAST = "last"; @@ -164,6 +167,7 @@ public static int suggestUpdateEveryNMillis(String tFileDir) { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDGridFromFiles fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridLon0360.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridLon0360.java index 40925c50..9928fb6c 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridLon0360.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridLon0360.java @@ -21,6 +21,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.EDDGridLon0360Handler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.variable.*; import java.io.BufferedReader; @@ -32,6 +34,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2021-05-28 */ +@SaxHandlerClass(EDDGridLon0360Handler.class) public class EDDGridLon0360 extends EDDGrid { private EDDGrid childDataset; @@ -65,6 +68,7 @@ public class EDDGridLon0360 extends EDDGrid { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDGridLon0360 fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { if (verbose) String2.log("\n*** constructing EDDGridLon0360(xmlReader)..."); diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridLonPM180.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridLonPM180.java index 494b1261..a3af28ba 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridLonPM180.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridLonPM180.java @@ -21,6 +21,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.EDDGridLonPM180Handler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.variable.*; import java.io.BufferedReader; @@ -32,6 +34,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2015-08-05 */ +@SaxHandlerClass(EDDGridLonPM180Handler.class) public class EDDGridLonPM180 extends EDDGrid { private EDDGrid childDataset; @@ -64,6 +67,7 @@ public class EDDGridLonPM180 extends EDDGrid { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDGridLonPM180 fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { if (verbose) String2.log("\n*** constructing EDDGridLonPM180(xmlReader)..."); diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridSideBySide.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridSideBySide.java index 1a2199dc..c76f108c 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridSideBySide.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDGridSideBySide.java @@ -15,6 +15,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.EDDGridSideBySideHandler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.variable.*; import java.text.MessageFormat; @@ -36,6 +38,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2008-02-04 */ +@SaxHandlerClass(EDDGridSideBySideHandler.class) public class EDDGridSideBySide extends EDDGrid { protected EDDGrid childDatasets[]; @@ -59,6 +62,7 @@ public class EDDGridSideBySide extends EDDGrid { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDGridSideBySide fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableAggregateRows.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableAggregateRows.java index 0b25a345..5426d58b 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableAggregateRows.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableAggregateRows.java @@ -15,6 +15,8 @@ import com.cohort.util.Test; import gov.noaa.pfel.coastwatch.util.SimpleXMLReader; import gov.noaa.pfel.erddap.Erddap; +import gov.noaa.pfel.erddap.handlers.EDDTableAggregateRowsHandler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.variable.*; import java.util.ArrayList; @@ -27,6 +29,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2016-02-19 */ +@SaxHandlerClass(EDDTableAggregateRowsHandler.class) public class EDDTableAggregateRows extends EDDTable { protected int nChildren; @@ -48,6 +51,7 @@ public class EDDTableAggregateRows extends EDDTable { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDTableAggregateRows fromXml(Erddap tErddap, SimpleXMLReader xmlReader) throws Throwable { diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableCopy.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableCopy.java index 5272e6cd..b07cadef 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableCopy.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableCopy.java @@ -15,6 +15,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.EDDTableCopyHandler; +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.*; @@ -25,6 +27,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2009-05-19 */ +@SaxHandlerClass(EDDTableCopyHandler.class) public class EDDTableCopy extends EDDTable { protected EDDTable sourceEdd; @@ -58,6 +61,7 @@ public int defaultStandardizeWhat() { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDTableCopy fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { // data to be obtained (or not) diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromAsciiService.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromAsciiService.java index fe5738ce..dda6fa50 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromAsciiService.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromAsciiService.java @@ -15,6 +15,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.EDDTableFromAsciiServiceHandler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.variable.*; import java.io.BufferedReader; @@ -28,6 +30,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2010-11-12 */ +@SaxHandlerClass(EDDTableFromAsciiServiceHandler.class) public abstract class EDDTableFromAsciiService extends EDDTable { protected String beforeData[]; @@ -48,6 +51,7 @@ public abstract class EDDTableFromAsciiService extends EDDTable { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDTableFromAsciiService fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromCassandra.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromCassandra.java index 3be3505e..50e62a83 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromCassandra.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromCassandra.java @@ -228,6 +228,8 @@ PRIMARY KEY ((deviceid, date), sampletime) 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.EDDTableFromCassandraHandler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.variable.*; import java.io.BufferedReader; @@ -260,6 +262,7 @@ PRIMARY KEY ((deviceid, date), sampletime) * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2014-11-03 */ +@SaxHandlerClass(EDDTableFromCassandraHandler.class) public class EDDTableFromCassandra extends EDDTable { // see getSession @@ -317,6 +320,7 @@ public class EDDTableFromCassandra extends EDDTable { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDTableFromCassandra fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromDapSequence.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromDapSequence.java index c051570a..4c08420a 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromDapSequence.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromDapSequence.java @@ -23,6 +23,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.EDDTableFromDapSequenceHandler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.variable.*; import java.io.ByteArrayInputStream; @@ -34,6 +36,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2007-06-08 */ +@SaxHandlerClass(EDDTableFromDapSequenceHandler.class) public class EDDTableFromDapSequence extends EDDTable { protected String outerSequenceName, innerSequenceName; @@ -58,6 +61,7 @@ public class EDDTableFromDapSequence extends EDDTable { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDTableFromDapSequence fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromDatabase.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromDatabase.java index 45d1885e..9ed7a732 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromDatabase.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromDatabase.java @@ -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.EDDTableFromDatabaseHandler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.variable.*; import java.math.BigDecimal; @@ -47,6 +49,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2007-06-08 */ +@SaxHandlerClass(EDDTableFromDatabaseHandler.class) public class EDDTableFromDatabase extends EDDTable { /** set by the constructor */ @@ -79,6 +82,7 @@ public class EDDTableFromDatabase extends EDDTable { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDTableFromDatabase fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { return lowFromXml(erddap, xmlReader, ""); diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromEDDGrid.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromEDDGrid.java index 08ff288f..6a849b0c 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromEDDGrid.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromEDDGrid.java @@ -21,6 +21,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.EDDTableFromEDDGridHandler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.variable.*; import java.io.BufferedReader; @@ -31,6 +33,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2013-03-08 */ +@SaxHandlerClass(EDDTableFromEDDGridHandler.class) public class EDDTableFromEDDGrid extends EDDTable { public static final int DEFAULT_MAX_AXIS0 = 10; @@ -53,6 +56,7 @@ public class EDDTableFromEDDGrid extends EDDTable { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDTableFromEDDGrid fromXml(Erddap tErddap, SimpleXMLReader xmlReader) throws Throwable { diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromErddap.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromErddap.java index a084463c..52dd92b9 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromErddap.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromErddap.java @@ -22,6 +22,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.EDDTableFromErddapHandler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.variable.*; import java.io.BufferedReader; @@ -29,16 +31,13 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.BitSet; -import ucar.ma2.*; -import ucar.nc2.*; -// import ucar.nc2.dods.*; -import ucar.nc2.util.*; /** * This class represents a table of data from an opendap sequence source. * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2007-06-08 */ +@SaxHandlerClass(EDDTableFromErddapHandler.class) public class EDDTableFromErddap extends EDDTable implements FromErddap { protected double sourceErddapVersion = @@ -66,6 +65,7 @@ public class EDDTableFromErddap extends EDDTable implements FromErddap { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDTableFromErddap fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromFileNames.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromFileNames.java index 5b2ebe6f..ba4d9228 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromFileNames.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromFileNames.java @@ -25,6 +25,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.EDDTableFromFileNamesHandler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.variable.*; import java.util.ArrayList; @@ -40,6 +42,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2015-01-06 */ +@SaxHandlerClass(EDDTableFromFileNamesHandler.class) public class EDDTableFromFileNames extends EDDTable { protected String fileDir; // has forward slashes and trailing slash @@ -99,6 +102,7 @@ public class EDDTableFromFileNames extends EDDTable { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDTableFromFileNames fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromFiles.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromFiles.java index de882683..3e86cfc2 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromFiles.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromFiles.java @@ -33,6 +33,8 @@ import gov.noaa.pfel.coastwatch.util.WatchDirectory; import gov.noaa.pfel.coastwatch.util.WatchUpdateHandler; import gov.noaa.pfel.erddap.Erddap; +import gov.noaa.pfel.erddap.handlers.EDDTableFromFilesHandler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.util.ThreadedWorkManager; import gov.noaa.pfel.erddap.variable.*; @@ -60,6 +62,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2008-04-12 */ +@SaxHandlerClass(EDDTableFromFilesHandler.class) public abstract class EDDTableFromFiles extends EDDTable implements WatchUpdateHandler { public static final String MF_FIRST = "first", MF_LAST = "last"; @@ -198,6 +201,7 @@ public static int suggestUpdateEveryNMillis(String tFileDir) { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDTableFromFiles fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromOBIS.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromOBIS.java index 03049f05..efb93282 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromOBIS.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromOBIS.java @@ -17,6 +17,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.EDDTableFromOBISHandler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.variable.*; import java.util.Arrays; @@ -28,6 +30,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2007-10-22 */ +@SaxHandlerClass(EDDTableFromOBISHandler.class) public class EDDTableFromOBIS extends EDDTable { protected String sourceCode; @@ -196,6 +199,7 @@ public class EDDTableFromOBIS extends EDDTable { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDTableFromOBIS fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromSOS.java b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromSOS.java index b5076052..2e44107f 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromSOS.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTableFromSOS.java @@ -24,6 +24,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.EDDTableFromSOSHandler; +import gov.noaa.pfel.erddap.handlers.SaxHandlerClass; import gov.noaa.pfel.erddap.util.EDStatic; import gov.noaa.pfel.erddap.variable.*; import java.io.BufferedReader; @@ -103,6 +105,7 @@ * * @author Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2007-09-21 */ +@SaxHandlerClass(EDDTableFromSOSHandler.class) public class EDDTableFromSOS extends EDDTable { /** stationTable */ @@ -179,6 +182,7 @@ public static String defaultResponseFormat(String tSosServerType) { * <erddapDatasets></dataset> . * @throws Throwable if trouble */ + @EDDFromXmlMethod public static EDDTableFromSOS fromXml(Erddap erddap, SimpleXMLReader xmlReader) throws Throwable { // data to be obtained (or not) diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/handlers/HandlerFactory.java b/WEB-INF/classes/gov/noaa/pfel/erddap/handlers/HandlerFactory.java index 27e1f29c..a82de4cd 100644 --- a/WEB-INF/classes/gov/noaa/pfel/erddap/handlers/HandlerFactory.java +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/handlers/HandlerFactory.java @@ -10,6 +10,9 @@ import gov.noaa.pfel.erddap.Erddap; import gov.noaa.pfel.erddap.dataset.EDD; import gov.noaa.pfel.erddap.util.EDStatic; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Parameter; import java.util.HashSet; public class HandlerFactory { @@ -32,99 +35,51 @@ public static State getHandlerFor( EDStatic.cldStartMillis = timeToLoadThisDataset; EDStatic.cldDatasetID = datasetID; + EDD.EDDClassInfo eddClassInfo = EDD.EDD_CLASS_INFO_MAP.get(datasetType); + if (eddClassInfo == null || !eddClassInfo.hasSaxHandlerClass()) { + throw new IllegalArgumentException("Unknown dataset type: " + datasetType); + } + nTry++; context.getNTryAndDatasets()[0] = nTry; - switch (datasetType) { - case "EDDTableFromErddap" -> { - return new EDDTableFromErddapHandler(saxHandler, datasetID, completeState); - } - case "EDDTableFromEDDGrid" -> { - return new EDDTableFromEDDGridHandler(saxHandler, datasetID, completeState, context); - } - case "EDDGridFromDap" -> { - return new EDDGridFromDapHandler(saxHandler, datasetID, completeState); - } - case "EDDGridLonPM180" -> { - return new EDDGridLonPM180Handler(saxHandler, datasetID, completeState, context); - } - case "EDDGridFromErddap" -> { - return new EDDGridFromErddapHandler(saxHandler, datasetID, completeState); - } - case "EDDTableFromAsciiFiles", - "EDDTableFromNcFiles", - "EDDTableFromAudioFiles", - "EDDTableFromAwsXmlFiles", - "EDDTableFromColumnarAsciiFiles", - "EDDTableFromHttpGet", - "EDDTableFromInvalidCRAFiles", - "EDDTableFromJsonlCSVFiles", - "EDDTableFromMultidimNcFiles", - "EDDTableFromNcCFFiles", - "EDDTableFromNccsvFiles", - "EDDTableFromHyraxFiles", - "EDDTableFromThreddsFiles", - "EDDTableFromWFSFiles" -> { - return new EDDTableFromFilesHandler(saxHandler, datasetID, completeState, datasetType); - } - case "EDDGridAggregateExistingDimension" -> { - return new EDDGridAggregateExistingDimensionHandler( - saxHandler, datasetID, completeState, context); - } - case "EDDGridCopy" -> { - return new EDDGridCopyHandler(saxHandler, datasetID, completeState, context); - } - case "EDDGridFromEDDTable" -> { - return new EDDGridFromEDDTableHandler(saxHandler, datasetID, completeState, context); - } - case "EDDGridLon0360" -> { - return new EDDGridLon0360Handler(saxHandler, datasetID, completeState, context); - } - case "EDDGridSideBySide" -> { - return new EDDGridSideBySideHandler(saxHandler, datasetID, completeState, context); - } - case "EDDTableAggregateRows" -> { - return new EDDTableAggregateRowsHandler(saxHandler, datasetID, completeState, context); - } - case "EDDTableCopy" -> { - return new EDDTableCopyHandler(saxHandler, datasetID, completeState, context); - } - case "EDDTableFromCassandra" -> { - return new EDDTableFromCassandraHandler(saxHandler, datasetID, completeState); - } - case "EDDTableFromDapSequence" -> { - return new EDDTableFromDapSequenceHandler(saxHandler, datasetID, completeState); - } - case "EDDTableFromDatabase" -> { - return new EDDTableFromDatabaseHandler(saxHandler, datasetID, completeState); - } - case "EDDTableFromAsciiService" -> { - return new EDDTableFromAsciiServiceHandler( - saxHandler, datasetID, completeState, datasetType); - } - case "EDDTableFromOBIS" -> { - return new EDDTableFromOBISHandler(saxHandler, datasetID, completeState); - } - case "EDDTableFromSOS" -> { - return new EDDTableFromSOSHandler(saxHandler, datasetID, completeState); - } - case "EDDTableFromFileNames" -> { - return new EDDTableFromFileNamesHandler(saxHandler, datasetID, completeState); - } - case "EDDGridFromAudioFiles", - "EDDGridFromNcFiles", - "EDDGridFromNcFilesUnpacked", - "EDDGridFromMergeIRFiles" -> { - return new EDDGridFromFilesHandler(saxHandler, datasetID, completeState, datasetType); - } - case "EDDGridFromEtopo" -> { - return new EDDGridFromEtopoHandler(saxHandler, datasetID, completeState); - } - default -> { - nTry--; - context.getNTryAndDatasets()[0] = nTry; - throw new IllegalArgumentException("Unknown dataset type: " + datasetType); + + // TODO using the first constructor here, should we scan through all to find the most + // appropriate one? + Constructor constructor = eddClassInfo.getSaxHandlerClass().get().getConstructors()[0]; + + // Constructors for handlers don't have uniform signatures so we have to do some investigation + // TODO: standardize the constructor signatures or change to accept a config object? + Parameter[] parameters = constructor.getParameters(); + if (parameters.length < 3 + || !parameters[0].getType().equals(SaxHandler.class) + || !parameters[1].getType().equals(String.class) + || !parameters[2].getType().equals(State.class)) { + throw new IllegalArgumentException( + "First constructor for " + datasetType + " did not have a valid signature"); + } + + // build array of constructor arguments based on the constructor signature + Object[] constructorArgs = new Object[parameters.length]; + constructorArgs[0] = saxHandler; + constructorArgs[1] = datasetID; + constructorArgs[2] = completeState; + for (int i = 3; i < parameters.length; i++) { + Class parameterClass = parameters[i].getType(); + if (parameterClass.equals(SaxParsingContext.class)) { + constructorArgs[i] = context; + } else if (parameterClass.equals(String.class)) { + constructorArgs[i] = datasetType; + } else { + throw new IllegalArgumentException( + "Unknown parameter type for " + datasetType + ": " + parameterClass); } } + + try { + return (State) constructor.newInstance(constructorArgs); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException("Error creating handler for " + datasetType, e); + } } public static boolean skipDataset( diff --git a/WEB-INF/classes/gov/noaa/pfel/erddap/handlers/SaxHandlerClass.java b/WEB-INF/classes/gov/noaa/pfel/erddap/handlers/SaxHandlerClass.java new file mode 100644 index 00000000..ea46f06e --- /dev/null +++ b/WEB-INF/classes/gov/noaa/pfel/erddap/handlers/SaxHandlerClass.java @@ -0,0 +1,14 @@ +package gov.noaa.pfel.erddap.handlers; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface SaxHandlerClass { + Class value(); +} diff --git a/pom.xml b/pom.xml index e989d886..1a3744c1 100644 --- a/pom.xml +++ b/pom.xml @@ -180,6 +180,7 @@ maven-war-plugin 3.4.0 + true ${project.basedir} **/*.java, **/*.javaINACTIVE, **/*.javaInactive, **/*.java_NOT_YET, **/*.javaNOT_FINISHED, **/*.javaOLD, content/**, data/**, development/**, download_cache/**, /src/test/**, target/**, src/**, WEB-INF/classes/gov/noaa/pfel/coastwatch/log.*, WEB-INF/lib/**, WEB-INF/NetCheck.*, WEB-INF/*.web.xml, WEB-INF/DoubleCenterGrids.sh, WEB-INF/FileVisitorDNLS.sh, WEB-INF/FindDuplicateTime.*, WEB-INF/GenerateO*, WEB-INF/GenerateT*, WEB-INF/GridSaveAs*, WEB-INF/incompleteMainCatalog.xml, WEB-INF/iobis.m, WEB-INF/obis.m, WEB-INF/MapViewer.*, WEB-INF/QN2005193*, WEB-INF/ValidateDataSetProperties*, WEB-INF/fonts/**, WEB-INF/temp/**, *.*, .settings/**, .github/**, .vscode/** @@ -924,6 +925,11 @@ prometheus-metrics-exporter-servlet-jakarta 1.3.1 + + io.github.classgraph + classgraph + 4.8.176 +