]> git.basschouten.com Git - openhab-addons.git/blob
1df59cdfa5a5c8741723040715ce081cb5769ac6
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.transform.jsonpath.internal.profiles;
14
15 import java.util.Arrays;
16 import java.util.Collection;
17 import java.util.Locale;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.core.thing.profiles.Profile;
22 import org.openhab.core.thing.profiles.ProfileCallback;
23 import org.openhab.core.thing.profiles.ProfileContext;
24 import org.openhab.core.thing.profiles.ProfileFactory;
25 import org.openhab.core.thing.profiles.ProfileType;
26 import org.openhab.core.thing.profiles.ProfileTypeBuilder;
27 import org.openhab.core.thing.profiles.ProfileTypeProvider;
28 import org.openhab.core.thing.profiles.ProfileTypeUID;
29 import org.openhab.core.transform.TransformationService;
30 import org.osgi.service.component.annotations.Component;
31 import org.osgi.service.component.annotations.Reference;
32
33 /**
34  * Profilefactory that creates the transformation profile for the jsonpath transformation service
35  *
36  * @author Stefan Triller - initial contribution
37  *
38  */
39 @NonNullByDefault
40 @Component(service = { ProfileFactory.class, ProfileTypeProvider.class })
41 public class JSonPathTransformationProfileFactory implements ProfileFactory, ProfileTypeProvider {
42
43     @NonNullByDefault({})
44     private TransformationService service;
45
46     @Override
47     public Collection<ProfileType> getProfileTypes(@Nullable Locale locale) {
48         return Arrays.asList(ProfileTypeBuilder.newState(JSonPathTransformationProfile.PROFILE_TYPE_UID,
49                 JSonPathTransformationProfile.PROFILE_TYPE_UID.getId()).build());
50     }
51
52     @Override
53     public @Nullable Profile createProfile(ProfileTypeUID profileTypeUID, ProfileCallback callback,
54             ProfileContext profileContext) {
55         return new JSonPathTransformationProfile(callback, profileContext, service);
56     }
57
58     @Override
59     public Collection<ProfileTypeUID> getSupportedProfileTypeUIDs() {
60         return Arrays.asList(JSonPathTransformationProfile.PROFILE_TYPE_UID);
61     }
62
63     @Reference(target = "(openhab.transform=JSONPATH)")
64     public void addTransformationService(TransformationService service) {
65         this.service = service;
66     }
67
68     public void removeTransformationService(TransformationService service) {
69         this.service = null;
70     }
71 }