Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / resource-container / bundle-java-api / src / main / java / org / iotivity / resourcecontainer / bundle / api / BundleResource.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 package org.iotivity.resourcecontainer.bundle.api;
22
23 import java.util.HashMap;
24 import java.util.Set;
25
26 /**
27  * Basic BundleResource that should be used as a base class by a bundle
28  * resources. A concrete technology has to override the setAttribute and
29  * getAttribute method and map the according reads and writes to the technology
30  * specific messages.
31  */
32 public abstract class BundleResource {
33         protected String m_name, m_uri, m_resourceType, m_address;
34
35         protected HashMap<String, String> m_attributes = new HashMap<String, String>();
36
37         /**
38          * Initialize the internal attribute structure.
39          */
40         protected abstract void initAttributes();
41
42         /**
43          * Set the attribute (map to a send command for the according protocol)
44          * 
45          * @param key
46          *            name of the attribute to be set
47          * @param value
48          *            new value of the attribute
49          */
50         protected final void setAttribute(String key, String value) {
51                 m_attributes.put(key, value);
52         }
53
54         /**
55          * Set the attribute (map to a send command for the according protocol)
56          * 
57          * @param key
58          *            name of the attribute to be set
59          * @param value
60          *            new value of the attribute
61          */
62         public abstract void handleSetAttributeRequest(String key, String value);
63
64         /**
65          * Retrieve the attribute (only data)
66          * 
67          * @param key
68          *            name of the attribute to be read
69          * @return Value of the attribute
70          */
71         protected final String getAttribute(String key) {
72                 return m_attributes.get(key);
73         }
74
75         /**
76          * Retrieve the attribute (map to read command)
77          * 
78          * @param key
79          *            name of the attribute to be set
80          * @param value
81          *            new value of the attribute
82          */
83         public abstract String handleGetAttributeRequest(String key);
84
85         /**
86          * Attribute keys provided through by the bundle resource.
87          * 
88          * @return Name of attribute keys as string array
89          */
90         public String[] getAttributeKeys() {
91                 Set<String> keys = m_attributes.keySet();
92                 return keys.toArray(new String[keys.size()]);
93         }
94
95         /**
96          * Setter for the uri property
97          * 
98          * @param uri
99          *            URI of the resource
100          */
101         public void setURI(String uri) {
102                 this.m_uri = uri;
103         }
104
105         /**
106          * Returns the URI of the resource
107          * 
108          * @return Resource URI
109          */
110         public String getURI() {
111                 return m_uri;
112         }
113
114         /**
115          * Sets the resource type property
116          * 
117          * @param resourceType
118          *            OIC resource type
119          */
120         public void setResourceType(String resourceType) {
121                 this.m_resourceType = resourceType;
122         }
123
124         /**
125          * Getter for the resource type
126          * 
127          * @return OIC resource type
128          */
129         public String getResourceType() {
130                 return m_resourceType;
131         }
132
133         /**
134          * Sets the technology specific address information (e.g., ZigBee short or
135          * long identifier)
136          * 
137          * @param address
138          *            Resource address
139          */
140         public void setAddress(String address) {
141                 this.m_address = address;
142         }
143
144         /**
145          * Returns the technology specific address information
146          * 
147          * @return Resource address
148          */
149         public String getAddress() {
150                 return m_address;
151         }
152
153         /**
154          * Sets the name property of the resource
155          * 
156          * @param name
157          *            Resource name
158          */
159         public void setName(String name) {
160                 this.m_name = name;
161         }
162
163         /**
164          * Returns the name property of the resource
165          * 
166          * @return Resource name
167          */
168         public String getName() {
169                 return m_name;
170         }
171
172 }