diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/DerivedParameterGenerator.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/DerivedParameterGenerator.java index 166520afe3..fa52cdb906 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/DerivedParameterGenerator.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/DerivedParameterGenerator.java @@ -251,7 +251,7 @@ public class DerivedParameterGenerator implements ILocalizationFileObserver { for (LocalizationFile file : xmlFiles) { try { DerivParamDesc desc = (DerivParamDesc) jaxbMan - .jaxbUnmarshalFromXmlFile(file.getFile()); + .unmarshalFromXmlFile(file.getFile()); if (derParLibrary.containsKey(desc.getAbbreviation())) { DerivParamDesc oldDesc = derParLibrary.get(desc .getAbbreviation()); diff --git a/cave/com.raytheon.uf.viz.ui.popupskewt/src/com/raytheon/uf/viz/ui/popupskewt/config/SoundingSourceConfigFactory.java b/cave/com.raytheon.uf.viz.ui.popupskewt/src/com/raytheon/uf/viz/ui/popupskewt/config/SoundingSourceConfigFactory.java index 16911d944d..a38b4d61c5 100644 --- a/cave/com.raytheon.uf.viz.ui.popupskewt/src/com/raytheon/uf/viz/ui/popupskewt/config/SoundingSourceConfigFactory.java +++ b/cave/com.raytheon.uf.viz.ui.popupskewt/src/com/raytheon/uf/viz/ui/popupskewt/config/SoundingSourceConfigFactory.java @@ -69,7 +69,7 @@ public class SoundingSourceConfigFactory { "Could not find skewt sources file: " + filePath); } SoundingSourceConfig config = (SoundingSourceConfig) mgr - .jaxbUnmarshalFromInputStream(file.openInputStream()); + .unmarshalFromInputStream(file.openInputStream()); if (config == null) { throw new SerializationException( "SkewT Config file could not be deserialized"); diff --git a/cave/com.raytheon.viz.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject b/cave/com.raytheon.viz.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject index c92a40e573..47f8ae7614 100644 --- a/cave/com.raytheon.viz.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject +++ b/cave/com.raytheon.viz.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject @@ -5,5 +5,3 @@ com.raytheon.viz.gfe.rsc.GFELegendResourceData com.raytheon.viz.gfe.rsc.GFEResourceData com.raytheon.uf.common.site.xml.AdjacentWfoXML com.raytheon.uf.common.site.xml.CwaXML -com.raytheon.viz.gfe.textformatter.CombinationsFileUtil$ComboData -com.raytheon.viz.gfe.textformatter.CombinationsFileUtil$ComboData$Entry diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/ReferenceSetManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/ReferenceSetManager.java index 9f80b1f03e..c5a04b9350 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/ReferenceSetManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/ReferenceSetManager.java @@ -67,7 +67,6 @@ import com.raytheon.uf.common.python.concurrent.AbstractPythonScriptFactory; import com.raytheon.uf.common.python.concurrent.IPythonExecutor; import com.raytheon.uf.common.python.concurrent.IPythonJobListener; import com.raytheon.uf.common.python.concurrent.PythonJobCoordinator; -import com.raytheon.uf.common.serialization.SerializationUtil; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; @@ -109,6 +108,7 @@ import com.vividsolutions.jts.geom.Envelope; * 02/26/2013 #1708 randerso Removed no longer needed near duplicate methods * 06/21/2013 14983 ryu Added method for synchronous evaluation of query. * 08/06/2013 1561 njensen Use pm.listFiles() instead of pm.listStaticFiles() + * 09/30/2013 2361 njensen Use JAXBManager for XML * * * @@ -779,8 +779,8 @@ public class ReferenceSetManager implements IReferenceSetManager, if (lf != null) { try { - refData = SerializationUtil.jaxbUnmarshalFromXmlFile( - ReferenceData.class, lf.getFile().getPath()); + refData = ReferenceData.getJAXBManager() + .unmarshalFromXmlFile(lf.getFile().getPath()); } catch (Exception e) { statusHandler.handle(Priority.PROBLEM, "Error reading xml file " @@ -886,7 +886,8 @@ public class ReferenceSetManager implements IReferenceSetManager, // save locally and then to server try { - SerializationUtil.jaxbMarshalToXmlFile(refData, file.getPath()); + ReferenceData.getJAXBManager().marshalToXmlFile(refData, + file.getPath()); lf.save(); } catch (Exception e) { Activator diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/SampleSetManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/SampleSetManager.java index 24aa91dc70..c5df3e1ff1 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/SampleSetManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/SampleSetManager.java @@ -43,7 +43,6 @@ import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.localization.exception.LocalizationException; import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException; import com.raytheon.uf.common.serialization.SerializationException; -import com.raytheon.uf.common.serialization.SerializationUtil; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; @@ -68,6 +67,7 @@ import com.vividsolutions.jts.geom.Coordinate; * 11Jun2008 #1193 ebabin Updates for toggling lat/lon for sample set. * Apr 9, 2009 1288 rjpeter Added ISampleSetChangedListener handling. * Aug 6, 2013 1561 njensen Use pm.listFiles() instead of pm.listStaticFiles() + * Sep 30, 2013 2361 njensen Use JAXBManager for XML * * * @author rbell @@ -193,19 +193,13 @@ public class SampleSetManager implements ISampleSetManager { } } - Object obj = null; + SampleData sampleData = null; try { - obj = SerializationUtil.jaxbUnmarshalFromXmlFile(f - .getAbsolutePath()); + sampleData = SampleData.getJAXBManager().unmarshalFromXmlFile( + f.getAbsolutePath()); } catch (Exception e) { throw new GFEException("Unable to load sampledata: " + f, e); } - if ((obj == null) || !(obj instanceof SampleData)) { - throw new GFEException("Unable to load sampledata: " + f - + " unmarshalled as " + obj); - } - - SampleData sampleData = (SampleData) obj; return sampleData.getPoints(); } @@ -223,18 +217,13 @@ public class SampleSetManager implements ISampleSetManager { File f = PathManagerFactory.getPathManager().getStaticFile( FileUtil.join(SAMPLE_SETS_DIR, sampleId.getName() + ".xml")); - Object obj = null; + SampleData sampleData = null; try { - obj = SerializationUtil.jaxbUnmarshalFromXmlFile(f.getPath()); + sampleData = SampleData.getJAXBManager().unmarshalFromXmlFile( + f.getPath()); } catch (Exception e) { throw new GFEException("Unable to load sampledata: " + f); } - if ((obj == null) || !(obj instanceof SampleData)) { - throw new GFEException("Unable to load sampledata: " + f - + " unmarshalled as " + obj); - } - - SampleData sampleData = (SampleData) obj; // set the loadedSet flag appropriately if ((loadMode == SampleSetLoadMode.REPLACE) @@ -413,8 +402,8 @@ public class SampleSetManager implements ISampleSetManager { FileUtil.join(SAMPLE_SETS_DIR, sampleId.getName() + ".xml")); try { - SerializationUtil - .jaxbMarshalToXmlFile(sd, file.getFile().getPath()); + SampleData.getJAXBManager().marshalToXmlFile(sd, + file.getFile().getPath()); file.save(); } catch (LocalizationOpFailedException e) { statusHandler.handle(Priority.PROBLEM, diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/WEGroupManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/WEGroupManager.java index 867f7c4780..3285138e08 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/WEGroupManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/internal/WEGroupManager.java @@ -30,6 +30,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import javax.xml.bind.JAXBException; + import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; import com.raytheon.uf.common.dataplugin.gfe.weatherelement.WEGroup; @@ -44,7 +46,7 @@ import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.localization.exception.LocalizationException; import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException; import com.raytheon.uf.common.serialization.SerializationException; -import com.raytheon.uf.common.serialization.SerializationUtil; +import com.raytheon.uf.common.serialization.SingleTypeJAXBManager; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; @@ -62,7 +64,8 @@ import com.raytheon.viz.gfe.core.IWEGroupManager; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Jun 5, 2008 chammack Initial creation + * Jun 5, 2008 chammack Initial creation + * Sep 30, 2013 2361 njensen Use JAXBManager for XML * * * @@ -89,9 +92,19 @@ public class WEGroupManager implements IWEGroupManager, private LocalizationFile weGroupDir; + private SingleTypeJAXBManager jaxb; + public WEGroupManager(final DataManager dataManager) { this.dataManager = dataManager; + try { + this.jaxb = new SingleTypeJAXBManager(WEGroup.class); + } catch (JAXBException e) { + statusHandler + .error("Error initializing WEGroup JAXBManager, Weather Element Groups will not work", + e); + } + loadGroups(); IPathManager pathManager = PathManagerFactory.getPathManager(); @@ -223,8 +236,7 @@ public class WEGroupManager implements IWEGroupManager, WEGroup weGroup = null; try { - weGroup = (WEGroup) SerializationUtil.jaxbUnmarshalFromXmlFile(file - .getFile().getPath()); + weGroup = jaxb.unmarshalFromXmlFile(file.getFile().getPath()); } catch (Exception e) { statusHandler.handle(Priority.PROBLEM, "Error getting weather element group", e); @@ -368,8 +380,7 @@ public class WEGroupManager implements IWEGroupManager, LocalizationFile file = pm.getLocalizationFile(lc, FileUtil.join(WEGROUP_DIR, getName(key))); try { - SerializationUtil.jaxbMarshalToXmlFile(objectToSave, file.getFile() - .getPath()); + jaxb.marshalToXmlFile(objectToSave, file.getFile().getPath()); file.save(); } catch (LocalizationOpFailedException e) { statusHandler.handle(Priority.PROBLEM, diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/textformatter/CombinationsFileUtil.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/textformatter/CombinationsFileUtil.java index 711b5976ac..539f1f4b02 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/textformatter/CombinationsFileUtil.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/textformatter/CombinationsFileUtil.java @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.xml.bind.JAXBException; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; @@ -47,9 +48,8 @@ import com.raytheon.uf.common.localization.exception.LocalizationException; import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException; import com.raytheon.uf.common.python.PyUtil; import com.raytheon.uf.common.python.PythonScript; -import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.SerializationException; -import com.raytheon.uf.common.serialization.SerializationUtil; +import com.raytheon.uf.common.serialization.SingleTypeJAXBManager; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.util.FileUtil; @@ -68,6 +68,7 @@ import com.raytheon.viz.gfe.textformatter.CombinationsFileUtil.ComboData.Entry; * Aug 07, 2013 1561 njensen Use pm.listFiles() instead of pm.listStaticFiles() * Sep 05, 2013 #2329 randerso Moved genereateAutoCombinationsFile here * Cleaned up error handling + * Sep 30, 2013 2361 njensen Use JAXBManager for XML * * * @@ -83,9 +84,11 @@ public class CombinationsFileUtil { public static String SAVED_COMBO_DIR = FileUtil.join("gfe", "comboData"); + private static final SingleTypeJAXBManager jaxb = initializeJAXB(); + @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) - public static class ComboData implements ISerializableObject { + public static class ComboData { @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) @@ -121,6 +124,23 @@ public class CombinationsFileUtil { } } + /** + * Initializes the JAXB manager for reading/writing ComboData to/from XML. + * + * @return the JAXBManager + */ + private static SingleTypeJAXBManager initializeJAXB() { + SingleTypeJAXBManager retVal = null; + try { + retVal = new SingleTypeJAXBManager(ComboData.class); + } catch (JAXBException e) { + statusHandler + .error("Error initializing ComboData JAXBManager, combinations files will not work", + e); + } + return retVal; + } + /** * Gets the saved combo files for the menus in text formatter * @@ -158,7 +178,7 @@ public class CombinationsFileUtil { LocalizationFile lf = idToFile(id); File file = lf.getFile(false); ComboData comboData = new ComboData(combos); - SerializationUtil.jaxbMarshalToXmlFile(comboData, file.getPath()); + jaxb.marshalToXmlFile(comboData, file.getPath()); lf.save(); } @@ -196,8 +216,7 @@ public class CombinationsFileUtil { throws SerializationException { LocalizationFile lf = idToFile(id); File file = lf.getFile(); - ComboData comboData = (ComboData) SerializationUtil - .jaxbUnmarshalFromXmlFile(file); + ComboData comboData = jaxb.unmarshalFromXmlFile(file); Map comboDict = new HashMap( comboData.combos.size()); diff --git a/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/perspective/MPEPerspectiveManager.java b/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/perspective/MPEPerspectiveManager.java index 7f94fc5976..2fa5d679a3 100644 --- a/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/perspective/MPEPerspectiveManager.java +++ b/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/perspective/MPEPerspectiveManager.java @@ -121,7 +121,7 @@ public class MPEPerspectiveManager extends AbstractCAVEPerspectiveManager { try { // Unmarshal default bundle xml Object unmarshalled = SerializationUtil.getJaxbManager() - .jaxbUnmarshalFromXmlFile( + .unmarshalFromXmlFile( PathManagerFactory.getPathManager().getStaticFile( MPE + IPathManager.SEPARATOR + "default-bundle.xml")); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject b/edexOsgi/com.raytheon.edex.plugin.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject index c13bd549c5..968d1866e0 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject @@ -1,4 +1,3 @@ -com.raytheon.edex.plugin.gfe.wcl.WclInfo com.raytheon.edex.plugin.gfe.isc.IscSendRecord com.raytheon.edex.plugin.gfe.smartinit.SmartInitRecord com.raytheon.edex.plugin.gfe.smartinit.SmartInitRecordPK \ No newline at end of file diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/reference/MapManager.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/reference/MapManager.java index 9c90805796..f74ae6c2c2 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/reference/MapManager.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/reference/MapManager.java @@ -69,7 +69,6 @@ import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.message.WsId; import com.raytheon.uf.common.python.PyUtil; import com.raytheon.uf.common.python.PythonEval; -import com.raytheon.uf.common.serialization.SerializationUtil; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; @@ -103,6 +102,7 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier; * Mar 28, 2013 #1837 dgilling Better error reporting if a map table * from localMaps.py could not be found, * warnings clean up. + * Sep 30, 2013 #2361 njensen Use JAXBManager for XML * * * @@ -359,7 +359,8 @@ public class MapManager { d = new File(FileUtil.join(commonStaticConfigDir, SAMPLE_SETS_DIR)); if (d.exists()) { - final FilenameFilter filter = FilenameFilters.byFilePrefix("ISC_Marker_Set"); + final FilenameFilter filter = FilenameFilters + .byFilePrefix("ISC_Marker_Set"); for (File file : FileUtil.listFiles(d, filter, false)) { file.delete(); } @@ -457,7 +458,7 @@ public class MapManager { sampleId.getName() + ".xml")); if (!path.exists()) { try { - SerializationUtil.jaxbMarshalToXmlFile(sd, + SampleData.getJAXBManager().marshalToXmlFile(sd, path.getAbsolutePath()); } catch (Exception e) { statusHandler.error( @@ -567,6 +568,7 @@ public class MapManager { if (!areaDir.exists()) { areaDir.mkdirs(); } + if (areaDir.isDirectory() && areaDir.canWrite()) { for (ReferenceData ref : data) { ref.getPolygons(CoordinateType.LATLON); @@ -577,8 +579,8 @@ public class MapManager { // old one, write a warning to the log. ReferenceData other = null; try { - other = SerializationUtil.jaxbUnmarshalFromXmlFile( - ReferenceData.class, path); + other = ReferenceData.getJAXBManager() + .unmarshalFromXmlFile(path); } catch (Exception e) { statusHandler.error("Error reading edit area file " + path.getAbsolutePath(), e); @@ -595,8 +597,8 @@ public class MapManager { } else { // Write the new edit area file. try { - SerializationUtil.jaxbMarshalToXmlFile(ref, - path.getAbsolutePath()); + ReferenceData.getJAXBManager().marshalToXmlFile( + ref, path.getAbsolutePath()); } catch (Exception e) { statusHandler.error("Error writing edit area to file " + path.getAbsolutePath(), e); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/reference/ReferenceMgr.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/reference/ReferenceMgr.java index b5c14554bc..d7df5c8ca7 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/reference/ReferenceMgr.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/reference/ReferenceMgr.java @@ -33,7 +33,6 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.LocalizationUtil; import com.raytheon.uf.common.localization.PathManagerFactory; -import com.raytheon.uf.common.serialization.SerializationUtil; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.util.FileUtil; @@ -49,6 +48,7 @@ import com.raytheon.uf.common.util.FileUtil; * ------------ ---------- ----------- -------------------------- * Jul 24, 2012 dgilling Initial creation * Aug 07, 2013 1561 njensen Use pm.listFiles() instead of pm.listStaticFiles() + * Sep 30, 2013 2361 njensen Use JAXBManager for XML * * * @@ -64,9 +64,9 @@ public class ReferenceMgr { private static final String EDIT_AREAS_DIR = FileUtil.join("gfe", "editAreas"); - IPathManager pathMgr; + private IPathManager pathMgr; - GridLocation dbGridLocation; + private GridLocation dbGridLocation; public ReferenceMgr(final IFPServerConfig config) { this.pathMgr = PathManagerFactory.getPathManager(); @@ -129,8 +129,8 @@ public class ReferenceMgr { // open and read the file ReferenceData refData = null; try { - refData = (ReferenceData) SerializationUtil - .jaxbUnmarshalFromXmlFile(lf.getFile().getPath()); + refData = ReferenceData.getJAXBManager() + .unmarshalFromXmlFile(lf.getFile().getPath()); } catch (Exception e) { sr.addMessage("Unable to read reference data [" + id + "]"); data = Collections.emptyList(); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/util/TranslateReferenceSet.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/util/TranslateReferenceSet.java index b3ef3ab2ff..6208915f8b 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/util/TranslateReferenceSet.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/util/TranslateReferenceSet.java @@ -301,7 +301,7 @@ public class TranslateReferenceSet { } } String path = FileUtil.join(dir, fname); - jbm.jaxbMarshalToXmlFile(refData, path); + jbm.marshalToXmlFile(refData, path); } } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/wcl/WclInfo.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/wcl/WclInfo.java index 9a0cbf8d6c..a934d9cfaa 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/wcl/WclInfo.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/wcl/WclInfo.java @@ -26,40 +26,39 @@ import java.util.Collections; import java.util.Date; import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; - -import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; /** * A class for the information in a WCL. * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#     Engineer    Description
+ * ------------ ----------  ----------- --------------------------
+ * --/--/----               wldougher   Initial creation
+ * 09/30/2013   2361        njensen     Removed XML annotations
+ * 
+ * 
+ * + * * @author wldougher * */ -@XmlAccessorType(XmlAccessType.NONE) @DynamicSerialize -public class WclInfo implements ISerializableObject { +public class WclInfo { - private static final long serialVersionUID = 1L; - - @XmlAttribute @DynamicSerializeElement private Date issueTime; - @XmlElement @DynamicSerializeElement private List lines; - @XmlAttribute @DynamicSerializeElement private String completeProductPil; - @XmlAttribute @DynamicSerializeElement private Boolean notify; diff --git a/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/spatial/GribSpatialCache.java b/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/spatial/GribSpatialCache.java index 9d57930ebf..6031da87a0 100644 --- a/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/spatial/GribSpatialCache.java +++ b/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/spatial/GribSpatialCache.java @@ -430,7 +430,7 @@ public class GribSpatialCache { if (f.length() > 0) { try { JAXBManager manager = new JAXBManager(SubGridDef.class); - rval = (SubGridDef) manager.jaxbUnmarshalFromXmlFile(f); + rval = (SubGridDef) manager.unmarshalFromXmlFile(f); if ((rval.getReferenceModel() == null && rval .getReferenceGrid() == null) || (rval.getModelNames() == null) @@ -596,7 +596,7 @@ public class GribSpatialCache { JAXBManager mgr = new JAXBManager( DefaultSubGridCenterPoint.class); DefaultSubGridCenterPoint defaultSubGridLocation = (DefaultSubGridCenterPoint) mgr - .jaxbUnmarshalFromXmlFile(defaultSubGridLocationFile); + .unmarshalFromXmlFile(defaultSubGridLocationFile); if ((defaultSubGridLocation != null) && (defaultSubGridLocation.getCenterLatitude() != null) && (defaultSubGridLocation.getCenterLongitude() != null)) { diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject index b7f03fd211..f61426db78 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject @@ -5,10 +5,5 @@ com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmStorageInfo -com.raytheon.uf.common.dataplugin.gfe.reference.ReferenceData -com.raytheon.uf.common.dataplugin.gfe.sample.SampleData com.raytheon.uf.common.dataplugin.gfe.server.lock.Lock -com.raytheon.uf.common.dataplugin.gfe.server.message.ServerMsg -com.raytheon.uf.common.dataplugin.gfe.weatherelement.WEGroup -com.raytheon.uf.common.dataplugin.gfe.weatherelement.WEItem com.raytheon.uf.common.dataplugin.gfe.GridDataHistory \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/reference/ReferenceData.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/reference/ReferenceData.java index 0b550a5894..bde0659a05 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/reference/ReferenceData.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/reference/ReferenceData.java @@ -22,6 +22,7 @@ package com.raytheon.uf.common.dataplugin.gfe.reference; import java.util.ArrayList; import java.util.List; +import javax.xml.bind.JAXBException; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; @@ -32,12 +33,11 @@ import org.geotools.geometry.jts.JTS; import org.opengis.metadata.spatial.PixelOrientation; import org.opengis.referencing.datum.PixelInCell; -import com.raytheon.uf.common.dataplugin.gfe.StatusConstants; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation; import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DBit; import com.raytheon.uf.common.dataplugin.gfe.util.GfeUtil; import com.raytheon.uf.common.geospatial.MapUtil; -import com.raytheon.uf.common.serialization.ISerializableObject; +import com.raytheon.uf.common.serialization.SingleTypeJAXBManager; import com.raytheon.uf.common.serialization.adapters.JTSGeometryAdapter; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; @@ -69,6 +69,7 @@ import com.vividsolutions.jts.geom.Polygonal; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 01/31/2008 randerso Initial creation + * 10/01/2013 2361 njensen Added static JAXBManager * * * @@ -79,10 +80,14 @@ import com.vividsolutions.jts.geom.Polygonal; @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) @DynamicSerialize -public class ReferenceData implements ISerializableObject { - private static final transient IUFStatusHandler statusHandler = UFStatus.getHandler(ReferenceData.class); +public class ReferenceData { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(ReferenceData.class); + private static final GeometryFactory geometryFactory = new GeometryFactory(); + private static final SingleTypeJAXBManager jaxb = initializeJAXB(); + public enum RefType { NONE, QUERY, POLYGON, QUERY_POLYGON }; @@ -107,6 +112,34 @@ public class ReferenceData implements ISerializableObject { private CoordinateType coordType; + /** + * Initializes the JAXB manager for reading/writing ReferenceData to/from + * XML. + * + * @return the JAXBManager + */ + private static SingleTypeJAXBManager initializeJAXB() { + SingleTypeJAXBManager retVal = null; + try { + retVal = new SingleTypeJAXBManager( + ReferenceData.class); + } catch (JAXBException e) { + statusHandler + .error("Error initializing ReferenceData JAXBManager, edit areas will not work", + e); + } + return retVal; + } + + /** + * Returns the JAXBManager that handles ReferenceData + * + * @return + */ + public static SingleTypeJAXBManager getJAXBManager() { + return jaxb; + } + /** * Default constructor */ @@ -396,8 +429,8 @@ public class ReferenceData implements ISerializableObject { try { calcGrid(); } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, - "getGrid() failed for " + this.getId().getName(), e); + statusHandler.handle(Priority.PROBLEM, "getGrid() failed for " + + this.getId().getName(), e); // return an empty grid grid = new Grid2DBit(gloc.getNx(), gloc.getNy()); diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/sample/SampleData.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/sample/SampleData.java index f82c665af5..84c5cdc5a8 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/sample/SampleData.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/sample/SampleData.java @@ -25,15 +25,18 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.xml.bind.JAXBException; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import com.raytheon.uf.common.serialization.ISerializableObject; +import com.raytheon.uf.common.serialization.SingleTypeJAXBManager; import com.raytheon.uf.common.serialization.adapters.CoordAdapter; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.MultiPoint; @@ -56,7 +59,7 @@ import com.vividsolutions.jts.geom.MultiPoint; @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) @DynamicSerialize -public class SampleData implements Cloneable, ISerializableObject { +public class SampleData implements Cloneable { private static final String LEGACY_FILE_HEADER_LINE_PATTERN = "\\d+"; @@ -66,12 +69,43 @@ public class SampleData implements Cloneable, ISerializableObject { private static final String LINE_STRING_COORDINATE_PATTERN = "\\s*(-?\\d+(?:\\.\\d+)?)\\s+(-?\\d+(?:\\.\\d+)?)\\s*"; + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(SampleData.class); + + private static final SingleTypeJAXBManager jaxb = initializeJAXB(); + private SampleId sampleId; @XmlJavaTypeAdapter(value = CoordAdapter.class) @DynamicSerializeElement private List points; + /** + * Initializes the JAXB manager for reading/writing SampleData to/from XML. + * + * @return the JAXBManager + */ + private static SingleTypeJAXBManager initializeJAXB() { + SingleTypeJAXBManager retVal = null; + try { + retVal = new SingleTypeJAXBManager(SampleData.class); + } catch (JAXBException e) { + statusHandler + .error("Error initializing SampleData JAXBManager, sample sets will not work", + e); + } + return retVal; + } + + /** + * Returns the JAXBManager that handles SampleData + * + * @return + */ + public static SingleTypeJAXBManager getJAXBManager() { + return jaxb; + } + /** * Default constructor */ diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/server/message/ServerMsg.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/server/message/ServerMsg.java index a71fbb786d..c65397710c 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/server/message/ServerMsg.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/server/message/ServerMsg.java @@ -34,20 +34,25 @@ package com.raytheon.uf.common.dataplugin.gfe.server.message; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; - -import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; -@XmlAccessorType(XmlAccessType.NONE) +/** + * Encapsulates a message on the server. + * + *
+ * SOFTWARE HISTORY
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * --/--/--                            Initial Creation
+ * 09/30/13     #2361      njensen     Removed XML annotations
+ * 
+ * + */ @DynamicSerialize -public class ServerMsg implements ISerializableObject { +public class ServerMsg { /** The message */ - @XmlAttribute @DynamicSerializeElement private String message; diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/weatherelement/WEGroup.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/weatherelement/WEGroup.java index 92b1d661c2..7a45cb0933 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/weatherelement/WEGroup.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/weatherelement/WEGroup.java @@ -32,7 +32,6 @@ import javax.xml.bind.annotation.XmlRootElement; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; -import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; @@ -56,7 +55,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; @XmlRootElement(name = "WEGroup") @XmlAccessorType(XmlAccessType.NONE) @DynamicSerialize -public class WEGroup implements ISerializableObject { +public class WEGroup { @XmlAttribute @DynamicSerializeElement diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/weatherelement/WEItem.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/weatherelement/WEItem.java index 6537b42cfc..27982d71de 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/weatherelement/WEItem.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/weatherelement/WEItem.java @@ -26,7 +26,6 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; import com.raytheon.uf.common.dataplugin.gfe.serialize.ParmIDAdapter; -import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; @@ -49,7 +48,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; @XmlAccessorType(XmlAccessType.NONE) @DynamicSerialize -public class WEItem implements ISerializableObject { +public class WEItem { @XmlAttribute @XmlJavaTypeAdapter(value = ParmIDAdapter.class) diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/dataset/DatasetInfoLookup.java b/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/dataset/DatasetInfoLookup.java index cb7721df58..ddd42fb155 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/dataset/DatasetInfoLookup.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.grid/src/com/raytheon/uf/common/dataplugin/grid/dataset/DatasetInfoLookup.java @@ -97,7 +97,7 @@ public class DatasetInfoLookup { return; } try { - Object obj = manager.jaxbUnmarshalFromXmlFile(file.getFile()); + Object obj = manager.unmarshalFromXmlFile(file.getFile()); DatasetInfoSet set = (DatasetInfoSet) obj; for (DatasetInfo info : set.getInfos()) { infoMap.put(info.getDatasetId(), info); diff --git a/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/AutoUpdatingLocalizationFile.java b/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/AutoUpdatingLocalizationFile.java index 45ece3f1a8..b147f66246 100644 --- a/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/AutoUpdatingLocalizationFile.java +++ b/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/AutoUpdatingLocalizationFile.java @@ -224,7 +224,7 @@ public class AutoUpdatingLocalizationFile { return null; } try { - return type.cast(manager.jaxbUnmarshalFromInputStream(internalFile + return type.cast(manager.unmarshalFromInputStream(internalFile .openInputStream())); } catch (LocalizationException e) { throw new SerializationException( diff --git a/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/LocalizationFile.java b/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/LocalizationFile.java index 4752991678..65d40683b7 100644 --- a/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/LocalizationFile.java +++ b/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/LocalizationFile.java @@ -619,7 +619,7 @@ public final class LocalizationFile implements Comparable { try { is = openInputStream(); T object = resultClass.cast(manager - .jaxbUnmarshalFromInputStream(is)); + .unmarshalFromInputStream(is)); return object; } catch (Exception e) { throw new LocalizationException("Could not unmarshal file " diff --git a/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/JAXBManager.java b/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/JAXBManager.java index 6e21e07ed5..b2e20b2788 100644 --- a/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/JAXBManager.java +++ b/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/JAXBManager.java @@ -42,7 +42,10 @@ import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; /** - * Provides utilities for serialization support + * Provides an easy and convenient layer to marshal or unmarshal objects to and + * from XML using JAXB. An instance of this class is thread-safe, it will use + * separate marshallers and unmarshallers if used simultaneously by different + * threads. * *
  * SOFTWARE HISTORY
@@ -52,6 +55,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
  * Nov 13, 2008            njensen      Added thrift methods
  * May 22, 2013 1917       rjpeter      Added non-pretty print option to jaxb serialize methods.
  * Aug 18, 2013 #2097      dhladky      Allowed extension by OGCJAXBManager
+ * Sep 30, 2013 2361       njensen      Refactored for cleanliness
  * 
* * @author chammack @@ -111,15 +115,44 @@ public class JAXBManager { protected final Queue marshallers = new ConcurrentLinkedQueue(); + /** + * Constructor. Clazz should include any classes that this JAXBManager needs + * to marshal to XML or unmarshal from XML. Does not need to include classes + * contained as fields or inner classes of other classes already passed to + * the constructor. + * + * @param clazz + * classes that this instance must know about for + * marshalling/unmarshalling + * @throws JAXBException + */ public JAXBManager(Class... clazz) throws JAXBException { jaxbContext = JAXBContext.newInstance(clazz); } + /** + * Returns the JAXB Context behind this JAXBManager. + * + * @return the JAXBContext + * @throws JAXBException + * @Deprecated TODO This method should be protected and the JAXBContext + * should be hidden from outside libraries. Any options needing + * to be applied to the context or its marshallers/unmarshallers + * should either have convenience methods or flags on + * JAXBManager to provide that functionality. + */ + @Deprecated public JAXBContext getJaxbContext() throws JAXBException { return jaxbContext; } - private Unmarshaller getUnmarshaller() throws JAXBException { + /** + * Gets an unmarshaller, creating one if one is not currently available. + * + * @return an unmarshaller + * @throws JAXBException + */ + protected Unmarshaller getUnmarshaller() throws JAXBException { Unmarshaller m = unmarshallers.poll(); if (m == null) { m = getJaxbContext().createUnmarshaller(); @@ -139,6 +172,12 @@ public class JAXBManager { return m; } + /** + * Gets a marshaller, creating one if one is not currently available. + * + * @return + * @throws JAXBException + */ protected Marshaller getMarshaller() throws JAXBException { Marshaller m = marshallers.poll(); if (m == null) { @@ -149,8 +188,7 @@ public class JAXBManager { } /** - * Instantiates an object from the XML representation in a string. Uses - * JAXB. + * Instantiates an object from the XML representation in a string. * * @param xml * The XML representation @@ -174,7 +212,10 @@ public class JAXBManager { } /** + * Processes the events received by an unmarshaller when parsing XML. + * * @param msh + * the unmarshaller */ private void handleEvents(Unmarshaller msh, String name) { try { @@ -224,7 +265,7 @@ public class JAXBManager { /** * Convert an instance of a class to an XML pretty print representation in a - * string. Uses JAXB. + * string. * * @param obj * Object being marshalled @@ -236,8 +277,7 @@ public class JAXBManager { } /** - * Convert an instance of a class to an XML representation in a string. Uses - * JAXB. + * Convert an instance of a class to an XML representation in a string. * * @param obj * Object being marshalled @@ -246,13 +286,13 @@ public class JAXBManager { * @return XML string representation of the object * @throws JAXBException */ - public String marshalToXml(Object obj, boolean formatedOutput) + public String marshalToXml(Object obj, boolean formattedOutput) throws JAXBException { Marshaller msh = getMarshaller(); try { StringWriter writer = new StringWriter(); msh.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean( - formatedOutput)); + formattedOutput)); msh.marshal(obj, writer); return writer.toString(); } finally { @@ -264,7 +304,7 @@ public class JAXBManager { /** * Convert an instance of a class to an XML representation and writes pretty - * print formatted XML to file. Uses JAXB. + * print formatted XML to file. * * @param obj * Object to be marshaled @@ -272,14 +312,14 @@ public class JAXBManager { * Path to the output file * @throws SerializationException */ - public void jaxbMarshalToXmlFile(Object obj, String filePath) + public void marshalToXmlFile(Object obj, String filePath) throws SerializationException { - jaxbMarshalToXmlFile(obj, filePath, true); + marshalToXmlFile(obj, filePath, true); } /** * Convert an instance of a class to an XML representation and writes XML to - * file. Uses JAXB. + * file. * * @param obj * Object to be marshaled @@ -289,10 +329,10 @@ public class JAXBManager { * True for pretty print xml. * @throws SerializationException */ - public void jaxbMarshalToXmlFile(Object obj, String filePath, + public void marshalToXmlFile(Object obj, String filePath, boolean formattedOutput) throws SerializationException { try { - jaxbMarshalToStream(obj, new FileOutputStream(new File(filePath)), + marshalToStream(obj, new FileOutputStream(new File(filePath)), formattedOutput); } catch (SerializationException e) { throw e; @@ -303,20 +343,20 @@ public class JAXBManager { /** * Convert an instance of a class to an XML representation and writes pretty - * print formatted XML to output stream. Uses JAXB. + * print formatted XML to output stream. * * @param obj * @param out * @throws SerializationException */ - public void jaxbMarshalToStream(Object obj, OutputStream out) + public void marshalToStream(Object obj, OutputStream out) throws SerializationException { - jaxbMarshalToStream(obj, out, true); + marshalToStream(obj, out, true); } /** * Convert an instance of a class to an XML representation and writes XML to - * output stream. Uses JAXB. + * output stream. * * @param obj * @param out @@ -324,7 +364,7 @@ public class JAXBManager { * * @throws SerializationException */ - public void jaxbMarshalToStream(Object obj, OutputStream out, + public void marshalToStream(Object obj, OutputStream out, boolean formattedOutput) throws SerializationException { Marshaller msh = null; try { @@ -349,27 +389,112 @@ public class JAXBManager { } /** - * Instantiates an object from the XML representation in a File. Uses JAXB. + * Instantiates an object from the XML representation in a File. * * @param filePath * The path to the XML file * @return A new instance from the XML representation * @throws SerializationException + * @Deprecated Use unmarshalFromXmlFile(Class, String) instead */ - public Object jaxbUnmarshalFromXmlFile(String filePath) + @Deprecated + public Object unmarshalFromXmlFile(String filePath) throws SerializationException { - return jaxbUnmarshalFromXmlFile(new File(filePath)); + return unmarshalFromXmlFile(new File(filePath)); } /** - * Instantiates an object from the XML representation in a File. Uses JAXB. + * Instantiates an object from the XML representation in a File. * + * @param file + * The XML file + * @return A new instance from the XML representation + * @throws SerializationException + * @Deprecated Use unmarshalFromXmlFile(Class, File) instead + */ + @Deprecated + public Object unmarshalFromXmlFile(File file) throws SerializationException { + return unmarshalFromXmlFile(Object.class, file); + } + + /** + * Instantiates an object of the specified type from the XML representation + * in a File. + * + * @param clazz + * The class to cast the Object in the file to * @param filePath + * The path to the XML file + * @return A new instance from the XML representation + * @throws SerializationException + */ + public T unmarshalFromXmlFile(Class clazz, String filePath) + throws SerializationException { + return unmarshalFromXmlFile(clazz, new File(filePath)); + } + + /** + * Instantiates an object from the XML representation in a File. + * + * @param clazz + * The class to cast the Object in the file to + * @param file * The XML file * @return A new instance from the XML representation * @throws SerializationException */ - public Object jaxbUnmarshalFromXmlFile(File file) + public T unmarshalFromXmlFile(Class clazz, File file) + throws SerializationException { + try { + return clazz.cast(internalUnmarshalFromXmlFile(file)); + } catch (ClassCastException cce) { + throw new SerializationException(cce); + } + } + + /** + * Instantiates an object from the XML representation in a stream. + * + * @param is + * The input stream. The stream will be closed by this operation. + * @return A new instance from the XML representation + * @throws SerializationException + */ + public Object unmarshalFromInputStream(InputStream is) + throws SerializationException { + Unmarshaller msh = null; + try { + msh = getUnmarshaller(); + Object obj = msh.unmarshal(is); + return obj; + } catch (Exception e) { + throw new SerializationException(e.getLocalizedMessage(), e); + } finally { + if (msh != null) { + handleEvents(msh, null); + } + if ((msh != null) && (unmarshallers.size() < QUEUE_SIZE)) { + unmarshallers.add(msh); + } + if (is != null) { + try { + is.close(); + } catch (IOException e) { + // ignore + } + } + } + } + + /** + * Unmarshals an object from an xml file. + * + * @param file + * the file to unmarshal and object from. + * @return the object from the file + * @throws SerializationException + */ + protected Object internalUnmarshalFromXmlFile(File file) throws SerializationException { FileReader reader = null; Unmarshaller msh = null; @@ -397,39 +522,4 @@ public class JAXBManager { } } - /** - * Instantiates an object from the XML representation in a stream. Uses - * JAXB. - * - * @param is - * The input stream. The stream will be closed by this operation. - * @return A new instance from the XML representation - * @throws SerializationException - */ - public Object jaxbUnmarshalFromInputStream(InputStream is) - throws SerializationException { - Unmarshaller msh = null; - try { - msh = getUnmarshaller(); - Object obj = msh.unmarshal(is); - return obj; - } catch (Exception e) { - throw new SerializationException(e.getLocalizedMessage(), e); - } finally { - if (msh != null) { - handleEvents(msh, null); - } - if ((msh != null) && (unmarshallers.size() < QUEUE_SIZE)) { - unmarshallers.add(msh); - } - if (is != null) { - try { - is.close(); - } catch (IOException e) { - // ignore - } - } - } - } - } diff --git a/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/SerializationUtil.java b/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/SerializationUtil.java index abf1070224..0dd8df7119 100644 --- a/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/SerializationUtil.java +++ b/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/SerializationUtil.java @@ -29,8 +29,8 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import com.raytheon.uf.common.serialization.DynamicSerializationManager.SerializationType; -import com.raytheon.uf.common.util.ServiceLoaderUtil; import com.raytheon.uf.common.util.DataUnzipper; +import com.raytheon.uf.common.util.ServiceLoaderUtil; /** * Provides utilities for serialization support @@ -49,6 +49,7 @@ import com.raytheon.uf.common.util.DataUnzipper; * May 01, 2013 1968 djohnson Prevent deadlock due to SerializableManager threads needing to serialize things. * Aug 06, 2013 2228 njensen More efficient transformFromThrift(Class, byte[]) * Aug 13, 2013 2169 bkowal Unzip any gzipped data before applying thrift transformations + * Oct 01, 2013 2163 njensen Updated calls to JAXBManager * * * @@ -96,6 +97,14 @@ public final class SerializationUtil { return result; } + /** + * Gets the JAXBContext behind the global JAXBManager instance. + * + * @return the global JAXBContext + * @throws JAXBException + * @Deprecated Use a specific JAXBManager instead. + */ + @Deprecated public static JAXBContext getJaxbContext() throws JAXBException { return getJaxbManager().getJaxbContext(); } @@ -160,7 +169,7 @@ public final class SerializationUtil { public static void jaxbMarshalToXmlFile(Object obj, String filePath) throws SerializationException { try { - getJaxbManager().jaxbMarshalToXmlFile(obj, filePath); + getJaxbManager().marshalToXmlFile(obj, filePath); } catch (JAXBException e) { throw new SerializationException(e); } @@ -198,8 +207,7 @@ public final class SerializationUtil { public static T jaxbUnmarshalFromXmlFile(Class clazz, String filePath) throws SerializationException { try { - return clazz.cast(getJaxbManager().jaxbUnmarshalFromXmlFile( - filePath)); + return getJaxbManager().unmarshalFromXmlFile(clazz, filePath); } catch (JAXBException e) { throw new SerializationException(e); } @@ -237,7 +245,7 @@ public final class SerializationUtil { public static T jaxbUnmarshalFromXmlFile(Class clazz, File file) throws SerializationException { try { - return clazz.cast(getJaxbManager().jaxbUnmarshalFromXmlFile(file)); + return getJaxbManager().unmarshalFromXmlFile(clazz, file); } catch (Exception e) { throw new SerializationException(e.getLocalizedMessage(), e); } @@ -276,8 +284,7 @@ public final class SerializationUtil { public static T jaxbUnmarshalFromInputStream(Class clazz, InputStream is) throws SerializationException { try { - return clazz - .cast(getJaxbManager().jaxbUnmarshalFromInputStream(is)); + return clazz.cast(getJaxbManager().unmarshalFromInputStream(is)); } catch (Exception e) { throw new SerializationException(e.getLocalizedMessage(), e); } diff --git a/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/SingleTypeJAXBManager.java b/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/SingleTypeJAXBManager.java new file mode 100644 index 0000000000..5f682c6f1f --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/SingleTypeJAXBManager.java @@ -0,0 +1,89 @@ +/** + * 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.common.serialization; + +import java.io.File; + +import javax.xml.bind.JAXBException; + +/** + * A JAXBManager that only supports a single class (including any classes that + * are contained within that class). Useful when dealing specifically with an + * XML file where you know the type that corresponds to it. + * + * Primarily used for convenience to avoid casting. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Oct 1, 2013  2361       njensen     Initial creation
+ * 
+ * 
+ * + * @author njensen + * @version 1.0 + * @param + */ + +public class SingleTypeJAXBManager extends JAXBManager { + + protected Class type; + + /** + * Constructor. Only accepts a single class. + * + * @param clazz + * the class of the object to read/write XML for. + * @throws JAXBException + */ + public SingleTypeJAXBManager(Class clazz) throws JAXBException { + super(clazz); + this.type = clazz; + } + + /** + * Instantiates an object from the XML representation in a File. + * + * @param file + * The XML file + * @return A new instance from the XML representation + * @throws SerializationException + */ + public T unmarshalFromXmlFile(File file) throws SerializationException { + return super.unmarshalFromXmlFile(type, file); + } + + /** + * Instantiates an object from the XML representation in a File. + * + * @param filePath + * The path to the XML file + * @return A new instance from the XML representation + * @throws SerializationException + */ + public T unmarshalFromXmlFile(String filePath) + throws SerializationException { + return super.unmarshalFromXmlFile(type, new File(filePath)); + } + +} diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.harvester/src/com/raytheon/uf/edex/datadelivery/harvester/crawler/CrawlLauncher.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.harvester/src/com/raytheon/uf/edex/datadelivery/harvester/crawler/CrawlLauncher.java index ee9210a436..2b30da160d 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.harvester/src/com/raytheon/uf/edex/datadelivery/harvester/crawler/CrawlLauncher.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.harvester/src/com/raytheon/uf/edex/datadelivery/harvester/crawler/CrawlLauncher.java @@ -145,7 +145,7 @@ public abstract class CrawlLauncher implements Job { for (LocalizationFile lf : files) { HarvesterConfig hc = (HarvesterConfig) jaxbMan - .jaxbUnmarshalFromXmlFile(lf.getFile()); + .unmarshalFromXmlFile(lf.getFile()); if (hc.getAgent() != null) { // we only want crawler types for CrawlerMetadata Agent agent = hc.getAgent(); diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.harvester/src/com/raytheon/uf/edex/datadelivery/harvester/crawler/SeedCrawlLauncher.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.harvester/src/com/raytheon/uf/edex/datadelivery/harvester/crawler/SeedCrawlLauncher.java index 914f3b7d6c..1bf84ed477 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.harvester/src/com/raytheon/uf/edex/datadelivery/harvester/crawler/SeedCrawlLauncher.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.harvester/src/com/raytheon/uf/edex/datadelivery/harvester/crawler/SeedCrawlLauncher.java @@ -77,7 +77,7 @@ public class SeedCrawlLauncher extends CrawlLauncher { for (LocalizationFile lf : getLocalizedFiles()) { HarvesterConfig hc = (HarvesterConfig) new JAXBManager( - HarvesterConfig.class).jaxbUnmarshalFromXmlFile( + HarvesterConfig.class).unmarshalFromXmlFile( lf.getFile()); if (hc.getProvider().getName().equals(providerName)) { diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.registry/src/com/raytheon/uf/edex/datadelivery/registry/federation/RegistryFederationManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.registry/src/com/raytheon/uf/edex/datadelivery/registry/federation/RegistryFederationManager.java index f56359707f..237ced6002 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.registry/src/com/raytheon/uf/edex/datadelivery/registry/federation/RegistryFederationManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.registry/src/com/raytheon/uf/edex/datadelivery/registry/federation/RegistryFederationManager.java @@ -162,7 +162,7 @@ public abstract class RegistryFederationManager { this.federationEnabled = false; } else { federationProperties = (FederationProperties) jaxbManager - .jaxbUnmarshalFromXmlFile(federationPropertiesFile); + .unmarshalFromXmlFile(federationPropertiesFile); } } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.registry/src/com/raytheon/uf/edex/datadelivery/registry/replication/RegistryReplicationManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.registry/src/com/raytheon/uf/edex/datadelivery/registry/replication/RegistryReplicationManager.java index 56ca32f0cd..9b30c51c81 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.registry/src/com/raytheon/uf/edex/datadelivery/registry/replication/RegistryReplicationManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.registry/src/com/raytheon/uf/edex/datadelivery/registry/replication/RegistryReplicationManager.java @@ -185,7 +185,7 @@ public class RegistryReplicationManager { return; } servers = (NotificationServers) jaxbManager - .jaxbUnmarshalFromXmlFile(notificationServerConfigFile); + .unmarshalFromXmlFile(notificationServerConfigFile); scheduler = Executors.newSingleThreadScheduledExecutor(); } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/src/com/raytheon/uf/edex/datadelivery/retrieval/util/RetrievalPersistUtil.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/src/com/raytheon/uf/edex/datadelivery/retrieval/util/RetrievalPersistUtil.java index bbcb2f971e..77d5d22fc4 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/src/com/raytheon/uf/edex/datadelivery/retrieval/util/RetrievalPersistUtil.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.retrieval/src/com/raytheon/uf/edex/datadelivery/retrieval/util/RetrievalPersistUtil.java @@ -163,7 +163,7 @@ public final class RetrievalPersistUtil { try { prl = (PluginRouteList) getJaxbManager() - .jaxbUnmarshalFromXmlFile(file); + .unmarshalFromXmlFile(file); } catch (Exception e) { statusHandler.error( "[Data Delivery] Configuration for plugin routes failed to load: File: " diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.npp.viirs/src/com/raytheon/uf/edex/plugin/npp/viirs/VIIRSDecoder.java b/edexOsgi/com.raytheon.uf.edex.plugin.npp.viirs/src/com/raytheon/uf/edex/plugin/npp/viirs/VIIRSDecoder.java index 4af307678c..b15e2de145 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.npp.viirs/src/com/raytheon/uf/edex/plugin/npp/viirs/VIIRSDecoder.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.npp.viirs/src/com/raytheon/uf/edex/plugin/npp/viirs/VIIRSDecoder.java @@ -135,7 +135,7 @@ public class VIIRSDecoder extends AbstractNPPDecoder { .getStaticLocalizationFile(VIIRS_MAPPING_FILE); in = mappingFile.openInputStream(); mapping = (VIIRSHeaderMapping) manager - .jaxbUnmarshalFromInputStream(in); + .unmarshalFromInputStream(in); } catch (Exception e) { throw new RuntimeException( "Error deserializing VIIRS header mapping file", e);