Commit abb7e3ba authored by Cristina Cocho's avatar Cristina Cocho

Work done in managers

parent e0ef0d48
......@@ -70,13 +70,13 @@ public class ControllerManager implements ServerConfigurationChangeListener {
public ControllerManager(String serverId) {
this.serverId = serverId;
addConfigurationChangeListener(this);
}
/**
*
*/
public void removeController(int controllerID) {
controllerServants.remove(controllerID);
}
protected void init() {
fillControllerNamesByTypeMaps();
}
......@@ -93,13 +93,12 @@ public class ControllerManager implements ServerConfigurationChangeListener {
private ControllerServant createController(ClientServantDescriptor descriptor) {
ControllerServant controller = new ControllerServant(0, descriptor.getId(), descriptor);
System.out.println("adding controller in ControllerManager " +controller.getName());
controllerServants.put(descriptor.getId(), controller);
System.out.println("SIZE " +controllerServants.size());
return controller;
}
/**
*
*/
public ControllerServant getController(String controllerName) throws ControllerNotFoundException {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getControllerDescriptor(controllerName);
if (descriptor != null) {
......@@ -153,11 +152,15 @@ public class ControllerManager implements ServerConfigurationChangeListener {
/*
* Is this method used?
*/
public void removeController(String controllerName) {
ClientServantDescriptor descriptor = ServantDatabase.getInstance().getControllerDescriptor(controllerName);
if (descriptor != null) {
ServantManagerAccessor.getInstance(serverId).removeController(descriptor);
}
// public void removeController(String controllerName) {
// ClientServantDescriptor descriptor = ServantDatabase.getInstance().getControllerDescriptor(controllerName);
// if (descriptor != null) {
// ServantManagerAccessor.getInstance(serverId).removeController(descriptor);
// }
// }
public Map<Integer, ControllerServant> getControllers() {
return controllerServants;
}
/**
......@@ -321,13 +324,11 @@ public class ControllerManager implements ServerConfigurationChangeListener {
return allControllerNamesByType.get(controllerType);
}
public void updateDynamicProperties(Controller servant) {
ControllerServant controller = (ControllerServant)servant;
ServantManagerAccessor.getInstance(serverId).updateDynamicProperties(controller.getId());
}
public void configurationChanged(int servantID, ClientConfigurationState enable) {
// The reloading of controllers is not made here but in the CommandsSelectionPlugin
// and SettingsSelectionPlugin classes.
......@@ -338,7 +339,6 @@ public class ControllerManager implements ServerConfigurationChangeListener {
}
}
public void reloadControllers() {
// reset controller information
reset();
......
......@@ -25,6 +25,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
......@@ -66,11 +67,13 @@ public class DriverManager {
// At this point the ServantDatabase should be loaded with the Nomad configuration. We can fill our driverServants map.
Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getDrivers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
ClientDriverServantDescriptor descriptor = (ClientDriverServantDescriptor)it.next(); // It must be always a ClientDriverServantDescriptor
int driverID = descriptor.getId();
// Think about a common use of DatabaseID
DriverServant driverServant = new DriverServant(0, descriptor.getId(), descriptor);
driverServant.setChannel(descriptor.getChannel());
driverServant.setMode(descriptor.getMode());
driverServants.put(driverID, driverServant);
}
}
......@@ -135,14 +138,22 @@ public class DriverManager {
return driverServants;
}
//TODO: Revise this method. Should only be using DriverServant items.
public Map<String, Map<String, Map<String, String>>> getInstalledDrivers() {
Map<String, Map<String, Map<String, String>>> installedDrivers = new TreeMap<String, Map<String, Map<String, String>>>();
Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getDrivers().iterator();
// Use local map of DriverServants in order to retrieve the data
Iterator<Entry<Integer, DriverServant>> it = driverServants.entrySet().iterator();
// Iterator<ClientServantDescriptor> it = ServantDatabase.getInstance().getDrivers().iterator();
while (it.hasNext()) {
ClientServantDescriptor descriptor = it.next();
if (descriptor.isEnabled() && descriptor.isRoot()) {
Map<String, Map<String, String>> children = getChildren(descriptor);
installedDrivers.put(descriptor.getName(), children);
// ClientServantDescriptor descriptor = it.next();
// if (descriptor.isEnabled() && descriptor.isRoot()) {
// Map<String, Map<String, String>> children = getChildren(descriptor);
// installedDrivers.put(descriptor.getName(), children);
// }
DriverServant driverServant = it.next().getValue();
if (driverServant.isEnabled() && driverServant.isRoot()) {
Map<String, Map<String, String>> children = getChildren(driverServant.getDescriptor());
installedDrivers.put(driverServant.getName(), children);
}
}
return installedDrivers;
......@@ -150,15 +161,17 @@ public class DriverManager {
private Map getChildren(ClientServantDescriptor descriptor) {
Map<String, Map<String, String>> allChildren = new LinkedHashMap<String, Map<String, String>>();
List<String> children = ServantManagerAccessor.getInstance(serverId).getChildServants(descriptor.getId());
Iterator<String> it = children.iterator();
while (it.hasNext()) {
String childName = it.next();
ClientServantDescriptor childDescriptor = ServantDatabase.getInstance().getDriverDescriptor(childName);
if (childDescriptor.isVisible() && childDescriptor.isEnabled()) {
allChildren.put(childName, getChildren(childDescriptor));
// Information should be already loaded in ServantDatabase. Validate the descriptor corresponds to a driver
if ((ClientDriverServantDescriptor) descriptor != null) {
List<String> children = ((ClientDriverServantDescriptor) descriptor).getChildrenNames();
// List<String> children = ServantManagerAccessor.getInstance(serverId).getChildServants(descriptor.getId());
Iterator<String> it = children.iterator();
while (it.hasNext()) {
String childName = it.next();
ClientServantDescriptor childDescriptor = ServantDatabase.getInstance().getDriverDescriptor(childName);
if (childDescriptor.isVisible() && childDescriptor.isEnabled()) {
allChildren.put(childName, getChildren(childDescriptor));
}
}
}
return allChildren;
......
......@@ -190,12 +190,8 @@ public class PropertyManager {
* Remove all the properties of a Driver or Controller given its ID
*/
public void removeAllPropertiesForServant(int servantID) {
// TODO: code controller case
Servant servant = DriverManager.getInstance().getDriver(servantID);
if (servant == null) {
// Obtain controller servant...
}
propertyMap.remove(servant.getId());
//TODO: clean rest of maps
propertyMap.remove(servantID);
}
public void createInheritedProperties(String type, String superType) {
......
package fr.ill.ics.nscclient.servant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ClientControllerServantDescriptor extends ClientServantDescriptor {
// NOTE: Discuss this point... we should only have a map <role, name>... is there the possibility to have the same role and different controller name?
private Map<String, List<String>> referencesInfo; //KEY = reference role, VALUE = reference name
public ClientControllerServantDescriptor(int ID, String name, String type, String family, String subfamily, boolean isCommand, boolean isVisible, boolean isEnabled, boolean isFavourite, boolean isRoot) {
super(ID, name, type, family, subfamily, isCommand, isVisible, isEnabled, isFavourite, isRoot);
referencesInfo = new HashMap<String, List<String>>();
}
public void addReferenceInfo(String role, List<String> name) {
referencesInfo.put(role, name);
}
public Map<String, List<String>> getReferencesInfo() {
return referencesInfo;
}
}
package fr.ill.ics.nscclient.servant;
import java.util.LinkedList;
import java.util.List;
import fr.ill.ics.nscclient.servant.DriverServant.Mode;
public class ClientDriverServantDescriptor extends ClientServantDescriptor {
......@@ -7,10 +10,14 @@ public class ClientDriverServantDescriptor extends ClientServantDescriptor {
private Mode mode;
private long channel;
private List<String> childrenNames;
public ClientDriverServantDescriptor(int ID, String name, String type, String family, String subfamily, boolean isCommand, boolean isVisible, boolean isEnabled, boolean isFavourite, boolean isRoot, Mode mode, long channel) {
super(ID, name, type, family, subfamily, isCommand, isVisible, isEnabled, isFavourite, isRoot);
this.mode = mode;
this.channel = channel;
childrenNames = new LinkedList<String>();
}
public Mode getMode() {
......@@ -20,4 +27,13 @@ public class ClientDriverServantDescriptor extends ClientServantDescriptor {
public long getChannel() {
return channel;
}
public void addChildName(String childName) {
childrenNames.add(childName);
}
public List<String> getChildrenNames() {
return childrenNames;
}
}
......@@ -18,7 +18,8 @@
package fr.ill.ics.nscclient.servant;
import java.util.List;
import java.util.Map;
public class ControllerServant extends Servant {
......@@ -26,4 +27,7 @@ public class ControllerServant extends Servant {
super(databaseId, servantId, descriptor);
}
public Map<String, List<String>> getReferencesInfo() {
return ((ClientControllerServantDescriptor)servantDescriptor).getReferencesInfo();
}
}
\ No newline at end of file
......@@ -18,7 +18,7 @@
package fr.ill.ics.nscclient.servant;
import java.util.List;
public class DriverServant extends Servant {
......@@ -47,4 +47,9 @@ public class DriverServant extends Servant {
return mode;
}
public List<String> getChildrenNames() {
// Returns a list with the children's names
return ((ClientDriverServantDescriptor)servantDescriptor).getChildrenNames();
}
}
\ No newline at end of file
......@@ -43,7 +43,7 @@ public class Servant implements Controller {
//public class WrongPropertyException extends Exception {};
//private Servant servant;
private ClientServantDescriptor servantDescriptor;
protected ClientServantDescriptor servantDescriptor;
private int databaseId;
private int servantId;
......@@ -88,6 +88,7 @@ public class Servant implements Controller {
}
}
// USED?
public String getControllerNameWithRole(String role) {
return ControllerManager.getInstance().getControllerNameWithRole(this, role);
}
......@@ -103,6 +104,10 @@ public class Servant implements Controller {
public HashMap<String, String> getPropertyNamesAndValues() {
return ControllerManager.getInstance().getServantPropertiesValue(databaseId, servantId);
}
public ClientServantDescriptor getDescriptor() {
return servantDescriptor;
}
public int getId() {
return servantId;
......
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