Commit 36709315 authored by Cristina Cocho's avatar Cristina Cocho

Work done in references retrieval when loading the whole configuration

parent cfa15617
......@@ -348,10 +348,10 @@ public class ControllerManager implements ServerConfigurationChangeListener {
reset();
}
public String getControllerNameWithRole(Controller servant, String role) {
ControllerServant controller = (ControllerServant)servant;
return ServantManagerAccessor.getInstance(serverId).getControllerNameWithRole(controller.getId(), role);
}
// public String getControllerNameWithRole(Controller servant, String role) {
// ControllerServant controller = (ControllerServant)servant;
// return ServantManagerAccessor.getInstance(serverId).getControllerNameWithRole(controller.getId(), role);
// }
public HashMap<String, String> getServantPropertiesValue(int databaseID, int servantID) {
return ServantManagerAccessor.getInstance(serverId).getServantPropertiesValue(databaseID, servantID);
......
......@@ -73,10 +73,10 @@ public class ServantManagerAccessor {
private static final long serialVersionUID = 1L;
};
private static class ChildServants {
String name;
List<String> childNames = new LinkedList<String>();
}
// private static class ChildServants {
// String name;
// List<String> childNames = new LinkedList<String>();
// }
private static final Logger LOGGER = Logger.getLogger(ServantManagerAccessor.class.getName());
private static int DATABASE_ID = 0;
......@@ -88,7 +88,7 @@ public class ServantManagerAccessor {
private static Map<String, ServantManagerAccessor> instances = new HashMap<String, ServantManagerAccessor>();
private Map<Integer, List<ChildServants>> childServantNames = new HashMap<Integer, List<ChildServants>>();
// private Map<Integer, List<ChildServants>> childServantNames = new HashMap<Integer, List<ChildServants>>();
private ServantManagerAccessor(String serverId) {
this.serverId = serverId;
......@@ -638,18 +638,10 @@ public class ServantManagerAccessor {
ServantDatabase.getInstance().addController(descriptor);
// Obtain references
List<ServantDataConfiguration.ChildDescriptor> pbChildren = pbServant.getChildrenList();
if (pbChildren.size() == 0) {
// There are no children (= configured references). Get the not configured references through ReferenceDescriptor
List<ServantDataConfiguration.ReferenceDescriptor> pbReferences = pbServant.getReferencesList();
if (pbReferences.size() > 0) {
addNotConfiguredControllerReferences((ClientControllerServantDescriptor)descriptor, pbReferences);
}
} else {
addConfiguredControllerReferences((ClientControllerServantDescriptor)descriptor, pbChildren);
}
addControllerReferences((ClientControllerServantDescriptor)descriptor, pbServant.getReferencesList());
}
/*
// add the list of child names
LinkedList<ChildServants> childNames = new LinkedList<ChildServants>();
......@@ -670,10 +662,10 @@ public class ServantManagerAccessor {
}
childNames.add(childServants);
}
childServantNames.put(descriptor.getId(), childNames);
*/
// initialise the controller
// initialize properties
Iterator<ServantDataConfiguration.PropertyDescriptor> p = pbServant.getPropertiesList().iterator();
while (p.hasNext()) {
......@@ -708,13 +700,14 @@ public class ServantManagerAccessor {
}
}
// Add commands
Iterator<ServantDataConfiguration.CommandDescriptor> d = pbServant.getCommandsList().iterator();
while (d.hasNext()) {
ServantDataConfiguration.CommandDescriptor pbCommand = d.next();
CommandDatabase.getInstance().addCommandDescriptor(descriptor.getId(), new ClientCommandDescriptor(pbCommand.getID(), pbCommand.getName()));
}
// add the spy properties
// Add the spy properties
if (ConfigurationManager.getInstance().isMainClient()) {
if (driver == false) {
addSpyProperties(servantID);
......@@ -739,42 +732,13 @@ public class ServantManagerAccessor {
}
/*
* Add Configured References info in the descriptor of the controller
* Add References (Configured and Not Configured) info in the descriptor of the controller
*/
private void addConfiguredControllerReferences(ClientControllerServantDescriptor controllerDescriptor, List<ServantDataConfiguration.ChildDescriptor> pbChildren) {
Iterator<ServantDataConfiguration.ChildDescriptor> cd = pbChildren.iterator();
while (cd.hasNext()) {
// This is quite confusing BUT for the controller case, the first level will contain the references roles.
// Associated to each role there MUST BE ONLY ONE children (pbChild1.getChildArrayList().size() == 1) which corresponds with the name of the reference
ServantDataConfiguration.ChildDescriptor pbChild1 = cd.next();
String referenceRole = pbChild1.getName();
// Important!!! I DO ASSUME HERE THAT THE NUMBER OF CHILDREN WITH THE SAME ROLE IS ONE. DISCUSS!
if (pbChild1.getChildArrayList().size() == 1) {
ServantDataConfiguration.ChildDescriptor.Child pbChild2 = pbChild1.getChildArrayList().get(0);
String referenceName = pbChild2.getName();
controllerDescriptor.addReference(referenceRole, referenceName, "");
} else {
// Error
System.err.println("There is more than one child with the same role for the controller " +controllerDescriptor.getName());
}
/*
List<String> controllerReferencesNames = new ArrayList<String>(); // its final size should be one
Iterator<ServantDataConfiguration.ChildDescriptor.Child> ccd = pbChild1.getChildArrayList().iterator();
while (ccd.hasNext()) {
ServantDataConfiguration.ChildDescriptor.Child pbChild2 = ccd.next();
String referenceName = pbChild2.getName();
controllerReferencesNames.add(referenceName);
}*/
}
}
private void addNotConfiguredControllerReferences(ClientControllerServantDescriptor controllerDescriptor, List<ServantDataConfiguration.ReferenceDescriptor> pbReferences) {
private void addControllerReferences(ClientControllerServantDescriptor controllerDescriptor, List<ServantDataConfiguration.ReferenceDescriptor> pbReferences) {
Iterator<ServantDataConfiguration.ReferenceDescriptor> rd = pbReferences.iterator();
while (rd.hasNext()) {
ServantDataConfiguration.ReferenceDescriptor refDescript = rd.next();
controllerDescriptor.addReference(refDescript.getRole(), "Not Configured", refDescript.getType());
controllerDescriptor.addReference(refDescript.getRole(), refDescript.getName(), refDescript.getType());
}
}
......@@ -876,31 +840,33 @@ public class ServantManagerAccessor {
// return null;
// }
public List<String> getChildServants(int id) {
// return the full list by aggregating the child names
List<String> fullList = new LinkedList<String>();
List<ChildServants> childServantsList = childServantNames.get(id);
for (ChildServants c : childServantsList) {
fullList.addAll(c.childNames);
}
return fullList;
}
public String getControllerNameWithRole(int servantID, String role) {
List<ChildServants> childServants = childServantNames.get(servantID);
for (ChildServants s : childServants) {
if (s.name.equals(role)) {
return s.childNames.get(0);
}
}
// NOT USED! MOVED to descriptor
// public List<String> getChildServants(int id) {
//
// // return the full list by aggregating the child names
// List<String> fullList = new LinkedList<String>();
//
// List<ChildServants> childServantsList = childServantNames.get(id);
//
// for (ChildServants c : childServantsList) {
// fullList.addAll(c.childNames);
// }
// return fullList;
// }
return "?";
}
// public String getControllerNameWithRole(int servantID, String role) {
//
// List<ChildServants> childServants = childServantNames.get(servantID);
//
// for (ChildServants s : childServants) {
// if (s.name.equals(role)) {
// return s.childNames.get(0);
// }
// }
//
// return "?";
// }
public void cloneController(ClientServantDescriptor descriptor) {
try {
......
package fr.ill.ics.nscclient.servant;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class ClientControllerServantDescriptor extends ClientServantDescriptor {
private Map<String, String> referencesInfo; //KEY = reference role, VALUE = reference name
public static String NOT_CONFIGURED_NAME = "Not configured";
private Set<ReferencesDescriptor> referencesDescriptors;
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, String>();
referencesDescriptors = new HashSet<ReferencesDescriptor>();
}
// public void addReferenceInfo(String role, String name) {
// referencesInfo.put(role, name);
// }
public Map<String, String> getReferencesInfo() {
return referencesInfo;
}
public void unconfiguredReferenceInfo(String role) {
// An unconfigured reference does not have any controller for a specific role
String name = "Not Configured";
referencesInfo.put(role, name);
for (ReferencesDescriptor refDesc : referencesDescriptors) {
if (refDesc.getRole().equals(role)) {
// We should obtain the type because it can be different
refDesc.setName(NOT_CONFIGURED_NAME);
}
}
}
public void addReference(String role, String name, String type) {
......@@ -66,7 +57,6 @@ public class ClientControllerServantDescriptor extends ClientServantDescriptor {
public void setName(String name) {
this.name = name;
}
}
}
......@@ -88,9 +88,10 @@ public class Servant implements Controller {
}
}
// USED?
// IT SEEMS NOT TO BE USED. BELONGS TO INTERFACE. DISCUSS
public String getControllerNameWithRole(String role) {
return ControllerManager.getInstance().getControllerNameWithRole(this, role);
// return ControllerManager.getInstance().getControllerNameWithRole(this, role);
return "";
}
public Set<String> getCommandNames() {
......
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