@Test public void testGetReferencedResources() throws ResourceKeyCreationException { ResourceManagerBackend resourceManagerBackend = Mockito.mock( ResourceManagerBackend.class ); ResourceManager resourceManager = new ResourceManager( resourceManagerBackend ); ResourceKey contentBase = new ResourceKey( "contentBase_schema", "contentBase_id", null ); ResourceKey elementSource = new ResourceKey( "elementSource_schema", "elementSource_id", null ); ResourceKey attributeValue = new ResourceKey( "attributeValue_schema", "attributeValue_id", null ); Mockito.doReturn( "Content" ).when( metaData ).getValueRole(); Mockito.doReturn( contentBase ).when( element ).getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.CONTENT_BASE ); Mockito.doReturn( elementSource ).when( element ) .getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.SOURCE ); Mockito.doReturn( elementSource ).when( resourceManagerBackend ).deriveKey( contentBase, "attr_0", null ); Mockito.doReturn( elementSource ).when( resourceManagerBackend ).createKey( "attr_0", null ); ResourceReference[] result = attrCore.getReferencedResources( metaData, element, resourceManager, attributeValue ); Assert.assertThat( result, CoreMatchers.is( CoreMatchers.notNullValue() ) ); Assert.assertThat( result.length, CoreMatchers.is( CoreMatchers.equalTo( 1 ) ) ); Assert.assertThat( result[ 0 ].getPath(), CoreMatchers.is( CoreMatchers.equalTo( attributeValue ) ) ); Assert.assertThat( result[ 0 ].isLinked(), CoreMatchers.is( CoreMatchers.equalTo( false ) ) ); result = attrCore.getReferencedResources( metaData, element, resourceManager, "attr_0" ); Assert.assertThat( result, CoreMatchers.is( CoreMatchers.notNullValue() ) ); Assert.assertThat( result.length, CoreMatchers.is( CoreMatchers.equalTo( 1 ) ) ); Assert.assertThat( result[ 0 ].getPath(), CoreMatchers.is( CoreMatchers.equalTo( elementSource ) ) ); Assert.assertThat( result[ 0 ].isLinked(), CoreMatchers.is( CoreMatchers.equalTo( true ) ) ); Mockito.doReturn( null ).when( element ) .getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.CONTENT_BASE ); result = attrCore.getReferencedResources( metaData, element, resourceManager, "attr_0" ); Assert.assertThat( result, CoreMatchers.is( CoreMatchers.notNullValue() ) ); Assert.assertThat( result.length, CoreMatchers.is( CoreMatchers.equalTo( 1 ) ) ); Assert.assertThat( result[ 0 ].getPath(), CoreMatchers.is( CoreMatchers.equalTo( elementSource ) ) ); Assert.assertThat( result[ 0 ].isLinked(), CoreMatchers.is( CoreMatchers.equalTo( true ) ) ); result = attrCore.getReferencedResources( metaData, element, resourceManager, null ); Assert.assertThat( result, CoreMatchers.is( Matchers.emptyArray() ) ); Mockito.doReturn( "incorrect" ).when( metaData ).getValueRole(); result = attrCore.getReferencedResources( metaData, element, resourceManager, "attr_0" ); Assert.assertThat( result, CoreMatchers.is( Matchers.emptyArray() ) ); }
public ResourceReference[] getReferencedResources( final AttributeMetaData metaData, final ReportElement element, final ResourceManager resourceManager, final Object attributeValue ) { if ( element == null ) { throw new NullPointerException(); } if ( resourceManager == null ) { throw new NullPointerException(); } final String valueRole = metaData.getValueRole(); if ( "Content".equals( valueRole ) ) { final ResourceKey contentBase = getContentBase( element ); final ResourceKey elementSource = getDefinitionSource( element ); if ( attributeValue instanceof ResourceKey ) { final ResourceKey path = (ResourceKey) attributeValue; final boolean linked = BundleUtilities.isSameBundle( elementSource, path ); return new ResourceReference[] { new ResourceReference( path, linked ) }; } else if ( attributeValue instanceof String && contentBase != null ) { try { final ResourceKey path = resourceManager.deriveKey( contentBase, String.valueOf( attributeValue ) ); final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) { } } else if ( attributeValue != null ) { try { final ResourceKey path = resourceManager.createKey( attributeValue ); final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) { } } } return EMPTY_RESOURCES; }
DefaultAttributeCore implements AttributeCore { public ResourceReference[] getReferencedResources( final AttributeMetaData metaData, final ReportElement element, final ResourceManager resourceManager, final Object attributeValue ) { if ( element == null ) { throw new NullPointerException(); } if ( resourceManager == null ) { throw new NullPointerException(); } final String valueRole = metaData.getValueRole(); if ( "Content".equals( valueRole ) ) { final ResourceKey contentBase = getContentBase( element ); final ResourceKey elementSource = getDefinitionSource( element ); if ( attributeValue instanceof ResourceKey ) { final ResourceKey path = (ResourceKey) attributeValue; final boolean linked = BundleUtilities.isSameBundle( elementSource, path ); return new ResourceReference[] { new ResourceReference( path, linked ) }; } else if ( attributeValue instanceof String && contentBase != null ) { try { final ResourceKey path = resourceManager.deriveKey( contentBase, String.valueOf( attributeValue ) ); final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) { } } else if ( attributeValue != null ) { try { final ResourceKey path = resourceManager.createKey( attributeValue ); final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) { } } } return EMPTY_RESOURCES; } }
DefaultAttributeCore implements AttributeCore { public ResourceReference[] getReferencedResources( final AttributeMetaData metaData, final ReportElement element, final ResourceManager resourceManager, final Object attributeValue ) { if ( element == null ) { throw new NullPointerException(); } if ( resourceManager == null ) { throw new NullPointerException(); } final String valueRole = metaData.getValueRole(); if ( "Content".equals( valueRole ) ) { final ResourceKey contentBase = getContentBase( element ); final ResourceKey elementSource = getDefinitionSource( element ); if ( attributeValue instanceof ResourceKey ) { final ResourceKey path = (ResourceKey) attributeValue; final boolean linked = BundleUtilities.isSameBundle( elementSource, path ); return new ResourceReference[] { new ResourceReference( path, linked ) }; } else if ( attributeValue instanceof String && contentBase != null ) { try { final ResourceKey path = resourceManager.deriveKey( contentBase, String.valueOf( attributeValue ) ); final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) { } } else if ( attributeValue != null ) { try { final ResourceKey path = resourceManager.createKey( attributeValue ); final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) { } } } return EMPTY_RESOURCES; } DefaultAttributeCore(); }
DefaultAttributeCore implements AttributeCore { public ResourceReference[] getReferencedResources( final AttributeMetaData metaData, final ReportElement element, final ResourceManager resourceManager, final Object attributeValue ) { if ( element == null ) { throw new NullPointerException(); } if ( resourceManager == null ) { throw new NullPointerException(); } final String valueRole = metaData.getValueRole(); if ( "Content".equals( valueRole ) ) { final ResourceKey contentBase = getContentBase( element ); final ResourceKey elementSource = getDefinitionSource( element ); if ( attributeValue instanceof ResourceKey ) { final ResourceKey path = (ResourceKey) attributeValue; final boolean linked = BundleUtilities.isSameBundle( elementSource, path ); return new ResourceReference[] { new ResourceReference( path, linked ) }; } else if ( attributeValue instanceof String && contentBase != null ) { try { final ResourceKey path = resourceManager.deriveKey( contentBase, String.valueOf( attributeValue ) ); final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) { } } else if ( attributeValue != null ) { try { final ResourceKey path = resourceManager.createKey( attributeValue ); final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) { } } } return EMPTY_RESOURCES; } DefaultAttributeCore(); String[] getReferencedFields( final AttributeMetaData metaData, final ReportElement element,
      final Object attributeValue ); String[] getReferencedGroups( final AttributeMetaData metaData, final ReportElement element,
      final Object attributeValue ); ResourceReference[] getReferencedResources( final AttributeMetaData metaData, final ReportElement element,
      final ResourceManager resourceManager, final Object attributeValue ); String[] getExtraCalculationFields( final AttributeMetaData metaData ); }
