1
1
/*
2
- * Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
2
+ * Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
3
3
*
4
4
* See the AUTHORS file(s) distributed with this work for additional
5
5
* information regarding authorship.
17
17
import java .io .FileInputStream ;
18
18
import java .io .IOException ;
19
19
import java .io .InputStream ;
20
+ import java .net .JarURLConnection ;
20
21
import java .net .URI ;
21
22
import java .nio .file .Path ;
22
23
import java .util .ArrayDeque ;
@@ -121,7 +122,7 @@ public AspectModelLoader( final ResolutionStrategy resolutionStrategy ) {
121
122
*/
122
123
public AspectModelLoader ( final List <ResolutionStrategy > resolutionStrategies ) {
123
124
TurtleLoader .init ();
124
- if ( resolutionStrategies .size () == 1 ) {
125
+ if ( 1 == resolutionStrategies .size () ) {
125
126
resolutionStrategy = resolutionStrategies .get ( 0 );
126
127
} else if ( resolutionStrategies .isEmpty () ) {
127
128
resolutionStrategy = DEFAULT_STRATEGY .get ();
@@ -416,7 +417,7 @@ public AspectModel loadNamespacePackage( final byte[] binaryContent, final URI l
416
417
* {@code https://example.com/package.zip}, the files in the package will have a location URI such as
417
418
* {@code jar:file:/some/path/package.zip!/com.example.namespace/1.0.0/AspectModel.ttl} or
418
419
* {@code jar:https://example.com/package.zip!/com.example.namespace/1.0.0/AspectModel.ttl}, respectively, as described in
419
- * the JavaDoc for {@link java.net. JarURLConnection}.
420
+ * the JavaDoc for {@link JarURLConnection}.
420
421
*
421
422
* @param location the source location
422
423
* @param inputStream the input stream to load the ZIP content from
@@ -473,7 +474,8 @@ private String replaceLegacyBammUrn( final String urn ) {
473
474
private boolean containsType ( final Model model , final String urn ) {
474
475
if ( model .contains ( model .createResource ( urn ), RDF .type , (RDFNode ) null ) ) {
475
476
return true ;
476
- } else if ( urn .startsWith ( AspectModelUrn .PROTOCOL_AND_NAMESPACE_PREFIX ) ) {
477
+ }
478
+ if ( urn .startsWith ( AspectModelUrn .PROTOCOL_AND_NAMESPACE_PREFIX ) ) {
477
479
// when deriving a URN from file (via "fileToUrn" method - mainly in samm-cli scenarios),
478
480
// we assume new "samm" format, but could actually have been the old "bamm"
479
481
return model .contains ( model .createResource ( toLegacyBammUrn ( urn ) ), RDF .type , (RDFNode ) null );
@@ -495,7 +497,7 @@ private Optional<AspectModelFile> applyResolutionStrategy( final String urn ) {
495
497
496
498
try {
497
499
final AspectModelUrn aspectModelUrn = AspectModelUrn .fromUrn ( replaceLegacyBammUrn ( urn ) );
498
- if ( aspectModelUrn . getElementType () != ElementType . NONE ) {
500
+ if ( ElementType . NONE != aspectModelUrn . getElementType () ) {
499
501
return Optional .empty ();
500
502
}
501
503
final AspectModelFile resolutionResult = resolutionStrategy .apply ( aspectModelUrn , this );
@@ -586,14 +588,18 @@ private void resolve( final List<AspectModelFile> inputFiles, final LoaderContex
586
588
@ Override
587
589
public boolean containsDefinition ( final AspectModelFile aspectModelFile , final AspectModelUrn urn ) {
588
590
final Model model = aspectModelFile .sourceModel ();
591
+ boolean result = model .contains ( model .createResource ( urn .toString () ), RDF .type , (RDFNode ) null );
592
+ if ( result ) {
593
+ LOG .debug ( "Checking if model contains {}: {}" , urn , result );
594
+ return result ;
595
+ }
589
596
if ( model .getNsPrefixMap ().values ().stream ().anyMatch ( prefixUri -> prefixUri .startsWith ( "urn:bamm:" ) ) ) {
590
- final boolean result = model .contains (
597
+ result = model .contains (
591
598
model .createResource ( urn .toString ().replace ( AspectModelUrn .PROTOCOL_AND_NAMESPACE_PREFIX , "urn:bamm:" ) ), RDF .type ,
592
599
(RDFNode ) null );
593
600
LOG .debug ( "Checking if model contains {}: {}" , urn , result );
594
601
return result ;
595
602
}
596
- final boolean result = model .contains ( model .createResource ( urn .toString () ), RDF .type , (RDFNode ) null );
597
603
LOG .debug ( "Checking if model contains {}: {}" , urn , result );
598
604
return result ;
599
605
}
@@ -674,7 +680,7 @@ public AspectModel loadAspectModelFiles( final Collection<AspectModelFile> input
674
680
.findFirst ()
675
681
.ifPresent ( aspect -> mergedModel .setNsPrefix ( "" , aspect .urn ().getUrnPrefix () ) );
676
682
for ( final AspectModelFile file : files ) {
677
- if ( file .aspects ().size () > 1 ) {
683
+ if ( 1 < file .aspects ().size () ) {
678
684
throw new AspectLoadingException (
679
685
"Aspect Model file " + file .humanReadableLocation () + " contains " + file .aspects ().size ()
680
686
+ " aspects, but may only contain one." );
@@ -709,7 +715,7 @@ private void setNamespaces( final Collection<AspectModelFile> files, final Colle
709
715
MetaModelBaseAttributes namespaceDefinition = null ;
710
716
AspectModelFile fileContainingNamespaceDefinition = null ;
711
717
final List <ModelElement > elementsForUrn = elementsGroupedByNamespaceUrn .get ( namespaceUrn );
712
- if ( elementsForUrn != null ) {
718
+ if ( null != elementsForUrn ) {
713
719
for ( final ModelElement element : elementsForUrn ) {
714
720
final AspectModelFile elementFile = element .getSourceFile ();
715
721
if ( elementFile .sourceModel ().contains ( null , RDF .type , SammNs .SAMM .Namespace () ) ) {
0 commit comments