blob: 9de9277818e9e2db2d38bcee31cc2b0de677baaf [file] [log] [blame]
Jian Li3bc6ef12017-05-04 21:51:41 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Li3bc6ef12017-05-04 21:51:41 +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.onosproject.ui.UiExtension;
25import org.onosproject.ui.UiExtensionService;
26import org.onosproject.ui.UiMessageHandlerFactory;
27import org.onosproject.ui.UiTopoOverlayFactory;
28import org.onosproject.ui.UiView;
29import org.onosproject.ui.UiViewHidden;
30import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
33import java.util.List;
34
35/**
36 * Mechanism to stream data to the topology UI.
37 */
38@Component(immediate = true)
39public class MappingsTopoUI {
40
41 private static final String MAPPING_TOPO_ID = "mappingTopo";
42 private static final String RES_PATH = "gui";
43 private static final ClassLoader CL = MappingsTopoUI.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(
53 new MappingsTopoMessageHandler()
54 );
55
56 // Factory for UI topology overlays
57 private final UiTopoOverlayFactory topoOverlayFactory =
58 () -> ImmutableList.of(
59 new MappingsTopoOverlay()
60 );
61
62 // List of application views
63 private final List<UiView> views = ImmutableList.of(
64 new UiViewHidden(MAPPING_TOPO_ID)
65 );
66
67 // Application UI extension
68 private final UiExtension uiExtension =
69 new UiExtension.Builder(CL, views)
70 .topoOverlayFactory(topoOverlayFactory)
71 .messageHandlerFactory(messageHandlerFactory)
72 .resourcePath(RES_PATH)
73 .build();
74
75 @Activate
76 protected void activate() {
77 uiExtensionService.register(uiExtension);
78 log.info("Started");
79 }
80
81 @Deactivate
82 protected void deactivate() {
83 uiExtensionService.unregister(uiExtension);
84 log.info("Stopped");
85 }
86}