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