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.List;
24 import oic.simulator.clientcontroller.utils.Constants;
26 import org.oic.simulator.SimulatorResourceModel;
27 import org.oic.simulator.client.SimulatorRemoteResource;
30 * This class represents a remote resource. It maintains all the necessary
31 * information about the resource.
33 public class RemoteResource {
35 private boolean observed;
37 // Native object references
38 private SimulatorRemoteResource remoteResourceRef;
39 private SimulatorResourceModel resourceModelRef;
40 private Map<String, RemoteResourceAttribute> resourceAttributesMap;
42 private boolean configUploaded;
44 private boolean getAutomtnInProgress;
45 private boolean putAutomtnInProgress;
46 private boolean postAutomtnInProgress;
48 private int getAutomtnId;
49 private int putAutomtnId;
50 private int postAutomtnId;
52 private boolean isFavorite;
54 public SimulatorResourceModel getResourceModelRef() {
55 return resourceModelRef;
58 public void setResourceModelRef(SimulatorResourceModel resourceModel) {
59 this.resourceModelRef = resourceModel;
62 public Map<String, RemoteResourceAttribute> getResourceAttributesMap() {
63 return resourceAttributesMap;
66 public void setResourceAttributesMap(
67 Map<String, RemoteResourceAttribute> resourceAttributesMap) {
68 this.resourceAttributesMap = resourceAttributesMap;
71 public int getGetAutomtnId() {
75 public void setGetAutomtnId(int getAutomtnId) {
76 this.getAutomtnId = getAutomtnId;
79 public int getPutAutomtnId() {
83 public void setPutAutomtnId(int putAutomtnId) {
84 this.putAutomtnId = putAutomtnId;
87 public int getPostAutomtnId() {
91 public void setPostAutomtnId(int postAutomtnId) {
92 this.postAutomtnId = postAutomtnId;
95 public boolean isGetAutomtnInProgress() {
96 return getAutomtnInProgress;
99 public void setGetAutomtnInProgress(boolean getAutomtnInProgress) {
100 this.getAutomtnInProgress = getAutomtnInProgress;
103 public boolean isPutAutomtnInProgress() {
104 return putAutomtnInProgress;
107 public void setPutAutomtnInProgress(boolean putAutomtnInProgress) {
108 this.putAutomtnInProgress = putAutomtnInProgress;
111 public boolean isPostAutomtnInProgress() {
112 return postAutomtnInProgress;
115 public void setPostAutomtnInProgress(boolean postAutomtnInProgress) {
116 this.postAutomtnInProgress = postAutomtnInProgress;
119 public boolean isConfigUploaded() {
120 return configUploaded;
123 public void setConfigUploaded(boolean configUploaded) {
124 this.configUploaded = configUploaded;
127 public SimulatorRemoteResource getRemoteResourceRef() {
128 return remoteResourceRef;
131 public void setRemoteResourceRef(SimulatorRemoteResource resource) {
132 this.remoteResourceRef = resource;
135 public boolean isObserved() {
139 public void setObserved(boolean observed) {
140 this.observed = observed;
143 public List<PutPostAttributeModel> getPutPostModel() {
144 Map<String, RemoteResourceAttribute> attMap = getResourceAttributesMap();
145 if (null == attMap || attMap.size() < 1) {
148 List<PutPostAttributeModel> putPostModelList = new ArrayList<PutPostAttributeModel>();
150 RemoteResourceAttribute attribute;
151 PutPostAttributeModel putPostModel;
152 Iterator<String> attItr = attMap.keySet().iterator();
153 while (attItr.hasNext()) {
154 attName = attItr.next();
155 attribute = attMap.get(attName);
156 putPostModel = PutPostAttributeModel.getModel(attribute);
157 if (null != putPostModel) {
158 putPostModelList.add(putPostModel);
161 return putPostModelList;
164 public String getAttributeValue(String attName) {
165 RemoteResourceAttribute attribute = resourceAttributesMap.get(attName);
166 if (null == attribute) {
169 return String.valueOf(attribute.getAttributeValue());
172 public int getAutomationtype(int autoId) {
173 if (getAutomtnId == autoId) {
174 return Constants.GET_AUTOMATION_INDEX;
175 } else if (putAutomtnId == autoId) {
176 return Constants.PUT_AUTOMATION_INDEX;
177 } else {// if(postAutomtnId == autoId) {
178 return Constants.POST_AUTOMATION_INDEX;
182 public void updateAutomationStatus(int autoId, boolean status) {
183 if (getAutomtnId == autoId) {
184 getAutomtnInProgress = status;
185 } else if (putAutomtnId == autoId) {
186 putAutomtnInProgress = status;
187 } else {// if(postAutomtnId == autoId) {
188 postAutomtnInProgress = status;
192 public boolean isFavorite() {
196 public void setFavorite(boolean isFavorite) {
197 this.isFavorite = isFavorite;