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);
}
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);
}
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);
}
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();
}
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();
}
}
}
Aggregations