Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / things-manager / sdk / java / src / org / iotivity / service / tm / Capability.java
1 /******************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 /**
22  * @file
23  * This file contains class which provides functions to specify an attribute key and value
24  * of the target resource.
25  *
26  */
27
28 package org.iotivity.service.tm;
29
30 import java.util.StringTokenizer;
31
32 import android.util.Log;
33
34 /**
35  * This class needs to be created to specify an attribute key and value of the
36  * target resource. The attribute key and value are written in capability and
37  * status variables of Capability instance class, respectively. After filling
38  * the Capability instance, store it to listOfCapability vector variable of
39  * Action instance.
40  */
41 public class Capability {
42     /**
43      * String Tag for Logging
44      */
45     private static final String LOG_TAG = "Capability";
46     /**
47      * Attribute Key of target resource
48      */
49     public String               capability;
50     /**
51      * Attribute Value of target resource
52      */
53     public String               status;
54
55     /**
56      * This function generates a Capability String.
57      *
58      * @return String for a specific Capability.
59      */
60     public String toString() {
61         StringBuilder result = new StringBuilder();
62         result.append(capability + "=" + status);
63         return result.toString();
64     }
65
66     /**
67      * This function parses the Capability String.
68      *
69      * @param capabilityString
70      *            Capability in String format.
71      *
72      * @return Capability class.
73      */
74     public static Capability toCapability(String capabilityString) {
75         StringTokenizer tokenizer = new StringTokenizer(capabilityString, "=");
76         if (2 != tokenizer.countTokens()) {
77             Log.e(LOG_TAG, "Invalid capability string = " + capabilityString);
78             return null;
79         }
80
81         Capability result = new Capability();
82
83         result.capability = tokenizer.nextToken();
84         result.status = tokenizer.nextToken();
85         return result;
86     }
87 }