blob: 78b902b4b531dee7649068316ecff5ca5501c15d [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
18import org.onosproject.core.Permission;
19import org.onosproject.core.Version;
20
21import java.net.URI;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080022import java.util.List;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080023import java.util.Optional;
24import java.util.Set;
25
26import static com.google.common.base.MoreObjects.toStringHelper;
27import static com.google.common.base.Preconditions.checkArgument;
28import static com.google.common.base.Preconditions.checkNotNull;
29
30/**
31 * Default implementation of network control/management application descriptor.
32 */
33public class DefaultApplicationDescription implements ApplicationDescription {
34
35 private final String name;
36 private final Version version;
37 private final String description;
38 private final String origin;
39 private final Set<Permission> permissions;
40 private final Optional<URI> featuresRepo;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080041 private final List<String> features;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080042
43 /**
44 * Creates a new application descriptor using the supplied data.
45 *
46 * @param name application name
47 * @param version application version
48 * @param description application description
49 * @param origin origin company
50 * @param permissions requested permissions
51 * @param featuresRepo optional features repo URI
52 * @param features application features
53 */
54 public DefaultApplicationDescription(String name, Version version,
55 String description, String origin,
56 Set<Permission> permissions,
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080057 URI featuresRepo, List<String> features) {
Thomas Vachuska02aeb032015-01-06 22:36:30 -080058 this.name = checkNotNull(name, "Name cannot be null");
59 this.version = checkNotNull(version, "Version cannot be null");
60 this.description = checkNotNull(description, "Description cannot be null");
61 this.origin = checkNotNull(origin, "Origin cannot be null");
62 this.permissions = checkNotNull(permissions, "Permissions cannot be null");
63 this.featuresRepo = Optional.ofNullable(featuresRepo);
64 this.features = checkNotNull(features, "Features cannot be null");
65 checkArgument(!features.isEmpty(), "There must be at least one feature");
66 }
67
68 @Override
69 public String name() {
70 return name;
71 }
72
73 @Override
74 public Version version() {
75 return version;
76 }
77
78 @Override
79 public String description() {
80 return description;
81 }
82
83 @Override
84 public String origin() {
85 return origin;
86 }
87
88 @Override
89 public Set<Permission> permissions() {
90 return permissions;
91 }
92
93 @Override
94 public Optional<URI> featuresRepo() {
95 return featuresRepo;
96 }
97
98 @Override
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080099 public List<String> features() {
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800100 return features;
101 }
102
103 @Override
104 public String toString() {
105 return toStringHelper(this)
106 .add("name", name)
107 .add("version", version)
108 .add("description", description)
109 .add("origin", origin)
110 .add("permissions", permissions)
111 .add("featuresRepo", featuresRepo)
112 .add("features", features)
113 .toString();
114 }
115}