Java API implementation for changes in simulator resource model.
authorG S Senthil Kumar <senthil.gs@samsung.com>
Fri, 5 Feb 2016 17:42:26 +0000 (23:12 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Thu, 11 Feb 2016 01:24:17 +0000 (01:24 +0000)
1. Seperated AttributeProperty from SimulatorResourceModel.
2. Implemented different types of attribute property classes and their
   corresponding validation classes and made necessary changes in other classes
   according to these changes.

Change-Id: I4d4b51eeeceb4be17a6e519dd602b0de8ebfe0d3
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4955
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Radha Bhavani <radha.p@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
19 files changed:
service/simulator/java/sdk/src/org/oic/simulator/ArrayProperty.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/ArrayValueValidator.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/AttributeProperty.java
service/simulator/java/sdk/src/org/oic/simulator/AttributeValueValidation.java [deleted file]
service/simulator/java/sdk/src/org/oic/simulator/AttributeValueVisitor.java
service/simulator/java/sdk/src/org/oic/simulator/BooleanProperty.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/DoubleProperty.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/DoubleValueValidator.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/IntegerProperty.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/IntegerValueValidator.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/ModelProperty.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/ModelValueValidator.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceModel.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorResult.java
service/simulator/java/sdk/src/org/oic/simulator/StringProperty.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/StringValueValidator.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/client/SimulatorRemoteResource.java
service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorResource.java
service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorSingleResource.java

diff --git a/service/simulator/java/sdk/src/org/oic/simulator/ArrayProperty.java b/service/simulator/java/sdk/src/org/oic/simulator/ArrayProperty.java
new file mode 100644 (file)
index 0000000..cf90e61
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.oic.simulator;
+
+public class ArrayProperty extends AttributeProperty {
+
+    private int               mMin;
+    private int               mMax;
+    private boolean           mIsVariableSize;
+    private boolean           mIsUnique;
+    private AttributeProperty mElementProperty;
+    private boolean           mHasRange = false;
+
+    private ArrayProperty(int min, int max, boolean variableSize,
+            boolean unique, AttributeProperty elementProperty) {
+        super(Type.ARRAY);
+        mMin = min;
+        mMax = max;
+        mIsVariableSize = variableSize;
+        mIsUnique = unique;
+        mElementProperty = elementProperty;
+        mHasRange = true;
+    }
+
+    private ArrayProperty(boolean variableSize, boolean unique,
+            AttributeProperty elementProperty) {
+        super(Type.ARRAY);
+        mIsVariableSize = variableSize;
+        mIsUnique = unique;
+        mElementProperty = elementProperty;
+    }
+
+    @Override
+    public boolean isArray() {
+        return true;
+    }
+
+    @Override
+    public ArrayProperty asArray() {
+        return this;
+    }
+
+    public boolean hasRange() {
+        return mHasRange;
+    }
+
+    public int minItems() {
+        return mMin;
+    }
+
+    public int maxItems() {
+        return mMax;
+    }
+
+    public boolean isVariable() {
+        return mIsVariableSize;
+    }
+
+    public boolean isUnique() {
+        return mIsUnique;
+    }
+
+    public AttributeProperty getElementProperty() {
+        return mElementProperty;
+    }
+
+    @Override
+    public boolean validate(AttributeValue value) {
+        return new ArrayValueValidator(this).validate(value);
+    }
+
+    public static class Builder {
+        private int               mMin;
+        private int               mMax;
+        private boolean           mIsVariableSize  = false;
+        private boolean           mIsUnique        = false;
+        private AttributeProperty mElementProperty = null;
+        private boolean           mHasRange        = false;
+
+        public void setRange(int minItems, int maxItems) {
+            mMin = minItems;
+            mMax = maxItems;
+            mHasRange = true;
+        }
+
+        public void setVariableSize(boolean state) {
+            mIsVariableSize = state;
+        }
+
+        public void setUnique(boolean state) {
+            mIsUnique = state;
+        }
+
+        public void setElementProperty(AttributeProperty property) {
+            mElementProperty = property;
+        }
+
+        public ArrayProperty build() {
+            if (null == mElementProperty)
+                return null;
+
+            if (mHasRange)
+                return new ArrayProperty(mMin, mMax, mIsVariableSize,
+                        mIsUnique, mElementProperty);
+            return new ArrayProperty(mIsVariableSize, mIsUnique,
+                    mElementProperty);
+        }
+    }
+}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/ArrayValueValidator.java b/service/simulator/java/sdk/src/org/oic/simulator/ArrayValueValidator.java
new file mode 100644 (file)
index 0000000..fad211a
--- /dev/null
@@ -0,0 +1,497 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.oic.simulator;
+
+class ArrayValueValidator implements
+        AttributeValueVisitor.VisitingMethods<Boolean> {
+
+    private ArrayProperty mProperty = null;
+
+    ArrayValueValidator(ArrayProperty property) {
+        mProperty = property;
+    }
+
+    public boolean validate(AttributeValue value) {
+        AttributeValueVisitor visitor = new AttributeValueVisitor(value, this);
+        return (Boolean) visitor.visit();
+    }
+
+    @Override
+    public Boolean visitingValue(Integer value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isInteger()) {
+            return false;
+        }
+
+        for (Integer value : values) {
+            if (false == elementProperty.asInteger().validate(value))
+                return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isDouble()) {
+            return false;
+        }
+
+        for (Double value : values) {
+            if (false == elementProperty.asDouble().validate(value))
+                return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isBoolean()) {
+            return false;
+        }
+
+        for (Boolean value : values) {
+            if (false == elementProperty.asBoolean().validate(value))
+                return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(String[] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isInteger()) {
+            return false;
+        }
+
+        for (String value : values) {
+            if (false == elementProperty.asString().validate(value))
+                return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isInteger()) {
+            return false;
+        }
+
+        for (SimulatorResourceModel value : values) {
+            if (false == elementProperty.asModel().validate(value))
+                return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[][] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isArray()) {
+            return false;
+        }
+
+        ArrayValueValidator validator = new ArrayValueValidator(
+                elementProperty.asArray());
+        for (Integer[] value : values) {
+            if (false == validator.visitingValue(value))
+                return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[][] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isArray()) {
+            return false;
+        }
+
+        ArrayValueValidator validator = new ArrayValueValidator(
+                elementProperty.asArray());
+        for (Double[] value : values) {
+            if (false == validator.visitingValue(value))
+                return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[][] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isArray()) {
+            return false;
+        }
+
+        ArrayValueValidator validator = new ArrayValueValidator(
+                elementProperty.asArray());
+        for (Boolean[] value : values) {
+            if (false == validator.visitingValue(value))
+                return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(String[][] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isArray()) {
+            return false;
+        }
+
+        ArrayValueValidator validator = new ArrayValueValidator(
+                elementProperty.asArray());
+        for (String[] value : values) {
+            if (false == validator.visitingValue(value))
+                return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[][] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isArray()) {
+            return false;
+        }
+
+        ArrayValueValidator validator = new ArrayValueValidator(
+                elementProperty.asArray());
+        for (SimulatorResourceModel[] value : values) {
+            if (false == validator.visitingValue(value))
+                return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[][][] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isArray()) {
+            return false;
+        }
+
+        ArrayValueValidator validator = new ArrayValueValidator(
+                elementProperty.asArray());
+        for (Integer[][] value : values) {
+            if (false == validator.visitingValue(value))
+                return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[][][] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isArray()) {
+            return false;
+        }
+
+        ArrayValueValidator validator = new ArrayValueValidator(
+                elementProperty.asArray());
+        for (Double[][] value : values) {
+            if (false == validator.visitingValue(value))
+                return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[][][] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isArray()) {
+            return false;
+        }
+
+        ArrayValueValidator validator = new ArrayValueValidator(
+                elementProperty.asArray());
+        for (Boolean[][] value : values) {
+            if (false == validator.visitingValue(value))
+                return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(String[][][] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isArray()) {
+            return false;
+        }
+
+        ArrayValueValidator validator = new ArrayValueValidator(
+                elementProperty.asArray());
+        for (String[][] value : values) {
+            if (false == validator.visitingValue(value))
+                return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[][][] values) {
+        if (null == mProperty)
+            return false;
+
+        // Validating length of array
+        if (mProperty.hasRange()) {
+            if (values.length < mProperty.minItems()
+                    || (values.length > mProperty.maxItems() && !mProperty
+                            .isVariable())) {
+                return false;
+            }
+        }
+
+        // Validating elements of array
+        AttributeProperty elementProperty = mProperty.getElementProperty();
+        if (!elementProperty.isArray()) {
+            return false;
+        }
+
+        ArrayValueValidator validator = new ArrayValueValidator(
+                elementProperty.asArray());
+        for (SimulatorResourceModel[][] value : values) {
+            if (false == validator.visitingValue(value))
+                return false;
+        }
+
+        return true;
+    }
+}
index 5f8d2fb..3015214 100644 (file)
@@ -19,150 +19,69 @@ package org.oic.simulator;
 /**
  * This class represents the resource attribute's value property.
  */
-public class AttributeProperty {
+public abstract class AttributeProperty {
 
-    private Type              mType          = Type.UNKNOWN;
-    private double            mMin           = -1;
-    private double            mMax           = -1;
-    private AttributeValue[]  mValueSet      = null;
-    private AttributeProperty mChildProperty = null;
-
-    /**
-     * Enum to represent property type.
-     */
     public enum Type {
-        UNKNOWN, RANGE, VALUESET
+        INTEGER, DOUBLE, BOOLEAN, STRING, MODEL, ARRAY
     }
 
-    /**
-     * Constructs {@link AttributeProperty} of type
-     * {@link AttributeProperty.Type#RANGE} with min and max values.
-     *
-     * @param min
-     *            Minimum value the attribute can have.
-     * @param max
-     *            Maximum value the attribute can have.
-     */
-    public AttributeProperty(double min, double max) {
-        mType = Type.RANGE;
-        mMin = min;
-        mMax = max;
+    private Type mType;
+
+    protected AttributeProperty(Type type) {
+        mType = type;
     }
 
-    /**
-     * Constructs {@link AttributeProperty} of type
-     * {@link AttributeProperty.Type#VALUESET} with array of integer.
-     *
-     * @param values
-     *            Array of int type values.
-     */
-    public AttributeProperty(int[] values) {
-        mType = Type.VALUESET;
-        mValueSet = new AttributeValue[values.length];
-        for (int i = 0; i < values.length; i++)
-            mValueSet[i] = new AttributeValue(values[i]);
+    public Type getType() {
+        return mType;
     }
 
-    /**
-     * Constructs {@link AttributeProperty} of type
-     * {@link AttributeProperty.Type#VALUESET} with array of double.
-     *
-     * @param values
-     *            Array of double type values.
-     */
-    public AttributeProperty(double[] values) {
-        mType = Type.VALUESET;
-        mValueSet = new AttributeValue[values.length];
-        for (int i = 0; i < values.length; i++)
-            mValueSet[i] = new AttributeValue(values[i]);
+    public boolean isInteger() {
+        return false;
     }
 
-    /**
-     * Constructs {@link AttributeProperty} of type
-     * {@link AttributeProperty.Type#VALUESET} with array of boolean.
-     *
-     * @param values
-     *            Array of boolean type values.
-     */
-    public AttributeProperty(boolean[] values) {
-        mType = Type.VALUESET;
-        mValueSet = new AttributeValue[values.length];
-        for (int i = 0; i < values.length; i++)
-            mValueSet[i] = new AttributeValue(values[i]);
+    public boolean isDouble() {
+        return false;
     }
 
-    /**
-     * Constructs {@link AttributeProperty} of type
-     * {@link AttributeProperty.Type#VALUESET} with array of Strings.
-     *
-     * @param values
-     *            Array of string type values.
-     */
-    public AttributeProperty(String[] values) {
-        mType = Type.VALUESET;
-        mValueSet = new AttributeValue[values.length];
-        for (int i = 0; i < values.length; i++)
-            mValueSet[i] = new AttributeValue(values[i]);
+    public boolean isBoolean() {
+        return false;
     }
 
-    /**
-     * API to get type of property.
-     *
-     * @return {@link AttributeProperty.Type}.
-     */
-    public Type type() {
-        return mType;
+    public boolean isString() {
+        return false;
     }
 
-    /**
-     * API to get minimum value which was set as property.
-     *
-     * @return Minimum value.
-     */
-    public double min() {
-        return mMin;
+    public boolean isArray() {
+        return false;
     }
 
-    /**
-     * API to get maximum value which was set as property.
-     *
-     * @return Maximum value.
-     */
-    public double max() {
-        return mMax;
+    public boolean isModel() {
+        return false;
     }
 
-    /**
-     * API to get array of values which was set as property.
-     *
-     * @return Array of {@link AttributeValue}.
-     */
-    public AttributeValue[] valueSet() {
-        return mValueSet;
+    public IntegerProperty asInteger() {
+        return null;
     }
 
-    /**
-     * API to set child attribute property.
-     *
-     * @param childProperty
-     *            Child element property used if the Attribute value is of array
-     *            type.
-     */
-    public void setChildProperty(AttributeProperty childProperty) {
-        mChildProperty = childProperty;
+    public DoubleProperty asDouble() {
+        return null;
     }
 
-    /**
-     * API to get child attribute property.
-     *
-     * @return Child element property.
-     */
-    public AttributeProperty getChildProperty() {
-        return mChildProperty;
+    public BooleanProperty asBoolean() {
+        return null;
     }
 
-    private AttributeProperty(AttributeValue[] values) {
-        mType = Type.VALUESET;
-        mValueSet = values;
+    public StringProperty asString() {
+        return null;
     }
+
+    public ArrayProperty asArray() {
+        return null;
+    }
+
+    public ModelProperty asModel() {
+        return null;
+    }
+
+    public abstract boolean validate(AttributeValue value);
 }
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/AttributeValueValidation.java b/service/simulator/java/sdk/src/org/oic/simulator/AttributeValueValidation.java
deleted file mode 100644 (file)
index 54bc4e1..0000000
+++ /dev/null
@@ -1,472 +0,0 @@
-/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.oic.simulator;
-
-/**
- * This class holds a set of methods for validating the attribute values of
- * different types using the given value properties {@link AttributeProperty}.
- */
-public class AttributeValueValidation implements
-        AttributeValueVisitor.VisitingMethods<Boolean> {
-    private AttributeProperty mProperty = null;
-
-    /**
-     * Constructs {@link AttributeValueValidation} with the given attribute
-     * value property.
-     *
-     * @param property
-     *            Attribute value property.
-     */
-    public AttributeValueValidation(AttributeProperty property) {
-        mProperty = property;
-    }
-
-    /**
-     * API to validate the given attribute value. The given value is said to be
-     * valid if it matches with the values given in the value property.
-     *
-     * @param value
-     *            {@link AttributeValue} to be validated.
-     * @return True if the given value is valid, otherwise false.
-     */
-    public boolean validate(AttributeValue value) {
-        AttributeValueVisitor visitor = new AttributeValueVisitor(value, this);
-        Boolean result = (Boolean) visitor.visit();
-        return result.booleanValue();
-    }
-
-    /**
-     * API to validate an Integer value.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(Integer value) {
-        if (mProperty == null)
-            return false;
-
-        if (checkRange(value.doubleValue()) || checkValueSet(value))
-            return true;
-        return false;
-    }
-
-    /**
-     * API to validate a Double value.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(Double value) {
-        if (mProperty == null)
-            return false;
-
-        if (checkRange(value.doubleValue()) || checkValueSet(value))
-            return true;
-        return false;
-    }
-
-    /**
-     * API to validate a Boolean value.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(Boolean value) {
-        if (mProperty == null)
-            return false;
-
-        if (checkValueSet(value))
-            return true;
-        return false;
-    }
-
-    /**
-     * API to validate a String value.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(String value) {
-        if (mProperty == null)
-            return false;
-
-        if (checkRange(value.length()) || checkValueSet(value))
-            return true;
-        return false;
-    }
-
-    /**
-     * API to validate a {@link SimulatorResourceModel} value.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(SimulatorResourceModel value) {
-        return false;
-    }
-
-    /**
-     * API to validate an array of integer values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(Integer[] values) {
-        if (mProperty == null)
-            return false;
-
-        if (!checkRange(values.length))
-            return false;
-
-        if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(
-                    mProperty.getChildProperty());
-            for (Integer value : values) {
-                if (rangeValidation.visitingValue(value) == false)
-                    return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * API to validate an array of double values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(Double[] values) {
-        if (mProperty == null)
-            return false;
-
-        if (!checkRange(values.length))
-            return false;
-
-        if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(
-                    mProperty.getChildProperty());
-            for (Double value : values) {
-                if (rangeValidation.visitingValue(value) == false)
-                    return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * API to validate an array of boolean values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(Boolean[] values) {
-        if (mProperty == null)
-            return false;
-
-        if (!checkRange(values.length))
-            return false;
-
-        if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(
-                    mProperty.getChildProperty());
-            for (Boolean value : values) {
-                if (rangeValidation.visitingValue(value) == false)
-                    return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * API to validate an array of string values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(String[] values) {
-        if (mProperty == null)
-            return false;
-
-        if (!checkRange(values.length))
-            return false;
-
-        if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(
-                    mProperty.getChildProperty());
-            for (String value : values) {
-                if (rangeValidation.visitingValue(value) == false)
-                    return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * API to validate an array of {@link SimulatorResourceModel} values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(SimulatorResourceModel[] value) {
-        return false;
-    }
-
-    /**
-     * API to validate a 2D array of integer values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(Integer[][] values) {
-        if (mProperty == null)
-            return false;
-
-        if (!checkRange(values.length))
-            return false;
-
-        if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(
-                    mProperty.getChildProperty());
-            for (Integer[] value : values) {
-                if (rangeValidation.visitingValue(value) == false)
-                    return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * API to validate a 2D array of double values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(Double[][] values) {
-        if (mProperty == null)
-            return false;
-
-        if (!checkRange(values.length))
-            return false;
-
-        if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(
-                    mProperty.getChildProperty());
-            for (Double[] value : values) {
-                if (rangeValidation.visitingValue(value) == false)
-                    return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * API to validate a 2D array of boolean values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(Boolean[][] values) {
-        if (mProperty == null)
-            return false;
-
-        if (!checkRange(values.length))
-            return false;
-
-        if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(
-                    mProperty.getChildProperty());
-            for (Boolean[] value : values) {
-                if (rangeValidation.visitingValue(value) == false)
-                    return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * API to validate a 2D array of string values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(String[][] values) {
-        if (mProperty == null)
-            return false;
-
-        if (!checkRange(values.length))
-            return false;
-
-        if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(
-                    mProperty.getChildProperty());
-            for (String[] value : values) {
-                if (rangeValidation.visitingValue(value) == false)
-                    return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * API to validate a 2D array of {@link SimulatorResourceModel} values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(SimulatorResourceModel[][] value) {
-        return false;
-    }
-
-    /**
-     * API to validate a 3D array of integer values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(Integer[][][] values) {
-        if (mProperty == null)
-            return false;
-
-        if (!checkRange(values.length))
-            return false;
-
-        if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(
-                    mProperty.getChildProperty());
-            for (Integer[][] value : values) {
-                if (rangeValidation.visitingValue(value) == false)
-                    return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * API to validate a 3D array of double values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(Double[][][] values) {
-        if (mProperty == null)
-            return false;
-
-        if (!checkRange(values.length))
-            return false;
-
-        if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(
-                    mProperty.getChildProperty());
-            for (Double[][] value : values) {
-                if (rangeValidation.visitingValue(value) == false)
-                    return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * API to validate a 3D array of boolean values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(Boolean[][][] values) {
-        if (mProperty == null)
-            return false;
-
-        if (!checkRange(values.length))
-            return false;
-
-        if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(
-                    mProperty.getChildProperty());
-            for (Boolean[][] value : values) {
-                if (rangeValidation.visitingValue(value) == false)
-                    return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * API to validate a 3D array of string values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(String[][][] values) {
-        if (mProperty == null)
-            return false;
-
-        if (!checkRange(values.length))
-            return false;
-
-        if (mProperty.getChildProperty() != null) {
-            AttributeValueValidation rangeValidation = new AttributeValueValidation(
-                    mProperty.getChildProperty());
-            for (String[][] value : values) {
-                if (rangeValidation.visitingValue(value) == false)
-                    return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * API to validate a 3D array of {@link SimulatorResourceModel} values.
-     *
-     * @return True if the given value is valid, otherwise false.
-     */
-    @Override
-    public Boolean visitingValue(SimulatorResourceModel[][][] value) {
-        return false;
-    }
-
-    private boolean checkRange(double value) {
-        if (AttributeProperty.Type.RANGE == mProperty.type()
-                && (value >= mProperty.min() && value <= mProperty.max())) {
-            return true;
-        }
-
-        return false;
-    }
-
-    private <T> boolean checkValueSet(T value) {
-        if (AttributeProperty.Type.VALUESET == mProperty.type()
-                && null != mProperty.valueSet()) {
-            for (AttributeValue allowedValue : mProperty.valueSet()) {
-                if (allowedValue.get().equals(value))
-                    return true;
-            }
-        }
-
-        return false;
-    }
-}
index 8a846a6..1dac15b 100644 (file)
@@ -35,35 +35,35 @@ public class AttributeValueVisitor {
 
         public T visitingValue(SimulatorResourceModel value);
 
-        public T visitingValue(Integer[] value);
+        public T visitingValue(Integer[] values);
 
-        public T visitingValue(Double[] value);
+        public T visitingValue(Double[] values);
 
-        public T visitingValue(Boolean[] value);
+        public T visitingValue(Boolean[] values);
 
-        public T visitingValue(String[] value);
+        public T visitingValue(String[] values);
 
-        public T visitingValue(SimulatorResourceModel[] value);
+        public T visitingValue(SimulatorResourceModel[] values);
 
-        public T visitingValue(Integer[][] value);
+        public T visitingValue(Integer[][] values);
 
-        public T visitingValue(Double[][] value);
+        public T visitingValue(Double[][] values);
 
-        public T visitingValue(Boolean[][] value);
+        public T visitingValue(Boolean[][] values);
 
-        public T visitingValue(String[][] value);
+        public T visitingValue(String[][] values);
 
-        public T visitingValue(SimulatorResourceModel[][] value);
+        public T visitingValue(SimulatorResourceModel[][] values);
 
-        public T visitingValue(Integer[][][] value);
+        public T visitingValue(Integer[][][] values);
 
-        public T visitingValue(Double[][][] value);
+        public T visitingValue(Double[][][] values);
 
-        public T visitingValue(Boolean[][][] value);
+        public T visitingValue(Boolean[][][] values);
 
-        public T visitingValue(String[][][] value);
+        public T visitingValue(String[][][] values);
 
-        public T visitingValue(SimulatorResourceModel[][][] value);
+        public T visitingValue(SimulatorResourceModel[][][] values);
     }
 
     /**
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/BooleanProperty.java b/service/simulator/java/sdk/src/org/oic/simulator/BooleanProperty.java
new file mode 100644 (file)
index 0000000..913e825
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.oic.simulator;
+
+public class BooleanProperty extends AttributeProperty {
+    private boolean mDefaultValue;
+
+    private BooleanProperty(boolean value) {
+        super(Type.BOOLEAN);
+        mDefaultValue = value;
+    }
+
+    @Override
+    public boolean isBoolean() {
+        return true;
+    }
+
+    @Override
+    public BooleanProperty asBoolean() {
+        return this;
+    }
+
+    public boolean getDefaultValue() {
+        return mDefaultValue;
+    }
+
+    @Override
+    public boolean validate(AttributeValue value) {
+        if (value.typeInfo().mType == AttributeValue.ValueType.BOOLEAN)
+            return true;
+        return false;
+    }
+
+    public boolean validate(boolean value) {
+        return true;
+    }
+
+    public static class Builder {
+        private boolean mDefaultValue = true;
+
+        public void setDefaultValue(boolean value) {
+            mDefaultValue = value;
+        }
+
+        public BooleanProperty build() {
+            return new BooleanProperty(mDefaultValue);
+        }
+    }
+}
\ No newline at end of file
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/DoubleProperty.java b/service/simulator/java/sdk/src/org/oic/simulator/DoubleProperty.java
new file mode 100644 (file)
index 0000000..95f5b9c
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.oic.simulator;
+
+import java.util.Arrays;
+
+public class DoubleProperty extends AttributeProperty {
+
+    private double   mDefaultValue;
+    private double   mMin;
+    private double   mMax;
+    private double[] mValues;
+    private boolean  mHasRange = false;
+
+    private DoubleProperty(double value) {
+        super(Type.DOUBLE);
+        mDefaultValue = value;
+    }
+
+    private DoubleProperty(double value, double min, double max) {
+        super(Type.DOUBLE);
+        mDefaultValue = value;
+        mMin = min;
+        mMax = max;
+        mHasRange = true;
+    }
+
+    private DoubleProperty(double value, double[] values) {
+        super(Type.DOUBLE);
+        mDefaultValue = value;
+        mValues = Arrays.copyOf(values, values.length);
+        Arrays.sort(mValues);
+    }
+
+    @Override
+    public boolean isDouble() {
+        return true;
+    }
+
+    @Override
+    public DoubleProperty asDouble() {
+        return this;
+    }
+
+    public double getDefaultValue() {
+        return mDefaultValue;
+    }
+
+    public boolean hasRange() {
+        return mHasRange;
+    }
+
+    public double min() {
+        return mMin;
+    }
+
+    public double max() {
+        return mMax;
+    }
+
+    public boolean hasValues() {
+        return (null != mValues && (mValues.length > 0));
+    }
+
+    public double[] getValues() {
+        return mValues;
+    }
+
+    @Override
+    public boolean validate(AttributeValue value) {
+        return new DoubleValueValidator(this).validate(value);
+    }
+
+    public boolean validate(double value) {
+        if (mHasRange && (value < mMin || value > mMax)) {
+            return false;
+        } else if (mValues.length > 0
+                && -1 == Arrays.binarySearch(mValues, value)) {
+            return false;
+        }
+
+        return true;
+    }
+
+    public static class Builder {
+        private double   mDefaultValue = 0;
+        private double   mMin;
+        private double   mMax;
+        private double[] mValues;
+        private boolean  mHasRange     = false;
+
+        public void setDefaultValue(double value) {
+            mDefaultValue = value;
+        }
+
+        public void setRange(double min, double max) {
+            mMin = min;
+            mMax = max;
+            mHasRange = true;
+        }
+
+        public void setValues(double[] values) {
+            mValues = values;
+        }
+
+        public DoubleProperty build() {
+            if (mHasRange)
+                return new DoubleProperty(mDefaultValue, mMin, mMax);
+            if (null != mValues && (0 != mValues.length))
+                return new DoubleProperty(mDefaultValue, mValues);
+            return new DoubleProperty(mDefaultValue);
+        }
+    }
+}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/DoubleValueValidator.java b/service/simulator/java/sdk/src/org/oic/simulator/DoubleValueValidator.java
new file mode 100644 (file)
index 0000000..e4111b8
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.oic.simulator;
+
+class DoubleValueValidator implements
+        AttributeValueVisitor.VisitingMethods<Boolean> {
+
+    private DoubleProperty mProperty = null;
+
+    DoubleValueValidator(DoubleProperty property) {
+        mProperty = property;
+    }
+
+    public boolean validate(AttributeValue value) {
+        AttributeValueVisitor visitor = new AttributeValueVisitor(value, this);
+        return (Boolean) visitor.visit();
+    }
+
+    @Override
+    public Boolean visitingValue(Integer value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double value) {
+        if (null != mProperty)
+            return mProperty.validate(value);
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[][][] value) {
+        return false;
+    }
+}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/IntegerProperty.java b/service/simulator/java/sdk/src/org/oic/simulator/IntegerProperty.java
new file mode 100644 (file)
index 0000000..0220718
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.oic.simulator;
+
+import java.util.Arrays;
+
+public class IntegerProperty extends AttributeProperty {
+    private int     mDefaultValue;
+    private int     mMin;
+    private int     mMax;
+    private int[]   mValues;
+    private boolean mHasRange = false;
+
+    private IntegerProperty(int value) {
+        super(Type.INTEGER);
+        mDefaultValue = value;
+    }
+
+    private IntegerProperty(int value, int min, int max) {
+        super(Type.INTEGER);
+        mDefaultValue = value;
+        mMin = min;
+        mMax = max;
+        mHasRange = true;
+    }
+
+    private IntegerProperty(int value, int[] values) {
+        super(Type.INTEGER);
+        mDefaultValue = value;
+        mValues = Arrays.copyOf(values, values.length);
+        Arrays.sort(mValues);
+    }
+
+    @Override
+    public boolean isInteger() {
+        return true;
+    }
+
+    @Override
+    public IntegerProperty asInteger() {
+        return this;
+    }
+
+    public int getDefaultValue() {
+        return mDefaultValue;
+    }
+
+    public boolean hasRange() {
+        return mHasRange;
+    }
+
+    public int min() {
+        return mMin;
+    }
+
+    public int max() {
+        return mMax;
+    }
+
+    public boolean hasValues() {
+        return (null != mValues && (mValues.length > 0));
+    }
+
+    public int[] getValues() {
+        return mValues;
+    }
+
+    @Override
+    public boolean validate(AttributeValue value) {
+        return new IntegerValueValidator(this).validate(value);
+    }
+
+    public boolean validate(int value) {
+        if (mHasRange && (value < mMin || value > mMax)) {
+            return false;
+        } else if (mValues.length > 0
+                && -1 == Arrays.binarySearch(mValues, value)) {
+            return false;
+        }
+
+        return true;
+    }
+
+    public static class Builder {
+        private int     mDefaultValue = 0;
+        private int     mMin;
+        private int     mMax;
+        private int[]   mValues;
+        private boolean mHasRange     = false;
+
+        public void setDefaultValue(int value) {
+            mDefaultValue = value;
+        }
+
+        public void setRange(int min, int max) {
+            mMin = min;
+            mMax = max;
+            mHasRange = true;
+        }
+
+        public void setValues(int[] values) {
+            mValues = values;
+        }
+
+        public IntegerProperty build() {
+            if (mHasRange)
+                return new IntegerProperty(mDefaultValue, mMin, mMax);
+            if (null != mValues && (0 != mValues.length))
+                return new IntegerProperty(mDefaultValue, mValues);
+            return new IntegerProperty(mDefaultValue);
+        }
+    }
+}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/IntegerValueValidator.java b/service/simulator/java/sdk/src/org/oic/simulator/IntegerValueValidator.java
new file mode 100644 (file)
index 0000000..787396f
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.oic.simulator;
+
+class IntegerValueValidator implements
+        AttributeValueVisitor.VisitingMethods<Boolean> {
+
+    private IntegerProperty mProperty = null;
+
+    IntegerValueValidator(IntegerProperty property) {
+        mProperty = property;
+    }
+
+    public boolean validate(AttributeValue value) {
+        AttributeValueVisitor visitor = new AttributeValueVisitor(value, this);
+        return (Boolean) visitor.visit();
+    }
+
+    @Override
+    public Boolean visitingValue(Integer value) {
+        if (null != mProperty)
+            return mProperty.validate(value);
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[][][] value) {
+        return false;
+    }
+}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/ModelProperty.java b/service/simulator/java/sdk/src/org/oic/simulator/ModelProperty.java
new file mode 100644 (file)
index 0000000..e62faa2
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.oic.simulator;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ModelProperty extends AttributeProperty {
+
+    private Map<String, Boolean>           mRequiredAttributes;
+    private Map<String, AttributeProperty> mChildProperties;
+
+    ModelProperty() {
+        super(Type.MODEL);
+        mRequiredAttributes = new HashMap<>();
+        mChildProperties = new HashMap<>();
+    }
+
+    @Override
+    public boolean isModel() {
+        return true;
+    }
+
+    @Override
+    public ModelProperty asModel() {
+        return this;
+    }
+
+    public boolean add(String name, AttributeProperty property, boolean required) {
+        if (null == name || null == property) {
+            return false;
+        }
+
+        mChildProperties.put(name, property);
+        mRequiredAttributes.put(name, required);
+        return true;
+    }
+
+    public void remove(String name) {
+        mChildProperties.remove(name);
+        mRequiredAttributes.remove(name);
+    }
+
+    public AttributeProperty get(String name) {
+        return mChildProperties.get(name);
+    }
+
+    public Map<String, AttributeProperty> getChildProperties() {
+        return mChildProperties;
+    }
+
+    public boolean isRequired(String name) {
+        return mRequiredAttributes.get(name);
+    }
+
+    @Override
+    public boolean validate(AttributeValue value) {
+        return new ModelValueValidator(this).validate(value);
+    }
+
+    public boolean validate(SimulatorResourceModel model) {
+        for (Map.Entry<String, AttributeValue> attributeEntry : model.get()
+                .entrySet()) {
+            AttributeProperty childProperty = get(attributeEntry.getKey());
+            if (null != childProperty
+                    && !childProperty.validate(attributeEntry.getValue())) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/ModelValueValidator.java b/service/simulator/java/sdk/src/org/oic/simulator/ModelValueValidator.java
new file mode 100644 (file)
index 0000000..93e7ecc
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.oic.simulator;
+
+class ModelValueValidator implements
+        AttributeValueVisitor.VisitingMethods<Boolean> {
+
+    private ModelProperty mProperty = null;
+
+    ModelValueValidator(ModelProperty property) {
+        mProperty = property;
+    }
+
+    public boolean validate(AttributeValue value) {
+        AttributeValueVisitor visitor = new AttributeValueVisitor(value, this);
+        return (Boolean) visitor.visit();
+    }
+
+    @Override
+    public Boolean visitingValue(Integer value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel value) {
+        if (null != mProperty)
+            return mProperty.validate(value);
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[][][] value) {
+        return false;
+    }
+}
index 65623c7..6ea68a9 100644 (file)
@@ -21,24 +21,24 @@ import java.util.Map;
 
 /**
  * This class represents the resource model of a resource. A resource model
- * contains a set of attributes and their properties. It represents the complex
- * value type of an attribute.
+ * contains a set of attributes. It also represents the complex value type of an
+ * attribute.
  */
 public class SimulatorResourceModel {
 
-    private Map<String, AttributeValue>    mValues     = null;
-    private Map<String, AttributeProperty> mProperties = null;
+    private Map<String, AttributeValue> mValues = null;
 
     /**
      * Constructs new {@link SimulatorResourceModel} object.
      */
     public SimulatorResourceModel() {
         mValues = new HashMap<>();
-        mProperties = new HashMap<>();
     }
 
     /**
-     * API to add an attribute to resource model.
+     * API to set an attribute to resource model. If an attribute exists with
+     * the given name, then it overwrites the existing value. Otherwise creates
+     * a new attribute.
      *
      * @param attrName
      *            Name of the attribute.
@@ -48,7 +48,7 @@ public class SimulatorResourceModel {
      * @throws InvalidArgsException
      *             This exception will be thrown on invalid input.
      */
-    public void addAttribute(String attrName, AttributeValue value)
+    public void set(String attrName, AttributeValue value)
             throws InvalidArgsException {
         if (null == attrName || attrName.isEmpty())
             throw new InvalidArgsException("Invalid attribute name!");
@@ -60,84 +60,21 @@ public class SimulatorResourceModel {
     }
 
     /**
-     * API to add an attribute to resource model.
-     *
-     * @param attribute
-     *            {@link SimulatorResourceAttribute} to be added to resource
-     *            model.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown on invalid input.
-     */
-    public void addAttribute(SimulatorResourceAttribute attribute)
-            throws InvalidArgsException {
-        if (null == attribute || null == attribute.name()
-                || attribute.name().isEmpty() || null == attribute.value())
-            throw new InvalidArgsException("Invalid attribute!");
-
-        mValues.put(attribute.name(), attribute.value());
-    }
-
-    /**
-     * API to set attribute's property.
-     *
-     * @param attrName
-     *            Name of the attribute.
-     * @param property
-     *            {@link AttributeProperty} to be set for attribute.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown on invalid input.
-     */
-    public void setAttributeProperty(String attrName, AttributeProperty property)
-            throws InvalidArgsException {
-        if (null == attrName || attrName.isEmpty())
-            throw new InvalidArgsException("Invalid attribute!");
-
-        if (null == property)
-            throw new InvalidArgsException("Invalid attribute property!");
-
-        mProperties.put(attrName, property);
-    }
-
-    /**
-     * API to set attribute's value.
+     * API to remove attribute from resource model.
      *
      * @param attrName
      *            Name of the attribute.
-     * @param value
-     *            {@link AttributeValue} to be set for attribute.
-     *
-     * @throws InvalidArgsException
-     *             This exception will be thrown on invalid input.
-     */
-    public void setAttributeValue(String attrName, AttributeValue value)
-            throws InvalidArgsException {
-        if (null == attrName || attrName.isEmpty())
-            throw new InvalidArgsException("Invalid attribute name!");
-
-        if (null == value)
-            throw new InvalidArgsException("Attribute value is null!");
-
-        mValues.put(attrName, value);
-    }
-
-    /**
-     * API to get all the attributes of resource model.
      *
-     * @return Map of attributes with attribute name as key and its
-     *         corresponding {@link SimulatorResourceAttribute} as value.
+     * @return true if resource model has an attribute with the given name,
+     *         otherwise false.
      */
-    public Map<String, SimulatorResourceAttribute> getAttributes() {
-        Map<String, SimulatorResourceAttribute> attributes = new HashMap<>();
-        for (Map.Entry<String, AttributeValue> entry : mValues.entrySet()) {
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    entry.getKey(), entry.getValue(), mProperties.get(entry
-                            .getKey()));
-            attributes.put(entry.getKey(), attribute);
+    public boolean remove(String attrName) {
+        if (mValues.containsKey(attrName)) {
+            mValues.remove(attrName);
+            return true;
         }
 
-        return attributes;
+        return false;
     }
 
     /**
@@ -148,17 +85,25 @@ public class SimulatorResourceModel {
      *
      * @return {@link SimulatorResourceAttribute}.
      */
-    public SimulatorResourceAttribute getAttribute(String attrName) {
+    public AttributeValue get(String attrName) {
         if (mValues.containsKey(attrName)) {
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    attrName, mValues.get(attrName), mProperties.get(attrName));
-            return attribute;
+            return mValues.get(attrName);
         }
 
         return null;
     }
 
     /**
+     * API to get all attributes of the model.
+     *
+     * @return A map of {@link AttributeValue} objects with attribute name as
+     *         the key.
+     */
+    public Map<String, AttributeValue> get() {
+        return mValues;
+    }
+
+    /**
      * API to check whether resource model has an attribute with given name.
      *
      * @param attrName
@@ -167,7 +112,7 @@ public class SimulatorResourceModel {
      * @return true if resource model has an attribute with given name,
      *         otherwise false.
      */
-    public boolean containsAttribute(String attrName) {
+    public boolean contains(String attrName) {
         if (mValues.containsKey(attrName))
             return true;
         return false;
@@ -180,36 +125,16 @@ public class SimulatorResourceModel {
      *            Name of the attribute.
      *
      * @return Attribute value type information {@link AttributeValue.TypeInfo
-     * 
+     *
      * }.
      */
-    public AttributeValue.TypeInfo getAttributeType(String attrName) {
+    public AttributeValue.TypeInfo getType(String attrName) {
         if (mValues.containsKey(attrName))
             return mValues.get(attrName).typeInfo();
         return null;
     }
 
     /**
-     * API to remove attribute from resource model.
-     *
-     * @param attrName
-     *            Name of the attribute.
-     *
-     * @return true if resource model has an attribute with the given name,
-     *         otherwise false.
-     */
-    public boolean removeAttribute(String attrName) {
-        if (mValues.containsKey(attrName)) {
-            mValues.remove(attrName);
-            if (mProperties.containsKey(attrName))
-                mProperties.remove(attrName);
-            return true;
-        }
-
-        return false;
-    }
-
-    /**
      * API to get number of attributes present in resource model.
      *
      * @return Number of attributes present in resource model.
@@ -219,38 +144,10 @@ public class SimulatorResourceModel {
     }
 
     /**
-     * API to update the attribute values from given
-     * {@link SimulatorResourceModel}.
-     * 
-     * @param resourceModel
-     *            {@link SimulatorResourceModel} holding the new attribute
-     *            values.
+     * These methods used by native layer.
      */
-    public void update(SimulatorResourceModel resourceModel) {
-        if (null == resourceModel || 0 == resourceModel.size())
-            return;
-
-        for (Map.Entry<String, SimulatorResourceAttribute> entry : resourceModel
-                .getAttributes().entrySet()) {
-            SimulatorResourceAttribute newAttribute = entry.getValue();
-            SimulatorResourceAttribute attribute = getAttribute(entry.getKey());
-            if (null != newAttribute && null != attribute) {
-                if (null != attribute.property()) {
-                    AttributeValueValidation validation = new AttributeValueValidation(
-                            attribute.property());
-                    if (!validation.validate(newAttribute.value())) {
-                        mValues.put(entry.getKey(), newAttribute.value());
-                    }
-                } else {
-                    mValues.put(entry.getKey(), newAttribute.value());
-                }
-            }
-        }
-    }
-
-    private SimulatorResourceModel(Map<String, AttributeValue> values,
-            Map<String, AttributeProperty> properties) {
+    @SuppressWarnings("unused")
+    private SimulatorResourceModel(Map<String, AttributeValue> values) {
         mValues = values;
-        mProperties = properties;
     }
 }
index c1ca1c7..96de7e3 100644 (file)
@@ -29,7 +29,7 @@ public enum SimulatorResult {
     /** Simulator specific error codes - START */
     SIMULATOR_INVALID_TYPE, SIMULATOR_NOT_SUPPORTED, SIMULATOR_OPERATION_NOT_ALLOWED, SIMULATOR_OPERATION_IN_PROGRESS,
 
-    SIMULATOR_INVALID_RESPONSE_CODE, SIMULATOR_UKNOWN_PROPERTY, SIMULATOR_TYPE_MISMATCH, SIMULATOR_BAD_VALUE, SIMULATOR_BAD_OBJECT,
+    SIMULATOR_INVALID_RESPONSE_CODE, SIMULATOR_UKNOWN_PROPERTY, SIMULATOR_TYPE_MISMATCH, SIMULATOR_BAD_VALUE, SIMULATOR_BAD_OBJECT, SIMULATOR_BAD_SCHEMA,
     /** Simulator specific error codes - END */
 
     SIMULATOR_ERROR;
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/StringProperty.java b/service/simulator/java/sdk/src/org/oic/simulator/StringProperty.java
new file mode 100644 (file)
index 0000000..39945eb
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.oic.simulator;
+
+import java.util.Arrays;
+
+public class StringProperty extends AttributeProperty {
+
+    private String   mDefaultValue;
+    private int      mMin;
+    private int      mMax;
+    private String[] mValues;
+    private boolean  mHasRange = false;
+
+    private StringProperty(String value) {
+        super(Type.STRING);
+        mDefaultValue = value;
+    }
+
+    private StringProperty(String value, int min, int max) {
+        super(Type.STRING);
+        mDefaultValue = value;
+        mMin = min;
+        mMax = max;
+        mHasRange = true;
+    }
+
+    private StringProperty(String value, String[] values) {
+        super(Type.STRING);
+        mDefaultValue = value;
+        mValues = values;
+    }
+
+    @Override
+    public boolean isString() {
+        return true;
+    }
+
+    @Override
+    public StringProperty asString() {
+        return this;
+    }
+
+    public String getDefaultValue() {
+        return mDefaultValue;
+    }
+
+    public boolean hasRange() {
+        return mHasRange;
+    }
+
+    public int min() {
+        return mMin;
+    }
+
+    public int max() {
+        return mMax;
+    }
+
+    public boolean hasValues() {
+        return (null != mValues && (mValues.length > 0));
+    }
+
+    public String[] getValues() {
+        return mValues;
+    }
+
+    @Override
+    public boolean validate(AttributeValue value) {
+        return new StringValueValidator(this).validate(value);
+    }
+
+    public boolean validate(String value) {
+        int length = value.length();
+        if (mHasRange && (length < mMin || length > mMax)) {
+            return false;
+        } else if (mValues.length > 0
+                && -1 == Arrays.binarySearch(mValues, value)) {
+            return false;
+        }
+
+        return true;
+    }
+
+    public static class Builder {
+        private String   mDefaultValue = new String();
+        private int      mMin;
+        private int      mMax;
+        private String[] mValues;
+        private boolean  mHasRange     = false;
+
+        public void setDefaultValue(String value) {
+            if (null != value)
+                mDefaultValue = value;
+        }
+
+        public void setRange(int min, int max) {
+            mMin = min;
+            mMax = max;
+            mHasRange = true;
+        }
+
+        public void setValues(String[] values) {
+            mValues = values;
+        }
+
+        public StringProperty build() {
+            if (mHasRange)
+                return new StringProperty(mDefaultValue, mMin, mMax);
+            if (null != mValues && (0 != mValues.length))
+                return new StringProperty(mDefaultValue, mValues);
+            return new StringProperty(mDefaultValue);
+        }
+    }
+}
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/StringValueValidator.java b/service/simulator/java/sdk/src/org/oic/simulator/StringValueValidator.java
new file mode 100644 (file)
index 0000000..2ef06d2
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.oic.simulator;
+
+class StringValueValidator implements
+        AttributeValueVisitor.VisitingMethods<Boolean> {
+
+    private StringProperty mProperty = null;
+
+    StringValueValidator(StringProperty property) {
+        mProperty = property;
+    }
+
+    public boolean validate(AttributeValue value) {
+        AttributeValueVisitor visitor = new AttributeValueVisitor(value, this);
+        return (Boolean) visitor.visit();
+    }
+
+    @Override
+    public Boolean visitingValue(Integer value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String value) {
+        if (null != mProperty)
+            return mProperty.validate(value);
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Integer[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Double[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(Boolean[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(String[][][] value) {
+        return false;
+    }
+
+    @Override
+    public Boolean visitingValue(SimulatorResourceModel[][][] value) {
+        return false;
+    }
+}
index 519b1d7..c1e6927 100644 (file)
@@ -32,7 +32,6 @@ import org.oic.simulator.SimulatorResult;
  * perform different operations or subscribe for event notifications.
  */
 public final class SimulatorRemoteResource {
-
     private long           mNativeHandle;
     private String         mUri;
     private int            mConnType;
@@ -77,6 +76,24 @@ public final class SimulatorRemoteResource {
     }
 
     /**
+     * API to get the address detail of the resource.
+     *
+     * @return Host address.
+     */
+    public String getHost() {
+        return mHost;
+    }
+
+    /**
+     * API to get a unique Id of the resource.
+     *
+     * @return Unique ID.
+     */
+    public String getId() {
+        return mId;
+    }
+
+    /**
      * API to get the connectivity type for this resource.
      *
      * @return Connectivity type.
@@ -104,24 +121,6 @@ public final class SimulatorRemoteResource {
     }
 
     /**
-     * API to get the address detail of the resource.
-     *
-     * @return Host address.
-     */
-    public String getHost() {
-        return mHost;
-    }
-
-    /**
-     * API to get a unique Id of the resource.
-     *
-     * @return Unique ID.
-     */
-    public String getId() {
-        return mId;
-    }
-
-    /**
      * API to get the observe policy of this resource.
      *
      * @return True if the resource is observable, otherwise false.
@@ -300,6 +299,29 @@ public final class SimulatorRemoteResource {
     /**
      * API to start observing the resource.
      *
+     * @param type
+     *            Type of observation.
+     * @param onObserveListener
+     *            The handler method which will be invoked with a map of
+     *            attribute names and values whenever there is a change in
+     *            resource model of the remote resource.
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown if any parameter has invalid
+     *             values.
+     * @throws SimulatorException
+     *             This exception will be thrown for other errors.
+     */
+    public void observe(ObserveNotificationListener onObserveListener)
+            throws InvalidArgsException, SimulatorException {
+        startObserve(null, onObserveListener);
+    }
+
+    /**
+     * API to start observing the resource.
+     *
+     * @param type
+     *            Type of observation.
      * @param queryParams
      *            Map which can have the query parameter names and values.
      * @param onObserveListener
@@ -313,9 +335,15 @@ public final class SimulatorRemoteResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native void startObserve(Map<String, String> queryParams,
+    public void observe(Map<String, String> queryParams,
             ObserveNotificationListener onObserveListener)
-            throws InvalidArgsException, SimulatorException;
+            throws InvalidArgsException, SimulatorException {
+        if (null == queryParams)
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM,
+                    "Invalid Query Parameters!");
+        startObserve(queryParams, onObserveListener);
+    }
 
     /**
      * API to stop observing the resource.
@@ -518,6 +546,9 @@ public final class SimulatorRemoteResource {
             SimulatorResourceModel representation,
             PostResponseListener onPostListener);
 
+    private native void startObserve(Map<String, String> queryParams,
+            ObserveNotificationListener onObserveListener);
+
     private native int startVerification(int type,
             VerificationListener onVerifyListener);
 }
index 78f2d0f..3a39ac1 100644 (file)
@@ -19,6 +19,7 @@ package org.oic.simulator.server;
 import java.util.Vector;
 
 import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.NoSupportException;
 import org.oic.simulator.SimulatorException;
 import org.oic.simulator.SimulatorResourceModel;
 
@@ -64,15 +65,18 @@ public class SimulatorResource {
     }
 
     /**
-     * API to get the name of the resource.
+     * API which indicates whether the resource is collection or single
+     * resource.
      *
-     * @return Name of the resource.
+     * @return True if the resource is collection, otherwise false.
      *
      * @throws SimulatorException
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native String getName() throws SimulatorException;
+    public boolean isCollection() {
+        return (this instanceof SimulatorCollectionResource);
+    }
 
     /**
      * API to get the type which indicates whether resource is single or
@@ -84,7 +88,24 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native Type getType() throws SimulatorException;
+    public Type getType() {
+        if (this instanceof SimulatorSingleResource) {
+            return Type.SINGLE;
+        } else {
+            return Type.COLLECTION;
+        }
+    }
+
+    /**
+     * API to get the name of the resource.
+     *
+     * @return Name of the resource.
+     *
+     * @throws SimulatorException
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
+     */
+    public native String getName() throws SimulatorException;
 
     /**
      * API to get the resource URI.
@@ -132,27 +153,27 @@ public class SimulatorResource {
     public native boolean isObservable() throws SimulatorException;
 
     /**
-     * API to get the start state of resource.
+     * API to get the discoverable state of resource.
      *
-     * @return Start state - true if resource is started, otherwise false.
+     * @return Discoverable state - true if resource is discoverable, otherwise
+     *         false.
      *
      * @throws SimulatorException
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native boolean isStarted() throws SimulatorException;
+    public native boolean isDiscoverable() throws SimulatorException;
 
     /**
-     * API to get the {@link SimulatorResourceModel} of the simulated resource.
+     * API to get the start state of resource.
      *
-     * @return {@link SimulatorResourceModel} object on success, otherwise null.
+     * @return Start state - true if resource is started, otherwise false.
      *
      * @throws SimulatorException
-     *             This exception will be thrown if simulated resource is not
-     *             proper.
+     *             This exception will be thrown if the native resource object
+     *             does not exist or for some general errors.
      */
-    public native SimulatorResourceModel getResourceModel()
-            throws SimulatorException;
+    public native boolean isStarted() throws SimulatorException;
 
     /**
      * API to set the name of the resource.
@@ -203,41 +224,51 @@ public class SimulatorResource {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * API to add interface type for resource.
+     * API to set interface to resource. Resource should be stopped before
+     * calling this API.
      *
      * @param interfaceType
-     *            Interface to be added for resource.
+     *            Interface to be set.
      *
      * @throws InvalidArgsException
      *             This exception will be thrown if the interface type is
      *             invalid.
      * @throws SimulatorException
      *             This exception will be thrown if the native resource object
-     *             does not exist or for some general errors.
+     *             does not exist or resource is still running or for some
+     *             general errors.
      */
-    public native void addInterface(String interfaceType)
+    public native void setInterface(String interfaceType)
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * API to remove interface type for resource.
+     * API to set a list of interfaces to resource. Resource should be stopped
+     * before calling this API.
+     *
+     * @param interfaceTypes
+     *            Interfaces to be set.
      *
-     * @param interfaceType
-     *            Interface to be remove for resource.
      * @throws InvalidArgsException
      *             This exception will be thrown if the interface type is
      *             invalid.
      * @throws SimulatorException
      *             This exception will be thrown if the native resource object
-     *             does not exist or for some general errors.
+     *             does not exist or resource is still running or for some
+     *             general errors.
      */
-    public native void removeInterface(String interfaceType)
+    public void setInterface(Vector<String> interfaceTypes)
+            throws InvalidArgsException, SimulatorException {
+        setInterfaces(interfaceTypes);
+    }
+
+    private native void setInterfaces(Vector<String> interfaceTypes)
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * API to add a list of interfaces for resource.
+     * API to add interface type for resource.
      *
      * @param interfaceType
-     *            List of interfaces to be added to the resource.
+     *            Interface to be added for resource.
      *
      * @throws InvalidArgsException
      *             This exception will be thrown if the interface type is
@@ -246,35 +277,33 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native void addInterfaces(Vector<String> interfaceType)
-            throws InvalidArgsException, SimulatorException;
+    public native void addInterface(String interfaceType)
+            throws InvalidArgsException, NoSupportException, SimulatorException;
 
     /**
-     * API to remove interface type for resource.
+     * API to make the resource observable or not observable.
+     *
+     * @param state
+     *            True makes the resource observable, otherwise non-observable.
      *
-     * @param interfaceType
-     *            List of interfaces to be removed from the resource.
-     * @throws InvalidArgsException
-     *             This exception will be thrown if the interface type is
-     *             invalid.
      * @throws SimulatorException
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native void removeInterfaces(Vector<String> interfaceType)
-            throws InvalidArgsException, SimulatorException;
+    public native void setObservable(boolean state) throws SimulatorException;
 
     /**
-     * API to make the resource observable or not.
+     * API to make the resource discoverable or not discoverable.
      *
      * @param state
-     *            True makes the resource observable, otherwise non-observable.
+     *            True makes the resource discoverable, otherwise
+     *            non-discoverable.
      *
      * @throws SimulatorException
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native void setObservable(boolean state) throws SimulatorException;
+    public native void setDiscoverable(boolean state) throws SimulatorException;
 
     /**
      * API to set the listener for receiving the notifications when observer is
@@ -327,6 +356,18 @@ public class SimulatorResource {
     public native void stop() throws SimulatorException;
 
     /**
+     * API to get the {@link SimulatorResourceModel} of the simulated resource.
+     *
+     * @return {@link SimulatorResourceModel} object on success, otherwise null.
+     *
+     * @throws SimulatorException
+     *             This exception will be thrown if simulated resource is not
+     *             proper.
+     */
+    public native SimulatorResourceModel getResourceModel()
+            throws SimulatorException;
+
+    /**
      * API to get observers which are registered with resource.
      *
      * @return observers as an array of {@link Observer}.
index ea6e9fb..e0e7b32 100644 (file)
@@ -16,6 +16,8 @@
 
 package org.oic.simulator.server;
 
+import java.util.Map;
+
 import org.oic.simulator.AttributeValue;
 import org.oic.simulator.InvalidArgsException;
 import org.oic.simulator.SimulatorException;
@@ -53,7 +55,24 @@ public final class SimulatorSingleResource extends SimulatorResource {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * API to add an attribute to resource's representation model.
+     * API to get all the attributes of the resource.
+     *
+     * @return Map of attributes with attribute name as key and its
+     *         corresponding {@link SimulatorResourceAttribute} as value.
+     *
+     * @throws InvalidArgsException
+     *             This exception will be thrown if the attribute name is
+     *             invalid.
+     * @throws SimulatorException
+     *             This exception will be thrown either if the resource model is
+     *             not found or for some general errors.
+     */
+    public native Map<String, SimulatorResourceAttribute> getAttributes()
+            throws InvalidArgsException, SimulatorException;
+
+    /**
+     * API to add an attribute to resource's representation model. Observers
+     * will be notified on success.
      *
      * @param attribute
      *            Attribute to be added to resource's representation model.
@@ -63,37 +82,39 @@ public final class SimulatorSingleResource extends SimulatorResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native void addAttribute(SimulatorResourceAttribute attribute)
+    public native boolean addAttribute(SimulatorResourceAttribute attribute)
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * API to update the value of an attribute.
+     * API to remove an attribute from the simulated resource. Observers will be
+     * notified on success.
      *
      * @param attrName
-     *            Name of the attribute.
-     * @param value
-     *            New value of the attribute.
+     *            Name of the attribute to be deleted.
      *
      * @throws InvalidArgsException
      *             This exception will be thrown on invalid input.
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native void updateAttribute(String attrName, AttributeValue value)
+    public native boolean removeAttribute(String attrName)
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * API to remove an attribute from the simulated resource.
+     * API to update the value of an attribute. Observers will be notified on
+     * success.
      *
      * @param attrName
-     *            Name of the attribute to be deleted.
+     *            Name of the attribute.
+     * @param value
+     *            New value of the attribute.
      *
      * @throws InvalidArgsException
      *             This exception will be thrown on invalid input.
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native void removeAttribute(String attrName)
+    public native boolean updateAttribute(String attrName, AttributeValue value)
             throws InvalidArgsException, SimulatorException;
 
     /**