Issue #2361 Get some of GFE away from using the global JAXB context, and in the process refactored JAXBManager
Change-Id: I83c36ee235066aa57da88f09090470bce84679f7 Former-commit-id:3e7dc7782f
[formerly f8d8a0033729878c8c6d94c00fd861ddc81f9d96] Former-commit-id:effa4f4f26
This commit is contained in:
parent
3bf9b72f52
commit
f529c077c6
32 changed files with 441 additions and 172 deletions
|
@ -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());
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
* </pre>
|
||||
*
|
||||
* @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,
|
||||
|
|
|
@ -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;
|
||||
|
@ -63,6 +65,7 @@ import com.raytheon.viz.gfe.core.IWEGroupManager;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 5, 2008 chammack Initial creation
|
||||
* Sep 30, 2013 2361 njensen Use JAXBManager for XML
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -89,9 +92,19 @@ public class WEGroupManager implements IWEGroupManager,
|
|||
|
||||
private LocalizationFile weGroupDir;
|
||||
|
||||
private SingleTypeJAXBManager<WEGroup> jaxb;
|
||||
|
||||
public WEGroupManager(final DataManager dataManager) {
|
||||
this.dataManager = dataManager;
|
||||
|
||||
try {
|
||||
this.jaxb = new SingleTypeJAXBManager<WEGroup>(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,
|
||||
|
|
|
@ -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
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -83,9 +84,11 @@ public class CombinationsFileUtil {
|
|||
|
||||
public static String SAVED_COMBO_DIR = FileUtil.join("gfe", "comboData");
|
||||
|
||||
private static final SingleTypeJAXBManager<ComboData> 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<ComboData> initializeJAXB() {
|
||||
SingleTypeJAXBManager<ComboData> retVal = null;
|
||||
try {
|
||||
retVal = new SingleTypeJAXBManager<ComboData>(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<String, Integer> comboDict = new HashMap<String, Integer>(
|
||||
comboData.combos.size());
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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();
|
||||
|
|
|
@ -301,7 +301,7 @@ public class TranslateReferenceSet {
|
|||
}
|
||||
}
|
||||
String path = FileUtil.join(dir, fname);
|
||||
jbm.jaxbMarshalToXmlFile(refData, path);
|
||||
jbm.marshalToXmlFile(refData, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* --/--/---- wldougher Initial creation
|
||||
* 09/30/2013 2361 njensen Removed XML annotations
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @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<String> lines;
|
||||
|
||||
@XmlAttribute
|
||||
@DynamicSerializeElement
|
||||
private String completeProductPil;
|
||||
|
||||
@XmlAttribute
|
||||
@DynamicSerializeElement
|
||||
private Boolean notify;
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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<ReferenceData> 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<ReferenceData> initializeJAXB() {
|
||||
SingleTypeJAXBManager<ReferenceData> retVal = null;
|
||||
try {
|
||||
retVal = new SingleTypeJAXBManager<ReferenceData>(
|
||||
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<ReferenceData> 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());
|
||||
|
|
|
@ -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<SampleData> jaxb = initializeJAXB();
|
||||
|
||||
private SampleId sampleId;
|
||||
|
||||
@XmlJavaTypeAdapter(value = CoordAdapter.class)
|
||||
@DynamicSerializeElement
|
||||
private List<Coordinate> points;
|
||||
|
||||
/**
|
||||
* Initializes the JAXB manager for reading/writing SampleData to/from XML.
|
||||
*
|
||||
* @return the JAXBManager
|
||||
*/
|
||||
private static SingleTypeJAXBManager<SampleData> initializeJAXB() {
|
||||
SingleTypeJAXBManager<SampleData> retVal = null;
|
||||
try {
|
||||
retVal = new SingleTypeJAXBManager<SampleData>(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<SampleData> getJAXBManager() {
|
||||
return jaxb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* <pre>
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* --/--/-- Initial Creation
|
||||
* 09/30/13 #2361 njensen Removed XML annotations
|
||||
* </pre>
|
||||
*
|
||||
*/
|
||||
@DynamicSerialize
|
||||
public class ServerMsg implements ISerializableObject {
|
||||
public class ServerMsg {
|
||||
|
||||
/** The message */
|
||||
@XmlAttribute
|
||||
@DynamicSerializeElement
|
||||
private String message;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -619,7 +619,7 @@ public final class LocalizationFile implements Comparable<LocalizationFile> {
|
|||
try {
|
||||
is = openInputStream();
|
||||
T object = resultClass.cast(manager
|
||||
.jaxbUnmarshalFromInputStream(is));
|
||||
.unmarshalFromInputStream(is));
|
||||
return object;
|
||||
} catch (Exception e) {
|
||||
throw new LocalizationException("Could not unmarshal file "
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* <pre>
|
||||
* 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
|
||||
* </pre>
|
||||
*
|
||||
* @author chammack
|
||||
|
@ -111,15 +115,44 @@ public class JAXBManager {
|
|||
|
||||
protected final Queue<Marshaller> marshallers = new ConcurrentLinkedQueue<Marshaller>();
|
||||
|
||||
/**
|
||||
* 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> T unmarshalFromXmlFile(Class<T> 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> T unmarshalFromXmlFile(Class<T> 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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> T jaxbUnmarshalFromXmlFile(Class<T> 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> T jaxbUnmarshalFromXmlFile(Class<T> 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> T jaxbUnmarshalFromInputStream(Class<T> 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);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 1, 2013 2361 njensen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author njensen
|
||||
* @version 1.0
|
||||
* @param <T>
|
||||
*/
|
||||
|
||||
public class SingleTypeJAXBManager<T extends Object> extends JAXBManager {
|
||||
|
||||
protected Class<T> type;
|
||||
|
||||
/**
|
||||
* Constructor. Only accepts a single class.
|
||||
*
|
||||
* @param clazz
|
||||
* the class of the object to read/write XML for.
|
||||
* @throws JAXBException
|
||||
*/
|
||||
public SingleTypeJAXBManager(Class<T> 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));
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -162,7 +162,7 @@ public abstract class RegistryFederationManager {
|
|||
this.federationEnabled = false;
|
||||
} else {
|
||||
federationProperties = (FederationProperties) jaxbManager
|
||||
.jaxbUnmarshalFromXmlFile(federationPropertiesFile);
|
||||
.unmarshalFromXmlFile(federationPropertiesFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -185,7 +185,7 @@ public class RegistryReplicationManager {
|
|||
return;
|
||||
}
|
||||
servers = (NotificationServers) jaxbManager
|
||||
.jaxbUnmarshalFromXmlFile(notificationServerConfigFile);
|
||||
.unmarshalFromXmlFile(notificationServerConfigFile);
|
||||
scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||
}
|
||||
|
||||
|
|
|
@ -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: "
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue