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.HashMap;
22 import org.oic.simulator.AttributeValue;
23 import org.oic.simulator.InvalidArgsException;
24 import org.oic.simulator.SimulatorResourceAttribute;
25 import org.oic.simulator.SimulatorResourceModel;
27 public class ResourceRepresentation {
28 private Map<String, AttributeElement> mAttributes = new HashMap<String, AttributeElement>();
30 public ResourceRepresentation(SimulatorResourceModel resourceModel) {
31 if (resourceModel != null && resourceModel.size() > 0) {
32 for (Map.Entry<String, AttributeValue> entry : resourceModel.get()
34 mAttributes.put(entry.getKey(),
35 new AttributeElement(this,
36 new SimulatorResourceAttribute(entry.getKey(),
41 public Map<String, AttributeElement> getAttributes() {
45 public void update(SimulatorResourceModel resourceModel,
46 boolean ramlUploaded) {
47 for (Map.Entry<String, AttributeValue> entry : resourceModel.get()
49 AttributeElement attributeElement = mAttributes.get(entry.getKey());
50 if (attributeElement != null) {
51 attributeElement.update(
52 new SimulatorResourceAttribute(entry.getKey(), entry
53 .getValue()), ramlUploaded);
55 // Display new attribute in UI
56 AttributeElement newAttribute = new AttributeElement(this,
57 new SimulatorResourceAttribute(entry.getKey(),
59 mAttributes.put(entry.getKey(), newAttribute);
64 public SimulatorResourceModel getModel() {
65 if (null == mAttributes || mAttributes.isEmpty()) {
68 SimulatorResourceModel model = new SimulatorResourceModel();
69 for (Map.Entry<String, AttributeElement> entry : mAttributes.entrySet()) {
70 AttributeElement attributeElement = mAttributes.get(entry.getKey());
71 if (attributeElement != null) {
73 model.set(entry.getKey(), attributeElement
74 .getSimulatorResourceAttribute().value());
75 } catch (InvalidArgsException e) {
83 public SimulatorResourceModel getSelectedModel() {
84 if (null == mAttributes || mAttributes.isEmpty()) {
87 SimulatorResourceModel model = new SimulatorResourceModel();
88 for (Map.Entry<String, AttributeElement> entry : mAttributes.entrySet()) {
89 AttributeElement attributeElement = mAttributes.get(entry.getKey());
90 if (attributeElement != null && attributeElement.getPostState()) {
92 model.set(entry.getKey(), attributeElement
93 .getSimulatorResourceAttribute().value());
94 } catch (InvalidArgsException e) {