Commit 4c8a7824 authored by helene ortiz's avatar helene ortiz
Browse files

Changes for NomadServerGUI

parent 2c6e94e2
...@@ -792,8 +792,8 @@ public class PropertyManager { ...@@ -792,8 +792,8 @@ public class PropertyManager {
/** /**
* Returns a sorted set containing all property names for given controller. * Returns a sorted set containing all property names for given controller.
* @param controllerType controller type * @param controllerName controller name
* @return a set containing all property names for given controller type * @return a set containing all property names for given controller name
*/ */
public Set<String> getPropertiesForController(String controllerName) { public Set<String> getPropertiesForController(String controllerName) {
int servantId = ServantDatabase.getInstance().getServantId(controllerName); int servantId = ServantDatabase.getInstance().getServantId(controllerName);
...@@ -809,6 +809,25 @@ public class PropertyManager { ...@@ -809,6 +809,25 @@ public class PropertyManager {
return properties; return properties;
} }
/**
* Returns a sorted set containing all dynamic property names for given controller.
* @param controllerName controller name
* @return a set containing all dynamic property names for given controller name
*/
public Set<String> getDynamicPropertiesForController(String controllerName) {
int servantId = ServantDatabase.getInstance().getServantId(controllerName);
SortedSet<String> properties = new TreeSet<String>();
Map<String, String> namesAndTypes = PropertyDatabase.getInstance().getDynamicPropertyNamesAndTypes(servantId);
if (namesAndTypes != null) {
properties.addAll(namesAndTypes.keySet());
} else {
System.out.println("property map has no entries for " + controllerName);
}
return properties;
}
/** /**
* *
* @param controller * @param controller
......
...@@ -41,7 +41,7 @@ public class PropertyDatabase { ...@@ -41,7 +41,7 @@ public class PropertyDatabase {
private Map<Integer, Set<DynamicPropertyDescriptor>> dynamicPropertiesByServant; // KEY=Servant id VALUE=Set of associated DynamicPropertyDescriptor private Map<Integer, Set<DynamicPropertyDescriptor>> dynamicPropertiesByServant; // KEY=Servant id VALUE=Set of associated DynamicPropertyDescriptor
private Map<Integer, Set<SpyPropertyDescriptor>> spyPropertiesByServant; // KEY=Servant id VALUE=Set of associated SpyPropertyDescriptor private Map<Integer, Set<SpyPropertyDescriptor>> spyPropertiesByServant; // KEY=Servant id VALUE=Set of associated SpyPropertyDescriptor
private static PropertyDatabase instance = null; private static PropertyDatabase instance = null;
public static PropertyDatabase getInstance() { public static PropertyDatabase getInstance() {
...@@ -75,9 +75,9 @@ public class PropertyDatabase { ...@@ -75,9 +75,9 @@ public class PropertyDatabase {
* @param standardPropertyDescriptor * @param standardPropertyDescriptor
*/ */
public void addStandardPropertyDescriptor(int servantId, StandardPropertyDescriptor standardPropertyDescriptor) { public void addStandardPropertyDescriptor(int servantId, StandardPropertyDescriptor standardPropertyDescriptor) {
//System.out.println("added property " + standardPropertyDescriptor.getName() + " to servant " + servantId); //System.out.println("added property " + standardPropertyDescriptor.getName() + " to servant " + servantId);
properties.put(standardPropertyDescriptor.getId(), standardPropertyDescriptor); properties.put(standardPropertyDescriptor.getId(), standardPropertyDescriptor);
if (!propertiesByServant.containsKey(servantId)) { if (!propertiesByServant.containsKey(servantId)) {
Set<Integer> set = new HashSet<Integer>(); Set<Integer> set = new HashSet<Integer>();
...@@ -110,13 +110,13 @@ public class PropertyDatabase { ...@@ -110,13 +110,13 @@ public class PropertyDatabase {
Set<SpyPropertyDescriptor> set = new TreeSet<SpyPropertyDescriptor>(new SpyPropertyDescriptorComparator()); Set<SpyPropertyDescriptor> set = new TreeSet<SpyPropertyDescriptor>(new SpyPropertyDescriptorComparator());
spyPropertiesByServant.put(servantId, set); spyPropertiesByServant.put(servantId, set);
} }
spyPropertiesByServant.get(servantId).add(descriptor); spyPropertiesByServant.get(servantId).add(descriptor);
// System.out.println("spy property for servant " + servantId); // System.out.println("spy property for servant " + servantId);
// System.out.println(descriptor); // System.out.println(descriptor);
} }
/** /**
* *
* @param id * @param id
...@@ -125,12 +125,12 @@ public class PropertyDatabase { ...@@ -125,12 +125,12 @@ public class PropertyDatabase {
public DynamicPropertyDescriptor getDynamicPropertyDescriptor(int id) { public DynamicPropertyDescriptor getDynamicPropertyDescriptor(int id) {
return dynamicProperties.get(id); return dynamicProperties.get(id);
} }
public StandardPropertyDescriptor getStandardPropertyDescriptor(int id) { public StandardPropertyDescriptor getStandardPropertyDescriptor(int id) {
return properties.get(id); return properties.get(id);
} }
public void removeDynamicPropertyDescriptors(int servantId) { public void removeDynamicPropertyDescriptors(int servantId) {
// only clearing the set for the servant ID // only clearing the set for the servant ID
...@@ -138,7 +138,7 @@ public class PropertyDatabase { ...@@ -138,7 +138,7 @@ public class PropertyDatabase {
dynamicPropertiesByServant.get(servantId).clear(); dynamicPropertiesByServant.get(servantId).clear();
} }
} }
/** /**
* *
* @param id * @param id
...@@ -147,7 +147,7 @@ public class PropertyDatabase { ...@@ -147,7 +147,7 @@ public class PropertyDatabase {
public Set<SpyPropertyDescriptor> getSpyPropertyDescriptors(int servantId) { public Set<SpyPropertyDescriptor> getSpyPropertyDescriptors(int servantId) {
return spyPropertiesByServant.get(servantId); return spyPropertiesByServant.get(servantId);
} }
/** /**
* *
* @param servantId * @param servantId
...@@ -166,6 +166,26 @@ public class PropertyDatabase { ...@@ -166,6 +166,26 @@ public class PropertyDatabase {
} }
return namesAndTypes; return namesAndTypes;
} }
/**
*
* @param servantId
* @return
*/
public Map<String, String> getDynamicPropertyNamesAndTypes(int servantId) {
Map<String, String> namesAndTypes = new HashMap<String, String>();
Set<DynamicPropertyDescriptor> propertyDescriptors = dynamicPropertiesByServant.get(servantId);
if (propertyDescriptors != null) {
Iterator<DynamicPropertyDescriptor> it = propertyDescriptors.iterator();
while (it.hasNext()) {
DynamicPropertyDescriptor descriptor = it.next();
namesAndTypes.put(descriptor.getName(), descriptor.getType());
}
}
return namesAndTypes;
}
/** /**
...@@ -198,25 +218,25 @@ public class PropertyDatabase { ...@@ -198,25 +218,25 @@ public class PropertyDatabase {
* @return * @return
*/ */
public String getPropertyType(int id) { public String getPropertyType(int id) {
StandardPropertyDescriptor descriptor = properties.get(id); StandardPropertyDescriptor descriptor = properties.get(id);
if (descriptor != null) { if (descriptor != null) {
return descriptor.getType(); return descriptor.getType();
} }
DynamicPropertyDescriptor dynamicDescriptor = dynamicProperties.get(id); DynamicPropertyDescriptor dynamicDescriptor = dynamicProperties.get(id);
if (dynamicDescriptor != null) { if (dynamicDescriptor != null) {
return dynamicDescriptor.getType(); return dynamicDescriptor.getType();
} }
// searching in the dynamic properties // searching in the dynamic properties
Iterator<Entry<Integer, DynamicPropertyDescriptor>> dit = dynamicProperties.entrySet().iterator(); Iterator<Entry<Integer, DynamicPropertyDescriptor>> dit = dynamicProperties.entrySet().iterator();
while (dit.hasNext()) { while (dit.hasNext()) {
Entry<Integer, DynamicPropertyDescriptor> entry = dit.next(); Entry<Integer, DynamicPropertyDescriptor> entry = dit.next();
dynamicDescriptor = entry.getValue(); dynamicDescriptor = entry.getValue();
Iterator<Integer> iit = dynamicDescriptor.getIds().iterator(); Iterator<Integer> iit = dynamicDescriptor.getIds().iterator();
while (iit.hasNext()) { while (iit.hasNext()) {
Integer index = iit.next(); Integer index = iit.next();
...@@ -224,9 +244,9 @@ public class PropertyDatabase { ...@@ -224,9 +244,9 @@ public class PropertyDatabase {
return dynamicDescriptor.getType(); return dynamicDescriptor.getType();
} }
} }
} }
return null; return null;
} }
...@@ -252,7 +272,7 @@ public class PropertyDatabase { ...@@ -252,7 +272,7 @@ public class PropertyDatabase {
if (propertyName.indexOf(".") != -1) { if (propertyName.indexOf(".") != -1) {
String parentPropertyName = propertyName.substring(0, propertyName.indexOf(".")); String parentPropertyName = propertyName.substring(0, propertyName.indexOf("."));
String indexString = propertyName.substring(propertyName.indexOf(".")+1); String indexString = propertyName.substring(propertyName.indexOf(".")+1);
Set<DynamicPropertyDescriptor> dynamicPropertyIdsForServant = dynamicPropertiesByServant.get(servantId); Set<DynamicPropertyDescriptor> dynamicPropertyIdsForServant = dynamicPropertiesByServant.get(servantId);
if (dynamicPropertyIdsForServant != null) { if (dynamicPropertyIdsForServant != null) {
Iterator<DynamicPropertyDescriptor> it = dynamicPropertyIdsForServant.iterator(); Iterator<DynamicPropertyDescriptor> it = dynamicPropertyIdsForServant.iterator();
...@@ -265,11 +285,11 @@ public class PropertyDatabase { ...@@ -265,11 +285,11 @@ public class PropertyDatabase {
return ids.get(index); return ids.get(index);
} }
} }
} }
} }
} }
return -1; return -1;
} }
......
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