diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.acarssounding/src/com/raytheon/uf/common/dataplugin/acarssounding/ACARSSoundingRecord.java b/edexOsgi/com.raytheon.uf.common.dataplugin.acarssounding/src/com/raytheon/uf/common/dataplugin/acarssounding/ACARSSoundingRecord.java index b4cba89404..4f41894b3c 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.acarssounding/src/com/raytheon/uf/common/dataplugin/acarssounding/ACARSSoundingRecord.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.acarssounding/src/com/raytheon/uf/common/dataplugin/acarssounding/ACARSSoundingRecord.java @@ -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 * * * @@ -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; diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.cwa/src/com/raytheon/uf/common/dataplugin/cwa/CWARecord.java b/edexOsgi/com.raytheon.uf.common.dataplugin.cwa/src/com/raytheon/uf/common/dataplugin/cwa/CWARecord.java index 767f9dc9ad..e2c985ec2a 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.cwa/src/com/raytheon/uf/common/dataplugin/cwa/CWARecord.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.cwa/src/com/raytheon/uf/common/dataplugin/cwa/CWARecord.java @@ -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 * * * @@ -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; diff --git a/javaUtilities/com.raytheon.uf.docs.datauri/.classpath b/javaUtilities/com.raytheon.uf.docs.datauri/.classpath new file mode 100644 index 0000000000..8cff3531d9 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.docs.datauri/.classpath @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/javaUtilities/com.raytheon.uf.docs.datauri/.project b/javaUtilities/com.raytheon.uf.docs.datauri/.project new file mode 100644 index 0000000000..bd02748510 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.docs.datauri/.project @@ -0,0 +1,28 @@ + + + com.raytheon.uf.docs.datauri + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/javaUtilities/com.raytheon.uf.docs.datauri/.settings/org.eclipse.jdt.core.prefs b/javaUtilities/com.raytheon.uf.docs.datauri/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..c537b63063 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.docs.datauri/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/javaUtilities/com.raytheon.uf.docs.datauri/META-INF/MANIFEST.MF b/javaUtilities/com.raytheon.uf.docs.datauri/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..8da9b20db5 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.docs.datauri/META-INF/MANIFEST.MF @@ -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" diff --git a/javaUtilities/com.raytheon.uf.docs.datauri/build.properties b/javaUtilities/com.raytheon.uf.docs.datauri/build.properties new file mode 100644 index 0000000000..34d2e4d2da --- /dev/null +++ b/javaUtilities/com.raytheon.uf.docs.datauri/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/javaUtilities/com.raytheon.uf.docs.datauri/src/com/raytheon/uf/docs/datauri/DataURIAnnotationComparator.java b/javaUtilities/com.raytheon.uf.docs.datauri/src/com/raytheon/uf/docs/datauri/DataURIAnnotationComparator.java new file mode 100644 index 0000000000..9cda5495fe --- /dev/null +++ b/javaUtilities/com.raytheon.uf.docs.datauri/src/com/raytheon/uf/docs/datauri/DataURIAnnotationComparator.java @@ -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. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 27, 2014            njensen     Initial creation
+ * 
+ * 
+ * + * @author njensen + * @version 1.0 + */ + +public class DataURIAnnotationComparator implements Comparator { + + @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)); + } + +} diff --git a/javaUtilities/com.raytheon.uf.docs.datauri/src/com/raytheon/uf/docs/datauri/DataURIOutputter.java b/javaUtilities/com.raytheon.uf.docs.datauri/src/com/raytheon/uf/docs/datauri/DataURIOutputter.java new file mode 100644 index 0000000000..84035b6094 --- /dev/null +++ b/javaUtilities/com.raytheon.uf.docs.datauri/src/com/raytheon/uf/docs/datauri/DataURIOutputter.java @@ -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. + * + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 27, 2014            njensen     Initial creation
+ * 
+ * 
+ * + * @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> clzSet = findPDOs(); + List> clzList = new ArrayList>( + clzSet); + + List pluginNames = new ArrayList(clzList.size()); + Map> map = new HashMap>(); + for (Class 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> 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 findDataUriFields(Class clz) { + Class superClz = clz.getSuperclass(); + List superFields = null; + if (!superClz.equals(Object.class)) { + superFields = findDataUriFields(superClz); + } else { + superFields = new ArrayList(); + } + + List thisFields = new ArrayList(); + 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 fields) throws IOException { + Iterator 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); + } + } + } + +}