private void fillEAttribute(EObject container, JsonNode root) { final EClass eClass = container.eClass(); // Iterates over all key values of the JSON Object, // if the value is not an object then // if the key corresponds to an EAttribute, fill it // if not and the EClass contains a MapEntry, fill it with the key, value. for (Iterator<Entry<String, JsonNode>> it = root.getFields(); it.hasNext(); ) { Entry<String, JsonNode> field = it.next(); String key = field.getKey(); JsonNode value = field.getValue(); if (value.isObject()) // not an attribute continue; EAttribute attribute = getEAttribute(eClass, key); if (attribute != null && !attribute.isTransient() && !attribute.isDerived()) { if (value.isArray()) { for (Iterator<JsonNode> itValue = value.getElements(); itValue.hasNext(); ) { setEAttributeValue(container, attribute, itValue.next()); } } else { setEAttributeValue(container, attribute, value); } } else { EStructuralFeature eFeature = getDynamicMapEntryFeature(eClass); if (eFeature != null) { @SuppressWarnings("unchecked") EList<EObject> values = (EList<EObject>) container.eGet(eFeature); values.add(createEntry(key, value)); } } } }
/** * This defines which attributes are used for building the OCL condition. The default * implementation uses only the primitive types contained in {@link * ElementSetReferenceCreator#PRIMITIVE_TYPES} and enumeration types. * * <p>Furthermore, all derived attributes are ignored. This is due to an issue with UML models. * * <p>Subclasses may override this to refine the set of types. * * @param eAttribute An {@link EAttribute} in the transformation. * @return <code>true</code>, if the attribute should be part of the condition; <code>false</code> * otherwise. */ protected boolean isRelevantAttribute(EAttribute eAttribute) { // is it an enumeration? if (eAttribute.getEType() instanceof EEnum) { return true; } // is it one of the supported primitive types? return PRIMITIVE_TYPES.contains(eAttribute.getEType().getInstanceClassName()) && !eAttribute.isDerived(); }