blob: d24bace38ce7fb88669f2b54efb1a22ead26761c [file] [log] [blame]
Thomas Vachuska02aeb032015-01-06 22:36:30 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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.app;
17
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090018import org.onosproject.core.ApplicationRole;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080019import org.onosproject.core.Permission;
20import org.onosproject.core.Version;
21
22import java.net.URI;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080023import java.util.List;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080024import java.util.Optional;
25import java.util.Set;
26
27import static com.google.common.base.MoreObjects.toStringHelper;
28import static com.google.common.base.Preconditions.checkArgument;
29import static com.google.common.base.Preconditions.checkNotNull;
30
31/**
32 * Default implementation of network control/management application descriptor.
33 */
34public class DefaultApplicationDescription implements ApplicationDescription {
35
36 private final String name;
37 private final Version version;
38 private final String description;
39 private final String origin;
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090040 private final ApplicationRole role;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080041 private final Set<Permission> permissions;
42 private final Optional<URI> featuresRepo;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080043 private final List<String> features;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080044
45 /**
46 * Creates a new application descriptor using the supplied data.
47 *
48 * @param name application name
49 * @param version application version
50 * @param description application description
51 * @param origin origin company
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090052 * @param role application role
Thomas Vachuska02aeb032015-01-06 22:36:30 -080053 * @param permissions requested permissions
54 * @param featuresRepo optional features repo URI
55 * @param features application features
56 */
57 public DefaultApplicationDescription(String name, Version version,
58 String description, String origin,
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090059 ApplicationRole role, Set<Permission> permissions,
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080060 URI featuresRepo, List<String> features) {
Thomas Vachuska02aeb032015-01-06 22:36:30 -080061 this.name = checkNotNull(name, "Name cannot be null");
62 this.version = checkNotNull(version, "Version cannot be null");
63 this.description = checkNotNull(description, "Description cannot be null");
64 this.origin = checkNotNull(origin, "Origin cannot be null");
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090065 this.role = checkNotNull(role, "Role cannot be null");
Thomas Vachuska02aeb032015-01-06 22:36:30 -080066 this.permissions = checkNotNull(permissions, "Permissions cannot be null");
67 this.featuresRepo = Optional.ofNullable(featuresRepo);
68 this.features = checkNotNull(features, "Features cannot be null");
69 checkArgument(!features.isEmpty(), "There must be at least one feature");
70 }
71
72 @Override
73 public String name() {
74 return name;
75 }
76
77 @Override
78 public Version version() {
79 return version;
80 }
81
82 @Override
83 public String description() {
84 return description;
85 }
86
87 @Override
88 public String origin() {
89 return origin;
90 }
91
92 @Override
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +090093 public ApplicationRole role() {
94 return role;
95 }
96
97 @Override
Thomas Vachuska02aeb032015-01-06 22:36:30 -080098 public Set<Permission> permissions() {
99 return permissions;
100 }
101
102 @Override
103 public Optional<URI> featuresRepo() {
104 return featuresRepo;
105 }
106
107 @Override
Thomas Vachuskaebf5e542015-02-03 19:38:13 -0800108 public List<String> features() {
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800109 return features;
110 }
111
112 @Override
113 public String toString() {
114 return toStringHelper(this)
115 .add("name", name)
116 .add("version", version)
117 .add("description", description)
118 .add("origin", origin)
Changhoon Yoonbdeb88a2015-05-12 20:35:31 +0900119 .add("role", role)
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800120 .add("permissions", permissions)
121 .add("featuresRepo", featuresRepo)
122 .add("features", features)
123 .toString();
124 }
125}