@Override public Object invoke( Object o, final Method method, Object[] objects ) throws Throwable { if( method.equals( NamedAssociation.class.getMethod( "get", String.class ) ) ) { Type namedAssociationType = GenericAssociationInfo.associationTypeOf( namedAssociation.accessor() ); if( namedAssociationType.getClass().equals( Class.class ) ) { return Proxy.newProxyInstance( method.getDeclaringClass().getClassLoader(), array( (Class) namedAssociationType, PropertyReference.class ), new TemplateHandler<T>( null, null, null, namedAssociation ) ); } } return null; } }
public static Type associationTypeOf( AccessibleObject accessor ) { return toAssociationType( typeOf( accessor ) ); }
@Override public Object invoke( Object o, final Method method, Object[] objects ) throws Throwable { if( method.equals( Association.class.getMethod( "get" ) ) ) { Type associationType = GenericAssociationInfo.associationTypeOf( association.accessor() ); if( associationType.getClass().equals( Class.class ) ) { return Proxy.newProxyInstance( method.getDeclaringClass().getClassLoader(), array( (Class) associationType, PropertyReference.class ), new TemplateHandler<T>( null, association, null, null ) ); } } return null; } }
public static Type toAssociationType( Type methodReturnType ) { if( methodReturnType instanceof ParameterizedType ) { ParameterizedType parameterizedType = (ParameterizedType) methodReturnType; if( AbstractAssociation.class.isAssignableFrom( (Class<?>) parameterizedType.getRawType() ) ) { return parameterizedType.getActualTypeArguments()[ 0 ]; } } Type[] interfaces = ( (Class<?>) methodReturnType ).getGenericInterfaces(); for( Type anInterface : interfaces ) { Type associationType = toAssociationType( anInterface ); if( associationType != null ) { return associationType; } } return null; } }
@Override public Object invoke( Object o, final Method method, Object[] objects ) throws Throwable { if( method.equals( ManyAssociation.class.getMethod( "get", Integer.TYPE ) ) ) { Type manyAssociationType = GenericAssociationInfo.associationTypeOf( manyAssociation.accessor() ); if( manyAssociationType.getClass().equals( Class.class ) ) { return Proxy.newProxyInstance( method.getDeclaringClass().getClassLoader(), array( (Class) manyAssociationType, PropertyReference.class ), new TemplateHandler<T>( null, null, manyAssociation, null ) ); } } return null; } }
public AssociationFunction( AssociationFunction<?> traversedAssociation, ManyAssociationFunction<?> traversedManyAssociation, NamedAssociationFunction<?> traversedNamedAssociation, AccessibleObject accessor ) { this.traversedAssociation = traversedAssociation; this.traversedManyAssociation = traversedManyAssociation; this.traversedNamedAssociation = traversedNamedAssociation; this.accessor = accessor; Type returnType = typeOf( accessor ); if( !Association.class.isAssignableFrom( Classes.RAW_CLASS.map( returnType ) ) && !ManyAssociation.class.isAssignableFrom( Classes.RAW_CLASS.map( returnType ) ) && !NamedAssociation.class.isAssignableFrom( Classes.RAW_CLASS.map( returnType ) ) ) { throw new QueryExpressionException( "Unsupported association type:" + returnType ); } Type associationTypeAsType = GenericAssociationInfo.toAssociationType( returnType ); if( !( associationTypeAsType instanceof Class ) ) { throw new QueryExpressionException( "Unsupported association type:" + associationTypeAsType ); } }
Type t = GenericAssociationInfo.associationTypeOf( method ); if( t instanceof Class ) Type t = GenericAssociationInfo.associationTypeOf( method ); if( t instanceof Class ) Type t = GenericAssociationInfo.associationTypeOf( method ); if( t instanceof Class )