Search in sources :

Example 1 with ModelPackage

use of org.openhab.binding.tinkerforge.internal.model.ModelPackage in project openhab1-addons by openhab.

the class ConfigurationHandler method checkTfType.

/**
     * Checks if the {@code deviceType} is known by the {@link Ecosystem}.
     *
     * @param ohId The name of the device found in openhab.cfg as {@code String}.
     * @param deviceType The device type found in openhab.cfg as {@code String}.
     * @throws ConfigurationException
     */
private void checkTfType(String ohId, String deviceType) throws ConfigurationException {
    ModelPackage modelPackage = ModelPackage.eINSTANCE;
    boolean deviceFound = false;
    for (EClassifier eClassifier : modelPackage.getEClassifiers()) {
        if (eClassifier instanceof EClass) {
            EList<EAttribute> attributes = ((EClass) eClassifier).getEAllAttributes();
            for (EAttribute attribute : attributes) {
                if (attribute.getName().equals("deviceType")) {
                    if (attribute.getDefaultValueLiteral().equals(deviceType)) {
                        deviceFound = true;
                        break;
                    }
                }
            }
        }
    }
    if (!deviceFound) {
        throw new ConfigurationException(ohId, "unknown device type: " + deviceType);
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) ConfigurationException(org.osgi.service.cm.ConfigurationException) ModelPackage(org.openhab.binding.tinkerforge.internal.model.ModelPackage) EClassifier(org.eclipse.emf.ecore.EClassifier)

Aggregations

EAttribute (org.eclipse.emf.ecore.EAttribute)1 EClass (org.eclipse.emf.ecore.EClass)1 EClassifier (org.eclipse.emf.ecore.EClassifier)1 ModelPackage (org.openhab.binding.tinkerforge.internal.model.ModelPackage)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1