diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/fileformat/FileFormatResource.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/fileformat/FileFormatResource.java index 9381edecf..aad3c45f7 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/fileformat/FileFormatResource.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/fileformat/FileFormatResource.java @@ -64,8 +64,8 @@ import org.openhab.core.items.ItemRegistry; import org.openhab.core.items.Metadata; import org.openhab.core.items.MetadataKey; import org.openhab.core.items.MetadataRegistry; -import org.openhab.core.items.fileconverter.ItemFileGenerator; -import org.openhab.core.items.fileconverter.ItemFileParser; +import org.openhab.core.items.fileconverter.ItemParser; +import org.openhab.core.items.fileconverter.ItemSerializer; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; @@ -76,8 +76,8 @@ import org.openhab.core.thing.binding.ThingFactory; import org.openhab.core.thing.dto.ChannelDTO; import org.openhab.core.thing.dto.ThingDTO; import org.openhab.core.thing.dto.ThingDTOMapper; -import org.openhab.core.thing.fileconverter.ThingFileGenerator; -import org.openhab.core.thing.fileconverter.ThingFileParser; +import org.openhab.core.thing.fileconverter.ThingParser; +import org.openhab.core.thing.fileconverter.ThingSerializer; import org.openhab.core.thing.link.ItemChannelLink; import org.openhab.core.thing.link.ItemChannelLinkRegistry; import org.openhab.core.thing.type.BridgeType; @@ -257,10 +257,10 @@ public class FileFormatResource implements RESTResource { private final ThingTypeRegistry thingTypeRegistry; private final ChannelTypeRegistry channelTypeRegistry; private final ConfigDescriptionRegistry configDescRegistry; - private final Map itemFileGenerators = new ConcurrentHashMap<>(); - private final Map itemFileParsers = new ConcurrentHashMap<>(); - private final Map thingFileGenerators = new ConcurrentHashMap<>(); - private final Map thingFileParsers = new ConcurrentHashMap<>(); + private final Map itemSerializers = new ConcurrentHashMap<>(); + private final Map itemParsers = new ConcurrentHashMap<>(); + private final Map thingSerializers = new ConcurrentHashMap<>(); + private final Map thingParsers = new ConcurrentHashMap<>(); private int counter; @@ -291,39 +291,39 @@ public class FileFormatResource implements RESTResource { } @Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.MULTIPLE) - protected void addItemFileGenerator(ItemFileGenerator itemFileGenerator) { - itemFileGenerators.put(itemFileGenerator.getFileFormatGenerator(), itemFileGenerator); + protected void addItemSerializer(ItemSerializer itemSerializer) { + itemSerializers.put(itemSerializer.getGeneratedFormat(), itemSerializer); } - protected void removeItemFileGenerator(ItemFileGenerator itemFileGenerator) { - itemFileGenerators.remove(itemFileGenerator.getFileFormatGenerator()); + protected void removeItemSerializer(ItemSerializer itemSerializer) { + itemSerializers.remove(itemSerializer.getGeneratedFormat()); } @Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.MULTIPLE) - protected void addItemFileParser(ItemFileParser itemFileParser) { - itemFileParsers.put(itemFileParser.getFileFormatParser(), itemFileParser); + protected void addItemParser(ItemParser itemParser) { + itemParsers.put(itemParser.getParserFormat(), itemParser); } - protected void removeItemFileParser(ItemFileParser itemFileParser) { - itemFileParsers.remove(itemFileParser.getFileFormatParser()); + protected void removeItemParser(ItemParser itemParser) { + itemParsers.remove(itemParser.getParserFormat()); } @Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.MULTIPLE) - protected void addThingFileGenerator(ThingFileGenerator thingFileGenerator) { - thingFileGenerators.put(thingFileGenerator.getFileFormatGenerator(), thingFileGenerator); + protected void addThingSerializer(ThingSerializer thingSerializer) { + thingSerializers.put(thingSerializer.getGeneratedFormat(), thingSerializer); } - protected void removeThingFileGenerator(ThingFileGenerator thingFileGenerator) { - thingFileGenerators.remove(thingFileGenerator.getFileFormatGenerator()); + protected void removeThingSerializer(ThingSerializer thingSerializer) { + thingSerializers.remove(thingSerializer.getGeneratedFormat()); } @Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.MULTIPLE) - protected void addThingFileParser(ThingFileParser thingFileParser) { - thingFileParsers.put(thingFileParser.getFileFormatParser(), thingFileParser); + protected void addThingParser(ThingParser thingParser) { + thingParsers.put(thingParser.getParserFormat(), thingParser); } - protected void removeThingFileParser(ThingFileParser thingFileParser) { - thingFileParsers.remove(thingFileParser.getFileFormatParser()); + protected void removeThingParser(ThingParser thingParser) { + thingParsers.remove(thingParser.getParserFormat()); } @POST @@ -343,8 +343,8 @@ public class FileFormatResource implements RESTResource { @Parameter(description = "Array of item names. If empty or omitted, return all Items.") @Nullable List itemNames) { String acceptHeader = httpHeaders.getHeaderString(HttpHeaders.ACCEPT); logger.debug("createFileFormatForItems: mediaType = {}, itemNames = {}", acceptHeader, itemNames); - ItemFileGenerator generator = getItemFileGenerator(acceptHeader); - if (generator == null) { + ItemSerializer serializer = getItemSerializer(acceptHeader); + if (serializer == null) { return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE) .entity("Unsupported media type '" + acceptHeader + "'!").build(); } @@ -363,7 +363,7 @@ public class FileFormatResource implements RESTResource { } } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - String genId = newIdForGeneration(); + String genId = newIdForSerialization(); Map stateFormatters = new HashMap<>(); items.forEach(item -> { StateDescription stateDescr = item.getStateDescription(); @@ -372,8 +372,8 @@ public class FileFormatResource implements RESTResource { stateFormatters.put(item.getName(), format); } }); - generator.setItemsToBeGenerated(genId, items, getMetadata(items), stateFormatters, hideDefaultParameters); - generator.generateFileFormat(genId, outputStream); + serializer.setItemsToBeSerialized(genId, items, getMetadata(items), stateFormatters, hideDefaultParameters); + serializer.generateFormat(genId, outputStream); return Response.ok(new String(outputStream.toByteArray())).build(); } @@ -394,8 +394,8 @@ public class FileFormatResource implements RESTResource { @Parameter(description = "Array of Thing UIDs. If empty or omitted, return all Things from the Registry.") @Nullable List thingUIDs) { String acceptHeader = httpHeaders.getHeaderString(HttpHeaders.ACCEPT); logger.debug("createFileFormatForThings: mediaType = {}, thingUIDs = {}", acceptHeader, thingUIDs); - ThingFileGenerator generator = getThingFileGenerator(acceptHeader); - if (generator == null) { + ThingSerializer serializer = getThingSerializer(acceptHeader); + if (serializer == null) { return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE) .entity("Unsupported media type '" + acceptHeader + "'!").build(); } @@ -410,9 +410,9 @@ public class FileFormatResource implements RESTResource { } } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - String genId = newIdForGeneration(); - generator.setThingsToBeGenerated(genId, things, true, hideDefaultParameters); - generator.generateFileFormat(genId, outputStream); + String genId = newIdForSerialization(); + serializer.setThingsToBeSerialized(genId, things, true, hideDefaultParameters); + serializer.generateFormat(genId, outputStream); return Response.ok(new String(outputStream.toByteArray())).build(); } @@ -446,44 +446,44 @@ public class FileFormatResource implements RESTResource { return Response.status(Response.Status.BAD_REQUEST).entity(String.join("\n", errors)).build(); } - ThingFileGenerator thingGenerator = getThingFileGenerator(acceptHeader); - ItemFileGenerator itemGenerator = getItemFileGenerator(acceptHeader); + ThingSerializer thingSerializer = getThingSerializer(acceptHeader); + ItemSerializer itemSerializer = getItemSerializer(acceptHeader); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - String genId = newIdForGeneration(); + String genId = newIdForSerialization(); switch (acceptHeader) { case "text/vnd.openhab.dsl.thing": - if (thingGenerator == null) { + if (thingSerializer == null) { return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE) .entity("Unsupported media type '" + acceptHeader + "'!").build(); } else if (things.isEmpty()) { return Response.status(Response.Status.BAD_REQUEST).entity("No thing loaded from input").build(); } - thingGenerator.setThingsToBeGenerated(genId, things, hideDefaultChannels, hideDefaultParameters); - thingGenerator.generateFileFormat(genId, outputStream); + thingSerializer.setThingsToBeSerialized(genId, things, hideDefaultChannels, hideDefaultParameters); + thingSerializer.generateFormat(genId, outputStream); break; case "text/vnd.openhab.dsl.item": - if (itemGenerator == null) { + if (itemSerializer == null) { return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE) .entity("Unsupported media type '" + acceptHeader + "'!").build(); } else if (items.isEmpty()) { return Response.status(Response.Status.BAD_REQUEST).entity("No item loaded from input").build(); } - itemGenerator.setItemsToBeGenerated(genId, items, hideChannelLinksAndMetadata ? List.of() : metadata, + itemSerializer.setItemsToBeSerialized(genId, items, hideChannelLinksAndMetadata ? List.of() : metadata, stateFormatters, hideDefaultParameters); - itemGenerator.generateFileFormat(genId, outputStream); + itemSerializer.generateFormat(genId, outputStream); break; case "application/yaml": - if (thingGenerator != null) { - thingGenerator.setThingsToBeGenerated(genId, things, hideDefaultChannels, hideDefaultParameters); + if (thingSerializer != null) { + thingSerializer.setThingsToBeSerialized(genId, things, hideDefaultChannels, hideDefaultParameters); } - if (itemGenerator != null) { - itemGenerator.setItemsToBeGenerated(genId, items, + if (itemSerializer != null) { + itemSerializer.setItemsToBeSerialized(genId, items, hideChannelLinksAndMetadata ? List.of() : metadata, stateFormatters, hideDefaultParameters); } - if (thingGenerator != null) { - thingGenerator.generateFileFormat(genId, outputStream); - } else if (itemGenerator != null) { - itemGenerator.generateFileFormat(genId, outputStream); + if (thingSerializer != null) { + thingSerializer.generateFormat(genId, outputStream); + } else if (itemSerializer != null) { + itemSerializer.generateFormat(genId, outputStream); } break; default: @@ -519,8 +519,8 @@ public class FileFormatResource implements RESTResource { Map stateFormatters = Map.of(); List errors = new ArrayList<>(); List warnings = new ArrayList<>(); - ThingFileParser thingParser = getThingFileParser(contentTypeHeader); - ItemFileParser itemParser = getItemFileParser(contentTypeHeader); + ThingParser thingParser = getThingParser(contentTypeHeader); + ItemParser itemParser = getItemParser(contentTypeHeader); String modelName = null; String modelName2 = null; switch (contentTypeHeader) { @@ -529,13 +529,13 @@ public class FileFormatResource implements RESTResource { return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE) .entity("Unsupported content type '" + contentTypeHeader + "'!").build(); } - modelName = thingParser.startParsingFileFormat(input, errors, warnings); + modelName = thingParser.startParsingFormat(input, errors, warnings); if (modelName == null) { return Response.status(Response.Status.BAD_REQUEST).entity(String.join("\n", errors)).build(); } - things = thingParser.getParsedThings(modelName); + things = thingParser.getParsedObjects(modelName); if (things.isEmpty()) { - thingParser.finishParsingFileFormat(modelName); + thingParser.finishParsingFormat(modelName); return Response.status(Response.Status.BAD_REQUEST).entity("No thing loaded from input").build(); } break; @@ -544,13 +544,13 @@ public class FileFormatResource implements RESTResource { return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE) .entity("Unsupported content type '" + contentTypeHeader + "'!").build(); } - modelName2 = itemParser.startParsingFileFormat(input, errors, warnings); + modelName2 = itemParser.startParsingFormat(input, errors, warnings); if (modelName2 == null) { return Response.status(Response.Status.BAD_REQUEST).entity(String.join("\n", errors)).build(); } - items = itemParser.getParsedItems(modelName2); + items = itemParser.getParsedObjects(modelName2); if (items.isEmpty()) { - itemParser.finishParsingFileFormat(modelName2); + itemParser.finishParsingFormat(modelName2); return Response.status(Response.Status.BAD_REQUEST).entity("No item loaded from input").build(); } metadata = itemParser.getParsedMetadata(modelName2); @@ -563,24 +563,24 @@ public class FileFormatResource implements RESTResource { break; case "application/yaml": if (thingParser != null) { - modelName = thingParser.startParsingFileFormat(input, errors, warnings); + modelName = thingParser.startParsingFormat(input, errors, warnings); if (modelName == null) { return Response.status(Response.Status.BAD_REQUEST).entity(String.join("\n", errors)).build(); } - things = thingParser.getParsedThings(modelName); + things = thingParser.getParsedObjects(modelName); channelLinks = thingParser.getParsedChannelLinks(modelName); } if (itemParser != null) { // Avoid parsing the input a second time if (modelName == null) { - modelName2 = itemParser.startParsingFileFormat(input, errors, warnings); + modelName2 = itemParser.startParsingFormat(input, errors, warnings); if (modelName2 == null) { return Response.status(Response.Status.BAD_REQUEST).entity(String.join("\n", errors)) .build(); } } String modelNameToUse = modelName != null ? modelName : Objects.requireNonNull(modelName2); - items = itemParser.getParsedItems(modelNameToUse); + items = itemParser.getParsedObjects(modelNameToUse); metadata = itemParser.getParsedMetadata(modelNameToUse); stateFormatters = itemParser.getParsedStateFormatters(modelNameToUse); } @@ -592,15 +592,15 @@ public class FileFormatResource implements RESTResource { ExtendedFileFormatDTO result = convertToFileFormatDTO(things, items, metadata, stateFormatters, channelLinks, warnings); if (modelName != null && thingParser != null) { - thingParser.finishParsingFileFormat(modelName); + thingParser.finishParsingFormat(modelName); } if (modelName2 != null && itemParser != null) { - itemParser.finishParsingFileFormat(modelName2); + itemParser.finishParsingFormat(modelName2); } return Response.ok(result).build(); } - private String newIdForGeneration() { + private String newIdForSerialization() { return GEN_ID_PATTERN.formatted(++counter); } @@ -748,35 +748,35 @@ public class FileFormatResource implements RESTResource { configDescRegistry); } - private @Nullable ItemFileGenerator getItemFileGenerator(String mediaType) { + private @Nullable ItemSerializer getItemSerializer(String mediaType) { return switch (mediaType) { - case "text/vnd.openhab.dsl.item" -> itemFileGenerators.get("DSL"); - case "application/yaml" -> itemFileGenerators.get("YAML"); + case "text/vnd.openhab.dsl.item" -> itemSerializers.get("DSL"); + case "application/yaml" -> itemSerializers.get("YAML"); default -> null; }; } - private @Nullable ThingFileGenerator getThingFileGenerator(String mediaType) { + private @Nullable ThingSerializer getThingSerializer(String mediaType) { return switch (mediaType) { - case "text/vnd.openhab.dsl.thing" -> thingFileGenerators.get("DSL"); - case "application/yaml" -> thingFileGenerators.get("YAML"); + case "text/vnd.openhab.dsl.thing" -> thingSerializers.get("DSL"); + case "application/yaml" -> thingSerializers.get("YAML"); default -> null; }; } - private @Nullable ItemFileParser getItemFileParser(String contentType) { + private @Nullable ItemParser getItemParser(String contentType) { return switch (contentType) { - case "text/vnd.openhab.dsl.item" -> itemFileParsers.get("DSL"); - case "application/yaml" -> itemFileParsers.get("YAML"); + case "text/vnd.openhab.dsl.item" -> itemParsers.get("DSL"); + case "application/yaml" -> itemParsers.get("YAML"); default -> null; }; } - private @Nullable ThingFileParser getThingFileParser(String contentType) { + private @Nullable ThingParser getThingParser(String contentType) { return switch (contentType) { - case "text/vnd.openhab.dsl.thing" -> thingFileParsers.get("DSL"); - case "text/vnd.openhab.dsl.item" -> thingFileParsers.get("DSL"); - case "application/yaml" -> thingFileParsers.get("YAML"); + case "text/vnd.openhab.dsl.thing" -> thingParsers.get("DSL"); + case "text/vnd.openhab.dsl.item" -> thingParsers.get("DSL"); + case "application/yaml" -> thingParsers.get("YAML"); default -> null; }; } diff --git a/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/fileconverter/DslItemFileConverter.java b/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/fileconverter/DslItemConverter.java similarity index 92% rename from bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/fileconverter/DslItemFileConverter.java rename to bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/fileconverter/DslItemConverter.java index ef1c5f0bb..aed1d72a4 100644 --- a/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/fileconverter/DslItemFileConverter.java +++ b/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/fileconverter/DslItemConverter.java @@ -37,9 +37,9 @@ import org.openhab.core.items.GroupItem; import org.openhab.core.items.Item; import org.openhab.core.items.ItemUtil; import org.openhab.core.items.Metadata; -import org.openhab.core.items.fileconverter.AbstractItemFileGenerator; -import org.openhab.core.items.fileconverter.ItemFileGenerator; -import org.openhab.core.items.fileconverter.ItemFileParser; +import org.openhab.core.items.fileconverter.AbstractItemSerializer; +import org.openhab.core.items.fileconverter.ItemParser; +import org.openhab.core.items.fileconverter.ItemSerializer; import org.openhab.core.model.core.ModelRepository; import org.openhab.core.model.item.internal.GenericItemProvider; import org.openhab.core.model.item.internal.GenericMetadataProvider; @@ -56,16 +56,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * {@link DslItemFileConverter} is the DSL file converter for {@link Item} object - * with the capabilities of parsing and generating file. + * {@link DslItemConverter} is the DSL converter for {@link Item} objects + * with the capabilities of parsing and serializing files. * * @author Laurent Garnier - Initial contribution */ @NonNullByDefault -@Component(immediate = true, service = { ItemFileGenerator.class, ItemFileParser.class }) -public class DslItemFileConverter extends AbstractItemFileGenerator implements ItemFileParser { +@Component(immediate = true, service = { ItemSerializer.class, ItemParser.class }) +public class DslItemConverter extends AbstractItemSerializer implements ItemParser { - private final Logger logger = LoggerFactory.getLogger(DslItemFileConverter.class); + private final Logger logger = LoggerFactory.getLogger(DslItemConverter.class); private final Map elementsToGenerate = new ConcurrentHashMap<>(); @@ -75,7 +75,7 @@ public class DslItemFileConverter extends AbstractItemFileGenerator implements I private final ConfigDescriptionRegistry configDescriptionRegistry; @Activate - public DslItemFileConverter(final @Reference ModelRepository modelRepository, + public DslItemConverter(final @Reference ModelRepository modelRepository, final @Reference GenericItemProvider itemProvider, final @Reference GenericMetadataProvider metadataProvider, final @Reference ConfigDescriptionRegistry configDescriptionRegistry) { @@ -86,12 +86,12 @@ public class DslItemFileConverter extends AbstractItemFileGenerator implements I } @Override - public String getFileFormatGenerator() { + public String getGeneratedFormat() { return "DSL"; } @Override - public void setItemsToBeGenerated(String id, List items, Collection metadata, + public void setItemsToBeSerialized(String id, List items, Collection metadata, Map stateFormatters, boolean hideDefaultParameters) { if (items.isEmpty()) { return; @@ -105,7 +105,7 @@ public class DslItemFileConverter extends AbstractItemFileGenerator implements I } @Override - public void generateFileFormat(String id, OutputStream out) { + public void generateFormat(String id, OutputStream out) { ItemModel model = elementsToGenerate.remove(id); if (model != null) { modelRepository.generateFileFormat(out, "items", model); @@ -299,18 +299,18 @@ public class DslItemFileConverter extends AbstractItemFileGenerator implements I } @Override - public String getFileFormatParser() { + public String getParserFormat() { return "DSL"; } @Override - public @Nullable String startParsingFileFormat(String syntax, List errors, List warnings) { + public @Nullable String startParsingFormat(String syntax, List errors, List warnings) { ByteArrayInputStream inputStream = new ByteArrayInputStream(syntax.getBytes()); return modelRepository.createIsolatedModel("items", inputStream, errors, warnings); } @Override - public Collection getParsedItems(String modelName) { + public Collection getParsedObjects(String modelName) { return itemProvider.getAllFromModel(modelName); } @@ -325,7 +325,7 @@ public class DslItemFileConverter extends AbstractItemFileGenerator implements I } @Override - public void finishParsingFileFormat(String modelName) { + public void finishParsingFormat(String modelName) { modelRepository.removeModel(modelName); } } diff --git a/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/fileconverter/DslThingFileConverter.java b/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/fileconverter/DslThingConverter.java similarity index 90% rename from bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/fileconverter/DslThingFileConverter.java rename to bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/fileconverter/DslThingConverter.java index 264d29e16..1096e1b91 100644 --- a/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/fileconverter/DslThingFileConverter.java +++ b/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/fileconverter/DslThingConverter.java @@ -41,9 +41,9 @@ import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Channel; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingUID; -import org.openhab.core.thing.fileconverter.AbstractThingFileGenerator; -import org.openhab.core.thing.fileconverter.ThingFileGenerator; -import org.openhab.core.thing.fileconverter.ThingFileParser; +import org.openhab.core.thing.fileconverter.AbstractThingSerializer; +import org.openhab.core.thing.fileconverter.ThingParser; +import org.openhab.core.thing.fileconverter.ThingSerializer; import org.openhab.core.thing.link.ItemChannelLink; import org.openhab.core.thing.type.ChannelKind; import org.openhab.core.thing.type.ChannelTypeRegistry; @@ -57,16 +57,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * {@link DslThingFileConverter} is the DSL file converter for {@link Thing} object - * with the capabilities of parsing and generating file. + * {@link DslThingConverter} is the DSL file converter for {@link Thing} objects + * with the capabilities of parsing and serializing files. * * @author Laurent Garnier - Initial contribution */ @NonNullByDefault -@Component(immediate = true, service = { ThingFileGenerator.class, ThingFileParser.class }) -public class DslThingFileConverter extends AbstractThingFileGenerator implements ThingFileParser { +@Component(immediate = true, service = { ThingSerializer.class, ThingParser.class }) +public class DslThingConverter extends AbstractThingSerializer implements ThingParser { - private final Logger logger = LoggerFactory.getLogger(DslThingFileConverter.class); + private final Logger logger = LoggerFactory.getLogger(DslThingConverter.class); private final ModelRepository modelRepository; private final GenericThingProvider thingProvider; @@ -76,7 +76,7 @@ public class DslThingFileConverter extends AbstractThingFileGenerator implements private final Map elementsToGenerate = new ConcurrentHashMap<>(); @Activate - public DslThingFileConverter(final @Reference ModelRepository modelRepository, + public DslThingConverter(final @Reference ModelRepository modelRepository, final @Reference GenericThingProvider thingProvider, final @Reference GenericItemChannelLinkProvider itemChannelLinkProvider, final @Reference ThingTypeRegistry thingTypeRegistry, @@ -91,12 +91,12 @@ public class DslThingFileConverter extends AbstractThingFileGenerator implements } @Override - public String getFileFormatGenerator() { + public String getGeneratedFormat() { return "DSL"; } @Override - public void setThingsToBeGenerated(String id, List things, boolean hideDefaultChannels, + public void setThingsToBeSerialized(String id, List things, boolean hideDefaultChannels, boolean hideDefaultParameters) { if (things.isEmpty()) { return; @@ -114,7 +114,7 @@ public class DslThingFileConverter extends AbstractThingFileGenerator implements } @Override - public void generateFileFormat(String id, OutputStream out) { + public void generateFormat(String id, OutputStream out) { ThingModel model = elementsToGenerate.remove(id); if (model != null) { // Double quotes are unexpectedly generated in thing UID when the segment contains a -. @@ -235,18 +235,18 @@ public class DslThingFileConverter extends AbstractThingFileGenerator implements } @Override - public String getFileFormatParser() { + public String getParserFormat() { return "DSL"; } @Override - public @Nullable String startParsingFileFormat(String syntax, List errors, List warnings) { + public @Nullable String startParsingFormat(String syntax, List errors, List warnings) { ByteArrayInputStream inputStream = new ByteArrayInputStream(syntax.getBytes()); return modelRepository.createIsolatedModel("things", inputStream, errors, warnings); } @Override - public Collection getParsedThings(String modelName) { + public Collection getParsedObjects(String modelName) { return thingProvider.getAllFromModel(modelName); } @@ -256,7 +256,7 @@ public class DslThingFileConverter extends AbstractThingFileGenerator implements } @Override - public void finishParsingFileFormat(String modelName) { + public void finishParsingFormat(String modelName) { modelRepository.removeModel(modelName); } } diff --git a/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImpl.java b/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImpl.java index dd13fda64..e75bc3e84 100644 --- a/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImpl.java +++ b/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImpl.java @@ -252,7 +252,7 @@ public class YamlModelRepositoryImpl implements WatchService.WatchEventListener, List newElementNames = new ArrayList<>(); // get sub-elements - Iterator> it = fileContent.fields(); + Iterator> it = fileContent.properties().iterator(); while (it.hasNext()) { Map.Entry element = it.next(); String elementName = element.getKey(); diff --git a/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/items/fileconverter/YamlItemFileConverter.java b/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/items/fileconverter/YamlItemConverter.java similarity index 92% rename from bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/items/fileconverter/YamlItemFileConverter.java rename to bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/items/fileconverter/YamlItemConverter.java index 6a6e786ee..d48791084 100644 --- a/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/items/fileconverter/YamlItemFileConverter.java +++ b/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/items/fileconverter/YamlItemConverter.java @@ -39,9 +39,9 @@ import org.openhab.core.items.GroupItem; import org.openhab.core.items.Item; import org.openhab.core.items.ItemUtil; import org.openhab.core.items.Metadata; -import org.openhab.core.items.fileconverter.AbstractItemFileGenerator; -import org.openhab.core.items.fileconverter.ItemFileGenerator; -import org.openhab.core.items.fileconverter.ItemFileParser; +import org.openhab.core.items.fileconverter.AbstractItemSerializer; +import org.openhab.core.items.fileconverter.ItemParser; +import org.openhab.core.items.fileconverter.ItemSerializer; import org.openhab.core.library.CoreItemFactory; import org.openhab.core.model.yaml.YamlElement; import org.openhab.core.model.yaml.YamlModelRepository; @@ -57,13 +57,13 @@ import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** - * {@link YamlItemFileConverter} is the YAML file converter for {@link Item} object. + * {@link YamlItemConverter} is the YAML converter for {@link Item} objects. * * @author Laurent Garnier - Initial contribution */ @NonNullByDefault -@Component(immediate = true, service = { ItemFileGenerator.class, ItemFileParser.class }) -public class YamlItemFileConverter extends AbstractItemFileGenerator implements ItemFileParser { +@Component(immediate = true, service = { ItemSerializer.class, ItemParser.class }) +public class YamlItemConverter extends AbstractItemSerializer implements ItemParser { private final YamlModelRepository modelRepository; private final YamlItemProvider itemProvider; @@ -72,7 +72,7 @@ public class YamlItemFileConverter extends AbstractItemFileGenerator implements private final ConfigDescriptionRegistry configDescriptionRegistry; @Activate - public YamlItemFileConverter(final @Reference YamlModelRepository modelRepository, + public YamlItemConverter(final @Reference YamlModelRepository modelRepository, final @Reference YamlItemProvider itemProvider, final @Reference YamlMetadataProvider metadataProvider, final @Reference YamlChannelLinkProvider channelLinkProvider, final @Reference ConfigDescriptionRegistry configDescRegistry) { @@ -84,12 +84,12 @@ public class YamlItemFileConverter extends AbstractItemFileGenerator implements } @Override - public String getFileFormatGenerator() { + public String getGeneratedFormat() { return "YAML"; } @Override - public void setItemsToBeGenerated(String id, List items, Collection metadata, + public void setItemsToBeSerialized(String id, List items, Collection metadata, Map stateFormatters, boolean hideDefaultParameters) { List elements = new ArrayList<>(); items.forEach(item -> { @@ -100,7 +100,7 @@ public class YamlItemFileConverter extends AbstractItemFileGenerator implements } @Override - public void generateFileFormat(String id, OutputStream out) { + public void generateFormat(String id, OutputStream out) { modelRepository.generateFileFormat(id, out); } @@ -283,18 +283,18 @@ public class YamlItemFileConverter extends AbstractItemFileGenerator implements } @Override - public String getFileFormatParser() { + public String getParserFormat() { return "YAML"; } @Override - public @Nullable String startParsingFileFormat(String syntax, List errors, List warnings) { + public @Nullable String startParsingFormat(String syntax, List errors, List warnings) { ByteArrayInputStream inputStream = new ByteArrayInputStream(syntax.getBytes()); return modelRepository.createIsolatedModel(inputStream, errors, warnings); } @Override - public Collection getParsedItems(String modelName) { + public Collection getParsedObjects(String modelName) { return itemProvider.getAllFromModel(modelName); } @@ -318,7 +318,7 @@ public class YamlItemFileConverter extends AbstractItemFileGenerator implements } @Override - public void finishParsingFileFormat(String modelName) { + public void finishParsingFormat(String modelName) { modelRepository.removeIsolatedModel(modelName); } } diff --git a/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/things/fileconverter/YamlThingFileConverter.java b/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/things/fileconverter/YamlThingConverter.java similarity index 87% rename from bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/things/fileconverter/YamlThingFileConverter.java rename to bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/things/fileconverter/YamlThingConverter.java index 3d66a5575..fc82dc1f3 100644 --- a/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/things/fileconverter/YamlThingFileConverter.java +++ b/bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/things/fileconverter/YamlThingConverter.java @@ -35,9 +35,9 @@ import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Channel; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingUID; -import org.openhab.core.thing.fileconverter.AbstractThingFileGenerator; -import org.openhab.core.thing.fileconverter.ThingFileGenerator; -import org.openhab.core.thing.fileconverter.ThingFileParser; +import org.openhab.core.thing.fileconverter.AbstractThingSerializer; +import org.openhab.core.thing.fileconverter.ThingParser; +import org.openhab.core.thing.fileconverter.ThingSerializer; import org.openhab.core.thing.link.ItemChannelLink; import org.openhab.core.thing.type.ChannelKind; import org.openhab.core.thing.type.ChannelType; @@ -50,13 +50,13 @@ import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** - * {@link YamlThingFileConverter} is the YAML file converter for {@link Thing} object. + * {@link YamlThingConverter} is the YAML converter for {@link Thing} objects. * * @author Laurent Garnier - Initial contribution */ @NonNullByDefault -@Component(immediate = true, service = { ThingFileGenerator.class, ThingFileParser.class }) -public class YamlThingFileConverter extends AbstractThingFileGenerator implements ThingFileParser { +@Component(immediate = true, service = { ThingSerializer.class, ThingParser.class }) +public class YamlThingConverter extends AbstractThingSerializer implements ThingParser { private final YamlModelRepository modelRepository; private final YamlThingProvider thingProvider; @@ -64,7 +64,7 @@ public class YamlThingFileConverter extends AbstractThingFileGenerator implement private final LocaleProvider localeProvider; @Activate - public YamlThingFileConverter(final @Reference YamlModelRepository modelRepository, + public YamlThingConverter(final @Reference YamlModelRepository modelRepository, final @Reference YamlThingProvider thingProvider, final @Reference YamlChannelLinkProvider itemChannelLinkProvider, final @Reference ThingTypeRegistry thingTypeRegistry, @@ -79,12 +79,12 @@ public class YamlThingFileConverter extends AbstractThingFileGenerator implement } @Override - public String getFileFormatGenerator() { + public String getGeneratedFormat() { return "YAML"; } @Override - public void setThingsToBeGenerated(String id, List things, boolean hideDefaultChannels, + public void setThingsToBeSerialized(String id, List things, boolean hideDefaultChannels, boolean hideDefaultParameters) { List elements = new ArrayList<>(); things.forEach(thing -> { @@ -94,7 +94,7 @@ public class YamlThingFileConverter extends AbstractThingFileGenerator implement } @Override - public void generateFileFormat(String id, OutputStream out) { + public void generateFormat(String id, OutputStream out) { modelRepository.generateFileFormat(id, out); } @@ -165,18 +165,18 @@ public class YamlThingFileConverter extends AbstractThingFileGenerator implement } @Override - public String getFileFormatParser() { + public String getParserFormat() { return "YAML"; } @Override - public @Nullable String startParsingFileFormat(String syntax, List errors, List warnings) { + public @Nullable String startParsingFormat(String syntax, List errors, List warnings) { ByteArrayInputStream inputStream = new ByteArrayInputStream(syntax.getBytes()); return modelRepository.createIsolatedModel(inputStream, errors, warnings); } @Override - public Collection getParsedThings(String modelName) { + public Collection getParsedObjects(String modelName) { return thingProvider.getAllFromModel(modelName); } @@ -186,7 +186,7 @@ public class YamlThingFileConverter extends AbstractThingFileGenerator implement } @Override - public void finishParsingFileFormat(String modelName) { + public void finishParsingFormat(String modelName) { modelRepository.removeIsolatedModel(modelName); } } diff --git a/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/items/fileconverter/YamlItemFileConverterTest.java b/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/items/fileconverter/YamlItemConverterTest.java similarity index 96% rename from bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/items/fileconverter/YamlItemFileConverterTest.java rename to bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/items/fileconverter/YamlItemConverterTest.java index a3d479dba..e02e30db2 100644 --- a/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/items/fileconverter/YamlItemFileConverterTest.java +++ b/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/items/fileconverter/YamlItemConverterTest.java @@ -37,7 +37,7 @@ import org.openhab.core.model.yaml.internal.items.YamlItemProvider; import org.openhab.core.model.yaml.internal.items.YamlMetadataProvider; @NonNullByDefault -public class YamlItemFileConverterTest { +public class YamlItemConverterTest { @Test public void testExpireMetadataConvertedToShortForm() { @@ -100,7 +100,7 @@ public class YamlItemFileConverterTest { private YamlItemDTO convertWithMetadata(Metadata metadata, String itemType) { CapturingYamlModelRepository repository = new CapturingYamlModelRepository(); - YamlItemFileConverter converter = new YamlItemFileConverter(repository, mock(YamlItemProvider.class), + YamlItemConverter converter = new YamlItemConverter(repository, mock(YamlItemProvider.class), mock(YamlMetadataProvider.class), mock(YamlChannelLinkProvider.class), mock(ConfigDescriptionRegistry.class)); @@ -112,7 +112,7 @@ public class YamlItemFileConverterTest { when(item.getGroupNames()).thenReturn(List.of()); when(item.getTags()).thenReturn(Set.of()); - converter.setItemsToBeGenerated("id", List.of(item), List.of(metadata), Map.of(), false); + converter.setItemsToBeSerialized("id", List.of(item), List.of(metadata), Map.of(), false); List elements = repository.getElements(); assertEquals(1, elements.size()); diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/AbstractThingFileGenerator.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/AbstractThingSerializer.java similarity index 96% rename from bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/AbstractThingFileGenerator.java rename to bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/AbstractThingSerializer.java index 522c8d2ce..ea20bc1a1 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/AbstractThingFileGenerator.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/AbstractThingSerializer.java @@ -37,19 +37,19 @@ import org.openhab.core.thing.type.ThingTypeRegistry; import org.osgi.service.component.annotations.Activate; /** - * {@link AbstractThingFileGenerator} is the base class for any {@link Thing} file generator. + * {@link AbstractThingSerializer} is the base class for any {@link Thing} serializer. * * @author Laurent Garnier - Initial contribution */ @NonNullByDefault -public abstract class AbstractThingFileGenerator implements ThingFileGenerator { +public abstract class AbstractThingSerializer implements ThingSerializer { protected final ThingTypeRegistry thingTypeRegistry; protected final ChannelTypeRegistry channelTypeRegistry; protected final ConfigDescriptionRegistry configDescRegistry; @Activate - public AbstractThingFileGenerator(ThingTypeRegistry thingTypeRegistry, ChannelTypeRegistry channelTypeRegistry, + public AbstractThingSerializer(ThingTypeRegistry thingTypeRegistry, ChannelTypeRegistry channelTypeRegistry, ConfigDescriptionRegistry configDescRegistry) { this.thingTypeRegistry = thingTypeRegistry; this.channelTypeRegistry = channelTypeRegistry; diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/ThingFileGenerator.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/ThingFileGenerator.java deleted file mode 100644 index b61e163dc..000000000 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/ThingFileGenerator.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2010-2026 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.thing.fileconverter; - -import java.io.OutputStream; -import java.util.List; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.core.thing.Thing; - -/** - * {@link ThingFileGenerator} is the interface to implement by any file generator for {@link Thing} object. - * - * @author Laurent Garnier - Initial contribution - */ -@NonNullByDefault -public interface ThingFileGenerator { - - /** - * Returns the format of the file. - * - * @return the file format - */ - String getFileFormatGenerator(); - - /** - * Define the list of things to be generated and associate them to an identifier. - * - * @param id the identifier of the file format generation - * @param things the things - * @param hideDefaultChannels true to hide the non extensible channels having a default configuration - * @param hideDefaultParameters true to hide the configuration parameters having the default value - */ - void setThingsToBeGenerated(String id, List things, boolean hideDefaultChannels, - boolean hideDefaultParameters); - - /** - * Generate the file format for all data that were associated to the provided identifier. - * - * @param id the identifier of the file format generation - * @param out the output stream to write to - */ - void generateFileFormat(String id, OutputStream out); -} diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/ThingFileParser.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/ThingFileParser.java deleted file mode 100644 index 2bd5061ba..000000000 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/ThingFileParser.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2010-2026 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.thing.fileconverter; - -import java.util.Collection; -import java.util.List; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.openhab.core.thing.Thing; -import org.openhab.core.thing.link.ItemChannelLink; - -/** - * {@link ThingFileParser} is the interface to implement by any file parser for {@link Thing} object. - * - * @author Laurent Garnier - Initial contribution - */ -@NonNullByDefault -public interface ThingFileParser { - - /** - * Returns the format of the syntax. - * - * @return the syntax format - */ - String getFileFormatParser(); - - /** - * Parse the provided syntax in file format without impacting the thing registry. - * - * @param syntax the syntax in file format - * @param errors the list to be used to fill the errors - * @param warnings the list to be used to fill the warnings - * @return the model name used for parsing if the parsing succeeded without errors; null otherwise - */ - @Nullable - String startParsingFileFormat(String syntax, List errors, List warnings); - - /** - * Get the {@link Thing} objects found when parsing the file format. - * - * @param modelName the model name used for parsing - * @return the collection of things - */ - Collection getParsedThings(String modelName); - - /** - * Get the {@link ItemChannelLink} objects found when parsing the file format. - * - * @param modelName the model name used for parsing - * @return the collection of items channel links - */ - Collection getParsedChannelLinks(String modelName); - - /** - * Release the data from a previously started file format parsing. - * - * @param modelName the model name used for parsing - */ - void finishParsingFileFormat(String modelName); -} diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/ThingParser.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/ThingParser.java new file mode 100644 index 000000000..2cbd1dedc --- /dev/null +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/ThingParser.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2010-2026 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.thing.fileconverter; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.core.converter.ObjectParser; +import org.openhab.core.thing.Thing; +import org.openhab.core.thing.link.ItemChannelLink; + +/** + * {@link ThingParser} is the interface to implement by any {@link Thing} parser. + * + * @author Laurent Garnier - Initial contribution + */ +@NonNullByDefault +public interface ThingParser extends ObjectParser { + + /** + * Parse the provided {@code syntax} string without impacting the thing registry. + * + * @param syntax the syntax in format. + * @param errors the {@link List} to use to report errors. + * @param warnings the {@link List} to be used to report warnings. + * @return The model name used for parsing if the parsing succeeded without errors; {@code null} otherwise. + */ + @Override + @Nullable + String startParsingFormat(String syntax, List errors, List warnings); + + /** + * Get the {@link Thing} objects found when parsing the format. + * + * @param modelName the model name used when parsing. + * @return The {@link Collection} of {@link Thing}s. + */ + @Override + Collection getParsedObjects(String modelName); + + /** + * Get the {@link ItemChannelLink} objects found when parsing the format. + * + * @param modelName the model name used when parsing. + * @return The {@link Collection} of {@link ItemChannelLink}s. + */ + Collection getParsedChannelLinks(String modelName); +} diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/ThingSerializer.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/ThingSerializer.java new file mode 100644 index 000000000..04305023c --- /dev/null +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/fileconverter/ThingSerializer.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010-2026 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.thing.fileconverter; + +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.core.converter.ObjectSerializer; +import org.openhab.core.thing.Thing; + +/** + * {@link ThingSerializer} is the interface to implement by any file generator for {@link Thing} object. + * + * @author Laurent Garnier - Initial contribution + */ +@NonNullByDefault +public interface ThingSerializer extends ObjectSerializer { + + /** + * Specify the {@link List} of {@link Thing}s to serialize and associate them with an identifier. + * + * @param id the identifier of the {@link Thing} format generation. + * @param things the {@link List} of {@link Thing}s to serialize. + * @param hideDefaultChannels {@code true} to hide the non extensible channels having a default configuration. + * @param hideDefaultParameters {@code true} to hide the configuration parameters having a default value. + */ + void setThingsToBeSerialized(String id, List things, boolean hideDefaultChannels, + boolean hideDefaultParameters); +} diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/converter/ObjectParser.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/converter/ObjectParser.java new file mode 100644 index 000000000..ff5a97703 --- /dev/null +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/converter/ObjectParser.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2010-2026 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.converter; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +/** + * A generic interface for parsers that parse strings into specific object types like Things, Items, Rules etc. + * + * @param The object type. + * + * @author Ravi Nadahar - Initial contribution + */ +@NonNullByDefault +public interface ObjectParser { + + /** + * Get the name of the format. + * + * @return The format name. + */ + String getParserFormat(); + + /** + * Parse the provided syntax in format without impacting any object registries. + * + * @param syntax the syntax in format. + * @param errors the {@link List} to use to report errors. + * @param warnings the {@link List} to be used to report warnings. + * @return The model name used for parsing if the parsing succeeded without errors; {@code null} otherwise. + */ + @Nullable + String startParsingFormat(String syntax, List errors, List warnings); + + /** + * Get the objects found when parsing the format. + * + * @param modelName the model name whose objects to get. + * @return The {@link Collection} of objects. + */ + Collection getParsedObjects(String modelName); + + /** + * Release the resources from a previously started format parsing. + * + * @param modelName the model name whose resources to release. + */ + void finishParsingFormat(String modelName); +} diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/converter/ObjectSerializer.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/converter/ObjectSerializer.java new file mode 100644 index 000000000..2113a643f --- /dev/null +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/converter/ObjectSerializer.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2010-2026 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.converter; + +import java.io.OutputStream; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * A generic interface for serializers that serialize specific object types like Things, Items, Rules etc. into a + * serialized representation that is written to an {@link OutputStream}. + * + * @param The object type. + * + * @author Ravi Nadahar - Initial contribution + */ +@NonNullByDefault +public interface ObjectSerializer { + + /** + * Get the name of the format. + * + * @return The format name. + */ + String getGeneratedFormat(); + + /** + * Generate the format for all data that were associated to the provided identifier. + * + * @param id the identifier of the format generation. + * @param out The {@link OutputStream} to write to. + */ + void generateFormat(String id, OutputStream out); +} diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/AbstractItemFileGenerator.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/AbstractItemSerializer.java similarity index 96% rename from bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/AbstractItemFileGenerator.java rename to bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/AbstractItemSerializer.java index 2c700ec46..3fd2c6903 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/AbstractItemFileGenerator.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/AbstractItemSerializer.java @@ -26,14 +26,14 @@ import org.openhab.core.items.Metadata; import org.openhab.core.library.CoreItemFactory; /** - * {@link AbstractItemFileGenerator} is the base class for any {@link Item} file generator. + * {@link AbstractItemSerializer} is the base class for any {@link Item} serializer. * * @author Laurent Garnier - Initial contribution */ @NonNullByDefault -public abstract class AbstractItemFileGenerator implements ItemFileGenerator { +public abstract class AbstractItemSerializer implements ItemSerializer { - public AbstractItemFileGenerator() { + public AbstractItemSerializer() { } /** diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/ItemFileGenerator.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/ItemFileGenerator.java deleted file mode 100644 index 850e31956..000000000 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/ItemFileGenerator.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2010-2026 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.items.fileconverter; - -import java.io.OutputStream; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.core.items.Item; -import org.openhab.core.items.Metadata; - -/** - * {@link ItemFileGenerator} is the interface to implement by any file generator for {@link Item} object. - * - * @author Laurent Garnier - Initial contribution - */ -@NonNullByDefault -public interface ItemFileGenerator { - - /** - * Returns the format of the file. - * - * @return the file format - */ - String getFileFormatGenerator(); - - /** - * Define the list of items (including metadata and channel links) to be generated and associate them - * to an identifier. - * - * @param id the identifier of the file format generation - * @param items the items - * @param metadata the provided collection of metadata for these items (including channel links) - * @param stateFormatters the optional state formatter for each item - * @param hideDefaultParameters true to hide the configuration parameters having the default value - */ - void setItemsToBeGenerated(String id, List items, Collection metadata, - Map stateFormatters, boolean hideDefaultParameters); - - /** - * Generate the file format for all data that were associated to the provided identifier. - * - * @param id the identifier of the file format generation - * @param out the output stream to write to - */ - void generateFileFormat(String id, OutputStream out); -} diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/ItemFileParser.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/ItemFileParser.java deleted file mode 100644 index ad09d0513..000000000 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/ItemFileParser.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2010-2026 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.items.fileconverter; - -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.openhab.core.items.Item; -import org.openhab.core.items.Metadata; - -/** - * {@link ItemFileParser} is the interface to implement by any file parser for {@link Item} object. - * - * @author Laurent Garnier - Initial contribution - */ -@NonNullByDefault -public interface ItemFileParser { - - /** - * Returns the format of the syntax. - * - * @return the syntax format - */ - String getFileFormatParser(); - - /** - * Parse the provided syntax in file format without impacting the item and metadata registries. - * - * @param syntax the syntax in file format - * @param errors the list to be used to fill the errors - * @param warnings the list to be used to fill the warnings - * @return the model name used for parsing if the parsing succeeded without errors; null otherwise - */ - @Nullable - String startParsingFileFormat(String syntax, List errors, List warnings); - - /** - * Get the {@link Item} objects found when parsing the file format. - * - * @param modelName the model name used for parsing - * @return the collection of items - */ - Collection getParsedItems(String modelName); - - /** - * Get the {@link Metadata} objects found when parsing the file format. - * - * @param modelName the model name used for parsing - * @return the collection of metadata - */ - Collection getParsedMetadata(String modelName); - - /** - * Get the state formatters found when parsing the file format. - * - * @param modelName the model name used for parsing - * @return the state formatters as a Map per item name - */ - Map getParsedStateFormatters(String modelName); - - /** - * Release the data from a previously started file format parsing. - * - * @param modelName the model name used for parsing - */ - void finishParsingFileFormat(String modelName); -} diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/ItemParser.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/ItemParser.java new file mode 100644 index 000000000..0dd0f2e4c --- /dev/null +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/ItemParser.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2010-2026 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.items.fileconverter; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.core.converter.ObjectParser; +import org.openhab.core.items.Item; +import org.openhab.core.items.Metadata; + +/** + * {@link ItemParser} is the interface to implement by any file parser for {@link Item} object. + * + * @author Laurent Garnier - Initial contribution + */ +@NonNullByDefault +public interface ItemParser extends ObjectParser { + + /** + * Parse the provided {@code syntax} string without impacting the item and metadata registries. + * + * @param syntax the syntax in format. + * @param errors the {@link List} to use to report errors. + * @param warnings the {@link List} to be used to report warnings. + * @return The model name used for parsing if the parsing succeeded without errors; {@code null} otherwise. + */ + @Override + @Nullable + String startParsingFormat(String syntax, List errors, List warnings); + + /** + * Get the {@link Item} objects found when parsing the format. + * + * @param modelName the model name used when parsing. + * @return The {@link Collection} of {@link Item}s. + */ + @Override + Collection getParsedObjects(String modelName); + + /** + * Get the {@link Metadata} objects found when parsing the format. + * + * @param modelName the model name used when parsing. + * @return The {@link Collection} of {@link Metadata}. + */ + Collection getParsedMetadata(String modelName); + + /** + * Get the state formatters found when parsing the format. + * + * @param modelName the model name used when parsing. + * @return the state formatters as a {@link Map} per item name. + */ + Map getParsedStateFormatters(String modelName); +} diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/ItemSerializer.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/ItemSerializer.java new file mode 100644 index 000000000..3284b94d1 --- /dev/null +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/fileconverter/ItemSerializer.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2010-2026 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.items.fileconverter; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.core.converter.ObjectSerializer; +import org.openhab.core.items.Item; +import org.openhab.core.items.Metadata; + +/** + * {@link ItemSerializer} is the interface to implement by any file generator for {@link Item} object. + * + * @author Laurent Garnier - Initial contribution + */ +@NonNullByDefault +public interface ItemSerializer extends ObjectSerializer { + + /** + * Specify the {@link List} of {@link Item}s (including {@link Metadata} and channel links) to be serialized and + * associate them with an identifier. + * + * @param id the identifier of the {@link Item} format generation. + * @param items the {@link List} of {@link Item}s to serialize. + * @param metadata the provided {@link Collection} of {@link Metadata} for the {@link Item}s (including channel + * links). + * @param stateFormatters a {@link Map} of {@link Item} name and state formatter for each {@link Item}. Callers + * should pass an empty map if no state formatters are provided. + * @param hideDefaultParameters {@code true} to hide the configuration parameters having a default value. + */ + void setItemsToBeSerialized(String id, List items, Collection metadata, + Map stateFormatters, boolean hideDefaultParameters); +}