Java Code Examples for org.aspectj.lang.JoinPoint#getTarget()
The following examples show how to use
org.aspectj.lang.JoinPoint#getTarget() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntroNewContentActionAspect.java From entando-components with GNU Lesser General Public License v3.0 | 6 votes |
@After("execution(* com.agiletec.plugins.jacms.apsadmin.content.IntroNewContentAction.createNew())") public void presetBlogAttributes(JoinPoint joinPoint) { try { IntroNewContentAction action = (IntroNewContentAction) joinPoint.getTarget(); Content content = action.getContent(); HttpServletRequest request = ServletActionContext.getRequest(); UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER); AttributeInterface authorAttribute = content.getAttributeByRole(JpblogSystemConstants.ATTRIBUTE_ROLE_AUTHOR); if (null != authorAttribute) { ((MonoTextAttribute) authorAttribute).setText(currentUser.getUsername()); } TimestampAttribute timeAttribute = (TimestampAttribute) content.getAttributeByRole(JpblogSystemConstants.ATTRIBUTE_ROLE_DATE); if (null != timeAttribute) { Date now = new Date(); ((TimestampAttribute) timeAttribute).setDate(now); } } catch (Throwable t) { _logger.error("Error presetting Blog Attributes", t); throw new RuntimeException("Error presetting Blog Attributes", t); } }
Example 2
Source File: SoftTransactionalAspect.java From Aooms with Apache License 2.0 | 6 votes |
@After("softTransaction()") public void endTransaction(JoinPoint point) throws Throwable { Signature signature = point.getSignature(); if (signature instanceof MethodSignature) { MethodSignature msig = (MethodSignature) signature; Object target = point.getTarget(); Method currentMethod = target.getClass().getMethod(msig.getName(), msig.getParameterTypes()); SoftTransactional softTransaction = currentMethod.getAnnotation(SoftTransactional.class); AbstractSoftTransaction transaction = SoftTransactionalHolder.getSoftTransaction(); if(softTransaction != null){ if(transaction == null){ throw new RuntimeException("SoftTransactionalHolder.getSoftTransaction() is null"); } transaction.end(); // 关闭事务 transaction.getConnection().close(); SoftTransactionalHolder.removeSoftTransaction(); logger.info(transaction.getTransactionType() + " SoftTransaction End"); } } }
Example 3
Source File: VertxLifecycleAspect.java From spring-vertx-ext with Apache License 2.0 | 6 votes |
/** * When a verticle will be stopped the stop() method will be executed. * In this case check if there is a running spring context, if so close it. * @param joinPoint the verticle stop method */ @After(value = "execution(* io.vertx.core.Verticle+.stop())") public void afterStop(JoinPoint joinPoint) { final Object target = joinPoint.getTarget(); log.debug("Stop invoked - Terminating spring context for verticle"); if (target.getClass().isAnnotationPresent(SpringVerticle.class)) { if (AnnotationConfigApplicationContext.class.isAssignableFrom(context.getClass())) { final ApplicationContext parent = AnnotationConfigApplicationContext.class.cast(context).getParent(); if (parent == null) { AnnotationConfigApplicationContext.class.cast(context).stop(); } else { if (GenericApplicationContext.class.isAssignableFrom(parent.getClass())) { GenericApplicationContext.class.cast(parent).stop(); } } } } }
Example 4
Source File: LoginAdvices.java From Mykit with Apache License 2.0 | 6 votes |
/** * 解析注解信息,模拟检验登录状态 * @param joinPoint * @throws Exception */ public void before(JoinPoint joinPoint) throws Exception { Object target = joinPoint.getTarget(); String methodName = joinPoint.getSignature().getName(); System.out.println(target + "-------" + methodName); Method method = target.getClass().getMethod(methodName); boolean annotationPresent = method.isAnnotationPresent(RequiresLogin.class); if (annotationPresent) { // 用户必须登录 boolean isLogin = false; if (!isLogin) { System.out.println("访问该接口必须先登录"); throw new Exception("访问该接口必须先登录"); } else { System.out.println("已登录..."); } }else{ System.out.println("不需登录"); } }
Example 5
Source File: SessionAspect.java From jdal with Apache License 2.0 | 6 votes |
/** * Before advice to prepare Session before call */ public void processSession(JoinPoint jp) { if (log.isDebugEnabled()) { String entityClassName = ""; Object target = jp.getTarget(); if (target instanceof HibernateDao) { entityClassName = ((HibernateDao<?, ?>) target).getEntityClass().getSimpleName(); } log.debug("Advising: " + jp.toShortString() + " of class: " + jp.getTarget().getClass().getSimpleName() +"<" + entityClassName + ">" ); } try { Session session = sessionFactory.getCurrentSession(); for (SessionProcessor sp : sessionProcessors) sp.processSession(session); } catch (HibernateException he) { log.error(he); } }
Example 6
Source File: RequiresParseDetailAspect.java From mp4parser with Apache License 2.0 | 5 votes |
@Before("this(org.mp4parser.support.AbstractBox) && ((execution(public * * (..)) && !( " + "execution(* parseDetails()) || " + "execution(* getNumOfBytesToFirstChild()) || " + "execution(* getType()) || " + "execution(* isParsed()) || " + "execution(* getHeader(*)) || " + "execution(* parse()) || " + "execution(* getBox(*)) || " + "execution(* getSize()) || " + "execution(* getOffset()) || " + "execution(* setOffset(*)) || " + "execution(* parseDetails()) || " + "execution(* _parseDetails(*)) || " + "execution(* parse(*,*,*,*)) || " + "execution(* getIsoFile()) || " + "execution(* getParent()) || " + "execution(* setParent(*)) || " + "execution(* getUserType()) || " + "execution(* setUserType(*))) && " + "!@annotation(org.mp4parser.support.DoNotParseDetail)) || @annotation(org.mp4parser.support.ParseDetail))") public void before(JoinPoint joinPoint) { if (joinPoint.getTarget() instanceof AbstractBox) { if (!((AbstractBox) joinPoint.getTarget()).isParsed()) { //System.err.println(String.format("parsed detail %s", joinPoint.getTarget().getClass().getSimpleName())); ((AbstractBox) joinPoint.getTarget()).parseDetails(); } } else { throw new RuntimeException("Only methods in subclasses of " + AbstractBox.class.getName() + " can be annotated with ParseDetail"); } }
Example 7
Source File: DynamicDataSourceAspect.java From Aooms with Apache License 2.0 | 5 votes |
@Before("dataSource()") public void changeDataSource(JoinPoint point) throws Throwable { Signature signature = point.getSignature(); if (signature instanceof MethodSignature) { MethodSignature msig = (MethodSignature) signature; Object target = point.getTarget(); Method currentMethod = target.getClass().getMethod(msig.getName(), msig.getParameterTypes()); if("use".equals(currentMethod.getName()) || "useOn".equals(currentMethod.getName()) || "uesOff".equals(currentMethod.getName())){ return; } DS dataSource = currentMethod.getAnnotation(DS.class); if(dataSource != null){ // 获取当前的指定的数据源; String name = dataSource.value(); if(StrUtil.isBlank(name)){ name = AoomsVar.DEFAULT_DATASOURCE; } if (!DynamicDataSourceHolder.containsDataSource(name)) { logger.error("datasource [{}] not found !",name); } else { logger.info(target.getClass().getName() + "." + currentMethod.getName() + " use datasource [{}]",name); DynamicDataSourceHolder.setDataSource(dataSource.value()); } } } }
Example 8
Source File: LogAspect.java From openregistry with Apache License 2.0 | 5 votes |
protected Logger getLog(final JoinPoint joinPoint) { final Object target = joinPoint.getTarget(); if (target != null) { return LoggerFactory.getLogger(target.getClass()); } return LoggerFactory.getLogger(getClass()); }
Example 9
Source File: TraceAspect.java From AspectJDemo with Apache License 2.0 | 5 votes |
/** * 在截获的目标方法调用之前执行该Advise * @param joinPoint * @throws Throwable */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Before("methodAnootatedWith()") public void onCreateBefore(JoinPoint joinPoint) throws Throwable{ Activity activity = null; //获取目标对象 activity = ((Activity)joinPoint.getTarget()); //插入自己的实现,控制目标对象的执行 ChooseDialog dialog = new ChooseDialog(activity); dialog.show(); //做其他的操作 buildLogMessage("test",20); }
Example 10
Source File: DataSourceAspect.java From springboot-multiple-dataSources with Apache License 2.0 | 5 votes |
@Before("declareJointPointExpression()") public void setDataSourceKey(JoinPoint point){ //根据连接点所属的类实例,动态切换数据源 if (point.getTarget() instanceof Test1Service || point.getTarget() instanceof Test1ServiceImpl) { DatabaseContextHolder.setDatabaseType(DatabaseType.test1); } else {//连接点所属的类实例是(当然,这一步也可以不写,因为defaultTargertDataSource就是该类所用的mytestdb) DatabaseContextHolder.setDatabaseType(DatabaseType.test2); } }
Example 11
Source File: FragmentInjection.java From FragmentRigger with MIT License | 5 votes |
@After("onViewCreated()") public void onViewCreatedProcess(JoinPoint joinPoint) throws Throwable { Object puppet = joinPoint.getTarget(); //Only inject the class that marked by Puppet annotation. Object[] args = joinPoint.getArgs(); Method onCreate = getRiggerMethod("onViewCreated", Object.class, View.class, Bundle.class); onCreate.invoke(getRiggerInstance(), puppet, args[0], args[1]); }
Example 12
Source File: CommandExecutionInterceptor.java From eventapis with Apache License 2.0 | 5 votes |
@Before("this(com.kloia.eventapis.api.CommandHandler) && @annotation(command)") public void before(JoinPoint jp, Command command) throws Throwable { Object target = jp.getTarget(); if (!(target instanceof CommandHandler)) throw new IllegalArgumentException("Point is not Instance of CommandHandler"); CommandHandler commandHandler = (CommandHandler) target; long commandTimeout = command.commandTimeout(); operationContext.startNewContext(commandTimeout); // Ability to generate new Context operationContext.setCommandContext(target.getClass().getSimpleName()); CommandRecord commandDto = recordCommand(jp, commandHandler, command); log.debug("before method:" + (commandDto == null ? "" : commandDto.toString())); }
Example 13
Source File: LogAspect.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
protected Logger getLog(final JoinPoint joinPoint) { final Object target = joinPoint.getTarget(); if (target != null) { return LoggerFactory.getLogger(target.getClass()); } return LoggerFactory.getLogger(getClass()); }
Example 14
Source File: LoggingAspect.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 5 votes |
@Before("execution(* cc.openhome.model.AccountDAO.*(..))") public void before(JoinPoint joinPoint) { Object target = joinPoint.getTarget(); String methodName = joinPoint.getSignature().getName(); Object[] args = joinPoint.getArgs(); Logger.getLogger(target.getClass().getName()) .info(String.format("%s.%s(%s)", target.getClass().getName(), methodName, Arrays.toString(args))); }
Example 15
Source File: DefaultAspect.java From java-client with Apache License 2.0 | 5 votes |
@After(EXECUTION_SEARCH) public void afterFindBy(JoinPoint joinPoint) throws Throwable { try { Object target = joinPoint.getTarget(); if (!WebElement.class.isAssignableFrom(target.getClass())) { listener.afterFindBy(castArgument(joinPoint, 0), null, driver); } else { listener.afterFindBy(castArgument(joinPoint, 0), castTarget(joinPoint), driver); } } catch (Throwable t) { throw getRootCause(t); } }
Example 16
Source File: ProfilingAspect.java From GreenSummer with GNU Lesser General Public License v2.1 | 5 votes |
protected static StringBuilder getMessage(JoinPoint joinPoint) { final StringBuilder messageSB = new StringBuilder(); if (joinPoint.getTarget() != null) { messageSB.append(joinPoint.getTarget().getClass().getSimpleName()); } else { messageSB.append(joinPoint.getSignature().getDeclaringType().getSimpleName()); } if (joinPoint.getSignature() != null) { messageSB.append('.'); String name = joinPoint.getSignature().getName(); if (joinPoint.getSignature() instanceof MethodSignature) { MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); Method targetMethod = methodSignature.getMethod(); Measured measured = targetMethod.getAnnotation(Measured.class); if (measured != null && measured.value() != null && measured.value().trim().length() > 0) { name = measured.value(); } else { Counted counted = targetMethod.getAnnotation(Counted.class); if (counted != null && counted.value() != null && counted.value().trim().length() > 0) { name = counted.value(); } } } messageSB.append(name); } return messageSB; }
Example 17
Source File: DynamicDataSourceAspect.java From Aooms with Apache License 2.0 | 5 votes |
@After("dataSource()") public void restoreDataSource(JoinPoint point) throws Throwable { Signature signature = point.getSignature(); if (signature instanceof MethodSignature) { MethodSignature msig = (MethodSignature) signature; Object target = point.getTarget(); Method currentMethod = target.getClass().getMethod(msig.getName(), msig.getParameterTypes()); if ("use".equals(currentMethod.getName()) || "useOn".equals(currentMethod.getName()) || "uesOff".equals(currentMethod.getName())) { //DynamicDataSourceHolder.setDataSource(); } else { DynamicDataSourceHolder.removeDataSource(); } } }
Example 18
Source File: KnoxShellTableHistoryAspect.java From knox with Apache License 2.0 | 4 votes |
@After("org.apache.knox.gateway.shell.table.KnoxShellTableHistoryAspect.knoxShellTableFilterPointcut()") public void afterFiltering(JoinPoint joinPoint) throws Throwable { final long builderId = ((KnoxShellTableFilter) joinPoint.getTarget()).filteredTable.id; saveKnoxShellTableCall(joinPoint, builderId); }
Example 19
Source File: DefaultAspect.java From java-client with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private <T> T castTarget(JoinPoint joinPoint) { return (T) joinPoint.getTarget(); }
Example 20
Source File: PageActionAspect.java From entando-components with GNU Lesser General Public License v3.0 | 4 votes |
@Before("execution(* com.agiletec.plugins.jacms.apsadmin.portal.PageAction.validate())") public void executeExtraValidation(JoinPoint joinPoint) { PageAction action = (PageAction) joinPoint.getTarget(); this.checkFriendlyCode(action); this.extractAndSetSeoFields(); }