sdt: throw an exception if a Light has no binarySwitch module.
binarySwitch module is mandatory for a Light device.
Signed-off-by: BOLLE Sebastien <sebastien.bolle@orange.com>
Signed-off-by: Cyrille Bareau <cyrille.bareau@orange.com>
Signed-off-by: BONNARDEL Gregory <gbonnardel.ext@orange.com>
diff --git a/org.eclipse.om2m.ipe.sample.sdt/src/main/java/org/eclipse/om2m/ipe/sample/sdt/model/SampleModel.java b/org.eclipse.om2m.ipe.sample.sdt/src/main/java/org/eclipse/om2m/ipe/sample/sdt/model/SampleModel.java
index a5a79f7..a32f367 100644
--- a/org.eclipse.om2m.ipe.sample.sdt/src/main/java/org/eclipse/om2m/ipe/sample/sdt/model/SampleModel.java
+++ b/org.eclipse.om2m.ipe.sample.sdt/src/main/java/org/eclipse/om2m/ipe/sample/sdt/model/SampleModel.java
@@ -26,6 +26,7 @@
import org.apache.commons.logging.LogFactory;
import org.eclipse.om2m.sdt.exceptions.AccessException;
import org.eclipse.om2m.sdt.exceptions.DataPointException;
+import org.eclipse.om2m.sdt.exceptions.ModuleException;
import org.eclipse.om2m.sdt.home.devices.Light;
import org.eclipse.om2m.sdt.home.modules.Colour;
@@ -47,7 +48,11 @@
*/
public static void setLampState(final String lampId, boolean value) throws DataPointException, AccessException {
Light light = getLamp(lampId);
- light.getBinarySwitch().setPowerState(value);
+ try {
+ light.getBinarySwitch().setPowerState(value);
+ } catch (ModuleException e) {
+ throw new DataPointException(e);
+ }
}
/**
@@ -58,7 +63,11 @@
* @throws DataPointException
*/
public static boolean getLampValue(String lampId) throws DataPointException, AccessException {
- return getLamp(lampId).getBinarySwitch().getPowerState();
+ try {
+ return getLamp(lampId).getBinarySwitch().getPowerState();
+ } catch (ModuleException e) {
+ throw new DataPointException(e);
+ }
}
public static void setColor(int red, int green, int blue) throws DataPointException, AccessException {
diff --git a/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.api/src/main/java/org/eclipse/om2m/sdt/exceptions/ModuleException.java b/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.api/src/main/java/org/eclipse/om2m/sdt/exceptions/ModuleException.java
new file mode 100644
index 0000000..e7a0bad
--- /dev/null
+++ b/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.api/src/main/java/org/eclipse/om2m/sdt/exceptions/ModuleException.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2016 Orange.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.om2m.sdt.exceptions;
+
+public class ModuleException extends Exception {
+
+ public ModuleException() {
+ super();
+ }
+
+ public ModuleException(String message) {
+ super(message);
+ }
+
+ public ModuleException(Throwable cause) {
+ super(cause);
+ }
+
+ public ModuleException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home/src/main/java/org/eclipse/om2m/sdt/home/devices/Light.java b/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home/src/main/java/org/eclipse/om2m/sdt/home/devices/Light.java
index 86fc1a4..eb543b1 100644
--- a/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home/src/main/java/org/eclipse/om2m/sdt/home/devices/Light.java
+++ b/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home/src/main/java/org/eclipse/om2m/sdt/home/devices/Light.java
@@ -9,6 +9,7 @@
import org.eclipse.om2m.sdt.Domain;
import org.eclipse.om2m.sdt.Module;
+import org.eclipse.om2m.sdt.exceptions.ModuleException;
import org.eclipse.om2m.sdt.home.modules.BinarySwitch;
import org.eclipse.om2m.sdt.home.modules.Colour;
import org.eclipse.om2m.sdt.home.modules.ColourSaturation;
@@ -76,7 +77,9 @@
return faultDetection;
}
- public BinarySwitch getBinarySwitch() {
+ public BinarySwitch getBinarySwitch() throws ModuleException {
+ if (binarySwitch == null)
+ throw new ModuleException("Not implemented");
return binarySwitch;
}