Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not assume Schema Locations are pointing to a Resource it can be an EObject #24

Closed
adaussy opened this issue Nov 20, 2023 · 0 comments · Fixed by #25
Closed

Do not assume Schema Locations are pointing to a Resource it can be an EObject #24

adaussy opened this issue Nov 20, 2023 · 0 comments · Fixed by #25

Comments

@adaussy
Copy link
Contributor

adaussy commented Nov 20, 2023

The current implementation assume that the URI located in schemaLocation attribute points to a resource. It not always the case it could target directly a EPackage inside a Resource. It is especially the case when dealing with UML profile.

org.eclipse.sirius.emfjson.utils.GsonEObjectDeserializer.deserialize(JsonElement, Type, JsonDeserializationContext)

 @Override
    public List<EObject> deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
       ...

        // schema location
        JsonObject jsonSchemaLocation = jsonRoot.getAsJsonObject(IGsonConstants.SCHEMA_LOCATION);
        if (jsonSchemaLocation != null) {
            Set<Entry<String, JsonElement>> schemaLocationSet = jsonSchemaLocation.entrySet();
            for (Entry<String, JsonElement> entry : schemaLocationSet) {
                String schemaLocation = entry.getValue().getAsString();

                if (this.resourceSet != null && schemaLocation != null && schemaLocation.length() > 0) {
                    URI uri = URI.createURI(schemaLocation);
                    if (this.uriHandler != null) {
                        uri = this.uriHandler.resolve(uri);
                    }
                    // TODO: in condition, add a test for extendedMetaData (see line 2898 of
                    // XMLHandler.class)
                    uri = this.helper.resolve(uri, this.resourceURI);
                    Resource ePackageResource = this.resourceSet.getResource(uri, true);
                    TreeIterator<EObject> iterator = ePackageResource.getAllContents();
                    while (iterator.hasNext()) {
                        EObject eObject = iterator.next();
                        if (eObject instanceof EPackage) {
                            EPackage ePackage = (EPackage) eObject;
                            this.resourceSet.getPackageRegistry().put(ePackage.getNsURI(), ePackage);
                        }
                    }
                }
            }
        }


        ...
    }

I think we need to check if a fragment is present an if it is directly use resourceSet.getEObject(URI).

Here is a model than can be used to check.

DynamicProfileTypeTests.profile.uml.zip

xsi:schemaLocation="http://www.eclipse.org/uml2/schemas/Ecore/5 pathmap://UML_PROFILES/Ecore.profile.uml#_z1OFcHjqEdy8S4Cr8Rc_NA"
adaussy added a commit to adaussy/sirius-emf-json that referenced this issue Nov 27, 2023
adaussy added a commit to adaussy/sirius-emf-json that referenced this issue Dec 4, 2023
sbegaudeau pushed a commit to adaussy/sirius-emf-json that referenced this issue Dec 5, 2023
sbegaudeau pushed a commit to adaussy/sirius-emf-json that referenced this issue Dec 5, 2023
@sbegaudeau sbegaudeau linked a pull request Dec 5, 2023 that will close this issue
sbegaudeau pushed a commit that referenced this issue Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant