Displaying and editing the complex value types for attributes.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / model / Resource.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package oic.simulator.serviceprovider.model;
18
19 import java.util.HashMap;
20 import java.util.HashSet;
21 import java.util.Map;
22 import java.util.Set;
23
24 import org.oic.simulator.SimulatorResourceModel;
25 import org.oic.simulator.server.Observer;
26 import org.oic.simulator.server.SimulatorResource;
27
28 public abstract class Resource {
29
30     // Java SDK object reference
31     SimulatorResource                           simulatorResource;
32     private SimulatorResourceModel              resourceModel;
33     private ResourceRepresentation              mResourceRepresentation;
34
35     private String                              resourceURI;
36     private String                              resourceName;
37     private Set<String>                         resourceTypes;
38     private Set<String>                         resourceInterfaces;
39     private boolean                             started;
40     private boolean                             observable;
41
42     private Set<Device>                         deviceMembership;
43
44     private Map<String, LocalResourceAttribute> attributes;
45
46     private Map<Integer, ObserverDetail>        observers;
47
48     public Resource() {
49         resourceTypes = new HashSet<String>();
50         resourceInterfaces = new HashSet<String>();
51         observers = new HashMap<Integer, ObserverDetail>();
52     }
53
54     public SimulatorResource getSimulatorResource() {
55         return simulatorResource;
56     }
57
58     public void setSimulatorResource(SimulatorResource simulatorResource) {
59         this.simulatorResource = simulatorResource;
60     }
61
62     public SimulatorResourceModel getResourceModel() {
63         return resourceModel;
64     }
65
66     public void setResourceModel(SimulatorResourceModel resourceModel) {
67         this.resourceModel = resourceModel;
68     }
69
70     public String getResourceURI() {
71         return resourceURI;
72     }
73
74     public void setResourceURI(String resourceURI) {
75         this.resourceURI = resourceURI;
76     }
77
78     public String getResourceName() {
79         return resourceName;
80     }
81
82     public void setResourceName(String resourceName) {
83         this.resourceName = resourceName;
84     }
85
86     public Set<String> getResourceTypes() {
87         return resourceTypes;
88     }
89
90     public void setResourceTypes(Set<String> resourceTypes) {
91         this.resourceTypes = resourceTypes;
92     }
93
94     public Set<String> getResourceInterfaces() {
95         return resourceInterfaces;
96     }
97
98     public void setResourceInterfaces(Set<String> resourceInterfaces) {
99         this.resourceInterfaces = resourceInterfaces;
100     }
101
102     public boolean isStarted() {
103         return started;
104     }
105
106     public void setStarted(boolean started) {
107         this.started = started;
108     }
109
110     public boolean isObservable() {
111         return observable;
112     }
113
114     public void setObservable(boolean observable) {
115         this.observable = observable;
116     }
117
118     public void addResourceType(String resType) {
119         if (null == resType) {
120             return;
121         }
122         if (null == resourceTypes) {
123             resourceTypes = new HashSet<String>();
124         }
125         resourceTypes.add(resType);
126     }
127
128     public void removeResourceType(String resType) {
129         if (null == resType || null == resourceTypes) {
130             return;
131         }
132         resourceTypes.remove(resType);
133     }
134
135     public boolean isResourceTypeExist(String resType) {
136         if (null == resType || null == resourceTypes) {
137             return false;
138         }
139         return resourceTypes.contains(resType);
140     }
141
142     public void addInterfaceType(String ifType) {
143         if (null == ifType) {
144             return;
145         }
146         if (null == resourceInterfaces) {
147             resourceInterfaces = new HashSet<String>();
148         }
149         resourceInterfaces.add(ifType);
150     }
151
152     public void removeInterfaceType(String ifType) {
153         if (null == ifType || null == resourceInterfaces) {
154             return;
155         }
156         resourceInterfaces.remove(ifType);
157     }
158
159     public boolean isInterfaceTypeExist(String ifType) {
160         if (null == ifType || null == resourceInterfaces) {
161             return false;
162         }
163         return resourceInterfaces.contains(ifType);
164     }
165
166     public Map<Integer, ObserverDetail> getObserver() {
167         return observers;
168     }
169
170     public void addObserverInfo(Observer observer) {
171         if (null == observer) {
172             return;
173         }
174         int id = observer.getId();
175         if (!observers.containsKey(id)) {
176             ObserverDetail obsDetail = new ObserverDetail();
177             obsDetail.setObserverInfo(observer);
178             observers.put(id, obsDetail);
179         }
180     }
181
182     public void removeObserverInfo(Observer observer) {
183         if (null == observer) {
184             return;
185         }
186         observers.remove(observer.getId());
187     }
188
189     public Set<Device> getDeviceMembership() {
190         return deviceMembership;
191     }
192
193     public void setDeviceMembership(Set<Device> deviceMembership) {
194         this.deviceMembership = deviceMembership;
195     }
196
197     public void addDeviceMembership(Device dev) {
198         if (null == dev) {
199             return;
200         }
201         if (null == deviceMembership) {
202             deviceMembership = new HashSet<Device>();
203         }
204         deviceMembership.add(dev);
205     }
206
207     public void addDeviceMembership(Set<Device> devices) {
208         if (null == devices) {
209             return;
210         }
211         if (null == deviceMembership) {
212             deviceMembership = new HashSet<Device>();
213         }
214         deviceMembership.addAll(devices);
215     }
216
217     public void removeDeviceMembership(Device dev) {
218         if (null == dev || null == deviceMembership) {
219             return;
220         }
221         deviceMembership.remove(dev);
222     }
223
224     public void removeDeviceMembership(Set<Device> devices) {
225         if (null == devices || null == deviceMembership) {
226             return;
227         }
228         deviceMembership.removeAll(devices);
229     }
230
231     public boolean isMemberOfAnyDevice() {
232         if (null == deviceMembership || deviceMembership.isEmpty()) {
233             return false;
234         }
235         return true;
236     }
237
238     public Map<String, LocalResourceAttribute> getResourceAttributes() {
239         return attributes;
240     }
241
242     public void setResourceAttributes(
243             Map<String, LocalResourceAttribute> attributes) {
244         this.attributes = attributes;
245     }
246
247     public void setResourceRepresentation(SimulatorResourceModel resModel) {
248         if (mResourceRepresentation == null)
249             mResourceRepresentation = new ResourceRepresentation(resModel);
250         else
251             mResourceRepresentation.update(resModel);
252     }
253
254     public ResourceRepresentation getResourceRepresentation() {
255         return mResourceRepresentation;
256     }
257 }