Commit 40fb0e74 authored by helene ortiz's avatar helene ortiz
Browse files

Modifications for 0-crash version

parent d45a91b4
......@@ -50,6 +50,7 @@ import fr.ill.ics.nscclient.servant.ResourceNotFoundException;
import fr.ill.ics.nscclient.servant.SpyPropertyDescriptor;
import fr.ill.ics.util.ConfigManager;
import fr.ill.ics.util.FileHelper;
import fr.ill.ics.util.exception.ConfigurationException.PluginType;
import fr.ill.ics.util.exception.PropertyNotFoundException;
public class PropertyManager {
......@@ -260,10 +261,11 @@ public class PropertyManager {
*
* @param controller
* @param propertyName
* @param pluginType TODO
* @return
* @throws PropertyNotFoundException
*/
public Property getProperty(Controller controller, String propertyName) throws PropertyNotFoundException {
public Property getProperty(Controller controller, String propertyName, PluginType pluginType) throws PropertyNotFoundException {
Property property;
if (controller instanceof CorbaServant) {
property = getPropertyForServant((CorbaServant)controller, propertyName);
......@@ -271,7 +273,7 @@ public class PropertyManager {
property = getPropertyForCommandBox((AtomicCommandWrapper)controller, propertyName);
}
if (property == null) {
PropertyNotFoundException pnfe = new PropertyNotFoundException(propertyName, controller.getType(), controller.getName(), getClass().getCanonicalName(), "getProperty");
PropertyNotFoundException pnfe = new PropertyNotFoundException(propertyName, controller.getType(), controller.getName(), getClass().getCanonicalName(), "getProperty", pluginType);
throw pnfe;
}
return property;
......@@ -456,7 +458,7 @@ public class PropertyManager {
int id = PropertyDatabase.getInstance().getPropertyIdForServant(servant.getId(), propertyName);
if (id < 0) {
System.err.println("Cannot get property " + propertyName + " from " + servant.getName());
//System.err.println("Cannot get property " + propertyName + " from " + servant.getName());
ConfigManager.CONFIGURATION_ERROR = true;
return null;
}
......@@ -490,7 +492,7 @@ public class PropertyManager {
int propertyId = PropertyDatabase.getInstance().getPropertyIdForServant(command.getServantId(), propertyName);
if (propertyId < 0) {
System.err.println("Cannot get property " + propertyName + " from servant " + command.getServantId());
//System.err.println("Cannot get property " + propertyName + " from servant " + command.getServantId());
ConfigManager.CONFIGURATION_ERROR = true;
return null;
}
......@@ -553,11 +555,12 @@ public class PropertyManager {
/**
*
* @param pluginType TODO
* @param controllers
* @param propertyName
* @return
*/
public Property getDynamicPropertyChild(Controller controller, String realPropertyName) throws PropertyNotFoundException {
public Property getDynamicPropertyChild(Controller controller, String realPropertyName, PluginType pluginType) throws PropertyNotFoundException {
String parentPropertyName = realPropertyName.substring(0, realPropertyName.lastIndexOf("."));
int index = Integer.parseInt(realPropertyName.substring(realPropertyName.lastIndexOf(".")+1));
Property property = null;
......@@ -580,7 +583,7 @@ public class PropertyManager {
}
}
if (property == null) {
PropertyNotFoundException pnfe = new PropertyNotFoundException(realPropertyName, controller.getType(), controller.getName(), getClass().getCanonicalName(), "getDynamicPropertyChild");
PropertyNotFoundException pnfe = new PropertyNotFoundException(realPropertyName, controller.getType(), controller.getName(), getClass().getCanonicalName(), "getDynamicPropertyChild", pluginType);
throw pnfe;
}
return property;
......@@ -906,7 +909,7 @@ public class PropertyManager {
public int getNumberOfDecimalPlaces(Controller controller, String propertyName) {
try {
Property property = getProperty(controller, propertyName);
Property property = getProperty(controller, propertyName, PluginType.GENERAL);
if (property != null) {
PropertyFormat format = property.getPropertyFormat();
if (format != null) {
......
......@@ -39,6 +39,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import fr.ill.ics.util.exception.ConfigurationException;
import fr.ill.ics.util.exception.ConfigurationException.PluginType;
import fr.ill.ics.util.exception.ParticularWidgetNotFoundException;
import fr.ill.ics.util.exception.PropertyNotFoundException;
......@@ -466,50 +467,58 @@ public class ConfigManager {
if (configurationExceptions == null) {
configurationExceptions = new HashSet<ConfigurationException>();
}
if (configurationExceptions.add(configurationException)) {
// First time for this property
System.out.println("Exception added: " + configurationException + " FROM " + configurationException.getClassName() + ".." + configurationException.getMethodName());
//System.out.println("Exception added: " + configurationException + " FROM " + configurationException.getClassName() + ".." + configurationException.getMethodName());
} else {
configurationException.setFirst(false);
}
}
public Set<ConfigurationException> getConfigurationExceptions(String controllerType, String controllerName) {
public Set<ConfigurationException> getConfigurationExceptions(String controllerType, String controllerName, PluginType pluginType) {
Set<ConfigurationException> set = null;
if (configurationExceptions != null) {
for (ConfigurationException configurationException : configurationExceptions) {
if (configurationException instanceof PropertyNotFoundException) {
PropertyNotFoundException pnfe = (PropertyNotFoundException)configurationException;
if (pnfe.getControllerName().equals(controllerName)) {
if (set == null) {
set = new HashSet<ConfigurationException>();
if (configurationException.getPluginType() == pluginType) {
if (configurationException instanceof PropertyNotFoundException) {
PropertyNotFoundException pnfe = (PropertyNotFoundException)configurationException;
if (pnfe.getControllerName().equals(controllerName)) {
if (set == null) {
set = new HashSet<ConfigurationException>();
}
set.add(pnfe);
}
set.add(pnfe);
}
} else if (configurationException instanceof ParticularWidgetNotFoundException) {
ParticularWidgetNotFoundException pwnfe = (ParticularWidgetNotFoundException)configurationException;
if (pwnfe.getControllerName().equals(controllerName)) {
if (set == null) {
set = new HashSet<ConfigurationException>();
} else if (configurationException instanceof ParticularWidgetNotFoundException) {
ParticularWidgetNotFoundException pwnfe = (ParticularWidgetNotFoundException)configurationException;
if (pwnfe.getControllerName().equals(controllerName)) {
if (set == null) {
set = new HashSet<ConfigurationException>();
}
set.add(configurationException);
}
set.add(configurationException);
}
} else if (configurationException instanceof ConfigurationException) {
if (configurationException.getControllerType().equals(controllerType)) {
if (set == null) {
set = new HashSet<ConfigurationException>();
} else if (configurationException instanceof ConfigurationException) { // ControllerNotFoundException managed here
if (configurationException.getControllerType().equals(controllerType)) {
if (set == null) {
set = new HashSet<ConfigurationException>();
}
set.add(configurationException);
}
set.add(configurationException);
}
}
}
}
return set;
}
public Set<ConfigurationException> getConfigurationExceptions() {
return configurationExceptions;
}
}
......@@ -26,6 +26,9 @@ import fr.ill.ics.util.ConfigManager;
*/
public class ConfigurationException extends Exception {
public enum PluginType {SETUP, COMMAND, SPY, GENERAL};
private PluginType pluginType = PluginType.GENERAL; // default value to avoid null pointer exception
protected String controllerType;
private String dynamicPropertyNamePrefix;
private String className;
......@@ -41,6 +44,16 @@ public class ConfigurationException extends Exception {
}
public ConfigurationException(String message, String controllerType, String dynamicPropertyNamePrefix, String className, String methodName, PluginType pluginType) {
super(message);
this.controllerType = controllerType;
this.className = className;
this.methodName = methodName;
this.pluginType = pluginType;
addToConfigManager();
}
public String getControllerType() {
return controllerType;
}
......@@ -51,6 +64,7 @@ public class ConfigurationException extends Exception {
}
public boolean equals(Object object) {
if (this == object) {
return true;
}
......@@ -58,16 +72,21 @@ public class ConfigurationException extends Exception {
return false;
}
ConfigurationException configurationException = (ConfigurationException)object;
if (this.controllerType.equals(configurationException.getControllerType())) {
if (this.controllerType.equals(configurationException.getControllerType()) && this.getPluginType() == configurationException.getPluginType()) {
return (this.getMessage().equals(configurationException.getMessage()));
}
return false;
}
private String getDynamicPropertyNamePrefix() {
return dynamicPropertyNamePrefix;
}
public int hashCode() {
return (this.getMessage() + this.getControllerType()).hashCode();
return (this.getMessage() + this.getControllerType() + this.getPluginType()).hashCode();
}
......@@ -104,4 +123,19 @@ public class ConfigurationException extends Exception {
protected void addToConfigManager() {
ConfigManager.getInstance().addConfigurationException(this);
}
public void setPluginType(PluginType pluginType) {
this.pluginType = pluginType;
}
public PluginType getPluginType() {
return pluginType;
}
public String getTableMessage() {
return toString();
}
}
......@@ -50,7 +50,7 @@ public class ControllerNotFoundException extends ConfigurationException {
}
ControllerNotFoundException controllerNotFoundException = (ControllerNotFoundException)object;
if (this.controllerName.equals(controllerNotFoundException.getControllerName())) {
if (this.controllerName.equals(controllerNotFoundException.getControllerName()) && this.getPluginType() == controllerNotFoundException.getPluginType()) {
if (this.controllerName != null) {
return (this.controllerName.equals(controllerNotFoundException.getControllerName()));
}
......@@ -63,7 +63,7 @@ public class ControllerNotFoundException extends ConfigurationException {
public int hashCode() {
return (this.getMessage() + this.getControllerName() + this.getControllerType()).hashCode();
return (this.getMessage() + this.getControllerName() + this.getControllerType() + this.getPluginType()).hashCode();
}
protected void addToConfigManager() {
......@@ -71,10 +71,11 @@ public class ControllerNotFoundException extends ConfigurationException {
}
public String toString() {
return getMessage() + controllerName + (controllerType == null ? "" : " (controller type: " + controllerType +")") + "\n" + getClassName() + ".." + getMethodName();
return getMessage() + controllerName + (controllerType == null ? "" : " (controller type: " + controllerType +")") + "\n" + getClassName() + ".." + getMethodName() + " (" + getPluginType() + ")";
}
public String format() {
return getMessage() + " " + controllerName;
}
}
......@@ -62,7 +62,7 @@ public class ParticularWidgetNotFoundException extends ConfigurationException {
}
ParticularWidgetNotFoundException particularWidgetNotFoundException = (ParticularWidgetNotFoundException)object;
if (this.widgetKey.equals(particularWidgetNotFoundException.getWidgetKey())) {
if (this.widgetKey.equals(particularWidgetNotFoundException.getWidgetKey()) && this.getPluginType() == particularWidgetNotFoundException.getPluginType()) {
if (this.controllerName != null) {
return (this.controllerName.equals(particularWidgetNotFoundException.getControllerName()));
}
......@@ -73,12 +73,12 @@ public class ParticularWidgetNotFoundException extends ConfigurationException {
public int hashCode() {
return (this.getMessage() + this.getWidgetKey() + this.getControllerName() + this.getControllerType()).hashCode();
return (this.getMessage() + this.getWidgetKey() + this.getControllerName() + this.getControllerType() + this.getPluginType()).hashCode();
}
public String toString() {
return getMessage() + widgetKey + (controllerName == null ? "" : " (controller name: " + controllerName +")") + (controllerType == null ? "" : " (controller type: " + controllerType +")") + "\n" + getClassName() + ".." + getMethodName();
return getMessage() + widgetKey + (controllerName == null ? "" : " (controller name: " + controllerName +")") + (controllerType == null ? "" : " (controller type: " + controllerType +")") + "\n" + getClassName() + ".." + getMethodName() + " (" + getPluginType() + ")";
}
public String format() {
......
......@@ -30,21 +30,21 @@ public class PropertyNotFoundException extends ConfigurationException {
private String controllerName;
private String propertyName;
public PropertyNotFoundException(String message, String propertyName, String controllerType, String controllerName, String className, String methodName) {
super(message, controllerType, null, className, methodName);
public PropertyNotFoundException(String propertyName, String controllerType, String controllerName, String className, String methodName) {
super(DEFAULT_MESSAGE, controllerType, null, className, methodName);
this.propertyName = propertyName;
this.controllerName = controllerName;
ConfigManager.getInstance().addConfigurationException(this);
}
public PropertyNotFoundException(String propertyName, String controllerType, String controllerName, String className, String methodName) {
super(DEFAULT_MESSAGE, controllerType, null, className, methodName);
public PropertyNotFoundException(String propertyName, String controllerType, String controllerName, String className, String methodName, PluginType pluginType) {
super(DEFAULT_MESSAGE, controllerType, null, className, methodName, pluginType);
this.propertyName = propertyName;
this.controllerName = controllerName;
ConfigManager.getInstance().addConfigurationException(this);
}
public String getControllerName() {
return controllerName;
}
......@@ -74,10 +74,10 @@ public class PropertyNotFoundException extends ConfigurationException {
}
PropertyNotFoundException propertyNotFoundException = (PropertyNotFoundException)object;
if (this.propertyName.equals(propertyNotFoundException.getPropertyName())) {
if (this.propertyName.equals(propertyNotFoundException.getPropertyName()) && this.getPluginType() == propertyNotFoundException.getPluginType()) {
if (this.controllerName != null) {
return (this.controllerName.equals(propertyNotFoundException.getControllerName()));
}
}
return (this.controllerType.equals(propertyNotFoundException.getControllerType()));
}
return false;
......@@ -85,12 +85,12 @@ public class PropertyNotFoundException extends ConfigurationException {
public int hashCode() {
return (this.getMessage() + this.getPropertyName() + this.getControllerName() + this.getControllerType()).hashCode();
return (this.getMessage() + this.getPropertyName() + this.getControllerName() + this.getControllerType() + this.getPluginType()).hashCode();
}
public String toString() {
return getMessage() + propertyName + (controllerName == null ? "" : " (controller name: " + controllerName +")") + (controllerType == null ? "" : " (controller type: " + controllerType +")") + "\n" + getClassName() + ".." + getMethodName();
return getMessage() + propertyName + (controllerName == null ? "" : " (controller name: " + controllerName +")") + (controllerType == null ? "" : " (controller type: " + controllerType +")") + "\n" + getClassName() + ".." + getMethodName() + " (" + getPluginType() + ")";
}
public String format() {
......@@ -100,4 +100,5 @@ public class PropertyNotFoundException extends ConfigurationException {
protected void addToConfigManager() {
// Already called in constructor => must not do anything
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment