/** * Retrieves the raw prop value from root object. * <p> * The similar {@link #getProperty(Object, String)} method (also in this class )should be * revisited and possibly eliminated. That version attempts to retrieve indexed prop * vals from lists/arrays, but doesn't provide a way to retrieve the list or array objects * themselves. */ public Object getPropVal( Object root, String propName ) { Queue<BeanLevelInfo> beanInfos = newLinkedList( Optional.ofNullable( info.getProperties().get( propName ) ) .orElseThrow( () -> new IllegalArgumentException( "Property not found: " + propName ) ) .path ); beanInfos.remove(); // pop off root return getPropVal( root, propName, beanInfos ); }
@SuppressWarnings ( "unchecked" ) private Object getPropVal( Object obj, String propName, Queue<BeanLevelInfo> beanInfos ) { BeanLevelInfo info = beanInfos.remove(); if ( beanInfos.isEmpty() ) { return getObjFromBeanInfo( obj, info ); } obj = getObjFromBeanInfo( obj, info ); switch ( info.dim ) { case LIST: return ( (List) requireNonNull( obj ) ).stream() .map( o -> getPropVal( o, propName, newLinkedList( beanInfos ) ) ) .collect( Collectors.toList() ); case ARRAY: return Arrays.stream( (Object[]) requireNonNull( obj ) ) .map( o -> getPropVal( o, propName, newLinkedList( beanInfos ) ) ) .toArray( Object[]::new ); case NONE: return getPropVal( obj, propName, beanInfos ); } throw new IllegalStateException( "Unexpected value of BeanLevelInfo.dim " + info.dim ); }
@SuppressWarnings ( "unchecked" ) private List<Object> getPropVal( StepMetaInterface stepMeta, BeanInjector injector, BeanInjectionInfo.Property prop ) { try { List ret; Object o = injector.getPropVal( stepMeta, prop.getName() ); if ( o instanceof List ) { ret = (List<Object>) o; } else if ( o instanceof Object[] ) { ret = asList( (Object[]) o ); } else { ret = singletonList( o ); } return maybeEncrypt( prop.getName(), ret ); } catch ( Exception e ) { throw new RuntimeException( e ); } }