DefaultAttributeCore implements AttributeCore { public ResourceReference[] getReferencedResources( final AttributeMetaData metaData, final ReportElement element, final ResourceManager resourceManager, final Object attributeValue ) { if ( element == null ) { throw new NullPointerException(); } if ( resourceManager == null ) { throw new NullPointerException(); } final String valueRole = metaData.getValueRole(); if ( "Content".equals( valueRole ) ) { final ResourceKey contentBase = getContentBase( element ); final ResourceKey elementSource = getDefinitionSource( element ); if ( attributeValue instanceof ResourceKey ) { final ResourceKey path = (ResourceKey) attributeValue; final boolean linked = BundleUtilities.isSameBundle( elementSource, path ); return new ResourceReference[] { new ResourceReference( path, linked ) }; } else if ( attributeValue instanceof String && contentBase != null ) { try { final ResourceKey path = resourceManager.deriveKey( contentBase, String.valueOf( attributeValue ) ); final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) { } } else if ( attributeValue != null ) { try { final ResourceKey path = resourceManager.createKey( attributeValue ); final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) { } } } return EMPTY_RESOURCES; } DefaultAttributeCore(); String[] getReferencedFields( final AttributeMetaData metaData, final ReportElement element,
      final Object attributeValue ); String[] getReferencedGroups( final AttributeMetaData metaData, final ReportElement element,
      final Object attributeValue ); ResourceReference[] getReferencedResources( final AttributeMetaData metaData, final ReportElement element,
      final ResourceManager resourceManager, final Object attributeValue ); String[] getExtraCalculationFields( final AttributeMetaData metaData );  }