= new ArrayList<String>(Arrays.asList(arguments.split(" ")));
DeviceGroup deviceGroup
= CommandUtil.findDeviceGroup(session, args);
if (!deviceGroup.getSupportedDeviceTypes()
.contains(GettableDevice.class)) {
throw new CommandExecutionException(ERROR_FORBIDDEN);
}
Device device;
if (deviceGroup instanceof SingleDeviceGroup) {
device = ((SingleDeviceGroup)deviceGroup).getDevice();
} else {
long address = CommandUtil.consumeNumber(args);
device = deviceGroup.getDevice(address);
if (device == null) {
if (!deviceGroup.allowImplicitCreation()) {
throw new CommandExecutionException
(Command.ERROR_UNSUPPORTED_DEVICE);
}
device = deviceGroup.createDevice(address);
if (!(device instanceof InitializableDevice)
|| !(device instanceof GettableDevice)) {
throw new CommandExecutionException
(Command.ERROR_UNSUPPORTED_DEVICE);
}
((InitializableDevice)device).init
(session, deviceGroup,
((InitializableDevice)device).getDescription());
device.addStateChangeListener(session.getServer());
}
}
if (!(device instanceof GettableDevice)) {
throw new CommandExecutionException
(ERROR_UNSUPPORTED_OPERATION);
}
String info;
if (args.size() > 0) {
if (device instanceof AddressableStateProvider) {
synchronized (device) {
info = ((AddressableStateProvider)device)
.getState(session, args);
}
} else {
throw new CommandExecutionException(ERROR_LIST_TOO_LONG);
}
} else {
synchronized (device) {
String[] states
= ((GettableDevice)device).getState(session);
if (states.length != 1) {
throw new CommandExecutionException
(Command.ERROR_UNSUPPORTED_OPERATION);
}
info = states[0];
}
}