Issue #2638 wrote java utility for generating list of data URIs and

their field names

Change-Id: I44435ed2a3f1f812b79b3d4fa906913064c60863

Former-commit-id: 7fb97ffad0 [formerly a3e2218d1fcc7cf8c83443f5f29cd9982b7e6f46]
Former-commit-id: 39e167fc76
This commit is contained in:
Nate Jensen 2014-02-27 17:10:20 -06:00
parent 35ea5b9eb2
commit 8bf8302811
9 changed files with 471 additions and 3 deletions

View file

@ -64,6 +64,7 @@ import com.vividsolutions.jts.geom.Geometry;
* PluginDataObject.
* Aug 30, 2013 2298 rjpeter Make getPluginName abstract
* Oct 22, 2013 2361 njensen Remove XML annotations and IDecoderGettable
* Feb 27, 2014 2638 njensen Remove bad dataURI annotation
*
* </pre>
*
@ -89,12 +90,11 @@ public class ACARSSoundingRecord extends PluginDataObject implements
// Time of the observation.
@Column
@DataURI(position = 1, embedded = true)
@DynamicSerializeElement
private Calendar timeObs;
@Embedded
@DataURI(position = 2, embedded = true)
@DataURI(position = 1, embedded = true)
@DynamicSerializeElement
private SurfaceObsLocation location;

View file

@ -59,6 +59,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* PluginDataObject.
* Aug 30, 2013 2298 rjpeter Make getPluginName abstract
* Oct 15, 2013 2361 njensen Removed XML annotations
* Feb 27, 2014 2638 njensen Corrected dataURI annotation for eventId
*
* </pre>
*
@ -93,7 +94,7 @@ public class CWARecord extends PersistablePluginDataObject implements
@DynamicSerializeElement
private CWADimension dimension;
@DataURI(position = 1, embedded = true)
@DataURI(position = 1)
@DynamicSerializeElement
private String eventId;

View file

@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.binlightning"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.bufrmos"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.bufrua"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.ccfp"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.gfe"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.goessounding"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.grib"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.ldad"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.ldadhydro"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.ldadmanual"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.ldadprofiler"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.obs"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.poessounding"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.profiler"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.radar"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.recco"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.redbook"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.satellite"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.sfcobs"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.shef"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.taf"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.text"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.textlightning"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.plugin.warning"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.edex.textdb"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataaccess"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.acars"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.acarssounding"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.binlightning"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.bufrascat"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.bufrhdw"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.bufrmthdw"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.bufrncwf"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.bufrquikscat"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.bufrsigwx"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.bufrssmi"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.bufrua"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.cwa"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.cwat"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.ffmp"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.fog"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.fssobs"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.gfe"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.goessounding"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.grid"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.ldadhydro"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.ldadmesonet"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.level"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.lsr"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.madis"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.maps"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.modelsounding"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.npp.crimss"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.npp.nucaps"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.npp.sounding"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.npp.viirs"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.obs"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.poessounding"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.preciprate"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.profiler"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.qc"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.qpf"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.radar"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.satellite"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.scan"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.sfcobs"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.shef"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.svrwx"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.tcg"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.tcs"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.text"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.vaa"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.vil"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.dataplugin.warning"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.mpe"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.nc4"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.ohd"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.pointdata"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.sounding"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.airep"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.airmet"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.atcf"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.aww"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.convsigmet"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.ffg"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.gempak"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.geomag"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.gpd"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.idft"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.intlsigmet"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.mcidas"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.ncpafm"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.ncscat"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.ncscd"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.nctaf"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.ncuair"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.nonconvsigmet"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.ntrans"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.pgen"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.pirep"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.sgwh"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.sgwhv"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.solarimage"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.ssha"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.stormtrack"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.tcm"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.dataplugin.wcp"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.common.staticdata"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.common"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.gempak.jna"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.ingest.grib.util"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.ingest.util"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.airep"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.airmet"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.atcf"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.aww"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.convsigmet"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.ffg"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.gempak"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.geomag"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.gpd"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.idft"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.intlsigmet"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.mcidas"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.mosaic"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.ncgrib"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.ncpafm"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.ncscat"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.ncscd"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.nctaf"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.nctext"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.ncuair"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.nonconvsigmet"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.ntrans"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.pgen"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.pirep"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.sgwh"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.sgwhv"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.solarimage"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.ssha"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.stormtrack"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.tcm"/>
<classpathentry combineaccessrules="false" kind="src" path="/gov.noaa.nws.ncep.edex.plugin.wcp"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.raytheon.uf.docs.datauri</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

View file

@ -0,0 +1,8 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: DataURI Documenter Tool
Bundle-SymbolicName: com.raytheon.uf.docs.datauri
Bundle-Version: 1.14.0.qualifier
Bundle-Vendor: RAYTHEON
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.reflections;bundle-version="0.9.9"

View file

@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.

View file

