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 org.oic.simulator;
19 import java.util.HashMap;
23 * This class represents the resource model of a resource. A resource model
24 * contains a set of attributes. It also represents the complex value type of an
27 public class SimulatorResourceModel {
29 private Map<String, AttributeValue> mValues = null;
32 * Constructs new {@link SimulatorResourceModel} object.
34 public SimulatorResourceModel() {
35 mValues = new HashMap<>();
39 * API to set an attribute to resource model. If an attribute exists with
40 * the given name, then it overwrites the existing value. Otherwise creates
44 * Name of the attribute.
46 * Value of the attribute.
48 * @throws InvalidArgsException
49 * This exception will be thrown on invalid input.
51 public void set(String attrName, AttributeValue value)
52 throws InvalidArgsException {
53 if (null == attrName || attrName.isEmpty())
54 throw new InvalidArgsException("Invalid attribute name!");
57 throw new InvalidArgsException("Attribute value is null!");
59 mValues.put(attrName, value);
63 * API to remove attribute from resource model.
66 * Name of the attribute.
68 * @return true if resource model has an attribute with the given name,
71 public boolean remove(String attrName) {
72 if (mValues.containsKey(attrName)) {
73 mValues.remove(attrName);
81 * API to get attribute by name.
84 * Name of the attribute.
86 * @return {@link SimulatorResourceAttribute}.
88 public AttributeValue get(String attrName) {
89 if (mValues.containsKey(attrName)) {
90 return mValues.get(attrName);
97 * API to get all attributes of the model.
99 * @return A map of {@link AttributeValue} objects with attribute name as
102 public Map<String, AttributeValue> get() {
107 * API to check whether resource model has an attribute with given name.
110 * Name of the attribute.
112 * @return true if resource model has an attribute with given name,
115 public boolean contains(String attrName) {
116 if (mValues.containsKey(attrName))
122 * API to get value type information of attribute.
125 * Name of the attribute.
127 * @return Attribute value type information {@link AttributeValue.TypeInfo
131 public AttributeValue.TypeInfo getType(String attrName) {
132 if (mValues.containsKey(attrName))
133 return mValues.get(attrName).typeInfo();
138 * API to get number of attributes present in resource model.
140 * @return Number of attributes present in resource model.
143 return mValues.size();
147 * These methods used by native layer.
149 @SuppressWarnings("unused")
150 private SimulatorResourceModel(Map<String, AttributeValue> values) {