Jian Li | 8780edc | 2017-08-26 02:44:29 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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.incubator.protobuf.models.core; |
| 17 | |
| 18 | import org.onosproject.core.ApplicationId; |
| 19 | import org.onosproject.core.DefaultApplicationId; |
| 20 | import org.onosproject.grpc.core.models.ApplicationIdProtoOuterClass.ApplicationIdProto; |
| 21 | |
| 22 | import static org.onosproject.grpc.core.models.ApplicationIdProtoOuterClass.ApplicationIdProto.getDefaultInstance; |
| 23 | |
| 24 | /** |
| 25 | * gRPC ApplicationIdProto message to equivalent ONOS ApplicationId conversion related utilities. |
| 26 | */ |
| 27 | public final class ApplicationIdProtoTranslator { |
| 28 | |
| 29 | /** |
| 30 | * Translates gRPC ApplicationId to {@link ApplicationId}. |
| 31 | * |
| 32 | * @param applicationId gRPC message |
| 33 | * @return {@link ApplicationId} |
| 34 | */ |
| 35 | public static ApplicationId translate(ApplicationIdProto applicationId) { |
| 36 | |
| 37 | return new DefaultApplicationId(applicationId.getId(), applicationId.getName()); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Translates {@link ApplicationId} to gRPC ApplicationId message. |
| 42 | * |
| 43 | * @param applicationId {@link ApplicationId} |
| 44 | * @return gRPC ApplicationId message |
| 45 | */ |
| 46 | public static ApplicationIdProto translate(ApplicationId applicationId) { |
| 47 | |
| 48 | if (applicationId != null) { |
| 49 | return ApplicationIdProto.newBuilder() |
| 50 | .setId(applicationId.id()) |
| 51 | .setName(applicationId.name()) |
| 52 | .build(); |
| 53 | } |
| 54 | |
| 55 | return getDefaultInstance(); |
| 56 | } |
| 57 | |
| 58 | // utility class not intended for instantiation. |
| 59 | private ApplicationIdProtoTranslator() {} |
| 60 | } |