use of org.eclipse.smarthome.core.binding.BindingInfo in project smarthome by eclipse.
the class BindingInfoConverter method unmarshal.
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
BindingInfoXmlResult bindingInfoXmlResult = null;
BindingInfo bindingInfo = null;
// read attributes
Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader);
String id = attributes.get("id");
// set automatically extracted URI for a possible 'config-description' section
context.put("config-description.uri", "binding:" + id);
// read values
List<?> nodes = (List<?>) context.convertAnother(context, List.class);
NodeIterator nodeIterator = new NodeIterator(nodes);
String name = (String) nodeIterator.nextValue("name", true);
String description = (String) nodeIterator.nextValue("description", false);
String author = (String) nodeIterator.nextValue("author", false);
String serviceId = (String) nodeIterator.nextValue("service-id", false);
URI configDescriptionURI = readConfigDescriptionURI(nodeIterator);
ConfigDescription configDescription = null;
if (configDescriptionURI == null) {
configDescription = readConfigDescription(nodeIterator);
if (configDescription != null) {
configDescriptionURI = configDescription.getUID();
}
}
nodeIterator.assertEndOfType();
// create object
bindingInfo = new BindingInfo(id, name, description, author, serviceId, configDescriptionURI);
bindingInfoXmlResult = new BindingInfoXmlResult(bindingInfo, configDescription);
return bindingInfoXmlResult;
}
use of org.eclipse.smarthome.core.binding.BindingInfo in project smarthome by eclipse.
the class BindingResource method normalizeConfiguration.
private Map<String, Object> normalizeConfiguration(Map<String, Object> properties, String bindingId) {
if (properties == null || properties.isEmpty()) {
return properties;
}
BindingInfo bindingInfo = this.bindingInfoRegistry.getBindingInfo(bindingId);
if (bindingInfo == null || bindingInfo.getConfigDescriptionURI() == null) {
return properties;
}
ConfigDescription configDesc = configDescRegistry.getConfigDescription(bindingInfo.getConfigDescriptionURI());
if (configDesc == null) {
return properties;
}
return ConfigUtil.normalizeTypes(properties, Collections.singletonList(configDesc));
}
use of org.eclipse.smarthome.core.binding.BindingInfo in project smarthome by eclipse.
the class BindingInfoXmlProvider method addingObject.
@Override
public synchronized void addingObject(BindingInfoXmlResult bindingInfoXmlResult) {
if (bindingInfoXmlResult != null) {
ConfigDescription configDescription = bindingInfoXmlResult.getConfigDescription();
if (configDescription != null) {
try {
this.configDescriptionProvider.add(this.bundle, configDescription);
} catch (Exception ex) {
this.logger.error("Could not register ConfigDescription!", ex);
}
}
BindingInfo bindingInfo = bindingInfoXmlResult.getBindingInfo();
this.bindingInfoProvider.add(bundle, bindingInfo);
}
}
use of org.eclipse.smarthome.core.binding.BindingInfo in project smarthome by eclipse.
the class BindingResource method getAll.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all bindings.", response = BindingInfoDTO.class, responseContainer = "Set")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = BindingInfoDTO.class, responseContainer = "Set") })
public Response getAll(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language) {
final Locale locale = LocaleUtil.getLocale(language);
Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos(locale);
return Response.ok(new Stream2JSONInputStream(bindingInfos.stream().map(b -> map(b, locale)))).build();
}
Aggregations