Commit 3ba3ce58 authored by helene ortiz's avatar helene ortiz
Browse files

First modifications for 0-crash version

parent 0df91acf
......@@ -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.PropertyNotFoundException;
public class PropertyManager {
......@@ -234,11 +235,13 @@ public class PropertyManager {
* @param servant
*/
public void createDynamicPropertiesForController(CorbaServant servant) {
if (dynamicPropertiesByControllerType.containsKey(servant.getType())) {
HashMap<String, DynamicProperty> dynamicProperties = PropertyFactory.getInstance().createDynamicPropertiesForController(servant.getDatabaseId(), servant.getId(), dynamicPropertiesByControllerType.get(servant.getType()).values());
if (dynamicProperties != null) {
dynamicPropertyMap.put(servant.getId(), dynamicProperties);
}
}
}
/**
......@@ -258,12 +261,46 @@ public class PropertyManager {
* @param controller
* @param propertyName
* @return
* @throws PropertyNotFoundException
*/
public Property getProperty(Controller controller, String propertyName) {
public Property getProperty(Controller controller, String propertyName) throws PropertyNotFoundException {
Property property;
if (controller instanceof CorbaServant) {
return getPropertyForServant((CorbaServant)controller, propertyName);
property = getPropertyForServant((CorbaServant)controller, propertyName);
} else {
property = getPropertyForCommandBox((AtomicCommandWrapper)controller, propertyName);
}
if (property == null) {
PropertyNotFoundException pnfe = new PropertyNotFoundException(propertyName, controller.getType(), controller.getName());
ConfigManager.getInstance().addConfigurationException(pnfe);
throw pnfe;
}
return property;
}
/**
*
* @param servantId
* @param minPropertyId
* @return
*/
public Property getProperty(int servantId, String propertyName) {
Property property = propertyMap.get(servantId).get(propertyName);
if (property == null) {
int propertyId = PropertyDatabase.getInstance().getPropertyIdForServant(servantId, propertyName);
// create the property from database
// container id should not be important unless for properties of command box that should already have been created
// should we test is command box?
property = PropertyFactory.getInstance().createProperty(0, propertyId, "unknown", false);
propertyMap.get(servantId).put(propertyName, property);
}
return getPropertyForCommandBox((AtomicCommandWrapper)controller, propertyName);
return property;
}
......@@ -273,7 +310,7 @@ public class PropertyManager {
* @param propertyName
* @return
*/
public Property getPropertyForServant(CorbaServant servant, String propertyName) {
private Property getPropertyForServant(CorbaServant servant, String propertyName) {
if (!this.propertyMap.containsKey(servant.getId())) {
// Verify that the parser has an xml file for the properties of ac
if (!propertiesByControllerType.containsKey(servant.getType())) {
......@@ -299,7 +336,7 @@ public class PropertyManager {
* @param propertyName
* @return
*/
public Property getPropertyForCommandBox(AtomicCommandWrapper command, String propertyName) {
private Property getPropertyForCommandBox(AtomicCommandWrapper command, String propertyName) {
CommandBoxKey key = new CommandBoxKey(command.getServerId(), command.getId());
......@@ -345,11 +382,6 @@ public class PropertyManager {
}
public void getDynamicPropertyForCommandBox(AtomicCommandWrapper controller) {
}
/**
*
* @param servant
......@@ -544,6 +576,7 @@ public class PropertyManager {
}
return null;
}
return null;
}
return getDynamicPropertyForCommandBox((AtomicCommandWrapper)controller, realPropertyName);
}
......@@ -611,12 +644,14 @@ public class PropertyManager {
*/
public XMLDynamicPropertyDescriptor getDynamicPropertyDescriptor(String controllerType, String propertyName) {
if (dynamicPropertiesByControllerType != null) {
if (dynamicPropertiesByControllerType.containsKey(controllerType)) {
if (propertyName.indexOf(".") == -1) {
// A generic property name is provided
return dynamicPropertiesByControllerType.get(controllerType).get(propertyName);
}
return dynamicPropertiesByControllerType.get(controllerType).get(propertyName.substring(0, propertyName.indexOf(".")));
}
}
return null;
}
......@@ -701,18 +736,18 @@ public class PropertyManager {
if (setOfDescriptors.size() <= 2) {
return false;
}
// if (setOfDescriptors.size() == 1) {
// // Verify the only property loaded is not a commandStatus property
// Iterator<SpyPropertyDescriptor> it = setOfDescriptors.iterator();
// SpyPropertyDescriptor spyDescriptor = it.next();
//
// int actualPropertyID = spyDescriptor.getActualID();
// String actualPropertyName = PropertyDatabase.getInstance().getPropertyName(actualPropertyID);
// if (actualPropertyName.equals("commandStatus")) {
// return false;
// }
// return true; //can this case happen? (that is: only one property & property != commandStatus)
// }
// if (setOfDescriptors.size() == 1) {
// // Verify the only property loaded is not a commandStatus property
// Iterator<SpyPropertyDescriptor> it = setOfDescriptors.iterator();
// SpyPropertyDescriptor spyDescriptor = it.next();
//
// int actualPropertyID = spyDescriptor.getActualID();
// String actualPropertyName = PropertyDatabase.getInstance().getPropertyName(actualPropertyID);
// if (actualPropertyName.equals("commandStatus")) {
// return false;
// }
// return true; //can this case happen? (that is: only one property & property != commandStatus)
// }
return true;
}
return false;
......@@ -844,30 +879,6 @@ public class PropertyManager {
}
/**
*
* @param servantId
* @param minPropertyId
* @return
*/
public Property getProperty(int servantId, String propertyName) {
Property property = propertyMap.get(servantId).get(propertyName);
if (property == null) {
int propertyId = PropertyDatabase.getInstance().getPropertyIdForServant(servantId, propertyName);
// create the property from database
// container id should not be important unless for properties of command box that should already have been created
// should we test is command box?
property = PropertyFactory.getInstance().createProperty(0, propertyId, "unknown", false);
propertyMap.get(servantId).put(propertyName, property);
}
return property;
}
public void removeDynamicProperties(int servantId) {
if (dynamicPropertyMap.containsKey(servantId)) {
......@@ -887,7 +898,9 @@ public class PropertyManager {
return PropertyDatabase.getInstance().getNumberOfChildProperties(propertyId);
}
public int getNumberOfDecimalPlaces(Controller controller, String propertyName) {
try {
Property property = getProperty(controller, propertyName);
if (property != null) {
PropertyFormat format = property.getPropertyFormat();
......@@ -897,6 +910,9 @@ public class PropertyManager {
}
}
}
} catch (PropertyNotFoundException e) {
e.printStackTrace();
}
return -1;
}
......
......@@ -38,6 +38,8 @@ import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import fr.ill.ics.util.exception.ConfigurationException;
/**
*
* <p>This class manages the nomad configuration
......@@ -94,6 +96,9 @@ public class ConfigManager {
public static boolean CONFIGURATION_ERROR = false;
private static Set<ConfigurationException> configurationExceptions;
/**
* @return the unique instance of this class
*/
......@@ -453,4 +458,30 @@ public class ConfigManager {
public String toString() {
return "ConfigManager preferences = " + preferences + "\n\n properties = " + properties;
}
public void addConfigurationException(ConfigurationException configurationException) {
if (configurationExceptions == null) {
configurationExceptions = new HashSet<ConfigurationException>();
}
if (configurationExceptions.add(configurationException)) {
System.out.println("Exception added: " + configurationException);
}
}
public Set<ConfigurationException> getConfigurationExceptionsForControllerType(String controllerType) {
Set<ConfigurationException> set = new HashSet<ConfigurationException>();
for (ConfigurationException configurationException : configurationExceptions) {
if (configurationException.getControllerType().equals(controllerType)) {
set.add(configurationException);
}
}
return set;
}
}
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.util.exception;
/**
*
* @author ortizh
*
*/
public abstract class ConfigurationException extends Exception {
protected String controllerType;
public ConfigurationException(String message, String controllerType) {
super(message);
this.controllerType = controllerType;
}
public String getControllerType() {
return controllerType;
}
public void setControllerType(String controllerType) {
this.controllerType = controllerType;
}
}
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.util.exception;
import fr.ill.ics.util.ConfigManager;
/**
*
* @author ortizh
*
*/
public class PropertyNotFoundException extends ConfigurationException {
private final static String DEFAULT_MESSAGE = ConfigManager.getInstance().getString("propertyNotFoundExceptionMessage");
private String controllerName;
private String propertyName;
public PropertyNotFoundException(String message, String propertyName, String controllerType, String controllerName) {
super(message, controllerType);
this.propertyName = propertyName;
this.controllerName = controllerName;
}
public PropertyNotFoundException(String propertyName, String controllerType, String controllerName) {
super(DEFAULT_MESSAGE, controllerType);
this.propertyName = propertyName;
this.controllerName = controllerName;
this.controllerType = controllerType;
}
public String getControllerName() {
return controllerName;
}
public void setControllerName(String controllerName) {
this.controllerName = controllerName;
}
public String getPropertyName() {
return propertyName;
}
public void setPropertyName(String propertyName) {
this.propertyName = propertyName;
}
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (!(object instanceof PropertyNotFoundException)) {
return false;
}
PropertyNotFoundException propertyNotFoundException = (PropertyNotFoundException)object;
if (this.propertyName.equals(propertyNotFoundException.getPropertyName())) {
if (this.controllerName != null) {
return (this.controllerName.equals(propertyNotFoundException.getControllerName()));
}
return (this.controllerType.equals(propertyNotFoundException.getControllerType()));
}
return false;
}
public int hashCode() {
return (this.getMessage() + this.getPropertyName() + this.getControllerName() + this.getControllerType()).hashCode();
}
public String toString() {
return getMessage() + propertyName + (controllerName == null ? "" : " (controller name: " + controllerName +")") + (controllerType == null ? "" : " (controller type: " + controllerType +")");
}
}
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