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;
22 public class ModelProperty extends AttributeProperty {
24 private Map<String, Boolean> mRequiredAttributes;
25 private Map<String, AttributeProperty> mChildProperties;
29 mRequiredAttributes = new HashMap<>();
30 mChildProperties = new HashMap<>();
34 public boolean isModel() {
39 public ModelProperty asModel() {
43 public boolean add(String name, AttributeProperty property, boolean required) {
44 if (null == name || null == property) {
48 mChildProperties.put(name, property);
49 mRequiredAttributes.put(name, required);
53 public void remove(String name) {
54 mChildProperties.remove(name);
55 mRequiredAttributes.remove(name);
58 public AttributeProperty get(String name) {
59 return mChildProperties.get(name);
62 public Map<String, AttributeProperty> getChildProperties() {
63 return mChildProperties;
66 public boolean isRequired(String name) {
67 return mRequiredAttributes.get(name);
71 public boolean validate(AttributeValue value) {
72 return new ModelValueValidator(this).validate(value);
75 public boolean validate(SimulatorResourceModel model) {
76 for (Map.Entry<String, AttributeValue> attributeEntry : model.get()
78 AttributeProperty childProperty = get(attributeEntry.getKey());
79 if (null != childProperty
80 && !childProperty.validate(attributeEntry.getValue())) {