blob: 09a154dfa4914f44e0f2343c565240dd502e9ca6 [file] [log] [blame]
Simon Huntbc30e682017-02-15 18:39:23 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Simon Huntbc30e682017-02-15 18:39:23 -08003 *
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 */
16
17package org.onosproject.net.device.impl;
18
19import org.onosproject.net.AnnotationKeys;
20import org.onosproject.net.DefaultAnnotations;
21import org.onosproject.net.config.ConfigOperator;
22import org.onosproject.net.config.basics.BasicElementConfig;
23
24/**
25 * Abstract base implementation for element operators.
26 */
27public abstract class BasicElementOperator implements ConfigOperator {
28
29 /**
30 * Sets all defined values from the element config on the supplied
31 * annotations builder.
32 *
33 * @param cfg element configuration
34 * @param builder annotations builder
35 */
36 protected static void combineElementAnnotations(BasicElementConfig cfg,
37 DefaultAnnotations.Builder builder) {
38
39 if (cfg.name() != null) {
40 builder.set(AnnotationKeys.NAME, cfg.name());
41 }
42 if (cfg.uiType() != null) {
43 builder.set(AnnotationKeys.UI_TYPE, cfg.uiType());
44 }
45
46 if (cfg.locType() != null) {
47 builder.set(AnnotationKeys.LOC_TYPE, cfg.locType());
48 }
49 if (cfg.geoCoordsSet()) {
50 builder.set(AnnotationKeys.LATITUDE, Double.toString(cfg.latitude()));
51 builder.set(AnnotationKeys.LONGITUDE, Double.toString(cfg.longitude()));
52 } else if (cfg.gridCoordsSet()) {
53 builder.set(AnnotationKeys.GRID_Y, Double.toString(cfg.gridY()));
54 builder.set(AnnotationKeys.GRID_X, Double.toString(cfg.gridX()));
55 }
56
57 if (cfg.rackAddress() != null) {
58 builder.set(AnnotationKeys.RACK_ADDRESS, cfg.rackAddress());
59 }
60 if (cfg.owner() != null) {
61 builder.set(AnnotationKeys.OWNER, cfg.owner());
62 }
63 }
64}