blob: 9f87004b6e5f538c8f5ef464fbce9081b7e97171 [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;
19import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
24import org.apache.felix.scr.annotations.Service;
25import org.onosproject.ui.UiExtension;
26import org.onosproject.ui.UiExtensionService;
27import org.onosproject.ui.UiMessageHandlerFactory;
28import org.onosproject.ui.UiView;
Jian Li3bc6ef12017-05-04 21:51:41 +090029import org.onosproject.ui.UiViewHidden;
Jian Lia23f46d2017-05-02 18:07:31 +090030import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
33import java.util.List;
34
Jian Lia23f46d2017-05-02 18:07:31 +090035/**
36 * Mechanism to stream data to the GUI.
37 */
38@Component(immediate = true, enabled = true)
39@Service(value = MappingsUI.class)
40public class MappingsUI {
41 private static final String MAPPING_ID = "mapping";
Jian Lia23f46d2017-05-02 18:07:31 +090042 private static final String RES_PATH = "gui";
43 private static final ClassLoader CL = MappingsUI.class.getClassLoader();
44
45 private final Logger log = LoggerFactory.getLogger(getClass());
46
47 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
48 protected UiExtensionService uiExtensionService;
49
50 // Factory for UI message handlers
51 private final UiMessageHandlerFactory messageHandlerFactory =
52 () -> ImmutableList.of(new MappingsViewMessageHandler());
53
54 // List of application views
55 private final List<UiView> views = ImmutableList.of(
Jian Li3bc6ef12017-05-04 21:51:41 +090056 new UiViewHidden(MAPPING_ID)
Jian Lia23f46d2017-05-02 18:07:31 +090057 );
58
59 // Application UI extension
60 private final UiExtension uiExtension =
61 new UiExtension.Builder(CL, views)
62 .messageHandlerFactory(messageHandlerFactory)
63 .resourcePath(RES_PATH)
64 .build();
65
66 @Activate
67 protected void activate() {
68 uiExtensionService.register(uiExtension);
69 log.info("Started");
70 }
71
72 @Deactivate
73 protected void deactivate() {
74 uiExtensionService.unregister(uiExtension);
75 log.info("Stopped");
76 }
77}