Omaha #5244 replaced deprecated method calls on LocalizationFile

Change-Id: Ifdd1382a35a8475137be54404cca0a5c48383990

Former-commit-id: fe12ffde9dcf6210b213ded4903d004263be50b4
This commit is contained in:
Nate Jensen 2016-01-12 16:42:48 -06:00
parent 8c21ca692b
commit b15fcd85b7
2 changed files with 71 additions and 93 deletions

View file

@ -26,13 +26,12 @@ import java.util.ArrayList;
import org.opengis.referencing.crs.ProjectedCRS; import org.opengis.referencing.crs.ProjectedCRS;
import com.raytheon.uf.common.localization.FileUpdatedMessage; import com.raytheon.uf.common.localization.ILocalizationFile;
import com.raytheon.uf.common.localization.ILocalizationFileObserver; import com.raytheon.uf.common.localization.ILocalizationPathObserver;
import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.localization.SaveableOutputStream; import com.raytheon.uf.common.localization.SaveableOutputStream;
import com.raytheon.uf.common.localization.exception.LocalizationException; import com.raytheon.uf.common.localization.exception.LocalizationException;
@ -59,6 +58,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* Oct 02, 2013 2361 njensen Use JAXBManager for XML * Oct 02, 2013 2361 njensen Use JAXBManager for XML
* Oct 08, 2015 4912 rferrel Update configXml when configuration file changes * Oct 08, 2015 4912 rferrel Update configXml when configuration file changes
* and removed deprecated code. * and removed deprecated code.
* Jan 12, 2016 5244 njensen Replaced calls to deprecated LocalizationFile methods
* *
* </pre> * </pre>
* *
@ -66,6 +66,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* @version 1.0 * @version 1.0
*/ */
public class CWATLocationConfigManager { public class CWATLocationConfigManager {
private static final IUFStatusHandler statusHandler = UFStatus private static final IUFStatusHandler statusHandler = UFStatus
.getHandler(CWATLocationConfigManager.class); .getHandler(CWATLocationConfigManager.class);
@ -108,10 +109,9 @@ public class CWATLocationConfigManager {
/** /**
* Observer to force updating the configXml. * Observer to force updating the configXml.
*/ */
private ILocalizationFileObserver configXmlObserver = new ILocalizationFileObserver() { private ILocalizationPathObserver configXmlObserver = new ILocalizationPathObserver() {
@Override @Override
public void fileUpdated(FileUpdatedMessage message) { public void fileChanged(ILocalizationFile file) {
readConfigXml(); readConfigXml();
} }
}; };
@ -122,14 +122,11 @@ public class CWATLocationConfigManager {
private CWATLocationConfigManager() { private CWATLocationConfigManager() {
configXml = new CWATLocationsXML(); configXml = new CWATLocationsXML();
IPathManager pm = PathManagerFactory.getPathManager(); IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
LocalizationLevel.SITE);
/* /*
* No need to remove the observer since the instance of this class * No need to remove the observer since the instance of this class
* remains until the JRE is shutdown. * remains until the JRE is shutdown.
*/ */
pm.getLocalizationFile(lc, CWAT_DIR).addFileUpdatedObserver( pm.addLocalizationPathObserver(CWAT_DIR, configXmlObserver);
configXmlObserver);
} }
/** /**
@ -145,7 +142,7 @@ public class CWATLocationConfigManager {
return instance; return instance;
} }
private LocalizationFile getConfigFile() { private ILocalizationFile getConfigFile() {
IPathManager pm = PathManagerFactory.getPathManager(); IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC, LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
LocalizationLevel.SITE); LocalizationLevel.SITE);
@ -169,21 +166,21 @@ public class CWATLocationConfigManager {
* Read the XML configuration data for the current XML file name. * Read the XML configuration data for the current XML file name.
*/ */
public void readConfigXml() { public void readConfigXml() {
LocalizationFile lFile = getConfigFile(); ILocalizationFile lFile = getConfigFile();
try { try {
if (lFile.exists()) { if (lFile.exists()) {
statusHandler.info("Reading CWAT configuration file: " statusHandler.info("Reading CWAT configuration file: "
+ lFile.getName()); + lFile.getPath());
try (InputStream stream = lFile.openInputStream()) { try (InputStream stream = lFile.openInputStream()) {
// This closes the stream // This closes the stream
CWATLocationsXML configXmltmp = (CWATLocationsXML) jaxb CWATLocationsXML configXmltmp = jaxb
.unmarshalFromInputStream(stream); .unmarshalFromInputStream(stream);
configXml = configXmltmp; configXml = configXmltmp;
} }
} else { } else {
statusHandler.handle(Priority.WARN, statusHandler.handle(Priority.WARN,
"No CWAT locations file found. Generating the file: " "No CWAT locations file found. Generating the file: "
+ lFile.getName()); + lFile.getPath());
// create a new one // create a new one
ArrayList<ThreatLocation> locations = ScanUtils.getCWASites( ArrayList<ThreatLocation> locations = ScanUtils.getCWASites(
getSiteCoor(), getCRS()); getSiteCoor(), getCRS());
@ -195,7 +192,7 @@ public class CWATLocationConfigManager {
} catch (Exception e) { } catch (Exception e) {
statusHandler.handle(Priority.WARN, statusHandler.handle(Priority.WARN,
"Unable to load location file: " + lFile.getName(), e); "Unable to load location file: " + lFile.getPath(), e);
} }
} }
@ -204,15 +201,15 @@ public class CWATLocationConfigManager {
*/ */
public void saveConfigXml() { public void saveConfigXml() {
// Save the xml object to disk // Save the xml object to disk
LocalizationFile lFile = getConfigFile(); ILocalizationFile lFile = getConfigFile();
statusHandler statusHandler
.info("Saving CWAT configuration file: " + lFile.getName()); .info("Saving CWAT configuration file: " + lFile.getPath());
try (SaveableOutputStream stream = lFile.openOutputStream()) { try (SaveableOutputStream stream = lFile.openOutputStream()) {
jaxb.marshalToStream(configXml, stream); jaxb.marshalToStream(configXml, stream);
stream.save(); stream.save();
} catch (LocalizationException | SerializationException | IOException e1) { } catch (LocalizationException | SerializationException | IOException e) {
statusHandler.handle(Priority.PROBLEM, statusHandler.handle(Priority.PROBLEM,
"Unable to save localized file: " + lFile.getName(), e1); "Unable to save localized file: " + lFile.getPath(), e);
} }
} }

View file

@ -1,19 +1,21 @@
package com.raytheon.uf.common.monitor.config; package com.raytheon.uf.common.monitor.config;
import java.io.File; import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import com.raytheon.uf.common.dataplugin.radar.util.RadarsInUseUtil; import com.raytheon.uf.common.dataplugin.radar.util.RadarsInUseUtil;
import com.raytheon.uf.common.localization.FileUpdatedMessage; import com.raytheon.uf.common.localization.ILocalizationFile;
import com.raytheon.uf.common.localization.ILocalizationFileObserver; import com.raytheon.uf.common.localization.ILocalizationPathObserver;
import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.localization.SaveableOutputStream;
import com.raytheon.uf.common.localization.exception.LocalizationException;
import com.raytheon.uf.common.monitor.events.MonitorConfigEvent; import com.raytheon.uf.common.monitor.events.MonitorConfigEvent;
import com.raytheon.uf.common.monitor.events.MonitorConfigListener; import com.raytheon.uf.common.monitor.events.MonitorConfigListener;
import com.raytheon.uf.common.monitor.xml.SCANModelParameterXML; import com.raytheon.uf.common.monitor.xml.SCANModelParameterXML;
@ -27,9 +29,9 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
/** /**
* ScanRunSiteConfigurationManager * ScanRunSiteConfigurationManager
* *
* Holds the SCAN configuration * Holds the SCAN configuration
* *
* <pre> * <pre>
* SOFTWARE HISTORY * SOFTWARE HISTORY
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
@ -40,30 +42,33 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
* Oct 02, 2013 2361 njensen Use JAXBManager for XML * Oct 02, 2013 2361 njensen Use JAXBManager for XML
* Jan 20, 2015 3949 nabowle Add lightning source. * Jan 20, 2015 3949 nabowle Add lightning source.
* Mar 27, 2015 4260 dhladky Updated default model. * Mar 27, 2015 4260 dhladky Updated default model.
* Jan 12, 2016 5244 njensen Replaced calls to deprecated LocalizationFile methods
* *
* </pre> * </pre>
* *
* @author dhladky * @author dhladky
* @version 1.0 * @version 1.0
*/ */
public class SCANRunSiteConfigurationManager implements public class SCANRunSiteConfigurationManager implements
ILocalizationFileObserver { ILocalizationPathObserver {
/** Path to FFMP Source config. */ /** Path to FFMP Source config. */
private static final String CONFIG_FILE_NAME = "scan" + File.separatorChar private static final String CONFIG_FILE_NAME = "scan"
+ "SCANRunSiteConfig.xml"; + IPathManager.SEPARATOR + "SCANRunSiteConfig.xml";
/** default model to set in XML **/ /** default model to set in XML **/
private static final String DEFAULT_MODEL = "HRRR"; private static final String DEFAULT_MODEL = "HRRR";
private static final IUFStatusHandler statusHandler = UFStatus private static final IUFStatusHandler statusHandler = UFStatus
.getHandler(SCANRunSiteConfigurationManager.class); .getHandler(SCANRunSiteConfigurationManager.class);
// This needs to initialize before the instance since the constructor will /*
// makes use of JAXB. JVM spec 12.4.2 step 9 indicates this will * This jaxb variable needs to be declared before the instance variable
// initialize ahead of the instance since it is earlier in * since the constructor makes use of JAXB. JVM spec 12.4.2 step 9 indicates
// in the text source. * jaxb will initialize ahead of instance since it is earlier in the text
* source.
*/
private static final SingleTypeJAXBManager<SCANSiteRunConfigXML> jaxb = SingleTypeJAXBManager private static final SingleTypeJAXBManager<SCANSiteRunConfigXML> jaxb = SingleTypeJAXBManager
.createWithoutException(SCANSiteRunConfigXML.class); .createWithoutException(SCANSiteRunConfigXML.class);
@ -75,8 +80,6 @@ public class SCANRunSiteConfigurationManager implements
*/ */
protected SCANSiteRunConfigXML configXml; protected SCANSiteRunConfigXML configXml;
private LocalizationFile lf = null;
private List<MonitorConfigListener> listeners = new CopyOnWriteArrayList<MonitorConfigListener>(); private List<MonitorConfigListener> listeners = new CopyOnWriteArrayList<MonitorConfigListener>();
protected boolean isPopulated; protected boolean isPopulated;
@ -84,6 +87,8 @@ public class SCANRunSiteConfigurationManager implements
/* Private Constructor */ /* Private Constructor */
private SCANRunSiteConfigurationManager() { private SCANRunSiteConfigurationManager() {
isPopulated = false; isPopulated = false;
IPathManager pm = PathManagerFactory.getPathManager();
pm.addLocalizationPathObserver(CONFIG_FILE_NAME, this);
try { try {
readConfigXml(); readConfigXml();
@ -95,7 +100,7 @@ public class SCANRunSiteConfigurationManager implements
/** /**
* Get an instance of this singleton. * Get an instance of this singleton.
* *
* @return Instance of this class * @return Instance of this class
*/ */
public static SCANRunSiteConfigurationManager getInstance() { public static SCANRunSiteConfigurationManager getInstance() {
@ -106,20 +111,14 @@ public class SCANRunSiteConfigurationManager implements
* Read the XML configuration data for the current XML file name. * Read the XML configuration data for the current XML file name.
*/ */
public synchronized void readConfigXml() throws SerializationException { public synchronized void readConfigXml() throws SerializationException {
IPathManager pm = PathManagerFactory.getPathManager(); IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC, LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
LocalizationLevel.SITE); LocalizationLevel.SITE);
ILocalizationFile lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME);
lf = pm.getLocalizationFile(lc, CONFIG_FILE_NAME); if (!lf.exists()) {
lf.addFileUpdatedObserver(this); statusHandler.handle(Priority.WARN,
File file = lf.getFile(); "SCANRunSiteConfigurationManager: " + lf.getPath()
// System.out.println("Reading -- " + file.getAbsolutePath()); + " does not exist. Creating default...");
if (!file.exists()) {
statusHandler.handle(
Priority.WARN,
"SCANRunSiteConfigurationManager: "
+ file.getAbsolutePath() + " does not exist.");
try { try {
createValidConfig(); createValidConfig();
} catch (Exception e) { } catch (Exception e) {
@ -129,12 +128,13 @@ public class SCANRunSiteConfigurationManager implements
} }
} }
SCANSiteRunConfigXML configXmltmp = null; try (InputStream is = lf.openInputStream()) {
configXml = jaxb.unmarshalFromInputStream(is);
configXmltmp = jaxb.unmarshalFromXmlFile(file.getAbsolutePath()); isPopulated = true;
} catch (IOException | LocalizationException e) {
configXml = configXmltmp; throw new SerializationException("Error reading config file "
isPopulated = true; + lf.getPath(), e);
}
} }
public void addListener(MonitorConfigListener fl) { public void addListener(MonitorConfigListener fl) {
@ -153,50 +153,32 @@ public class SCANRunSiteConfigurationManager implements
IPathManager pm = PathManagerFactory.getPathManager(); IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC, LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
LocalizationLevel.SITE); LocalizationLevel.SITE);
ILocalizationFile newXmlFile = pm.getLocalizationFile(lc,
LocalizationFile newXmlFile = pm.getLocalizationFile(lc,
CONFIG_FILE_NAME); CONFIG_FILE_NAME);
if (newXmlFile.getFile().getParentFile().exists() == false) { try (SaveableOutputStream sos = newXmlFile.openOutputStream()) {
// System.out.println("Creating new directory"); jaxb.marshalToStream(configXml, sos);
sos.save();
if (newXmlFile.getFile().getParentFile().mkdirs() == false) {
// System.out.println("Could not create new directory...");
}
}
try {
// System.out.println("Saving -- "
// + newXmlFile.getFile().getAbsolutePath());
jaxb.marshalToXmlFile(configXml, newXmlFile.getFile()
.getAbsolutePath());
newXmlFile.save();
setPopulated(true); setPopulated(true);
lf = newXmlFile;
} catch (Exception e) { } catch (Exception e) {
statusHandler.handle(Priority.WARN, statusHandler.handle(Priority.WARN,
"SCANRunSiteConfigurationManager: " + newXmlFile.getName() "SCANRunSiteConfigurationManager: " + newXmlFile.getPath()
+ " couldn't be saved.", e); + " couldn't be saved.", e);
} }
} }
@Override @Override
public void fileUpdated(FileUpdatedMessage message) { public void fileChanged(ILocalizationFile file) {
if (file.getPath().equals(CONFIG_FILE_NAME)) {
if (message.getFileName().equals(CONFIG_FILE_NAME)) {
try { try {
readConfigXml(); readConfigXml();
// inform listeners // inform listeners
for (MonitorConfigListener fl : listeners) { for (MonitorConfigListener fl : listeners) {
fl.configChanged(new MonitorConfigEvent(this)); fl.configChanged(new MonitorConfigEvent(this));
} }
} catch (Exception e) { } catch (Exception e) {
statusHandler.handle( statusHandler.handle(Priority.WARN,
Priority.WARN, "SCANRunSiteConfigurationManager: " + file.getPath()
"SCANRunSiteConfigurationManager: "
+ message.getFileName()
+ " couldn't be updated.", e); + " couldn't be updated.", e);
} }
} }
@ -216,7 +198,7 @@ public class SCANRunSiteConfigurationManager implements
/** /**
* Get a site listing * Get a site listing
* *
* @return * @return
*/ */
public ArrayList<String> getSiteNames() { public ArrayList<String> getSiteNames() {
@ -228,7 +210,7 @@ public class SCANRunSiteConfigurationManager implements
/** /**
* Get a local site listing * Get a local site listing
* *
* @return * @return
*/ */
public ArrayList<String> getLocalSiteNames() { public ArrayList<String> getLocalSiteNames() {
@ -240,7 +222,7 @@ public class SCANRunSiteConfigurationManager implements
/** /**
* Get a dial site listing * Get a dial site listing
* *
* @return * @return
*/ */
public ArrayList<String> getDialSiteNames() { public ArrayList<String> getDialSiteNames() {
@ -252,7 +234,7 @@ public class SCANRunSiteConfigurationManager implements
/** /**
* Get the lightning source. * Get the lightning source.
* *
* @return * @return
*/ */
public String getLightningSource() { public String getLightningSource() {
@ -264,7 +246,7 @@ public class SCANRunSiteConfigurationManager implements
/** /**
* Get the Site you are seeking * Get the Site you are seeking
* *
* @param name * @param name
* @return * @return
*/ */
@ -284,9 +266,8 @@ public class SCANRunSiteConfigurationManager implements
/** /**
* Creates a valid configuration based on radar config * Creates a valid configuration based on radar config
*/ */
public void createValidConfig() throws Exception { public void createValidConfig() {
/*
/**
* Don't have one, so create an EDEX generated default * Don't have one, so create an EDEX generated default
*/ */
List<String> localsites = RadarsInUseUtil.getSite(null, List<String> localsites = RadarsInUseUtil.getSite(null,
@ -319,10 +300,10 @@ public class SCANRunSiteConfigurationManager implements
} }
/** /**
* *
* Enumeration for which type of ModelData. CAPE is: Convective Available * Enumeration for which type of ModelData. CAPE is: Convective Available
* Potential Energy. HELI is: storm relative HELIcity. * Potential Energy. HELI is: storm relative HELIcity.
* *
* @author dhladky * @author dhladky
* @version 1.0 * @version 1.0
*/ */
@ -340,6 +321,6 @@ public class SCANRunSiteConfigurationManager implements
public String getType() { public String getType() {
return type; return type;
} }
}; }
} }