All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quincy.core.aspect.ChannelSftpInjectorAop Maven / Gradle / Ivy

The newest version!
package com.quincy.core.aspect;

import java.util.ArrayList;
import java.util.List;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.jcraft.jsch.ChannelSftp;
import com.quincy.core.sftp.ChannelSftpSource;
import com.quincy.sdk.helper.AopHelper;

@Aspect
@Order(5)
@Component
public class ChannelSftpInjectorAop {
	@Autowired
	private ChannelSftpSource channelSftpSource;

	@Pointcut("@annotation(com.quincy.sdk.annotation.ChannelSftpInjector)")
    public void pointCut() {}

    @Around("pointCut()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
    	MethodSignature methodSignature = (MethodSignature)joinPoint.getSignature();
    	Class[] classes = methodSignature.getParameterTypes();
    	Object[] args = joinPoint.getArgs();
    	List index = new ArrayList(classes.length);
    	for(int i=0;i0) {
    		ChannelSftp channel = null;
    		try {
    			channel = channelSftpSource.get();
    			for(int i:index)
    				args[i] = channel;
    			return joinPoint.proceed(args);
    		} finally {
    			if(channel!=null)
    				channel.disconnect();
    		}
    	} else
    		return joinPoint.proceed(args);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy