-
-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified finder discovery schema to make future finders easier to cre…
…ate (#3924) * change discovery method schema Signed-off-by: Mark Herwege <[email protected]>
- Loading branch information
Showing
14 changed files
with
224 additions
and
56 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
62 changes: 62 additions & 0 deletions
62
bundles/org.openhab.core.addon/src/main/java/org/openhab/core/addon/AddonParameter.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,62 @@ | ||
/** | ||
* 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; | ||
|
||
import java.util.Objects; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
/** | ||
* DTO for serialization of a add-on discovery parameter. | ||
* | ||
* @author Mark Herwege - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class AddonParameter { | ||
private @NonNullByDefault({}) String name; | ||
private @NonNullByDefault({}) String value; | ||
|
||
public AddonParameter(String name, String value) { | ||
this.name = name; | ||
this.value = value; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, value); | ||
} | ||
|
||
@Override | ||
public boolean equals(@Nullable Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
AddonParameter other = (AddonParameter) obj; | ||
return Objects.equals(name, other.name) && Objects.equals(value, other.value); | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
...core.addon/src/main/java/org/openhab/core/addon/internal/xml/AddonParameterConverter.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,53 @@ | ||
/** | ||
* 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.AddonMatchProperty; | ||
import org.openhab.core.addon.AddonParameter; | ||
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 AddonParameterConverter} is a concrete implementation of the {@code XStream} {@link Converter} | ||
* interface used to convert add-on discovery method parameter information within an XML document into a | ||
* {@link AddonMatchProperty} object. | ||
* | ||
* @author Mark Herwege - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class AddonParameterConverter extends GenericUnmarshaller<AddonParameter> { | ||
|
||
public AddonParameterConverter() { | ||
super(AddonParameter.class); | ||
} | ||
|
||
@Override | ||
public @Nullable Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { | ||
List<?> nodes = (List<?>) context.convertAnother(context, List.class); | ||
NodeIterator nodeIterator = new NodeIterator(nodes); | ||
|
||
String name = requireNonEmpty((String) nodeIterator.nextValue("name", true), "Name is null or empty"); | ||
String value = requireNonEmpty((String) nodeIterator.nextValue("value", true), "Value is null or empty"); | ||
|
||
nodeIterator.assertEndOfType(); | ||
|
||
return new AddonParameter(name, value); | ||
} | ||
} |
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
Oops, something went wrong.