Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.app; |
| 17 | |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 18 | import org.onosproject.core.ApplicationRole; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 19 | import org.onosproject.core.Permission; |
| 20 | import org.onosproject.core.Version; |
| 21 | |
| 22 | import java.net.URI; |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 23 | import java.util.List; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 24 | import java.util.Optional; |
| 25 | import java.util.Set; |
| 26 | |
| 27 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 28 | import static com.google.common.base.Preconditions.checkArgument; |
| 29 | import static com.google.common.base.Preconditions.checkNotNull; |
| 30 | |
| 31 | /** |
| 32 | * Default implementation of network control/management application descriptor. |
| 33 | */ |
| 34 | public 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 Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 40 | private final ApplicationRole role; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 41 | private final Set<Permission> permissions; |
| 42 | private final Optional<URI> featuresRepo; |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 43 | private final List<String> features; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 44 | |
| 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 Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 52 | * @param role application role |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 53 | * @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 Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 59 | ApplicationRole role, Set<Permission> permissions, |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 60 | URI featuresRepo, List<String> features) { |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 61 | 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 Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 65 | this.role = checkNotNull(role, "Role cannot be null"); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 66 | 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 Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 93 | public ApplicationRole role() { |
| 94 | return role; |
| 95 | } |
| 96 | |
| 97 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 98 | public Set<Permission> permissions() { |
| 99 | return permissions; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public Optional<URI> featuresRepo() { |
| 104 | return featuresRepo; |
| 105 | } |
| 106 | |
| 107 | @Override |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 108 | public List<String> features() { |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 109 | 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 Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 119 | .add("role", role) |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 120 | .add("permissions", permissions) |
| 121 | .add("featuresRepo", featuresRepo) |
| 122 | .add("features", features) |
| 123 | .toString(); |
| 124 | } |
| 125 | } |