Search in sources :

Example 1 with EStructuralFeature

use of org.eclipse.emf.ecore.EStructuralFeature in project openhab1-addons by openhab.

the class ConfigurationHandler method fillupConfig.

/**
     * Fills in the configuration into the configuration object and adds it to the {@link OHConfig}.
     *
     * @param ohtfDevice The device specific configuration object {@link OHTFDevice}.
     * @param deviceConfig The device configuration as {@code Map} of {@code Strings}.
     * @throws ConfigurationException
     */
private void fillupConfig(OHTFDevice<?, ?> ohtfDevice, Map<String, String> deviceConfig) throws ConfigurationException {
    String uid = deviceConfig.get(ConfigKey.uid.name());
    if (uid == null || uid.equals("")) {
        // das kommt hier gar nie an
        logger.error("===== uid missing");
        throw new ConfigurationException(deviceConfig.toString(), "config is an invalid missing uid: openhab.cfg has to be fixed!");
    } else {
        logger.debug("*** uid is \"{}\"", uid);
    }
    ohtfDevice.setUid(uid);
    String subid = deviceConfig.get(ConfigKey.subid.name());
    if (subid != null) {
        if (!ohtfDevice.isValidSubId(subid)) {
            throw new ConfigurationException(subid, String.format("\"%s\" is an invalid subId: openhab.cfg has to be fixed!", subid));
        }
        logger.trace("fillupConfig ohtfDevice subid {}", subid);
        ohtfDevice.setSubid(subid);
    }
    if (ohConfig.getConfigByTFId(uid, subid) != null) {
        throw new ConfigurationException(String.format("uid: %s subId: %s", uid, subid), String.format("%s: duplicate device config for uid \"%s\" and subId \"%s\": fix openhab.cfg", LoggerConstants.CONFIG, uid, subid));
    }
    String symbolicName = deviceConfig.get(ConfigKeyAdmin.ohId.name());
    if (ohConfig.getConfigByOHId(symbolicName) != null) {
        throw new ConfigurationException(String.format("symbolic name: %s", symbolicName), String.format("%s: duplicate device config for symbolic name \"%s\": fix openhab.cfg", LoggerConstants.CONFIG, symbolicName));
    }
    ohtfDevice.setOhid(symbolicName);
    EObject tfConfig = ohtfDevice.getTfConfig();
    EList<EStructuralFeature> features = null;
    if (tfConfig != null) {
        features = tfConfig.eClass().getEAllStructuralFeatures();
    }
    ArrayList<String> configKeyList = new ArrayList<String>();
    for (ConfigKeyAdmin configKey : ConfigKeyAdmin.values()) {
        configKeyList.add(configKey.toString());
    }
    for (String property : deviceConfig.keySet()) {
        if (configKeyList.contains(property)) {
            continue;
        } else {
            logger.trace("{} found  property {}", LoggerConstants.CONFIG, property);
        }
        if (features != null) {
            for (EStructuralFeature feature : features) {
                logger.trace("found feature: {}", feature.getName());
                if (feature.getName().equals(property)) {
                    logger.trace("{} feature type {}", LoggerConstants.CONFIG, feature.getEType().getInstanceClassName());
                    logger.debug("configuring feature: {} for uid {} subid {}", feature.getName(), uid, subid);
                    String className = feature.getEType().getInstanceClassName();
                    if (className.equals("int") || className.equals("java.lang.Integer")) {
                        tfConfig.eSet(feature, Integer.parseInt(deviceConfig.get(property)));
                    } else if (className.equals("short") || className.equals("java.lang.Short")) {
                        tfConfig.eSet(feature, Short.parseShort(deviceConfig.get(property)));
                    } else if (className.equals("long") || className.equals("java.lang.Long")) {
                        tfConfig.eSet(feature, Long.parseLong(deviceConfig.get(property)));
                    } else if (className.equals("boolean") || className.equals("java.lang.Boolean")) {
                        logger.debug("{} found boolean value", LoggerConstants.CONFIG);
                        tfConfig.eSet(feature, Boolean.parseBoolean(deviceConfig.get(property)));
                    } else if (className.equals("java.lang.String")) {
                        logger.debug("{} found String value", LoggerConstants.CONFIG);
                        tfConfig.eSet(feature, deviceConfig.get(property));
                    } else if (className.equals("java.math.BigDecimal")) {
                        logger.debug("{} found BigDecimal value", LoggerConstants.CONFIG);
                        tfConfig.eSet(feature, new BigDecimal(deviceConfig.get(property)));
                    // } else if (feature.getEType().getInstanceClassName().equals("EList")){
                    // logger.debug("{} found EList value", LoggerConstants.CONFIG);
                    // List<String> strings = new
                    // ArrayList<String>(Arrays.asList(deviceConfig.get(property).trim().split("\\s+")));
                    // tfConfig.eSet(feature, strings);
                    } else {
                        throw new ConfigurationException(feature.getName(), "unsupported configuration type needed: " + className);
                    }
                    break;
                }
            }
        }
    }
    ohConfig.getOhTfDevices().add(ohtfDevice);
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) EObject(org.eclipse.emf.ecore.EObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal)

