Skip to content

Commit 0052262

Browse files
committed
Refactoring and add logic for anonymous elements
1 parent 53f2902 commit 0052262

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/serializer/RdfModelCreatorVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ public ElementModel visitProperty( final Property property, final ModelElement c
646646
model.add( serializeDescriptions( resource, property ) );
647647

648648
property.getExampleValue().ifPresent( exampleValue -> {
649-
final ElementModel exampleValueElementModel = ( exampleValue ).accept( this, property );
649+
final ElementModel exampleValueElementModel = exampleValue.accept( this, property );
650650
model.add( exampleValueElementModel.model() );
651651
exampleValueElementModel.focusElement().ifPresent( exampleValueNode ->
652652
model.add( resource, SammNs.SAMM.exampleValue(), exampleValueNode ) );

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/metamodel/builder/SammBuilder.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import static org.eclipse.esmf.metamodel.DataTypes.dataTypeByUri;
1717
import static org.eclipse.esmf.metamodel.DataTypes.xsd;
18-
import static org.eclipse.esmf.metamodel.Elements.*;
18+
import static org.eclipse.esmf.metamodel.Elements.samm_e;
1919

2020
import java.math.BigInteger;
2121
import java.net.URI;
@@ -1391,20 +1391,33 @@ public static ScalarValue value( final double doubleValue ) {
13911391
public static ScalarValue value( final Object value, final Scalar type ) {
13921392
MetaModelBaseAttributes metaModelBaseAttributes;
13931393

1394-
if ( value instanceof ScalarValue scalarValue ) {
1395-
metaModelBaseAttributes = MetaModelBaseAttributes.builder()
1396-
.withUrn( scalarValue.urn() )
1397-
.withPreferredNames( scalarValue.getPreferredNames() )
1398-
.withDescriptions( scalarValue.getDescriptions() )
1399-
.withSee( scalarValue.getSee() )
1400-
.isAnonymous( scalarValue.isAnonymous() )
1401-
.withSourceFile( scalarValue.getSourceFile() )
1402-
.build();
1394+
if ( value instanceof ModelElement modelElement ) {
1395+
boolean hasUrn = modelElement.urn() != null;
1396+
1397+
MetaModelBaseAttributes.Builder builder = MetaModelBaseAttributes.builder()
1398+
.isAnonymous( !hasUrn );
1399+
1400+
if ( hasUrn ) {
1401+
builder.withUrn( modelElement.urn() );
1402+
} else if ( !builder.build().isAnonymous() ) {
1403+
throw new IllegalStateException( "Non-anonymous ModelElement must have a URN: " + modelElement );
1404+
}
1405+
1406+
if ( modelElement instanceof ScalarValue scalarValue ) {
1407+
builder
1408+
.withPreferredNames( scalarValue.getPreferredNames() )
1409+
.withDescriptions( scalarValue.getDescriptions() )
1410+
.withSee( scalarValue.getSee() )
1411+
.withSourceFile( scalarValue.getSourceFile() );
1412+
}
1413+
1414+
metaModelBaseAttributes = builder.build();
14031415
} else {
14041416
metaModelBaseAttributes = MetaModelBaseAttributes.builder()
1405-
.isAnonymous( false )
1417+
.isAnonymous( true )
14061418
.build();
14071419
}
1420+
14081421
return new DefaultScalarValue( metaModelBaseAttributes, value, dataTypeByUri( type.getUrn() ) );
14091422
}
14101423

0 commit comments

Comments
 (0)