1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 package org.iotivity.service.resourcecontainer;
23 import java.util.HashMap;
25 import android.content.Context;
26 import android.util.Log;
29 * Basic BundleResource that should be used as a base class by a bundle
30 * resources. A concrete technology has to override the setAttribute and
31 * getAttribute method and map the according reads and writes to the technology
34 public abstract class BundleResource {
35 protected String m_name, m_uri, m_resourceType, m_address;
37 protected RcsResourceAttributes m_attributes = new RcsResourceAttributes();
39 protected Context m_context;
43 protected native void updateNativeInstance(RcsResourceAttributes update);
45 public BundleResource() {
49 public BundleResource(Context context) {
51 this.m_context = context;
55 * Initialize the internal attribute structure.
57 protected abstract void initAttributes();
60 * Set the attribute (map to a send command for the according protocol)
63 * name of the attribute to be set
65 * new value of the attribute
67 protected final void setAttribute(String key, RcsValue value, boolean notify) {
68 m_attributes.put(key, value);
71 updateNativeInstance(m_attributes);
76 * Set the attribute (map to a send command for the according protocol)
79 * name of the attribute to be set
81 * new value of the attribute
83 protected final void setAttribute(String key, RcsValue value) {
84 setAttribute(key, value, false);
88 * Set the attribute (map to a send command for the according protocol)
91 * name of the attribute to be set
93 * new value of the attribute
95 protected final void setAttributes(RcsResourceAttributes value, boolean notify) {
96 m_attributes.put(value);
99 updateNativeInstance(m_attributes);
103 protected final void setAttributes(RcsResourceAttributes value) {
104 setAttributes(value, false);
108 * Set the attribute (map to a send command for the according protocol)
111 * name of the attribute to be set
113 * new value of the attribute
115 public abstract void handleSetAttributesRequest(RcsResourceAttributes value);
118 * Deactivates the resource
120 public abstract void deactivateResource();
123 * Retrieve the attribute (only data)
126 * name of the attribute to be read
127 * @return Value of the attribute
129 protected final RcsValue getAttribute(String key) {
130 return m_attributes.get(key);
133 protected final RcsResourceAttributes getAttributes() {
134 RcsResourceAttributes ret = new RcsResourceAttributes(this.m_attributes);
139 * Retrieve the attribute (map to read command)
142 * name of the attribute to be set
144 * new value of the attribute
146 public abstract RcsResourceAttributes handleGetAttributesRequest();
149 * Attribute keys provided through by the bundle resource.
151 * @return Name of attribute keys as string array
153 public String[] getAttributeKeys() {
154 Set<String> keys = m_attributes.keySet();
155 return keys.toArray(new String[keys.size()]);
159 * Setter for the uri property
162 * URI of the resource
164 public void setURI(String uri) {
169 * Returns the URI of the resource
171 * @return Resource URI
173 public String getURI() {
178 * Sets the resource type property
180 * @param resourceType
183 public void setResourceType(String resourceType) {
184 this.m_resourceType = resourceType;
188 * Getter for the resource type
190 * @return OIC resource type
192 public String getResourceType() {
193 return m_resourceType;
197 * Sets the technology specific address information (e.g., ZigBee short or
203 public void setAddress(String address) {
204 this.m_address = address;
208 * Returns the technology specific address information
210 * @return Resource address
212 public String getAddress() {
217 * Sets the name property of the resource
222 public void setName(String name) {
227 * Returns the name property of the resource
229 * @return Resource name
231 public String getName() {