@ -0,0 +1,54 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.docs.datauri;
import java.lang.reflect.Field;
import java.util.Comparator;
import com.raytheon.uf.common.dataplugin.annotations.DataURI;
/**
* Shamelessly stolen from DataURIUtil.java. I didn't want to change that to be
* public since this plugin is only a utility.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 27, 2014 njensen Initial creation
*
* </pre>
*
* @author njensen
* @version 1.0
*/
public class DataURIAnnotationComparator implements Comparator<Field> {
@Override
public int compare(Field f1, Field f2) {
int i1 = f1.getAnnotation(DataURI.class).position();
int i2 = f2.getAnnotation(DataURI.class).position();
return (i1 < i2 ? -1 : (i1 == i2 ? 0 : 1));
}
}

View file

@ -0,0 +1,214 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.docs.datauri;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.annotations.DataURI;
/**
* Outputs the dataURI field names related to all plugins by using the
* reflections plugin to find subclasses of PluginDataObject.
*
* If running this on future builds, you need to make sure it has knowledge of
* the plugins and packages that a subclass of PluginDataObject might reside in.
*
* Specifically plugins are added to the Eclipse build path by right clicking
* this class's plugin project and editing the build path to include other
* projects in the workspace that may contain PluginDataObjects.
*
* Package names that are scanned within those plugins are in the constant
* PKG_NAMES below.
*
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 27, 2014 njensen Initial creation
*
* </pre>
*
* @author njensen
* @version 1.0
*/
public class DataURIOutputter {
private static final String[] PKG_NAMES = { "com.raytheon", "gov.noaa" };
private static final DataURIAnnotationComparator fieldCompare = new DataURIAnnotationComparator();
protected Writer writer;
public DataURIOutputter(Writer writer) {
this.writer = writer;
}
/**
* Main method that actually runs the tool
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// could change it to write to a file if we desire
StringWriter writer = new StringWriter();
DataURIOutputter tool = new DataURIOutputter(writer);
tool.run();
System.out.println(writer.toString());
}
/**
* Finds classes that extend PluginDataObject and analyzes their dataURI
* annotations to produce output for the writer.
*
* @throws IOException
*/
public void run() throws IOException {
Set<Class<? extends PluginDataObject>> clzSet = findPDOs();
List<Class<? extends PluginDataObject>> clzList = new ArrayList<Class<? extends PluginDataObject>>(
clzSet);
List<String> pluginNames = new ArrayList<String>(clzList.size());
Map<String, Class<?>> map = new HashMap<String, Class<?>>();
for (Class<? extends PluginDataObject> clz : clzList) {
if (!Modifier.isAbstract(clz.getModifiers())
&& !Modifier.isPrivate(clz.getModifiers()))
try {
PluginDataObject pdo = clz.newInstance();
String pluginName = pdo.getPluginName();
pluginNames.add(pluginName);
map.put(pluginName, clz);
} catch (Exception e) {
System.err.println("Error instantiating " + clz.getName());
e.printStackTrace();
}
}
// sort the plugins alphabetically
Collections.sort(pluginNames);
// produce the output
for (String plugin : pluginNames) {
writer.append(DataURI.SEPARATOR);
writer.append(plugin);
writer.append(DataURI.SEPARATOR);
processFields(findDataUriFields(map.get(plugin)));
writer.append("\n");
}
}
/**
* Finds the classes that extend PluginDataObject
*
* @return
*/
private Set<Class<? extends PluginDataObject>> findPDOs() {
ConfigurationBuilder cb = new ConfigurationBuilder();
for (String pkg : PKG_NAMES) {
cb.addUrls(ClasspathHelper.forPackage(pkg));
}
cb.setScanners(new SubTypesScanner());
Reflections refl = cb.build();
return refl.getSubTypesOf(PluginDataObject.class);
}
/**
* Walks up the class inheritance tree and over the class's member variables
* looking for @DataURI annotations and returns the corresponding fields in
* proper order.
*
* @param clz
* the class to find @DataURI fields
* @return
*/
private List<Field> findDataUriFields(Class<?> clz) {
Class<?> superClz = clz.getSuperclass();
List<Field> superFields = null;
if (!superClz.equals(Object.class)) {
superFields = findDataUriFields(superClz);
} else {
superFields = new ArrayList<Field>();
}
List<Field> thisFields = new ArrayList<Field>();
for (Field field : clz.getDeclaredFields()) {
if (field.isAnnotationPresent(DataURI.class)) {
thisFields.add(field);
}
}
/*
* sorting only applies to this particular class, as a position's
* numeric value can repeat in a super class
*/
Collections.sort(thisFields, fieldCompare);
// super fields always come first
superFields.addAll(thisFields);
return superFields;
}
/**
* Loops through the fields and appends corresponding output to the writer
*
* @param fields
* fields that have @DataURI annotations
* @throws IOException
*/
private void processFields(List<Field> fields) throws IOException {
Iterator<Field> itr = fields.iterator();
while (itr.hasNext()) {
Field f = itr.next();
DataURI dataURI = f.getAnnotation(DataURI.class);
if (!dataURI.embedded()) {
writer.append(f.getName());
} else {
processFields(findDataUriFields(f.getType()));
}
if (itr.hasNext()) {
writer.append(DataURI.SEPARATOR);
}
}
}
}