@Test public void testGetReferencedResources() throws ResourceKeyCreationException { Element elem = mock( Element.class ); ResourceManagerBackend resourceManagerBackend = 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 ); doReturn( "Content" ).when( metaData ).getPropertyRole(); doReturn( contentBase ).when( elem ).getContentBase(); doReturn( elementSource ).when( elem ).getDefinitionSource(); doReturn( elementSource ).when( resourceManagerBackend ).deriveKey( contentBase, "attr_0", null ); doReturn( elementSource ).when( resourceManagerBackend ).createKey( "attr_0", null ); ResourceReference[] result = preProcessor.getReferencedResources( metaData, expression, attributeValue, elem, resourceManager ); assertThat( result, is( notNullValue() ) ); assertThat( result.length, is( equalTo( 1 ) ) ); assertThat( result[0].getPath(), is( equalTo( attributeValue ) ) ); assertThat( result[0].isLinked(), is( equalTo( false ) ) ); result = preProcessor.getReferencedResources( metaData, expression, "attr_0", elem, resourceManager ); assertThat( result, is( notNullValue() ) ); assertThat( result.length, is( equalTo( 1 ) ) ); assertThat( result[0].getPath(), is( equalTo( elementSource ) ) ); assertThat( result[0].isLinked(), is( equalTo( true ) ) ); doReturn( null ).when( elem ).getContentBase(); result = preProcessor.getReferencedResources( metaData, expression, "attr_0", elem, resourceManager ); assertThat( result, is( notNullValue() ) ); assertThat( result.length, is( equalTo( 1 ) ) ); assertThat( result[0].getPath(), is( equalTo( elementSource ) ) ); assertThat( result[0].isLinked(), is( equalTo( true ) ) ); result = preProcessor.getReferencedResources( metaData, expression, null, elem, resourceManager ); assertThat( result, is( emptyArray() ) ); doReturn( "incorrect" ).when( metaData ).getPropertyRole(); result = preProcessor.getReferencedResources( metaData, expression, "attr_0", elem, resourceManager ); assertThat( result, is( emptyArray() ) ); }
public ResourceReference[] getReferencedResources( final ExpressionPropertyMetaData metaData, final Expression expression, final Object attributeValue, final Element reportElement, final ResourceManager resourceManager ) { if ( expression == null ) { throw new NullPointerException(); } if ( reportElement == null ) { throw new NullPointerException(); } if ( resourceManager == null ) { throw new NullPointerException(); } final String propertyRole = metaData.getPropertyRole(); if ( "Content".equals( propertyRole ) ) { final ResourceKey contentBase = reportElement.getContentBase(); final ResourceKey elementSource = reportElement.getDefinitionSource(); 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; }
DefaultExpressionPropertyCore implements ExpressionPropertyCore { public ResourceReference[] getReferencedResources( final ExpressionPropertyMetaData metaData, final Expression expression, final Object attributeValue, final Element reportElement, final ResourceManager resourceManager ) { if ( expression == null ) { throw new NullPointerException(); } if ( reportElement == null ) { throw new NullPointerException(); } if ( resourceManager == null ) { throw new NullPointerException(); } final String propertyRole = metaData.getPropertyRole(); if ( "Content".equals( propertyRole ) ) { final ResourceKey contentBase = reportElement.getContentBase(); final ResourceKey elementSource = reportElement.getDefinitionSource(); 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; } }
DefaultExpressionPropertyCore implements ExpressionPropertyCore { public ResourceReference[] getReferencedResources( final ExpressionPropertyMetaData metaData, final Expression expression, final Object attributeValue, final Element reportElement, final ResourceManager resourceManager ) { if ( expression == null ) { throw new NullPointerException(); } if ( reportElement == null ) { throw new NullPointerException(); } if ( resourceManager == null ) { throw new NullPointerException(); } final String propertyRole = metaData.getPropertyRole(); if ( "Content".equals( propertyRole ) ) { final ResourceKey contentBase = reportElement.getContentBase(); final ResourceKey elementSource = reportElement.getDefinitionSource(); 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; } DefaultExpressionPropertyCore(); }
DefaultExpressionPropertyCore implements ExpressionPropertyCore { public ResourceReference[] getReferencedResources( final ExpressionPropertyMetaData metaData, final Expression expression, final Object attributeValue, final Element reportElement, final ResourceManager resourceManager ) { if ( expression == null ) { throw new NullPointerException(); } if ( reportElement == null ) { throw new NullPointerException(); } if ( resourceManager == null ) { throw new NullPointerException(); } final String propertyRole = metaData.getPropertyRole(); if ( "Content".equals( propertyRole ) ) { final ResourceKey contentBase = reportElement.getContentBase(); final ResourceKey elementSource = reportElement.getDefinitionSource(); 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; } DefaultExpressionPropertyCore(); String[] getReferencedFields( final ExpressionPropertyMetaData metaData, final Expression expression,
      final Object attributeValue ); String[] getReferencedGroups( final ExpressionPropertyMetaData metaData, final Expression expression,
      final Object attributeValue ); String[] getReferencedElements( final ExpressionPropertyMetaData metaData, final Expression expression,
      final Object attributeValue ); ResourceReference[] getReferencedResources( final ExpressionPropertyMetaData metaData,
      final Expression expression, final Object attributeValue, final Element reportElement,
      final ResourceManager resourceManager ); String[] getExtraCalculationFields( final ExpressionPropertyMetaData metaData ); }
DefaultExpressionPropertyCore implements ExpressionPropertyCore { public ResourceReference[] getReferencedResources( final ExpressionPropertyMetaData metaData, final Expression expression, final Object attributeValue, final Element reportElement, final ResourceManager resourceManager ) { if ( expression == null ) { throw new NullPointerException(); } if ( reportElement == null ) { throw new NullPointerException(); } if ( resourceManager == null ) { throw new NullPointerException(); } final String propertyRole = metaData.getPropertyRole(); if ( "Content".equals( propertyRole ) ) { final ResourceKey contentBase = reportElement.getContentBase(); final ResourceKey elementSource = reportElement.getDefinitionSource(); 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; } DefaultExpressionPropertyCore(); String[] getReferencedFields( final ExpressionPropertyMetaData metaData, final Expression expression,
      final Object attributeValue ); String[] getReferencedGroups( final ExpressionPropertyMetaData metaData, final Expression expression,
      final Object attributeValue ); String[] getReferencedElements( final ExpressionPropertyMetaData metaData, final Expression expression,
      final Object attributeValue ); ResourceReference[] getReferencedResources( final ExpressionPropertyMetaData metaData,
      final Expression expression, final Object attributeValue, final Element reportElement,
      final ResourceManager resourceManager ); String[] getExtraCalculationFields( final ExpressionPropertyMetaData metaData );  }