org.eclipse.ditto.wot.model.ThingModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ditto-wot-model Show documentation
Show all versions of ditto-wot-model Show documentation
Eclipse Ditto is a framework for creating and managing digital twins in the IoT.
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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.eclipse.ditto.wot.model;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.eclipse.ditto.json.JsonArray;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonFieldDefinition;
import org.eclipse.ditto.json.JsonObject;
/**
* The Thing Model can be used to mainly provide the data model definitions within Things' {@link Properties},
* {@link Actions}, and/or {@link Events} and can be potentially used as template for creating
* {@link ThingDescription} instances
*
* @see WoT TD Thing Model
* @since 2.4.0
*/
public interface ThingModel extends ThingSkeleton {
static ThingModel fromJson(final JsonObject jsonObject) {
return new ImmutableThingModel(jsonObject);
}
static ThingModel.Builder newBuilder() {
return ThingModel.Builder.newBuilder();
}
static ThingModel.Builder newBuilder(final JsonObject jsonObject) {
return ThingModel.Builder.newBuilder(jsonObject);
}
Optional getTmOptional();
@Override
default ThingModel.Builder toBuilder() {
return ThingModel.Builder.newBuilder(toJson());
}
interface Builder extends ThingSkeletonBuilder {
static Builder newBuilder() {
return new MutableThingModelBuilder(JsonObject.newBuilder());
}
static Builder newBuilder(final JsonObject jsonObject) {
return new MutableThingModelBuilder(jsonObject.toBuilder());
}
Builder setTmOptional(@Nullable TmOptional tmOptional);
}
/**
* An enumeration of the known {@link JsonFieldDefinition}s of a ThingModel.
*/
@Immutable
final class JsonFields {
public static final JsonFieldDefinition TM_OPTIONAL = JsonFactory.newJsonArrayFieldDefinition(
"tm:optional");
private JsonFields() {
throw new AssertionError();
}
}
}