private static JsonArray buildControllerArray(Room room) {
JsonArrayBuilder controllerArrayBuilder = Json.createArrayBuilder();
List<IController> controllers = room.getControllers();
if (controllers != null) {
for (IController controller : controllers) {
JsonObjectBuilder controllerObjectBuilder = Json
.createObjectBuilder();
controllerObjectBuilder.add("id", controller.getId()).add(
"class", controller.getClass().getName());
List<ISensor> attachedSensors = controller.getAttachedSensors();
if (attachedSensors != null) {
JsonArrayBuilder sensorArrayBuilder = Json
.createArrayBuilder();
for (ISensor sensor : attachedSensors) {
sensorArrayBuilder.add(sensor.getId());
}
controllerObjectBuilder.add("sensors",
sensorArrayBuilder.build());
}
List<IActuator> attachedActuators = controller
.getAttachedActuators();
if (attachedActuators != null) {
JsonArrayBuilder actuatorArrayBuilder = Json
.createArrayBuilder();
for (IActuator actuator : attachedActuators) {
actuatorArrayBuilder.add(actuator.getId());
}
controllerObjectBuilder.add("actuators",
actuatorArrayBuilder.build());
}
controllerArrayBuilder.add(controllerObjectBuilder.build());
}
}
return controllerArrayBuilder.build();
}