Java Code Examples for org.aspectj.lang.ProceedingJoinPoint#getThis()

The following examples show how to use org.aspectj.lang.ProceedingJoinPoint#getThis() . 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: CompensableMethodInterceptor.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
@org.aspectj.lang.annotation.Around("@within(org.bytesoft.compensable.Compensable)")
public Object invoke(final ProceedingJoinPoint pjp) throws Throwable {
	CompensableManager compensableManager = this.beanFactory.getCompensableManager();
	CompensableTransaction compensable = compensableManager.getCompensableTransactionQuietly();
	if (compensable != null && compensable.getTransactionContext() != null
			&& compensable.getTransactionContext().isCompensating()) {
		return pjp.proceed();
	}

	Object bean = pjp.getThis();
	String identifier = this.getBeanName(bean);

	MethodSignature signature = (MethodSignature) pjp.getSignature();
	Method method = signature.getMethod();
	Object[] args = pjp.getArgs();
	AspectJoinpoint point = new AspectJoinpoint(pjp);
	return this.execute(identifier, method, args, point);
}
 
Example 2
Source File: ViewInspectorAspect.java    From ViewInspector with Apache License 2.0 6 votes vote down vote up
@Around("activityOnCreatedCall()")
public Object injectViewInspector(ProceedingJoinPoint joinPoint) throws Throwable {
  Log.d(ViewInspector.TAG, "injectViewInspector");
  Context context = (Context) joinPoint.getThis();

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    if (Settings.canDrawOverlays(context)) {
      mViewInspector.onCreate(context);
      isRestarting = false;
    } else {
      isRequestingOverlayPermission = true;
      Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
      ((Activity) context).startActivityForResult(intent, OVERLAY_PERMISSION_CALL);
    }
  } else {
    mViewInspector.onCreate(context);
  }

  return joinPoint.proceed();
}
 
Example 3
Source File: ViewInspectorAspect.java    From ViewInspector with Apache License 2.0 6 votes vote down vote up
@Around("activityOnResumeCall()") public Object showViewInspector(ProceedingJoinPoint joinPoint)
    throws Throwable {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    Context context = (Context) joinPoint.getThis();
    if (isRequestingOverlayPermission) {
      if (Settings.canDrawOverlays(context)) {
        // relaunching the app for deploying Probe features
        Intent intent =
            context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        ((Activity) context).finish();
        isRequestingOverlayPermission = false;
        isRestarting = true;
        context.startActivity(intent);
      }
    } else {
      mViewInspector.onResume();
    }
  } else {
    mViewInspector.onResume();
  }

  return joinPoint.proceed();
}
 
Example 4
Source File: DataInspectorAspect.java    From DataInspector with Apache License 2.0 6 votes vote down vote up
@Around("activityOnCreatedCall()")
public Object injectDataInspector(ProceedingJoinPoint joinPoint) throws Throwable {
  Log.d(DataInspector.TAG, "injectDataInspector");
  Context context = (Context) joinPoint.getThis();

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    if (Settings.canDrawOverlays(context)) {
      dataInspector.onCreate(context);
      isRestarting = false;
    } else {
      isRequestingOverlayPermission = true;
      Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
      ((Activity) context).startActivityForResult(intent, OVERLAY_PERMISSION_CALL);
    }
  } else {
    dataInspector.onCreate(context);
  }

  return joinPoint.proceed();
}
 
Example 5
Source File: DataInspectorAspect.java    From DataInspector with Apache License 2.0 6 votes vote down vote up
@Around("activityOnResumeCall()") public Object showDataInspector(ProceedingJoinPoint joinPoint)
    throws Throwable {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    Context context = (Context) joinPoint.getThis();
    if (isRequestingOverlayPermission) {
      if (Settings.canDrawOverlays(context)) {
        // relaunching the app for deploying Probe features
        Intent intent =
            context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        ((Activity) context).finish();
        isRequestingOverlayPermission = false;
        isRestarting = true;
        context.startActivity(intent);
      }
    } else {
      dataInspector.onResume();
    }
  } else {
    dataInspector.onResume();
  }

  return joinPoint.proceed();
}
 
Example 6
Source File: MandatoryAspect.java    From bdt with Apache License 2.0 6 votes vote down vote up
/**
 * @param pjp ProceedingJoinPoint
 * @param pickle pickle
 * @throws Throwable exception
 */
@Around(value = "addMandatoryPointcutScenario(pickle)")
public void aroundAddMandatoryPointcut(ProceedingJoinPoint pjp, PickleEvent pickle) throws Throwable {
    Runner runner = (Runner) pjp.getThis();

    Class<?> sc = runner.getClass();
    Method tt = sc.getDeclaredMethod("buildBackendWorlds");
    tt.setAccessible(true);
    tt.invoke(runner);

    String scenarioName = pickle.pickle.getName();
    List<PickleTag> pickleTagList = pickle.pickle.getTags();
    List<String> tagList = new ArrayList<>();
    for (PickleTag pt:pickleTagList) {
        tagList.add(pt.getName());
    }

    boolean exec = manageTags(tagList);
    if (!exec) {
        logger.error("Feature will not be executed. Mandatory variables not defined.");
    } else {
        pjp.proceed();
    }
}
 
