Imported Upstream version 0.9.1
[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  * @file    Capability.java
22  *
23  * @brief   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
36  * of the target resource. The attribute key and value are written in
37  * capability and status variables of Capability instance class,
38  * respectively. After filling the Capability instance, store it to
39  * listOfCapability vector variable of Action instance.
40  *
41  */
42 public class Capability {
43     /**
44      * String Tag for Logging
45      */
46     private static final String LOG_TAG = "Capability";
47     /**
48      * Attribute Key of target resource
49      */
50     public String               capability;
51     /**
52      * Attribute Value of target resource
53      */
54     public String               status;
55
56     /**
57      * This function generates a Capability String.
58      *
59      * @return String for a specific Capability.
60      *
61      */
62     public String toString() {
63         StringBuilder result = new StringBuilder();
64         result.append(capability + "=" + status);
65         return result.toString();
66     }
67
68     /**
69      * This function parses the Capability String.
70      *
71      * @param capabilityString
72      *            Capability in String format.
73      *
74      * @return Capability class.
75      *
76      */
77     public static Capability toCapability(String capabilityString) {
78         StringTokenizer tokenizer = new StringTokenizer(capabilityString, "=");
79         if (2 != tokenizer.countTokens()) {
80             Log.e(LOG_TAG, "Invalid capability string = " + capabilityString);
81             return null;
82         }
83
84         Capability result = new Capability();
85
86         result.capability = tokenizer.nextToken();
87         result.status = tokenizer.nextToken();
88         return result;
89     }
90 }