Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / resourceContainer / 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
28  * by a bundle resources. A concrete technology has 
29  * to override the setAttribute and getAttribute method
30  * and map the according reads and writes to the technology specific 
31  * messages.
32  */
33 public abstract class BundleResource {
34     protected String m_name, m_uri, m_resourceType, m_address;
35
36     protected HashMap<String, String> m_attributes;
37
38     /**
39      * Initialize the internal attribute structure.
40      */
41     protected abstract void initAttributes();
42
43     /**
44      * Set the attribute (map to a send command for the according protocol)
45      * @param key name of the attribute to be set
46      * @param value new value of the attribute
47      */
48     public abstract void setAttribute(String key, String value);
49
50     /**
51      * Retrieve the attribute (map to read command for the according protocol)
52      * @param key name of the attribute to be read
53      * @return Value of the attribute
54      */
55     public abstract String getAttribute(String key);     
56
57     /**
58      * Attribute keys provided through by the bundle resource.
59      * @return Name of attribute keys as string array
60      */
61     public String[] getAttributeKeys() {
62         Set<String> keys = m_attributes.keySet();
63         return keys.toArray(new String[keys.size()]);
64     }
65
66     /**
67      * Setter for the uri property
68      * @param uri URI of the resource
69      */
70     public void setURI(String uri) {
71         this.m_uri = uri;
72     }
73
74     /**
75      * Returns the URI of the resource
76      * @return
77      */
78     public String getURI() {
79         return m_uri;
80     }
81
82     /**
83      * Sets the resource type property
84      * @param resourceType OIC resource type
85      */
86     public void setResourceType(String resourceType) {
87         this.m_resourceType = resourceType;
88     }
89
90     /**
91      * Getter for the resource type
92      * @return OIC resource type
93      */
94     public String getResourceType() {
95         return m_resourceType;
96     }
97
98     /**
99      * Sets the technology specific address information (e.g., ZigBee short or long identifier)    
100      * @param address
101      */
102     public void setAddress(String address) {
103         this.m_address = address;
104     }
105
106     /**
107      * Returns the technology specific address information
108      * @return
109      */
110     public String getAddress() {
111         return m_address;
112     }
113
114     /**
115      * Sets the name property of the resource
116      * @param name
117      */
118     public void setName(String name) {
119         this.m_name = name;
120     }
121
122     /**
123      * Returns the name property of the resource
124      * @return
125      */
126     public String getName() {
127         return m_name;
128     }
129
130 }