Example 7
Source File: TransactionAspect.java    From tx-lcn with Apache License 2.0 5 votes vote down vote up
@Around("this(com.codingapi.txlcn.tc.annotation.ITxTransaction) && execution( * *(..))")
public Object around(ProceedingJoinPoint point) throws Throwable {
    if (!(point.getThis() instanceof ITxTransaction)) {
        throw new IllegalStateException("error join point");
    }
    DTXInfo dtxInfo = DTXInfo.getFromCache(point);
    ITxTransaction txTransaction = (ITxTransaction) point.getThis();
    dtxInfo.setTransactionType(txTransaction.transactionType());
    dtxInfo.setTransactionPropagation(DTXPropagation.REQUIRED);
    return dtxLogicWeaver.runTransaction(dtxInfo, point::proceed);
}
 
Example 8
Source File: ViewInspectorAspect.java    From ViewInspector with Apache License 2.0 5 votes vote down vote up
@Around("activityOnDestroyCall()")
public Object destroyViewInspector(ProceedingJoinPoint joinPoint) throws Throwable {
  if (!isRequestingOverlayPermission && !isRestarting) {
    Context context = (Context) joinPoint.getThis();
    mViewInspector.onDestroy(context);
  }
  return joinPoint.proceed();
}
 
Example 9
Source File: DataInspectorAspect.java    From DataInspector with Apache License 2.0 5 votes vote down vote up
@Around("activityOnDestroyCall()")
public Object destroyDataInspector(ProceedingJoinPoint joinPoint) throws Throwable {
  if (!isRequestingOverlayPermission && !isRestarting) {
    Context context = (Context) joinPoint.getThis();
    dataInspector.onDestroy(context);
  }
  return joinPoint.proceed();
}
 
Example 10
Source File: IgnoreTagAspect.java    From bdt with Apache License 2.0 5 votes vote down vote up
/**
 * @param pjp    ProceedingJoinPoint
 * @param pickle pickle
 * @throws Throwable exception
 */
@Around(value = "addIgnoreTagPointcutScenario(pickle)")
public void aroundAddIgnoreTagPointcut(ProceedingJoinPoint pjp, PickleEvent pickle) throws Throwable {
    Runner runner = (Runner) pjp.getThis();

    Class<?> sc = runner.getClass();
    Method tt = sc.getDeclaredMethod("buildBackendWorlds");
    tt.setAccessible(true);
    tt.invoke(runner);

    String scenarioName = pickle.pickle.getName();
    List<PickleTag> pickleTagList = pickle.pickle.getTags();
    List<String> tagList = new ArrayList<>();
    for (PickleTag pt : pickleTagList) {
        tagList.add(pt.getName());
    }

    ignoreReasons exitReason = manageTags(tagList, scenarioName);
    if (exitReason.equals(ignoreReasons.NOREASON)) {
        logger.error("Scenario '" + scenarioName + "' failed due to wrong use of the @ignore tag.");
    }

    if ((!(exitReason.equals(ignoreReasons.NOTIGNORED))) && (!(exitReason.equals(ignoreReasons.NOREASON)))) {
        tt = sc.getDeclaredMethod("disposeBackendWorlds");
        tt.setAccessible(true);
        tt.invoke(runner);
    } else {
        pjp.proceed();
    }
}
 
Example 11
Source File: TargetHandle.java    From Surgeon with Apache License 2.0 4 votes vote down vote up
TargetHandle(ProceedingJoinPoint origin) {
    if (origin != null) {
        this.origin = origin;
        this.target = origin.getThis();
    }
}
 
Example 12
Source File: RouteExtensions.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Around("execution(@org.alfresco.traitextender.Extend * *(..)) && (@annotation(extendAnnotation))")
public Object intercept(ProceedingJoinPoint pjp, Extend extendAnnotation) throws Throwable
{
    boolean ajPointsEnabled = AJExtender.areAJPointsEnabled();
    try
    {
        AJExtender.enableAJPoints();
        if (ajPointsEnabled)
        {
            Object extensibleObject = pjp.getThis();
            if (!(extensibleObject instanceof Extensible))
            {
                throw new InvalidExtension("Invalid extension point for non extensible class  : "
                            + extensibleObject.getClass());
            }
            Extensible extensible = (Extensible) extensibleObject;

            @SuppressWarnings({ "rawtypes", "unchecked" })
            ExtensionPoint point = new ExtensionPoint(extendAnnotation.extensionAPI(),
                                                      extendAnnotation.traitAPI());
            @SuppressWarnings("unchecked")
            Object extension = Extender.getInstance().getExtension(extensible,
                                                                   point);
            if (extension != null)
            {

                return AJExtender.extendAroundAdvice(pjp,
                                                     extensible,
                                                     extendAnnotation,
                                                     extension);
            }
            else if (logger.isDebugEnabled())
            {
                MethodSignature ms = (MethodSignature) pjp.getSignature();
                Method traitMethod = ms.getMethod();

                AJExtender.oneTimeLiveLog(logger,
                                          new ExtensionRoute(extendAnnotation,
                                                             traitMethod));
            }
        }
        return pjp.proceed();
    }
    finally
    {
        AJExtender.revertAJPoints();
    }
}