private ParserContext singleBackingTypeParserContext ( ) throws ExpressionCompileException { ParserContext context = new ParserContext ( ) ; context . setStrongTyping ( true ) ; context . addInput ( "this" , backingType ) ; PropertyDescriptor [ ] propertyDescriptors ; try { propertyDescriptors = Introspector . getBeanInfo ( backingType ) . getPropertyDescriptors ( ) ; } catch ( IntrospectionException e ) { throw new ExpressionCompileException ( "Could not read class " + backingType ) ; } // read @Visible annotated fields. for ( Field field : backingType . getDeclaredFields ( ) ) { if ( field . isAnnotationPresent ( Visible . class ) ) { context . addInput ( field . getName ( ) , field . getType ( ) ) ; if ( ! field . getAnnotation ( Visible . class ) . readOnly ( ) ) { writeableProperties . add ( field . getName ( ) ) ; } } } // read javabean properties -- these override @Visible fields. for ( PropertyDescriptor propertyDescriptor : propertyDescriptors ) { // skip getClass() if ( CLASS . equals ( propertyDescriptor . getName ( ) ) ) continue ; if ( null != propertyDescriptor . getWriteMethod ( ) ) { writeableProperties . add ( propertyDescriptor . getName ( ) ) ; } // if this is a collection, determine its type parameter if ( Collection . class . isAssignableFrom ( propertyDescriptor . getPropertyType ( ) ) ) { Type propertyType ; if ( propertyDescriptor . getReadMethod ( ) != null ) { propertyType = propertyDescriptor . getReadMethod ( ) . getGenericReturnType ( ) ; } else { propertyType = propertyDescriptor . getWriteMethod ( ) . getGenericParameterTypes ( ) [ 0 ] ; } ParameterizedType collectionType = ( ParameterizedType ) Generics . getExactSuperType ( propertyType , Collection . class ) ; Class < ? > [ ] parameterClasses = new Class [ 1 ] ; Type parameterType = collectionType . getActualTypeArguments ( ) [ 0 ] ; parameterClasses [ 0 ] = Generics . erase ( parameterType ) ; context . addInput ( propertyDescriptor . getName ( ) , propertyDescriptor . getPropertyType ( ) , parameterClasses ) ; } else { context . addInput ( propertyDescriptor . getName ( ) , propertyDescriptor . getPropertyType ( ) ) ; } } return context ; }
generates a parsing context with type information from the backing type s javabean properties