private void writePreProcessor( final XmlWriter writer, final ReportPreProcessor preProcessor ) throws IntrospectionException, BeanException, IOException { if ( writer == null ) { throw new NullPointerException(); } if ( preProcessor == null ) { throw new NullPointerException(); } // the classic way, in case the expression does not provide any meta-data. This is // in the code for legacy reasons, as there are many expression implementations out there // that do not yet provide meta-data descriptions .. final BeanUtility beanUtility = new BeanUtility( preProcessor ); final String[] propertyNames = beanUtility.getProperties(); for ( int i = 0; i < propertyNames.length; i++ ) { final String key = propertyNames[i]; final Object property = beanUtility.getProperty( key ); final Class propertyType = beanUtility.getPropertyType( key ); final String value = beanUtility.getPropertyAsString( key ); if ( value != null && property != null ) { final AttributeList attList = new AttributeList(); attList.setAttribute( BundleNamespaces.LAYOUT, "name", key ); if ( BeanUtility.isSameType( propertyType, property.getClass() ) == false ) { attList.setAttribute( BundleNamespaces.LAYOUT, "class", property.getClass().getName() ); } writer.writeTag( BundleNamespaces.LAYOUT, "property", attList, XmlWriterSupport.OPEN ); writer.writeTextNormalized( value, false ); writer.writeCloseTag(); } } }
private void validateProperty( final BeanUtility bu, final String name, final Object value, final Object nullValue ) throws BeanException { bu.setProperty( name, nullValue ); assertValue( nullValue, bu.getProperty( name ) ); bu.setProperty( name, value ); assertValue( value, bu.getProperty( name ) ); final String valString = bu.getPropertyAsString( name ); assertNotNull( valString ); bu.setProperty( name, nullValue ); assertValue( nullValue, bu.getProperty( name ) ); bu.setPropertyAsString( name, valString ); assertValue( value, bu.getProperty( name ) ); bu.setProperty( name, nullValue ); assertValue( nullValue, bu.getProperty( name ) ); }
public String[] getProperties() throws BeanException { final ArrayList<String> propertyNames = new ArrayList<String>(); final PropertyDescriptor[] pd = getPropertyInfos(); for ( int i = 0; i < pd.length; i++ ) { final PropertyDescriptor property = pd[i]; if ( property.isHidden() ) { continue; } if ( property.getReadMethod() == null || property.getWriteMethod() == null ) { // it will make no sense to write a property now, that // we can't read in later... continue; } if ( BeanUtility.getPropertyType( property ).isArray() ) { final int max = findMaximumIndex( property ); for ( int idx = 0; idx < max; idx++ ) { propertyNames.add( property.getName() + '[' + idx + ']' ); } } else { propertyNames.add( property.getName() ); } } return propertyNames.toArray( new String[propertyNames.size()] ); }
public void setPropertyAsString( final String name, final String txt ) throws BeanException { if ( name == null ) { throw new NullPointerException( "Name must not be null" ); } if ( txt == null ) { throw new NullPointerException( "Text must not be null" ); } final PropertySpecification ps = new PropertySpecification( name ); final PropertyDescriptor pd = properties.get( ps.getName() ); if ( pd == null ) { throw new BeanException( bean.getClass() + ": No such property:" + name ); } setPropertyAsString( name, BeanUtility.getPropertyType( pd ), txt ); }
public void writeExpressionParameter( final XmlWriter writer, final BeanUtility beanUtility, final String propertyName, final String namespaceUri ) throws IOException, BeanException { // filter some of the standard properties. These are system-properties // and are set elsewhere final Object property = beanUtility.getProperty( propertyName ); final Class propertyType = beanUtility.getPropertyType( propertyName ); final String value = beanUtility.getPropertyAsString( propertyName ); if ( value != null && property != null ) { final AttributeList attList = new AttributeList(); attList.setAttribute( namespaceUri, "name", propertyName ); if ( BeanUtility.isSameType( propertyType, property.getClass() ) == false ) { attList.setAttribute( namespaceUri, "class", property.getClass().getName() ); } writer.writeTag( namespaceUri, "property", attList, XmlWriterSupport.OPEN ); writer.writeTextNormalized( value, false ); writer.writeCloseTag(); } }
String namespaceUri ) throws IOException, BeanException { final Object property = beanUtility.getProperty( propertyName ); if ( property == null ) { return; final Class propertyType = beanUtility.getPropertyType( propertyName ); final AttributeList attList = new AttributeList(); attList.setAttribute( namespaceUri, "name", propertyName ); if ( BeanUtility.isSameType( propertyType, property.getClass() ) == false ) { attList.setAttribute( namespaceUri, "class", property.getClass().getName() );
final BeanUtility bu = new BeanUtility( expression ); final ExpressionPropertyMetaData[] expressionProperties = emd.getPropertyDescriptions(); boolean propertiesOpen = false; final BeanUtility beanUtility = new BeanUtility( expression ); final String[] propertyNames = beanUtility.getProperties();
public ExpressionPropertiesReadHandler( final Expression expression, final String originalExpressionClass, final String expressionClass ) throws IntrospectionException { this.originalExpressionClass = originalExpressionClass; this.expressionClass = expressionClass; this.beanUtility = new BeanUtility( expression ); this.expression = expression; }
private void updateArrayProperty( final PropertyDescriptor pd, final PropertySpecification name, final Object o ) throws BeanException { final Method readMethod = pd.getReadMethod(); if ( readMethod == null ) { throw new BeanException( "Property is not readable, cannot perform array update: " + name ); } try { // System.out.println(readMethod); final Object value = readMethod.invoke( bean ); // we have (possibly) an array. final int index = Integer.parseInt( name.getIndex() ); final Object array = validateArray( BeanUtility.getPropertyType( pd ), value, index ); Array.set( array, index, o ); final Method writeMethod = pd.getWriteMethod(); writeMethod.invoke( bean, array ); } catch ( BeanException e ) { throw e; } catch ( Exception e ) { BeanUtility.logger.warn( "Failed to read property, cannot perform array update: " + name, e ); throw new BeanException( "Failed to read property, cannot perform array update: " + name ); } }
public void setProperty( final String name, final Object o ) throws BeanException { if ( name == null ) { throw new NullPointerException( "Name must not be null" ); } setProperty( new PropertySpecification( name ), o ); }
public Class getPropertyType( final String name ) throws BeanException { if ( name == null ) { throw new NullPointerException( "Name must not be null" ); } final PropertySpecification ps = new PropertySpecification( name ); final PropertyDescriptor pd = properties.get( ps.getName() ); if ( pd == null ) { throw new BeanException( "No such property:" + name ); } return BeanUtility.getPropertyType( pd ); }
/** * Done parsing. * * @throws SAXException * if there is a parsing error. */ public void doneParsing() throws SAXException { super.doneParsing(); final String result = getResult(); if ( beanUtility == null ) { throw new SAXException( "No current beanUtility" ); } try { if ( propertyType != null ) { final ClassLoader cl = ObjectUtilities.getClassLoader( ExpressionPropertyReadHandler.class ); final Class c = Class.forName( propertyType, false, cl ); beanUtility.setPropertyAsString( propertyName, c, result ); } else { beanUtility.setPropertyAsString( propertyName, result ); } } catch ( BeanException e ) { throw new ParseException( "Unable to assign property '" + propertyName + "' to the specified Layout-PreProcessor", e, getLocator() ); } catch ( ClassNotFoundException e ) { throw new ParseException( "Unable to assign property '" + propertyName + "' to expression Layout-PreProcessor", e, getLocator() ); } }
if ( propertyMetaData != null ) { try { return beanUtility.getProperty( name ); } catch ( BeanException e ) {
private int findMaximumIndex( final PropertyDescriptor id ) { try { final Object o = getPropertyForSpecification( new PropertySpecification( id.getName() ) ); return Array.getLength( o ); } catch ( Exception e ) { // ignore, we run 'til we encounter an index out of bounds Ex. } return 0; }
final Object property = beanUtility.getProperty( key ); final Class propertyType = beanUtility.getPropertyType( key ); final String value = beanUtility.getPropertyAsString( key ); if ( value != null && property != null ) { final AttributeList attList = new AttributeList(); attList.setAttribute( ExtParserModule.NAMESPACE, "name", key ); if ( BeanUtility.isSameType( propertyType, property.getClass() ) == false ) { attList.setAttribute( ExtParserModule.NAMESPACE, "class", property.getClass().getName() );
String namespaceUri ) throws IOException, BeanException { final Object property = beanUtility.getProperty( propertyName ); if (property == null) { return; final Class propertyType = beanUtility.getPropertyType( propertyName ); final AttributeList attList = new AttributeList(); attList.setAttribute( namespaceUri, "name", propertyName ); if ( BeanUtility.isSameType( propertyType, property.getClass() ) == false ) { attList.setAttribute( namespaceUri, "class", property.getClass().getName() );
final BeanUtility bu = new BeanUtility( expression ); final String[] propertyNames = bu.getProperties(); if ( propertyNames.length == 0 ) { final AttributeList properties = new AttributeList();
public ExpressionsDataAttributes( final Expression expression ) { if ( expression == null ) { throw new NullPointerException(); } if ( expression.getName() == null ) { throw new IllegalStateException(); } this.expressionType = expression.getClass(); if ( ExpressionRegistry.getInstance().isExpressionRegistered( expressionType.getName() ) ) { this.expressionMetaData = ExpressionRegistry.getInstance().getExpressionMetaData( expressionType.getName() ); this.resultType = expressionMetaData.getResultType(); this.expressionProperties = StringUtils.merge( expressionMetaData.getPropertyNames(), ExpressionsDataAttributes.EXPRESSIONNAMES ); } else { this.expressionMetaData = null; this.resultType = Object.class; this.expressionProperties = ExpressionsDataAttributes.EXPRESSIONNAMES; } this.expressionName = expression.getName(); try { this.beanUtility = new BeanUtility( expression ); } catch ( IntrospectionException e ) { // should not happen, but if it does, we simply ignore the bean-metadata. } }
@Override public void doneParsing() throws SAXException { try { LinkedHashMap<String, Expression> map = new LinkedHashMap<>(); for ( ExpressionReadHandler handler : expressionHandlers ) { final Expression object = handler.getObject(); if ( object != null ) { final String name = object.getName(); // Style/attribute expressions have no explicit name. // The parser sets the name because we have a name-attribute in the XML. if ( name != null ) { object.setName( null ); map.put( name, object ); } } } expression.setProperty( propertyName, map ); } catch ( BeanException e ) { throw new ParseException( "Unable to set property" , e, getLocator()); } } }
/** * Converts the attribute to a string. * * @param o * the attribute ({@link Integer} expected). * @return A string representing the {@link Integer} value. * @throws BeanException * if there was an error during the conversion. */ public String toAttributeValue( final Object o ) throws BeanException { if ( o == null ) { throw new NullPointerException(); } final Class aClass = BeanUtility.getPropertyType( propertyDescriptor ); if ( aClass.isInstance( o ) == false ) { throw new BeanException( "Failed to convert object of type " + o.getClass() + ": Not a " + aClass.getName() ); } propertyEditor.setValue( o ); return propertyEditor.getAsText(); }