/** * Create a new Query Property instance. * * @param <T> type of the Property * @param mixinClass mixin of the Property * @param fieldName name of the Property field * * @return a new Query Property instance for the given mixin and property name. */ @SuppressWarnings( "unchecked" ) public static <T> Property<T> property( Class<?> mixinClass, String fieldName ) { try { Field field = mixinClass.getField( fieldName ); if( !Property.class.isAssignableFrom( field.getType() ) ) { throw new IllegalArgumentException( "Field must be of type Property<?>" ); } return (Property<T>) Proxy.newProxyInstance( mixinClass.getClassLoader(), array( field.getType() ), new PropertyReferenceHandler<>( new PropertyFunction<T>( null, null, null, null, field ) ) ); } catch( NoSuchFieldException e ) { throw new IllegalArgumentException( "No such field '" + fieldName + "' in mixin " + mixinClass.getName() ); } }
/** * Create a Query Template using the given mixin class and association. * * @param <T> the type of the template * @param mixinType a class declaring the type of the template * @param association an association * * @return a new Query Template */ public static <T> T templateFor( final Class<T> mixinType, Association<?> association ) { NullArgumentException.validateNotNull( "Mixin class", mixinType ); NullArgumentException.validateNotNull( "Association", association ); return mixinType.cast( Proxy.newProxyInstance( mixinType.getClassLoader(), array( mixinType ), new TemplateHandler<T>( null, association( association ), null, null ) ) ); }
array( clazz ), new TemplateHandler<T>( null, null, null, null ) ) ); array( field.getType() ), new PropertyReferenceHandler<>( new PropertyFunction<T>( null, null, null, null, field ) ) ) ); array( field.getType() ), new AssociationReferenceHandler<>( new AssociationFunction<T>( null, null, null, field ) ) ) ); array( field.getType() ), new ManyAssociationReferenceHandler<>( new ManyAssociationFunction<T>( null, null, null, field ) ) ) ); array( field.getType() ), new NamedAssociationReferenceHandler<>( new NamedAssociationFunction<T>( null, null, null, field ) ) ) );