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 AndroidBundleResource {
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 AndroidBundleResource() {
49 public AndroidBundleResource(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 * Retrieve the attribute (only data)
121 * name of the attribute to be read
122 * @return Value of the attribute
124 protected final RcsValue getAttribute(String key) {
125 return m_attributes.get(key);
128 protected final RcsResourceAttributes getAttributes() {
129 RcsResourceAttributes ret = new RcsResourceAttributes(this.m_attributes);
134 * Retrieve the attribute (map to read command)
137 * name of the attribute to be set
139 * new value of the attribute
141 public abstract RcsResourceAttributes handleGetAttributesRequest();
144 * Attribute keys provided through by the bundle resource.
146 * @return Name of attribute keys as string array
148 public String[] getAttributeKeys() {
149 Set<String> keys = m_attributes.keySet();
150 return keys.toArray(new String[keys.size()]);
154 * Setter for the uri property
157 * URI of the resource
159 public void setURI(String uri) {
164 * Returns the URI of the resource
166 * @return Resource URI
168 public String getURI() {
173 * Sets the resource type property
175 * @param resourceType
178 public void setResourceType(String resourceType) {
179 this.m_resourceType = resourceType;
183 * Getter for the resource type
185 * @return OIC resource type
187 public String getResourceType() {
188 return m_resourceType;
192 * Sets the technology specific address information (e.g., ZigBee short or
198 public void setAddress(String address) {
199 this.m_address = address;
203 * Returns the technology specific address information
205 * @return Resource address
207 public String getAddress() {
212 * Sets the name property of the resource
217 public void setName(String name) {
222 * Returns the name property of the resource
224 * @return Resource name
226 public String getName() {