Package: DeviceAssetChannelXmlAdapter
DeviceAssetChannelXmlAdapter
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DeviceAssetChannelXmlAdapter() |
|
|
|
|
|
||||||||||||||||||||
marshal(DeviceAssetChannel) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
||||||||||||||||||||
unmarshal(XmlAdaptedDeviceAssetChannel) |
|
|
|
|
|
Coverage
1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.device.management.asset.xml;
14:
15: import org.eclipse.kapua.locator.KapuaLocator;
16: import org.eclipse.kapua.model.type.ObjectValueConverter;
17: import org.eclipse.kapua.service.device.management.asset.DeviceAssetChannel;
18: import org.eclipse.kapua.service.device.management.asset.DeviceAssetFactory;
19:
20: import javax.xml.bind.annotation.adapters.XmlAdapter;
21:
22: /**
23: * {@link DeviceAssetChannel} {@link XmlAdapter} implementation.
24: *
25: * @see javax.xml.bind.annotation.adapters.XmlAdapter
26: * @since 1.0.0
27: */
28: public class DeviceAssetChannelXmlAdapter extends XmlAdapter<XmlAdaptedDeviceAssetChannel, DeviceAssetChannel> {
29:
30: private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
31: private static final DeviceAssetFactory DEVICE_ASSET_FACTORY = LOCATOR.getFactory(DeviceAssetFactory.class);
32:
33: @Override
34: public XmlAdaptedDeviceAssetChannel marshal(DeviceAssetChannel deviceAssetChannel) throws Exception {
35:
36: XmlAdaptedDeviceAssetChannel xmlAdaptedDeviceAssetChannel = new XmlAdaptedDeviceAssetChannel();
37: xmlAdaptedDeviceAssetChannel.setName(deviceAssetChannel.getName());
38: xmlAdaptedDeviceAssetChannel.setValueType(deviceAssetChannel.getType());
39: xmlAdaptedDeviceAssetChannel.setValue(ObjectValueConverter.toString(deviceAssetChannel.getValue()));
40: xmlAdaptedDeviceAssetChannel.setMode(deviceAssetChannel.getMode());
41: xmlAdaptedDeviceAssetChannel.setError(deviceAssetChannel.getError());
42: xmlAdaptedDeviceAssetChannel.setTimestamp(deviceAssetChannel.getTimestamp());
43:
44: return xmlAdaptedDeviceAssetChannel;
45: }
46:
47: @Override
48: public DeviceAssetChannel unmarshal(XmlAdaptedDeviceAssetChannel xmlAdaptedDeviceAssetChannel) throws Exception {
49:
50: DeviceAssetChannel adaptedDeviceAssetChannel = DEVICE_ASSET_FACTORY.newDeviceAssetChannel();
51: adaptedDeviceAssetChannel.setName(xmlAdaptedDeviceAssetChannel.getName());
52: adaptedDeviceAssetChannel.setType(xmlAdaptedDeviceAssetChannel.getValueType());
53: adaptedDeviceAssetChannel.setValue(ObjectValueConverter.fromString(xmlAdaptedDeviceAssetChannel.getValue(), adaptedDeviceAssetChannel.getType()));
54: adaptedDeviceAssetChannel.setMode(xmlAdaptedDeviceAssetChannel.getMode());
55: adaptedDeviceAssetChannel.setError(xmlAdaptedDeviceAssetChannel.getError());
56: adaptedDeviceAssetChannel.setTimestamp(xmlAdaptedDeviceAssetChannel.getTimestamp());
57:
58: return adaptedDeviceAssetChannel;
59: }
60: }