Example 2 with EStructuralFeature

use of org.eclipse.emf.ecore.EStructuralFeature in project tdi-studio-se by Talend.

the class AssignmentPropertySection method getItemPropertyDescriptor.

private IItemPropertyDescriptor getItemPropertyDescriptor() {
    // PTODO mhelleboid find another way to itempropertysource without an eobject
    BusinessAssignment sampleBusinessAssignment = BusinessFactory.eINSTANCE.createBusinessAssignment();
    EStructuralFeature businessAssignment_Comment = BusinessPackage.eINSTANCE.getBusinessAssignment_Comment();
    IItemPropertySource itemPropertySource = EmfPropertyHelper.getItemPropertySource(adapterFactory, sampleBusinessAssignment);
    return EmfPropertyHelper.getItemPropertyDescriptor(itemPropertySource, sampleBusinessAssignment, businessAssignment_Comment);
}
Also used : BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) IItemPropertySource(org.eclipse.emf.edit.provider.IItemPropertySource)

Example 3 with EStructuralFeature

use of org.eclipse.emf.ecore.EStructuralFeature in project tdi-studio-se by Talend.

the class BusinessAssignmentComposite method getItemPropertyDescriptor.

private IItemPropertyDescriptor getItemPropertyDescriptor() {
    // PTODO mhelleboid find another way to itempropertysource without an eobject
    BusinessAssignment sampleBusinessAssignment = BusinessFactory.eINSTANCE.createBusinessAssignment();
    EStructuralFeature businessAssignment_Comment = BusinessPackage.eINSTANCE.getBusinessAssignment_Comment();
    IItemPropertySource itemPropertySource = EmfPropertyHelper.getItemPropertySource(adapterFactory, sampleBusinessAssignment);
    return EmfPropertyHelper.getItemPropertyDescriptor(itemPropertySource, sampleBusinessAssignment, businessAssignment_Comment);
}
Also used : BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) IItemPropertySource(org.eclipse.emf.edit.provider.IItemPropertySource)

Example 4 with EStructuralFeature

use of org.eclipse.emf.ecore.EStructuralFeature in project tdi-studio-se by Talend.

the class BusinessStructuralFeaturesParser method getStringByPattern.

/**
     * @generated
     */
