|
1 | 1 | /*
|
2 | 2 | * Copyright 2017, OpenRemote Inc.
|
3 | 3 | *
|
4 |
| - * See the CONTRIBUTORS.txt file in the distribution for a |
5 |
| - * full listing of individual contributors. |
6 |
| - * |
7 | 4 | * This program is free software: you can redistribute it and/or modify
|
8 | 5 | * it under the terms of the GNU Affero General Public License as
|
9 | 6 | * published by the Free Software Foundation, either version 3 of the
|
|
15 | 12 | * GNU Affero General Public License for more details.
|
16 | 13 | *
|
17 | 14 | * You should have received a copy of the GNU Affero General Public License
|
18 |
| - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + * |
| 17 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
19 | 18 | */
|
20 | 19 | package org.openremote.agent.custom;
|
21 | 20 |
|
| 21 | +import java.util.Optional; |
| 22 | + |
22 | 23 | import org.openremote.model.asset.Asset;
|
23 | 24 | import org.openremote.model.asset.agent.Agent;
|
24 | 25 | import org.openremote.model.asset.agent.AgentDescriptor;
|
|
27 | 28 | import org.openremote.model.value.ValueDescriptor;
|
28 | 29 |
|
29 | 30 | import jakarta.persistence.Entity;
|
30 |
| -import java.util.Optional; |
31 | 31 |
|
32 | 32 | /**
|
33 |
| - * This is an example of a custom {@link Agent} type; this must be registered via an |
34 |
| - * {@link org.openremote.model.AssetModelProvider} and must conform to the same requirements as custom {@link Asset}s and |
35 |
| - * in addition the following requirements: |
| 33 | + * This is an example of a custom {@link Agent} type; this must be registered via an {@link |
| 34 | + * org.openremote.model.AssetModelProvider} and must conform to the same requirements as custom |
| 35 | + * {@link Asset}s and in addition the following requirements: |
36 | 36 | *
|
37 | 37 | * <ul>
|
38 |
| - * <li>Optionally add a custom {@link org.openremote.model.asset.agent.AgentLink} (the {@link Class#getSimpleName} must |
39 |
| - * be unique compared to all other registered {@link org.openremote.model.asset.agent.AgentLink}s) |
40 |
| - * <li>Must define a {@link org.openremote.model.asset.agent.Protocol} implementation that corresponds to this {@link Agent} |
41 |
| - * <li>Must have a public static final {@link org.openremote.model.asset.agent.AgentDescriptor} rather than an |
42 |
| - * {@link org.openremote.model.asset.AssetDescriptor} |
| 38 | + * <li>Optionally add a custom {@link org.openremote.model.asset.agent.AgentLink} (the {@link |
| 39 | + * Class#getSimpleName} must be unique compared to all other registered {@link |
| 40 | + * org.openremote.model.asset.agent.AgentLink}s) |
| 41 | + * <li>Must define a {@link org.openremote.model.asset.agent.Protocol} implementation that |
| 42 | + * corresponds to this {@link Agent} |
| 43 | + * <li>Must have a public static final {@link org.openremote.model.asset.agent.AgentDescriptor} |
| 44 | + * rather than an {@link org.openremote.model.asset.AssetDescriptor} |
43 | 45 | * </ul>
|
44 | 46 | */
|
45 | 47 | @Entity
|
46 | 48 | public class CustomAgent extends Agent<CustomAgent, CustomProtocol, DefaultAgentLink> {
|
47 | 49 |
|
48 |
| - public enum Option { |
49 |
| - ONE, |
50 |
| - TWO, |
51 |
| - THREE |
52 |
| - }; |
| 50 | + public enum Option { |
| 51 | + ONE, |
| 52 | + TWO, |
| 53 | + THREE |
| 54 | + }; |
53 | 55 |
|
54 |
| - public static final ValueDescriptor<Option> OPTION_VALUE_DESCRIPTOR = new ValueDescriptor<>("customAgentOption", Option.class); |
| 56 | + public static final ValueDescriptor<Option> OPTION_VALUE_DESCRIPTOR = |
| 57 | + new ValueDescriptor<>("customAgentOption", Option.class); |
55 | 58 |
|
56 |
| - public static final AttributeDescriptor<Option> OPTION_ATTRIBUTE_DESCRIPTOR = new AttributeDescriptor<>("option", OPTION_VALUE_DESCRIPTOR); |
| 59 | + public static final AttributeDescriptor<Option> OPTION_ATTRIBUTE_DESCRIPTOR = |
| 60 | + new AttributeDescriptor<>("option", OPTION_VALUE_DESCRIPTOR); |
57 | 61 |
|
58 |
| - public static final AgentDescriptor<CustomAgent, CustomProtocol, DefaultAgentLink> DESCRIPTOR = new AgentDescriptor<>( |
59 |
| - CustomAgent.class, CustomProtocol.class, DefaultAgentLink.class |
60 |
| - ); |
| 62 | + public static final AgentDescriptor<CustomAgent, CustomProtocol, DefaultAgentLink> DESCRIPTOR = |
| 63 | + new AgentDescriptor<>(CustomAgent.class, CustomProtocol.class, DefaultAgentLink.class); |
61 | 64 |
|
62 |
| - protected CustomAgent() { |
63 |
| - } |
| 65 | + protected CustomAgent() {} |
64 | 66 |
|
65 |
| - public CustomAgent(String name) { |
66 |
| - super(name); |
67 |
| - } |
| 67 | + public CustomAgent(String name) { |
| 68 | + super(name); |
| 69 | + } |
68 | 70 |
|
69 |
| - @Override |
70 |
| - public CustomProtocol getProtocolInstance() { |
71 |
| - return new CustomProtocol(this); |
72 |
| - } |
| 71 | + @Override |
| 72 | + public CustomProtocol getProtocolInstance() { |
| 73 | + return new CustomProtocol(this); |
| 74 | + } |
73 | 75 |
|
74 |
| - public Optional<Option> getOption() { |
75 |
| - return getAttributes().getValue(OPTION_ATTRIBUTE_DESCRIPTOR); |
76 |
| - } |
| 76 | + public Optional<Option> getOption() { |
| 77 | + return getAttributes().getValue(OPTION_ATTRIBUTE_DESCRIPTOR); |
| 78 | + } |
77 | 79 |
|
78 |
| - public CustomAgent setOption(Option value) { |
79 |
| - getAttributes().getOrCreate(OPTION_ATTRIBUTE_DESCRIPTOR).setValue(value); |
80 |
| - return this; |
81 |
| - } |
| 80 | + public CustomAgent setOption(Option value) { |
| 81 | + getAttributes().getOrCreate(OPTION_ATTRIBUTE_DESCRIPTOR).setValue(value); |
| 82 | + return this; |
| 83 | + } |
82 | 84 | }
|
83 |
| - |
|
0 commit comments