Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / service / protocol-plugin / plugin-manager / src / Android / src / org / iotivity / service / ppm / Plugin.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 Plugin.java
22
23 /// @brief This class provides information of each plugin installed for JAVA.
24
25 package org.iotivity.service.ppm;
26
27 import java.util.HashMap;
28 import java.util.Iterator;
29 import java.util.Map;
30 import java.util.Map.Entry;
31 import java.util.Vector;
32
33 public class Plugin {
34
35     private Map<String, String> m_attributeMap;
36     private Vector<String>      m_supportedType;
37
38     /**
39      * Constructor for Plugin.
40      *
41      */
42     public Plugin() {
43         m_attributeMap = new HashMap<String, String>();
44         m_supportedType = new Vector<String>();
45     }
46
47     /**
48      * Constructor for Plugin(Overlading).
49      *
50      * @param Plugin's name and id Strings.
51      */
52     public Plugin(String name, String id) {
53         this();
54         setValue("Name", name);
55         setValue("Id", id);
56     }
57
58     /**
59      * Get unique ID of the plugin.
60      *
61      * @return unique id String of the plugin. if ID is not exist, it return "".
62      */
63     public String getID() {
64         Iterator<Entry<String, String>> m_iterator = m_attributeMap.entrySet()
65                 .iterator();
66
67         while (m_iterator.hasNext()) {
68             Entry<String, String> entryMap = m_iterator.next();
69             if (entryMap.getKey().equals("Id"))
70                 return entryMap.getValue();
71         }
72         return "";
73     }
74
75     /**
76      * Get version of the plugin.
77      *
78      * @return version information String of the plugin. if Version is not
79      *         exist, it return "".
80      */
81     public String getVersion() {
82         Iterator<Entry<String, String>> m_iterator = m_attributeMap.entrySet()
83                 .iterator();
84
85         while (m_iterator.hasNext()) {
86             Entry<String, String> entryMap = m_iterator.next();
87             if (entryMap.getKey().equals("Version"))
88                 return entryMap.getValue();
89         }
90         return "";
91     }
92
93     /**
94      * Get name of the plugin.
95      *
96      * @return name String of the plugin. if Name is not exist, it return "".
97      */
98     public String getName() {
99         Iterator<Entry<String, String>> m_iterator = m_attributeMap.entrySet()
100                 .iterator();
101
102         while (m_iterator.hasNext()) {
103             Entry<String, String> entryMap = m_iterator.next();
104             if (entryMap.getKey().equals("Name"))
105                 return entryMap.getValue();
106         }
107         return "";
108     }
109
110     /**
111      * Get provider name of the plugin.
112      *
113      * @return provider name of the plugin. if ProviderName is not exist, it
114      *         return "".
115      */
116     public String getProviderName() {
117         Iterator<Entry<String, String>> m_iterator = m_attributeMap.entrySet()
118                 .iterator();
119
120         while (m_iterator.hasNext()) {
121             Entry<String, String> entryMap = m_iterator.next();
122             if (entryMap.getKey().equals("Provider"))
123                 return entryMap.getValue();
124         }
125         return "";
126     }
127
128     /**
129      * Get value for the attributes.
130      *
131      * @param attriubute
132      *            String to get value.
133      * @return value String of the attribute. if "attribute" is not exist, it
134      *         return "".
135      */
136     public String getValueByAttribute(String attribute) {
137         Iterator<Entry<String, String>> m_iterator = m_attributeMap.entrySet()
138                 .iterator();
139
140         while (m_iterator.hasNext()) {
141             Entry<String, String> entryMap = m_iterator.next();
142             if (entryMap.getKey().equals(attribute))
143                 return entryMap.getValue();
144         }
145         return "";
146     }
147
148     /**
149      * Set key, value. key is attribute name.
150      *
151      * @param key
152      *            is atrribute name.
153      * @param value
154      *            for the attribute.
155      * @return void.
156      */
157     public void setValue(String key, String value) {
158         m_attributeMap.put(key, value);
159     }
160 }