protected String getStringByPattern(IAdaptable adapter, int flags, String pattern, MessageFormat processor) {
    EObject element = (EObject) adapter.getAdapter(EObject.class);
    List values = new ArrayList(features.size());
    for (Iterator it = features.iterator(); it.hasNext(); ) {
        EStructuralFeature feature = (EStructuralFeature) it.next();
        Object value = element.eGet(feature);
        value = getValidValue(feature, value);
        values.add(value);
    }
    return processor.format(values.toArray(new Object[values.size()]), new StringBuffer(), new FieldPosition(0)).toString();
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ArrayList(java.util.ArrayList) List(java.util.List) EObject(org.eclipse.emf.ecore.EObject) FieldPosition(java.text.FieldPosition)

Example 5 with EStructuralFeature

use of org.eclipse.emf.ecore.EStructuralFeature in project benchmarx by eMoflon.

the class ChangeRecorder method notifyChanged.

public void notifyChanged(Notification n) {
    super.notifyChanged(n);
    if (n.getEventType() == Notification.REMOVING_ADAPTER)
        return;
    EObject affectedElement = (EObject) n.getNotifier();
    EStructuralFeature feature = (EStructuralFeature) n.getFeature();
    if (feature == null) {
        System.out.println("This comes unexpected.");
    }
    if (feature instanceof EReference) {
        EReference reference = (EReference) feature;
        if (reference.getUpperBound() == 1) {
            if (reference.isContainment()) {
                this.WriteStartChange("CompositionChange", feature);
                this.WriteElement(affectedElement, "affectedElement");
                if (n.getOldValue() != null) {
                    this.WriteElement((EObject) n.getOldValue(), "oldValue");
                }
                buffer.append(">\n");
                if (n.getNewValue() != null) {
                    this.WriteFullElement((EObject) n.getNewValue(), "newValue");
                }
                this.WriteEndChange("CompositionChange");
            } else {
                if (reference.isContainer())
                    return;
                this.WriteStartChange("AssociationChange", feature);
                if (n.getNewValue() != null) {
                    this.WriteElement((EObject) n.getNewValue(), "newValue");
                }
                if (n.getOldValue() != null) {
                    this.WriteElement((EObject) n.getOldValue(), "oldValue");
                }
                this.WriteElement(affectedElement, "affectedElement");
                this.WriteSelfClosingChange();
            }
        } else if (reference.isOrdered()) {
            int position = n.getPosition();
            if (reference.isContainment()) {
                if (n.getEventType() == Notification.ADD) {
                    this.WriteStartChange("CompositionListInsertion", feature);
                    this.WriteElement(affectedElement, "affectedElement");
                    this.WritePosition(position);
                    buffer.append(">\n");
                    this.WriteFullElement((EObject) n.getNewValue(), "addedElement");
                    this.WriteEndChange("CompositionListInsertion");
                } else if (n.getEventType() == Notification.REMOVE) {
                    this.WriteStartChange("CompositionListDeletion", feature);
                    this.WriteElement((EObject) n.getOldValue(), "deletedElement");
                    this.WriteElement(affectedElement, "affectedElement");
                    this.WritePosition(position);
                    this.WriteSelfClosingChange();
                } else {
                    buffer.append("(Change type not supported)");
                }
            } else {
                if (reference.isContainer())
                    return;
                if (n.getEventType() == Notification.ADD) {
                    this.WriteStartChange("AssociationListInsertion", feature);
                    this.WriteElement((EObject) n.getNewValue(), "addedElement");
                } else if (n.getEventType() == Notification.REMOVE) {
                    this.WriteStartChange("AssociationListDeletion", feature);
                    this.WriteElement((EObject) n.getOldValue(), "deletedElement");
                } else {
                    buffer.append("(Change type not supported)");
                }
                this.WriteElement(affectedElement, "affectedElement");
                this.WritePosition(position);
                this.WriteSelfClosingChange();
            }
        } else {
            if (reference.isContainment()) {
                if (n.getEventType() == Notification.ADD) {
                    this.WriteStartChange("CompositionCollectionInsertion", feature);
                    this.WriteElement(affectedElement, "affectedElement");
                    buffer.append(">\n");
                    this.WriteFullElement((EObject) n.getNewValue(), "addedElement");
                    this.WriteEndChange("CompositionCollectionInsertion");
                } else if (n.getEventType() == Notification.REMOVE) {
                    this.WriteStartChange("CompositionCollectionDeletion", feature);
                    this.WriteElement((EObject) n.getOldValue(), "deletedElement");
                    this.WriteElement(affectedElement, "affectedElement");
                    this.WriteSelfClosingChange();
                } else {
                    System.out.println("Change type not supported");
                }
            } else {
                if (n.getEventType() == Notification.ADD) {
                    this.WriteStartChange("AssociationCollectionInsertion", feature);
                    this.WriteElement((EObject) n.getNewValue(), "addedElement");
                } else if (n.getEventType() == Notification.REMOVE) {
                    this.WriteStartChange("AssociationCollectionDeletion", feature);
                    this.WriteElement((EObject) n.getOldValue(), "deletedElement");
                } else {
                    buffer.append("(Change type not supported)");
                }
                this.WriteElement(affectedElement, "affectedElement");
                this.WriteSelfClosingChange();
            }
        }
    } else {
        if (feature.getUpperBound() == 1) {
            this.WriteStartChange("AttributeChange", feature);
            if (n.getNewStringValue() != null) {
                this.WriteAttribute("newValue", toCompatibleString(n.getNewValue()));
            }
            if (n.getOldStringValue() != null) {
                this.WriteAttribute("oldValue", toCompatibleString(n.getOldValue()));
            }
            this.WriteElement(affectedElement, "affectedElement");
            this.WriteSelfClosingChange();
        } else if (feature.isOrdered()) {
            int position = n.getPosition();
            if (n.getEventType() == Notification.ADD) {
                this.WriteStartChange("AttributeListInsertion", feature);
                this.WriteAttribute("addedValue", n.getNewStringValue());
            } else if (n.getEventType() == Notification.REMOVE) {
                this.WriteStartChange("AttributeListDeletion", feature);
                this.WriteAttribute("deletedValue", n.getOldStringValue());
            } else {
                buffer.append("(Change type not supported)");
            }
            this.WriteElement(affectedElement, "affectedElement");
            this.WritePosition(position);
            this.WriteSelfClosingChange();
        } else {
            if (n.getEventType() == Notification.ADD) {
                this.WriteStartChange("AttributeCollectionInsertion", feature);
                this.WriteAttribute("addedValue", n.getNewStringValue());
            } else if (n.getEventType() == Notification.REMOVE) {
                this.WriteStartChange("AttributeCollectionDeletion", feature);
                this.WriteAttribute("deletedValue", n.getOldStringValue());
            } else {
                System.out.println("Change type not supported");
            }
            this.WriteElement(affectedElement, "affectedElement");
            this.WriteSelfClosingChange();
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)6 EObject (org.eclipse.emf.ecore.EObject)4 ArrayList (java.util.ArrayList)2 IItemPropertySource (org.eclipse.emf.edit.provider.IItemPropertySource)2 BusinessAssignment (org.talend.designer.business.model.business.BusinessAssignment)2 BigDecimal (java.math.BigDecimal)1 FieldPosition (java.text.FieldPosition)1 Iterator (java.util.Iterator)1 List (java.util.List)1 EReference (org.eclipse.emf.ecore.EReference)1 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)1 CompositeTransactionalCommand (org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1