2 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package oic.simulator.clientcontroller.remoteresource;
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.LinkedList;
22 import java.util.List;
25 import oic.simulator.clientcontroller.utils.Constants;
27 import org.oic.simulator.SimulatorResourceModel;
28 import org.oic.simulator.clientcontroller.SimulatorConnectivityType;
29 import org.oic.simulator.clientcontroller.SimulatorRemoteResource;
32 * This class represents a remote resource. It maintains all the necessary
33 * information about the resource.
35 public class RemoteResource {
37 private String resourceURI;
39 private LinkedList<String> resourceTypes;
40 private LinkedList<String> resourceInterfaces;
41 private SimulatorConnectivityType connectivityType;
42 private boolean isObservable;
44 private boolean observed;
46 // Native object references
47 private SimulatorRemoteResource resourceN;
48 private SimulatorResourceModel resourceModel;
49 private Map<String, RemoteResourceAttribute> resourceAttributesMap;
51 private boolean configUploaded;
53 private boolean getAutomtnInProgress;
54 private boolean putAutomtnInProgress;
55 private boolean postAutomtnInProgress;
57 private int getAutomtnId;
58 private int putAutomtnId;
59 private int postAutomtnId;
61 private boolean isFavorite;
63 public SimulatorResourceModel getResourceModel() {
67 public void setResourceModel(SimulatorResourceModel resourceModel) {
68 this.resourceModel = resourceModel;
71 public Map<String, RemoteResourceAttribute> getResourceAttributesMap() {
72 return resourceAttributesMap;
75 public void setResourceAttributesMap(
76 Map<String, RemoteResourceAttribute> resourceAttributesMap) {
77 this.resourceAttributesMap = resourceAttributesMap;
80 public int getGetAutomtnId() {
84 public void setGetAutomtnId(int getAutomtnId) {
85 this.getAutomtnId = getAutomtnId;
88 public int getPutAutomtnId() {
92 public void setPutAutomtnId(int putAutomtnId) {
93 this.putAutomtnId = putAutomtnId;
96 public int getPostAutomtnId() {
100 public void setPostAutomtnId(int postAutomtnId) {
101 this.postAutomtnId = postAutomtnId;
104 public String getResourceURI() {
108 public void setResourceURI(String resourceURI) {
109 this.resourceURI = resourceURI;
112 public String getHost() {
116 public void setHost(String host) {
120 public LinkedList<String> getResourceTypes() {
121 return resourceTypes;
124 public void setResourceTypes(LinkedList<String> resourceTypes) {
125 this.resourceTypes = resourceTypes;
128 public LinkedList<String> getResourceInterfaces() {
129 return resourceInterfaces;
132 public void setResourceInterfaces(LinkedList<String> resourceInterfaces) {
133 this.resourceInterfaces = resourceInterfaces;
136 public SimulatorConnectivityType getConnectivityType() {
137 return connectivityType;
140 public void setConnectivityType(SimulatorConnectivityType connectivityType) {
141 this.connectivityType = connectivityType;
144 public boolean isObservable() {
148 public void setObservable(boolean isObservable) {
149 this.isObservable = isObservable;
152 public boolean isGetAutomtnInProgress() {
153 return getAutomtnInProgress;
156 public void setGetAutomtnInProgress(boolean getAutomtnInProgress) {
157 this.getAutomtnInProgress = getAutomtnInProgress;
160 public boolean isPutAutomtnInProgress() {
161 return putAutomtnInProgress;
164 public void setPutAutomtnInProgress(boolean putAutomtnInProgress) {
165 this.putAutomtnInProgress = putAutomtnInProgress;
168 public boolean isPostAutomtnInProgress() {
169 return postAutomtnInProgress;
172 public void setPostAutomtnInProgress(boolean postAutomtnInProgress) {
173 this.postAutomtnInProgress = postAutomtnInProgress;
176 public boolean isConfigUploaded() {
177 return configUploaded;
180 public void setConfigUploaded(boolean configUploaded) {
181 this.configUploaded = configUploaded;
184 public SimulatorRemoteResource getResource() {
188 public void setResource(SimulatorRemoteResource resource) {
189 this.resourceN = resource;
192 public boolean isObserved() {
196 public void setObserved(boolean observed) {
197 this.observed = observed;
200 public List<PutPostAttributeModel> getPutPostModel() {
201 Map<String, RemoteResourceAttribute> attMap = getResourceAttributesMap();
202 if (null == attMap || attMap.size() < 1) {
205 List<PutPostAttributeModel> putPostModelList = new ArrayList<PutPostAttributeModel>();
207 RemoteResourceAttribute attribute;
208 PutPostAttributeModel putPostModel;
209 Iterator<String> attItr = attMap.keySet().iterator();
210 while (attItr.hasNext()) {
211 attName = attItr.next();
212 attribute = attMap.get(attName);
213 putPostModel = PutPostAttributeModel.getModel(attribute);
214 if (null != putPostModel) {
215 putPostModelList.add(putPostModel);
218 return putPostModelList;
221 public String getAttributeValue(String attName) {
222 RemoteResourceAttribute attribute = resourceAttributesMap.get(attName);
223 if (null == attribute) {
226 return String.valueOf(attribute.getAttributeValue());
229 public String getuId() {
233 public void setuId(String uId) {
237 public int getAutomationtype(int autoId) {
238 if (getAutomtnId == autoId) {
239 return Constants.GET_AUTOMATION_INDEX;
240 } else if (putAutomtnId == autoId) {
241 return Constants.PUT_AUTOMATION_INDEX;
242 } else {// if(postAutomtnId == autoId) {
243 return Constants.POST_AUTOMATION_INDEX;
247 public void updateAutomationStatus(int autoId, boolean status) {
248 if (getAutomtnId == autoId) {
249 getAutomtnInProgress = status;
250 } else if (putAutomtnId == autoId) {
251 putAutomtnInProgress = status;
252 } else {// if(postAutomtnId == autoId) {
253 postAutomtnInProgress = status;
257 public boolean isFavorite() {
261 public void setFavorite(boolean isFavorite) {
262 this.isFavorite = isFavorite;