Search in sources :

Example 1 with AnyType

use of org.eclipse.emf.ecore.xml.type.AnyType in project InformationSystem by ObeoNetwork.

the class ClassDiagramGenerator method getOptionalNodes.

private Map<String, Collection<EObject>> getOptionalNodes(Map<EObject, AnyType> eObjectToExtensionMap) {
    Map<String, Collection<EObject>> result = new HashMap<String, Collection<EObject>>();
    for (Entry<EObject, AnyType> entry : eObjectToExtensionMap.entrySet()) {
        AnyType anyType = entry.getValue();
        FeatureMap anyAttribute = anyType.getAnyAttribute();
        for (org.eclipse.emf.ecore.util.FeatureMap.Entry featureMapEntry : anyAttribute) {
            EStructuralFeature feature = featureMapEntry.getEStructuralFeature();
            if (GENERATOR_OPTIONAL_NODE.equals(feature.getName())) {
                String id = (String) featureMapEntry.getValue();
                // Put value into result map
                if (result.get(id) == null) {
                    result.put(id, new ArrayList<EObject>());
                }
                result.get(id).add(entry.getKey());
            }
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) EObject(org.eclipse.emf.ecore.EObject) Collection(java.util.Collection) AnyType(org.eclipse.emf.ecore.xml.type.AnyType)

Example 2 with AnyType

use of org.eclipse.emf.ecore.xml.type.AnyType in project InformationSystem by ObeoNetwork.

the class MigrationResourceHandler method processUnknownData.

protected void processUnknownData(final XMLResource resource) {
    final Map<EObject, AnyType> extMap = resource.getEObjectToExtensionMap();
    for (final EObject key : extMap.keySet()) {
        final AnyType value = extMap.get(key);
        handleUnknownData(key, value);
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) AnyType(org.eclipse.emf.ecore.xml.type.AnyType)

Example 3 with AnyType

use of org.eclipse.emf.ecore.xml.type.AnyType in project InformationSystem by ObeoNetwork.

the class ClassDiagramGenerator method removeOptionalElements.

private void removeOptionalElements(Collection<GenerationInfo> generationInfos, Resource vsmFromTemplate) {
    // Remove optional elements
    if (vsmFromTemplate instanceof XMLResource) {
        Map<EObject, AnyType> eObjectToExtensionMap = ((XMLResource) vsmFromTemplate).getEObjectToExtensionMap();
        Map<String, Collection<EObject>> optionalNodes = getOptionalNodes(eObjectToExtensionMap);
        for (Entry<String, Collection<EObject>> optionalNodeEntry : optionalNodes.entrySet()) {
            String optionalNodeId = optionalNodeEntry.getKey();
            if (optionalNodeId.startsWith("{")) {
                optionalNodeId = optionalNodeId.substring(1);
            }
            if (optionalNodeId.endsWith("}")) {
                optionalNodeId = optionalNodeId.substring(0, optionalNodeId.length() - 1);
            }
            // Check if we have informations on this node
            boolean toBeDeleted = false;
            for (GenerationInfo generationInfo : generationInfos) {
                Boolean optionalNodeActivated = generationInfo.getBooleanInfos().get(optionalNodeId);
                if (optionalNodeActivated == Boolean.FALSE) {
                    toBeDeleted = true;
                    break;
                }
            }
            if (toBeDeleted) {
                // Remove the node
                for (EObject object : optionalNodeEntry.getValue()) {
                    EcoreUtil.delete(object);
                }
            }
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Collection(java.util.Collection) AnyType(org.eclipse.emf.ecore.xml.type.AnyType) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)3 AnyType (org.eclipse.emf.ecore.xml.type.AnyType)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)1 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)1