-
-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[suggestion-finder] update xml schema, converters, and tests
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
- Loading branch information
Showing
19 changed files
with
414 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ddon/src/main/java/org/openhab/core/addon/internal/xml/AddonDiscoveryMethodConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.addon.internal.xml; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.core.addon.AddonDiscoveryMethod; | ||
import org.openhab.core.addon.AddonMatchProperty; | ||
import org.openhab.core.config.core.xml.util.GenericUnmarshaller; | ||
import org.openhab.core.config.core.xml.util.NodeIterator; | ||
|
||
import com.thoughtworks.xstream.converters.UnmarshallingContext; | ||
import com.thoughtworks.xstream.io.HierarchicalStreamReader; | ||
|
||
/** | ||
* The {@link AddonDiscoveryMethodConverter} is a concrete implementation of the {@code XStream} {@link Converter} | ||
* interface used to convert add-on discovery method information within an XML document into a | ||
* {@link AddonDiscoveryMethod} object. | ||
* | ||
* @author Andrew Fiddian-Green - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class AddonDiscoveryMethodConverter extends GenericUnmarshaller<AddonDiscoveryMethod> { | ||
|
||
public AddonDiscoveryMethodConverter() { | ||
super(AddonDiscoveryMethod.class); | ||
} | ||
|
||
@Override | ||
public @Nullable Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { | ||
List<?> nodes = (List<?>) context.convertAnother(context, List.class); | ||
NodeIterator nodeIterator = new NodeIterator(nodes); | ||
|
||
String serviceType = requireNonEmpty((String) nodeIterator.nextValue("service-type", true), | ||
"Service type is null or empty"); | ||
|
||
String mdnsServiceType = (String) nodeIterator.nextValue("mdns-service-type", false); | ||
|
||
Object object = nodeIterator.nextList("match-properties", false); | ||
List<AddonMatchProperty> matchProperties = !(object instanceof List<?> list) ? null | ||
: list.stream().filter(e -> (e instanceof AddonMatchProperty)).map(e -> ((AddonMatchProperty) e)) | ||
.toList(); | ||
|
||
nodeIterator.assertEndOfType(); | ||
|
||
return new AddonDiscoveryMethod().setServiceType(serviceType).setMdnsServiceType(mdnsServiceType) | ||
.setMatchProperties(matchProperties); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
....core.addon/src/main/java/org/openhab/core/addon/internal/xml/AddonInfoListConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.addon.internal.xml; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.core.addon.AddonInfo; | ||
import org.openhab.core.addon.AddonInfoList; | ||
import org.openhab.core.config.core.xml.util.GenericUnmarshaller; | ||
import org.openhab.core.config.core.xml.util.NodeIterator; | ||
|
||
import com.thoughtworks.xstream.converters.Converter; | ||
import com.thoughtworks.xstream.converters.UnmarshallingContext; | ||
import com.thoughtworks.xstream.io.HierarchicalStreamReader; | ||
|
||
/** | ||
* The {@link AddonInfoListConverter} is a concrete implementation of the {@code XStream} {@link Converter} | ||
* interface used to convert a list of add-on information within an XML document into a list of {@link AddonInfo} | ||
* objects. | ||
* | ||
* @author Andrew Fiddian-Green - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class AddonInfoListConverter extends GenericUnmarshaller<AddonInfoList> { | ||
|
||
public AddonInfoListConverter() { | ||
super(AddonInfoList.class); | ||
} | ||
|
||
@Override | ||
public @Nullable Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { | ||
List<?> nodes = (List<?>) context.convertAnother(context, List.class); | ||
NodeIterator nodeIterator = new NodeIterator(nodes); | ||
|
||
Object object = nodeIterator.nextList("addons", false); | ||
List<AddonInfo> addons = (object instanceof List<?> list) | ||
? list.stream().filter(e -> (e instanceof AddonInfoXmlResult)).map(e -> (AddonInfoXmlResult) e) | ||
.map(r -> r.addonInfo()).toList() | ||
: null; | ||
|
||
nodeIterator.assertEndOfType(); | ||
|
||
return new AddonInfoList().setAddons(addons); | ||
} | ||
} |
Oops, something went wrong.