@Test public void testGetReferencedFields() { String[] result = attrCore.getReferencedFields( metaData, element, null ); Assert.assertThat( result, CoreMatchers.is( Matchers.emptyArray() ) ); String[] attributeValue = new String[] { "attr_0" }; Mockito.doReturn( "Field" ).when( metaData ).getValueRole(); result = attrCore.getReferencedFields( metaData, element, attributeValue ); Assert.assertThat( result, CoreMatchers.is( CoreMatchers.equalTo( attributeValue ) ) ); result = attrCore.getReferencedFields( metaData, element, attributeValue[ 0 ] ); Assert.assertThat( result, CoreMatchers.is( CoreMatchers.equalTo( attributeValue ) ) ); Mockito.doReturn( "Message" ).when( metaData ).getValueRole(); result = attrCore.getReferencedFields( metaData, element, attributeValue[ 0 ] ); Assert.assertThat( result, CoreMatchers.is( Matchers.emptyArray() ) ); Mockito.doReturn( "Formula" ).when( metaData ).getValueRole(); result = attrCore.getReferencedFields( metaData, element, "namespace:[a+b]" ); Assert.assertThat( result, CoreMatchers.is( CoreMatchers.equalTo( new String[] { "a+b" } ) ) ); Mockito.doReturn( "Formula" ).when( metaData ).getValueRole(); result = attrCore.getReferencedFields( metaData, element, "namespace" ); Assert.assertThat( result, CoreMatchers.is( Matchers.emptyArray() ) ); Mockito.doReturn( "incorrect" ).when( metaData ).getValueRole(); result = attrCore.getReferencedFields( metaData, element, "namespace:[a+b]" ); Assert.assertThat( result, CoreMatchers.is( Matchers.emptyArray() ) ); }
public String[] getReferencedFields( final AttributeMetaData metaData, final ReportElement element, final Object attributeValue ) { if ( element == null ) { throw new NullPointerException(); } if ( attributeValue == null ) { return EMPTY; } final String valueRole = metaData.getValueRole(); if ( "Field".equals( valueRole ) ) { if ( attributeValue instanceof String[] ) { final String[] vals = (String[]) attributeValue; return vals.clone(); } return new String[] { String.valueOf( attributeValue ) }; } else if ( "Message".equals( valueRole ) ) { final String message = String.valueOf( attributeValue ); final MessageFormatSupport messageFormatSupport = new MessageFormatSupport(); messageFormatSupport.setFormatString( message ); return messageFormatSupport.getFields(); } else if ( "Formula".equals( valueRole ) ) { final String formula = String.valueOf( attributeValue ); try { final Object[] objects = FormulaUtil.getReferences( formula ); final ArrayList<String> list = new ArrayList<String>(); for ( int i = 0; i < objects.length; i++ ) { final Object object = objects[i]; if ( object instanceof String ) { list.add( (String) object ); } } return list.toArray( new String[list.size()] ); } catch ( ParseException e ) { return EMPTY; } } return EMPTY; }
DefaultAttributeCore implements AttributeCore { public String[] getReferencedFields( final AttributeMetaData metaData, final ReportElement element, final Object attributeValue ) { if ( element == null ) { throw new NullPointerException(); } if ( attributeValue == null ) { return EMPTY; } final String valueRole = metaData.getValueRole(); if ( "Field".equals( valueRole ) ) { if ( attributeValue instanceof String[] ) { final String[] vals = (String[]) attributeValue; return vals.clone(); } return new String[] { String.valueOf( attributeValue ) }; } else if ( "Message".equals( valueRole ) ) { final String message = String.valueOf( attributeValue ); final MessageFormatSupport messageFormatSupport = new MessageFormatSupport(); messageFormatSupport.setFormatString( message ); return messageFormatSupport.getFields(); } else if ( "Formula".equals( valueRole ) ) { final String formula = String.valueOf( attributeValue ); try { final Object[] objects = FormulaUtil.getReferences( formula ); final ArrayList<String> list = new ArrayList<String>(); for ( int i = 0; i < objects.length; i++ ) { final Object object = objects[i]; if ( object instanceof String ) { list.add( (String) object ); } } return list.toArray( new String[list.size()] ); } catch ( ParseException e ) { return EMPTY; } } return EMPTY; } }
DefaultAttributeCore implements AttributeCore { public String[] getReferencedFields( final AttributeMetaData metaData, final ReportElement element, final Object attributeValue ) { if ( element == null ) { throw new NullPointerException(); } if ( attributeValue == null ) { return EMPTY; } final String valueRole = metaData.getValueRole(); if ( "Field".equals( valueRole ) ) { if ( attributeValue instanceof String[] ) { final String[] vals = (String[]) attributeValue; return vals.clone(); } return new String[] { String.valueOf( attributeValue ) }; } else if ( "Message".equals( valueRole ) ) { final String message = String.valueOf( attributeValue ); final MessageFormatSupport messageFormatSupport = new MessageFormatSupport(); messageFormatSupport.setFormatString( message ); return messageFormatSupport.getFields(); } else if ( "Formula".equals( valueRole ) ) { final String formula = String.valueOf( attributeValue ); try { final Object[] objects = FormulaUtil.getReferences( formula ); final ArrayList<String> list = new ArrayList<String>(); for ( int i = 0; i < objects.length; i++ ) { final Object object = objects[i]; if ( object instanceof String ) { list.add( (String) object ); } } return list.toArray( new String[list.size()] ); } catch ( ParseException e ) { return EMPTY; } } return EMPTY; } DefaultAttributeCore(); }
DefaultAttributeCore implements AttributeCore { public String[] getReferencedFields( final AttributeMetaData metaData, final ReportElement element, final Object attributeValue ) { if ( element == null ) { throw new NullPointerException(); } if ( attributeValue == null ) { return EMPTY; } final String valueRole = metaData.getValueRole(); if ( "Field".equals( valueRole ) ) { if ( attributeValue instanceof String[] ) { final String[] vals = (String[]) attributeValue; return vals.clone(); } return new String[] { String.valueOf( attributeValue ) }; } else if ( "Message".equals( valueRole ) ) { final String message = String.valueOf( attributeValue ); final MessageFormatSupport messageFormatSupport = new MessageFormatSupport(); messageFormatSupport.setFormatString( message ); return messageFormatSupport.getFields(); } else if ( "Formula".equals( valueRole ) ) { final String formula = String.valueOf( attributeValue ); try { final Object[] objects = FormulaUtil.getReferences( formula ); final ArrayList<String> list = new ArrayList<String>(); for ( int i = 0; i < objects.length; i++ ) { final Object object = objects[i]; if ( object instanceof String ) { list.add( (String) object ); } } return list.toArray( new String[list.size()] ); } catch ( ParseException e ) { return EMPTY; } } return EMPTY; } 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 String[] getReferencedFields( final AttributeMetaData metaData, final ReportElement element, final Object attributeValue ) { if ( element == null ) { throw new NullPointerException(); } if ( attributeValue == null ) { return EMPTY; } final String valueRole = metaData.getValueRole(); if ( "Field".equals( valueRole ) ) { if ( attributeValue instanceof String[] ) { final String[] vals = (String[]) attributeValue; return vals.clone(); } return new String[] { String.valueOf( attributeValue ) }; } else if ( "Message".equals( valueRole ) ) { final String message = String.valueOf( attributeValue ); final MessageFormatSupport messageFormatSupport = new MessageFormatSupport(); messageFormatSupport.setFormatString( message ); return messageFormatSupport.getFields(); } else if ( "Formula".equals( valueRole ) ) { final String formula = String.valueOf( attributeValue ); try { final Object[] objects = FormulaUtil.getReferences( formula ); final ArrayList<String> list = new ArrayList<String>(); for ( int i = 0; i < objects.length; i++ ) { final Object object = objects[i]; if ( object instanceof String ) { list.add( (String) object ); } } return list.toArray( new String[list.size()] ); } catch ( ParseException e ) { return EMPTY; } } return EMPTY; } 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 );  }