📄 applicationstate.java
字号:
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
* This code is licensed under the GPL 2.0 license, availible at the root
* application directory.
*/
package org.vfny.geoserver.global;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.geotools.validation.dto.PlugInDTO;
import org.geotools.validation.dto.TestDTO;
import org.geotools.validation.dto.TestSuiteDTO;
import org.springframework.beans.factory.InitializingBean;
import org.vfny.geoserver.global.xml.XMLConfigWriter.WriterUtils;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
/**
* This class represents the state of the GeoServer appliaction.
*
* <p>
* ApplicationState used by the state.jsp tile as a single view on the state of
* the GeoServer application. This class may be extended in the future to
* provide runtime statistics.
* </p>
*
* <p>
* This class is not a bean - content is updated based on methods. As an
* example consider the following State diagram:
* </p>
*
* @author dzwiers, Refractions Research, Inc.
* @version $Id: ApplicationState.java 7579 2007-10-09 22:30:14Z jdeolive $
*/
public class ApplicationState implements PlugIn, InitializingBean {
/** The key used to store this value in the Web Container */
public static final String WEB_CONTAINER_KEY = "GeoServer.ApplicationState";
/** Non null if configuration has been edited (but not applied) */
private Date configTimestamp;
/** Non null if the geoserver setup has been changed (but not saved) */
private Date appTimestamp;
/** Non null if the modification date of the xml files is known */
private Date xmlTimestamp;
/** magic, be very careful with this array. defined below in loadStatus() */
private int[] geoserverStatus = new int[13];
private Map geoserverNSErrors;
private Map geoserverDSErrors;
private Map geoserverVPErrors;
/**
* Data module
*/
Data data;
/**
* Validation module
*/
GeoValidator validator;
/**
* Configuration module
*/
Config config;
/**
*
* @deprecated use {@link #ApplicationState(Data, GeoValidator, Config)}
*/
public ApplicationState() {
this(null, null, null);
}
/**
* Creates a new appliction state.
*
* @param data The data modle.
* @param validator The validation module
*/
public ApplicationState(Data data, GeoValidator validator, Config config) {
this.data = data;
this.validator = validator;
this.config = config;
}
/**
* Clean up the Configuration State during application exit.
*
* <p>
* Since this class just holds data, no resources need to be released.
* </p>
*
* @see org.apache.struts.action.PlugIn#destroy()
*/
public void destroy() {
}
/**
* Set up the ApplicationState during Application start up.
*
* <p>
* ApplicationState simply registers itself with the WEB_CONTAINER_KEY
* ("GeoServer.ApplicationState") during start up.
* </p>
*
* @param actionServlet ActionServlet representing the Application
* @param moduleConfig Configuration used to set up this plug in
*
* @throws ServletException
*
* @see org.apache.struts.action.PlugIn#init(org.apache.struts.action.ActionServlet,
* org.apache.struts.config.ModuleConfig)
*
* @deprecated This class is no longer loaded with struts,
* use {@link #afterPropertiesSet()}
*/
public void init(ActionServlet actionServlet, ModuleConfig moduleConfig)
throws ServletException {
try {
afterPropertiesSet();
} catch (Exception e) {
throw new ServletException(e);
}
}
public void afterPropertiesSet() throws Exception {
configTimestamp = getXmlTimestamp();
appTimestamp = configTimestamp;
geoserverStatus[0] = -1;
}
/**
* True if the user has changed the Configuration and not yet applied them.
*
* @return <code>true</code> if Configuration needs changing.
*/
public boolean isConfigChanged() {
return (configTimestamp != null)
&& ((appTimestamp == null) || configTimestamp.after(appTimestamp));
}
/** Validation is part of the Configuration Process */
private boolean isValidationChanged() {
return isConfigChanged();
}
/**
* True if the user has changed GeoServer and not yet saved the changes.
*
* @return <code>true</code> if GeoServer has been changed (but not saved)
*/
public boolean isAppChanged() {
return (appTimestamp != null) && appTimestamp.after(getXmlTimestamp());
}
/**
* Notification that Config has been updated from XML config files
*/
public void notifyLoadXML() {
// Correct, this represents a load into config from xml
appTimestamp = xmlTimestamp;
configTimestamp = xmlTimestamp;
}
/**
* Notification that Global has been updated from Configuration
*/
public void notifyToGeoServer() {
appTimestamp = new Date();
}
/**
* Notification that Global has been saved to XML config files.
*/
public void notifiySaveXML() {
xmlTimestamp = new Date();
}
/**
* Notification that the User has changed the Configuration
*/
public void notifyConfigChanged() {
configTimestamp = new Date();
}
/**
* signal to any listeners that config has changed.
*/
public void fireChange() {
data.getGeoServer().fireChange();
}
/** Q: what is this supposed to do? */
public int getWcsGood() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return geoserverStatus[4];
}
/** q: What foul manner of magic is this? */
public int getWcsBad() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return geoserverStatus[5];
}
/** q: This does not make a lot of sense - did you want to consult both ConfigChanged and GeoServer changed? */
public int getWcsDisabled() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return geoserverStatus[6];
}
/** Q: what is this supposed to do? */
public int getWfsGood() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return geoserverStatus[1];
}
/** q: What foul manner of magic is this? */
public int getWfsBad() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return geoserverStatus[2];
}
/** q: This does not make a lot of sense - did you want to consult both ConfigChanged and GeoServer changed? */
public int getWfsDisabled() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return geoserverStatus[3];
}
/** Q: scary magic */
public int getWmsGood() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return geoserverStatus[4];
}
/** Q: scary magic */
public int getWmsBad() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return geoserverStatus[5];
}
/** Q: scary magic */
public int getWmsDisabled() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return geoserverStatus[6];
}
public int getDataGood() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return geoserverStatus[7];
}
public int getDataBad() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return geoserverStatus[8];
}
public int getDataDisabled() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return geoserverStatus[9];
}
public int getGeoserverGood() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return (int) ((geoserverStatus[1] + geoserverStatus[4] + geoserverStatus[7]) / 3.0);
}
public int getGeoserverBad() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return (int) ((geoserverStatus[2] + geoserverStatus[5] + geoserverStatus[8]) / 3.0);
}
public int getGeoserverDisabled() {
if (geoserverStatus[0] != ((isAppChanged() ? 1 : 0) + (isConfigChanged() ? 2 : 0)
+ (isValidationChanged() ? 4 : 0))) {
loadStatus();
}
return (int) ((geoserverStatus[3] + geoserverStatus[6] + geoserverStatus[9]) / 3.0);
}
/**
*
* loadStatus purpose.
* <p>
* Magic occurs here, so be careful. This sets the values in the geoserverStatus array.
* </p>
* <p>
* The array is broken into four blocks, [0],[1-3],[4-6],[7-9].
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -