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.serviceprovider.model;
19 import java.util.HashMap;
22 import oic.simulator.serviceprovider.manager.UiListenerHandler;
24 import org.oic.simulator.AttributeValue;
25 import org.oic.simulator.SimulatorResourceAttribute;
26 import org.oic.simulator.SimulatorResourceModel;
28 public class ResourceRepresentation {
29 private Map<String, AttributeElement> mAttributes = new HashMap<String, AttributeElement>();
31 public ResourceRepresentation(
32 Map<String, SimulatorResourceAttribute> attributes)
33 throws NullPointerException {
34 if (attributes != null && attributes.size() > 0) {
35 for (Map.Entry<String, SimulatorResourceAttribute> entry : attributes
37 mAttributes.put(entry.getKey(), new AttributeElement(this,
38 entry.getValue(), true));
43 public Map<String, AttributeElement> getAttributes() {
47 public void update(SimulatorResourceModel model) {
51 for (Map.Entry<String, AttributeValue> entry : model.get().entrySet()) {
52 AttributeElement attributeElement = mAttributes.get(entry.getKey());
53 if (null != attributeElement) {
54 if (!attributeElement.getEditLock())
55 attributeElement.update(new SimulatorResourceAttribute(
56 entry.getKey(), entry.getValue()));
58 // Display new attribute in UI
59 AttributeElement newAttribute = new AttributeElement(this,
60 new SimulatorResourceAttribute(entry.getKey(),
61 entry.getValue()), true);
62 mAttributes.put(entry.getKey(), newAttribute);
64 UiListenerHandler.getInstance().attributeAddedUINotification(