Search in sources :

Example 6 with Root

use of org.obeonetwork.dsl.entity.Root in project InformationSystem by ObeoNetwork.

the class MLDToEntity method getTargetNamespace.

protected Namespace getTargetNamespace(TableContainer tableContainer) {
    if (!cacheTableContainerToNamespace.containsKey(tableContainer)) {
        Namespace targetNamespace = null;
        // First we look for a namespace with the right name
        String namespaceName = tableContainer.getName();
        // Look for a namespace with the right name
        targetNamespace = getNamespaceByName(namespaceName);
        if (targetNamespace == null) {
            if (defaultTarget instanceof Namespace) {
                if (EntityUtils.getEntitiesInNamespace((Namespace) defaultTarget).isEmpty()) {
                    // We consider the namespace is contained is a newly created model
                    // we can change its physical name
                    targetNamespace = (Namespace) defaultTarget;
                    AnnotationHelper.setPhysicalNameAnnotation(targetNamespace, namespaceName);
                }
            } else if (defaultTarget instanceof Root) {
                Root entityRoot = (Root) defaultTarget;
                if (entityRoot.getOwnedNamespaces().size() == 1 && EntityUtils.getEntitiesInNamespace(entityRoot.getOwnedNamespaces().get(0)).isEmpty()) {
                    targetNamespace = entityRoot.getOwnedNamespaces().get(0);
                    AnnotationHelper.setPhysicalNameAnnotation(targetNamespace, namespaceName);
                }
            }
            // We create a namespace if the target object is a entity root
            if (targetNamespace == null) {
                targetNamespace = createNamespace(namespaceName);
            }
            // Last solution, can occur only if the default target is a non empty namespace, we then select it
            if (targetNamespace == null) {
                if (defaultTarget instanceof Namespace) {
                    targetNamespace = (Namespace) defaultTarget;
                }
            }
        }
        cacheTableContainerToNamespace.put(tableContainer, targetNamespace);
    }
    Namespace namespace = cacheTableContainerToNamespace.get(tableContainer);
    // Ensure description is taken from tableContainer's comments
    namespace.setDescription(tableContainer.getComments());
    return namespace;
}
Also used : Root(org.obeonetwork.dsl.entity.Root) Namespace(org.obeonetwork.dsl.environment.Namespace)

Example 7 with Root

use of org.obeonetwork.dsl.entity.Root in project InformationSystem by ObeoNetwork.

the class AbstractTransformationTest method getRootObject.

private EObject getRootObject(URI modelURI) {
    ResourceSet set = getResourceSet();
    Resource resource = set.getResource(modelURI, true);
    for (Iterator<EObject> it = resource.getAllContents(); it.hasNext(); ) {
        EObject object = it.next();
        if (object instanceof TableContainer || object instanceof Root || object instanceof Namespace || object instanceof ScaffoldInfo) {
            return object;
        }
    }
    return null;
}
Also used : Root(org.obeonetwork.dsl.entity.Root) TableContainer(org.obeonetwork.dsl.database.TableContainer) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) ScaffoldInfo(fr.gouv.mindef.safran.database.scaffold.ScaffoldInfo) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Namespace(org.obeonetwork.dsl.environment.Namespace)

Aggregations

Root (org.obeonetwork.dsl.entity.Root)7 Namespace (org.obeonetwork.dsl.environment.Namespace)5 EObject (org.eclipse.emf.ecore.EObject)2 TableContainer (org.obeonetwork.dsl.database.TableContainer)2 ScaffoldInfo (fr.gouv.mindef.safran.database.scaffold.ScaffoldInfo)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 EReference (org.eclipse.emf.ecore.EReference)1 Setting (org.eclipse.emf.ecore.EStructuralFeature.Setting)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)1 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)1 Entity (org.obeonetwork.dsl.entity.Entity)1 RootPropertiesEditionPart (org.obeonetwork.dsl.entity.parts.RootPropertiesEditionPart)1 Reference (org.obeonetwork.dsl.environment.Reference)1