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.Version; |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 20 | import org.onosproject.security.Permission; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 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 | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 44 | private final List<String> requiredApps; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Creates a new application descriptor using the supplied data. |
| 48 | * |
| 49 | * @param name application name |
| 50 | * @param version application version |
| 51 | * @param description application description |
| 52 | * @param origin origin company |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 53 | * @param role application role |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 54 | * @param permissions requested permissions |
| 55 | * @param featuresRepo optional features repo URI |
| 56 | * @param features application features |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 57 | * @param requiredApps list of required application names |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 58 | */ |
| 59 | public DefaultApplicationDescription(String name, Version version, |
| 60 | String description, String origin, |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 61 | ApplicationRole role, Set<Permission> permissions, |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 62 | URI featuresRepo, List<String> features, |
| 63 | List<String> requiredApps) { |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 64 | this.name = checkNotNull(name, "Name cannot be null"); |
| 65 | this.version = checkNotNull(version, "Version cannot be null"); |
| 66 | this.description = checkNotNull(description, "Description cannot be null"); |
| 67 | this.origin = checkNotNull(origin, "Origin cannot be null"); |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 68 | this.role = checkNotNull(role, "Role cannot be null"); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 69 | this.permissions = checkNotNull(permissions, "Permissions cannot be null"); |
| 70 | this.featuresRepo = Optional.ofNullable(featuresRepo); |
| 71 | this.features = checkNotNull(features, "Features cannot be null"); |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 72 | this.requiredApps = checkNotNull(requiredApps, "Required apps cannot be null"); |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 73 | checkArgument(!features.isEmpty(), "There must be at least one feature"); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public String name() { |
| 78 | return name; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public Version version() { |
| 83 | return version; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public String description() { |
| 88 | return description; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public String origin() { |
| 93 | return origin; |
| 94 | } |
| 95 | |
| 96 | @Override |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 97 | public ApplicationRole role() { |
| 98 | return role; |
| 99 | } |
| 100 | |
| 101 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 102 | public Set<Permission> permissions() { |
| 103 | return permissions; |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public Optional<URI> featuresRepo() { |
| 108 | return featuresRepo; |
| 109 | } |
| 110 | |
| 111 | @Override |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 112 | public List<String> features() { |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 113 | return features; |
| 114 | } |
| 115 | |
| 116 | @Override |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 117 | public List<String> requiredApps() { |
| 118 | return requiredApps; |
| 119 | } |
| 120 | |
| 121 | @Override |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 122 | public String toString() { |
| 123 | return toStringHelper(this) |
| 124 | .add("name", name) |
| 125 | .add("version", version) |
| 126 | .add("description", description) |
| 127 | .add("origin", origin) |
Changhoon Yoon | bdeb88a | 2015-05-12 20:35:31 +0900 | [diff] [blame] | 128 | .add("role", role) |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 129 | .add("permissions", permissions) |
| 130 | .add("featuresRepo", featuresRepo) |
| 131 | .add("features", features) |
Thomas Vachuska | 761f004 | 2015-11-11 19:10:17 -0800 | [diff] [blame] | 132 | .add("requiredApps", requiredApps) |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 133 | .toString(); |
| 134 | } |
| 135 | } |