Commit a3564c15 authored by helene ortiz's avatar helene ortiz
Browse files

Inherited controllers / drivers management

parent 2aa518c5
3.0.0
-----
* First release with Maven build process management.
\ No newline at end of file
* First release with Maven build process management.
* "GUI zero-crash" mode.
* Inherited controllers / drivers management.
* Introduction of Cameo for starting the Nomad server.
......@@ -147,13 +147,49 @@ public class PropertyManager {
}
public void createInheritedProperties(String type, String superType) {
if (!propertiesByControllerType.containsKey(superType)) {
initialiseControllerTypeProperties(superType);
}
if (propertiesByControllerType.containsKey(superType)) {
propertiesByControllerType.put(type, propertiesByControllerType.get(superType));
clientFilesFoundPerControllerType.put(type, true);
}
if (dynamicPropertiesByControllerType.containsKey(superType)) {
dynamicPropertiesByControllerType.put(type, dynamicPropertiesByControllerType.get(superType));
clientFilesFoundPerControllerType.put(type, true);
}
Set<String> drivers = ServantDatabase.getInstance().getDriversOfType(type, false);
if (drivers != null && !drivers.isEmpty()) {
for (String driverName : drivers) {
Controller controller = DriverManager.getInstance().getDriver(driverName);
createPropertiesForController((CorbaServant)controller);
if (dynamicPropertiesByControllerType != null && dynamicPropertiesByControllerType.containsKey(((CorbaServant)controller).getType())) {
createDynamicPropertiesForController((CorbaServant)controller);
}
}
}
Set<String> controllers = ControllerManager.getInstance().getControllersOfType(type, false);
if (controllers != null && !controllers.isEmpty()) {
for (String controllerName : controllers) {
Controller controller = ControllerManager.getInstance().getController(controllerName);
createPropertiesForController((CorbaServant)controller);
if (dynamicPropertiesByControllerType != null && dynamicPropertiesByControllerType.containsKey(((CorbaServant)controller).getType())) {
createDynamicPropertiesForController((CorbaServant)controller);
}
}
}
}
/**
*
* @param controllerType
* @return
*/
private boolean readPropertiesClientFilesFor(String controllerType) {
if (clientFilesFoundPerControllerType.containsKey(controllerType)) {
return clientFilesFoundPerControllerType.get(controllerType);
}
......@@ -405,9 +441,12 @@ public class PropertyManager {
String fileContent;
try {
fileContent = ResourceManager.getInstance().getFileContent(servant.getType(), fileName);
propertyParser.parseXmlString(fileContent);
processParsedProperties();
} catch (ResourceNotFoundException e) {
// file does not exist on server side either
String propertiesFile = propertyParser.createPropertyFile(servant.getType(), propertyNamesAndTypes, servant.getId());
String propertiesFile = propertyParser.createPropertyFile(servant.getType(), propertyNamesAndTypes);
if (propertiesFile != null) {
propertyParser.parseXmlFile(propertiesFile);
if (propertyParser.getProperties() != null) {
......@@ -423,6 +462,32 @@ public class PropertyManager {
}
}
/**
* Initialises properties for a given controller type. Necessary since inherited gui files is available.
* @param controllerType
*/
private void initialiseControllerTypeProperties(String controllerType) {
// Does controllerTypeProperties.xml file exist on client side ?
String fileName = ConfigManager.CONTROLLERS_DIRECTORY + controllerType + ConfigManager.FILE_SEPARATOR + controllerType + ConfigManager.PROPERTIES_PATTERN;
boolean existsOnClientSide = new File(fileName).exists();
if (!existsOnClientSide) {
fileName = controllerType + ConfigManager.PROPERTIES_PATTERN;
String fileContent;
try {
fileContent = ResourceManager.getInstance().getFileContent(controllerType, fileName);
propertyParser.parseXmlString(fileContent);
processParsedProperties();
} catch (ResourceNotFoundException e) {
System.err.println("Unable to find properties for super type: " + controllerType);
}
}
}
/**
* Initialises the controller directly by the content of the XML properties file.
* Used for Android system which has a different file system from Linux.
......
......@@ -205,7 +205,7 @@ public class PropertyParser extends GenericParser {
* Create a new file
* @param type
*/
public String createPropertyFile(String controllerType, Map propertiesAndTypes, int servantId) {
public String createPropertyFile(String controllerType, Map propertiesAndTypes) {
String filename = controllerType + ConfigManager.PROPERTIES_PATTERN;
......
......@@ -152,8 +152,8 @@ public class ServantDatabase {
}
public Set getDriversOfType(String type, boolean onlyVisibleOnes) {
Set driversOfType = new TreeSet();
public Set<String> getDriversOfType(String type, boolean onlyVisibleOnes) {
Set<String> driversOfType = new TreeSet<String>();
Iterator<ClientServantDescriptor> it = drivers.values().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
......
......@@ -18,6 +18,8 @@
package fr.ill.ics.nscclient.servant;
import java.util.List;
public class ClientServantDescriptor {
private int id;
......@@ -30,8 +32,9 @@ public class ClientServantDescriptor {
boolean isEnabled;
boolean isFavourite;
boolean isRoot;
private List<String> superTypes;
public ClientServantDescriptor(int ID, String name, String type, String family, String subfamily, boolean isCommand, boolean isVisible, boolean isEnabled, boolean isFavourite, boolean isRoot) {
public ClientServantDescriptor(int ID, String name, String type, String family, String subfamily, boolean isCommand, boolean isVisible, boolean isEnabled, boolean isFavourite, boolean isRoot, List<String> superTypes) {
this.id = ID;
this.name = name;
this.type = type;
......@@ -42,10 +45,18 @@ public class ClientServantDescriptor {
this.isEnabled = isEnabled;
this.isFavourite = isFavourite;
this.isRoot = isRoot;
if (superTypes != null && !superTypes.isEmpty()) {
this.superTypes = superTypes;
}
//System.out.println("New servant : " + name + " , type = " + type);
}
public List<String> getSuperTypes() {
return superTypes;
}
public int getId() {
return id;
}
......
......@@ -203,6 +203,8 @@ public class CorbaServantManager {
CorbaServant servant = null;
//System.out.println("servant " + pbServant.getName() + " has types #" + pbServant.getTypesList().size());
// add the controller in ServantDatabase
ClientServantDescriptor descriptor = new ClientServantDescriptor(pbServant.getID(),
pbServant.getName(),
......@@ -213,8 +215,9 @@ public class CorbaServantManager {
pbServant.getVisible(),
pbServant.getEnabled(),
false,
pbServant.getRoot());
pbServant.getRoot(),
pbServant.getTypesList());
if (driver) {
ServantDatabase.getInstance().addDriver(descriptor);
......
......@@ -85,7 +85,6 @@ public class GenericParser extends DefaultHandler {
*/
public void parseXmlString(String string) {
try {
reader.parse(new InputSource(new ByteArrayInputStream(string.getBytes("utf-8"))));
} catch (SAXException e) {
LOGGER.logp(Level.WARNING, GenericParser.class.getName(), "parseXmlString", "SAXException while parsing XML string: " + string + " (" + e.getMessage() + ")");
......
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