blob: 2b059881e00f639e373a8a54200788dbe04a6791 [file] [log] [blame]
Jian Lia23f46d2017-05-02 18:07:31 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Lia23f46d2017-05-02 18:07:31 +09003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.mapping.web.gui;
17
18import com.google.common.collect.ImmutableList;
Jian Lia23f46d2017-05-02 18:07:31 +090019import org.onosproject.ui.UiExtension;
20import org.onosproject.ui.UiExtensionService;
21import org.onosproject.ui.UiMessageHandlerFactory;
22import org.onosproject.ui.UiView;
Jian Li3bc6ef12017-05-04 21:51:41 +090023import org.onosproject.ui.UiViewHidden;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070024import org.osgi.service.component.annotations.Activate;
25import org.osgi.service.component.annotations.Component;
26import org.osgi.service.component.annotations.Deactivate;
27import org.osgi.service.component.annotations.Reference;
28import org.osgi.service.component.annotations.ReferenceCardinality;
Jian Lia23f46d2017-05-02 18:07:31 +090029import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
32import java.util.List;
33
Jian Lia23f46d2017-05-02 18:07:31 +090034/**
35 * Mechanism to stream data to the GUI.
36 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070037@Component(immediate = true, service = MappingsUI.class)
Jian Lia23f46d2017-05-02 18:07:31 +090038public class MappingsUI {
39 private static final String MAPPING_ID = "mapping";
Jian Lia23f46d2017-05-02 18:07:31 +090040 private static final String RES_PATH = "gui";
41 private static final ClassLoader CL = MappingsUI.class.getClassLoader();
42
43 private final Logger log = LoggerFactory.getLogger(getClass());
44
Ray Milkeyd84f89b2018-08-17 14:54:17 -070045 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jian Lia23f46d2017-05-02 18:07:31 +090046 protected UiExtensionService uiExtensionService;
47
48 // Factory for UI message handlers
49 private final UiMessageHandlerFactory messageHandlerFactory =
50 () -> ImmutableList.of(new MappingsViewMessageHandler());
51
52 // List of application views
53 private final List<UiView> views = ImmutableList.of(
Jian Li3bc6ef12017-05-04 21:51:41 +090054 new UiViewHidden(MAPPING_ID)
Jian Lia23f46d2017-05-02 18:07:31 +090055 );
56
57 // Application UI extension
58 private final UiExtension uiExtension =
59 new UiExtension.Builder(CL, views)
60 .messageHandlerFactory(messageHandlerFactory)
61 .resourcePath(RES_PATH)
62 .build();
63
64 @Activate
65 protected void activate() {
66 uiExtensionService.register(uiExtension);
67 log.info("Started");
68 }
69
70 @Deactivate
71 protected void deactivate() {
72 uiExtensionService.unregister(uiExtension);
73 log.info("Stopped");
74 }
75}