Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 52f2cd1 | 2018-11-08 21:20:04 -0800 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 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 | */ |
Thomas Vachuska | 52f2cd1 | 2018-11-08 21:20:04 -0800 | [diff] [blame] | 16 | package org.onosproject.net; |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 17 | |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 18 | import org.onlab.util.Identifier; |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 19 | |
| 20 | import static com.google.common.base.Preconditions.checkArgument; |
| 21 | |
| 22 | /** |
| 23 | * Representation of network tenant. |
| 24 | */ |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 25 | public final class TenantId extends Identifier<String> { |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Represents no tenant, or an unspecified tenant. |
| 29 | */ |
| 30 | public static final TenantId NONE = new TenantId(); |
| 31 | |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 32 | // Public construction is prohibited |
| 33 | private TenantId(String id) { |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 34 | super(id); |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 35 | checkArgument(id != null && id.length() > 0, "Tenant ID cannot be null or empty"); |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 38 | // Default constructor for serialization |
| 39 | protected TenantId() { |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 40 | super(""); |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Creates a tenant id using the supplied backing id. |
| 45 | * |
| 46 | * @param id network id |
| 47 | * @return network identifier |
| 48 | */ |
| 49 | public static TenantId tenantId(String id) { |
| 50 | return new TenantId(id); |
| 51 | } |
Thomas Vachuska | 7b438af | 2015-07-07 09:52:07 -0700 | [diff] [blame] | 52 | } |