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.resourcecontainer.bundle.api;
23 import java.util.HashMap;
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
32 public abstract class BundleResource {
33 protected String m_name, m_uri, m_resourceType, m_address;
35 protected HashMap<String, String> m_attributes = new HashMap<String, String>();
38 * Initialize the internal attribute structure.
40 protected abstract void initAttributes();
43 * Set the attribute (map to a send command for the according protocol)
46 * name of the attribute to be set
48 * new value of the attribute
50 protected final void setAttribute(String key, String value) {
51 m_attributes.put(key, value);
55 * Set the attribute (map to a send command for the according protocol)
58 * name of the attribute to be set
60 * new value of the attribute
62 public abstract void handleSetAttributeRequest(String key, String value);
65 * Retrieve the attribute (only data)
68 * name of the attribute to be read
69 * @return Value of the attribute
71 protected final String getAttribute(String key) {
72 return m_attributes.get(key);
76 * Retrieve the attribute (map to read command)
79 * name of the attribute to be set
81 * new value of the attribute
83 public abstract String handleGetAttributeRequest(String key);
86 * Attribute keys provided through by the bundle resource.
88 * @return Name of attribute keys as string array
90 public String[] getAttributeKeys() {
91 Set<String> keys = m_attributes.keySet();
92 return keys.toArray(new String[keys.size()]);
96 * Setter for the uri property
101 public void setURI(String uri) {
106 * Returns the URI of the resource
108 * @return Resource URI
110 public String getURI() {
115 * Sets the resource type property
117 * @param resourceType
120 public void setResourceType(String resourceType) {
121 this.m_resourceType = resourceType;
125 * Getter for the resource type
127 * @return OIC resource type
129 public String getResourceType() {
130 return m_resourceType;
134 * Sets the technology specific address information (e.g., ZigBee short or
140 public void setAddress(String address) {
141 this.m_address = address;
145 * Returns the technology specific address information
147 * @return Resource address
149 public String getAddress() {
154 * Sets the name property of the resource
159 public void setName(String name) {
164 * Returns the name property of the resource
166 * @return Resource name
168 public String getName() {