* @param name the factory name
* @throws IOException if the json object cannot be written.
*/
private void getFactoryDetail(PrintWriter pw, String name) throws IOException{
// Find the factory
Factory factory = null;
for (Factory fact : m_factories) {
if (fact.getName().equals(name)) {
factory = fact;
}
}
if (factory == null) {
// This will be used a error message (cannot be interpreted as json)
pw.println("The factory " + name + " does not exist or is private");
return;
}
try {
JSONObject resp = new JSONObject();
// Statline.
resp.put("count", m_factories.size());
resp.put("valid_count", StateUtils.getValidFactoriesCount(m_factories));
resp.put("invalid_count", StateUtils.getInvalidFactoriesCount(m_factories));
// End of the statline
// Factory object
JSONObject data = new JSONObject();
data.put("name", factory.getName());
data.put("state", StateUtils.getFactoryState(factory.getState()));
String bundle = factory.getBundleContext().getBundle().getSymbolicName()
+ " (" + factory.getBundleContext().getBundle().getBundleId() + ")";
data.put("bundle", bundle);
// Provided service specifications
if (factory.getComponentDescription().getprovidedServiceSpecification().length != 0) {
JSONArray services = new JSONArray
(Arrays.asList(factory.getComponentDescription().getprovidedServiceSpecification()));
data.put("services", services);
}
// Properties
PropertyDescription[] props = factory.getComponentDescription().getProperties();
if (props != null && props.length != 0) {
JSONArray properties = new JSONArray();
for (int i = 0; i < props.length; i++) {
JSONObject prop = new JSONObject();
prop.put("name", props[i].getName());
prop.put("type", props[i].getType());
prop.put("mandatory", props[i].isMandatory());
prop.put("immutable", props[i].isImmutable());
if (props[i].getValue() != null) {
prop.put("value", props[i].getValue());
}
properties.put(prop);
}
data.put("properties", properties);
}
if (! factory.getRequiredHandlers().isEmpty()) {
JSONArray req = new JSONArray
(factory.getRequiredHandlers());
data.put("requiredHandlers", req);
}
if (! factory.getMissingHandlers().isEmpty()) {
JSONArray req = new JSONArray
(factory.getMissingHandlers());
data.put("missingHandlers", req);
}
List<?> instances = StateUtils.getInstanceList(m_archs, name);
if (! instances.isEmpty()) {
JSONArray req = new JSONArray(instances);
data.put("instances", req);
}
data.put("architecture", factory.getDescription().toString());
resp.put("data", data);
pw.print(resp.toString());
} catch (JSONException e) {
// Propagate the exception.