1 package oic.simulator.clientcontroller.remoteresource;
3 import java.util.HashMap;
6 import org.oic.simulator.InvalidArgsException;
7 import org.oic.simulator.SimulatorResourceAttribute;
8 import org.oic.simulator.SimulatorResourceModel;
10 public class ResourceRepresentation {
11 private Map<String, AttributeElement> mAttributes = new HashMap<String, AttributeElement>();
13 public ResourceRepresentation(SimulatorResourceModel resourceModel) {
14 if (resourceModel != null && resourceModel.size() > 0) {
15 for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
16 .getAttributes().entrySet())
17 mAttributes.put(entry.getKey(), new AttributeElement(this,
22 public Map<String, AttributeElement> getAttributes() {
26 public void update(SimulatorResourceModel resourceModel,
27 boolean ramlUploaded) {
28 for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
29 .getAttributes().entrySet()) {
30 AttributeElement attributeElement = mAttributes.get(entry.getKey());
31 if (attributeElement != null) {
33 attributeElement.updateForRAMLUpload(entry.getValue());
35 attributeElement.update(entry.getValue());
36 } else // Display new attribute in UI
38 AttributeElement newAttribute = new AttributeElement(this,
40 mAttributes.put(entry.getKey(), newAttribute);
45 public SimulatorResourceModel getModel() {
46 if (null == mAttributes || mAttributes.isEmpty()) {
49 SimulatorResourceModel model = new SimulatorResourceModel();
50 for (Map.Entry<String, AttributeElement> entry : mAttributes.entrySet()) {
51 AttributeElement attributeElement = mAttributes.get(entry.getKey());
52 if (attributeElement != null) {
54 model.addAttribute(attributeElement
55 .getSimulatorResourceAttribute());
56 } catch (InvalidArgsException e) {
64 public SimulatorResourceModel getSelectedModel() {
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 && attributeElement.getPostState()) {
73 model.addAttribute(attributeElement
74 .getSimulatorResourceAttribute());
75 } catch (InvalidArgsException e) {