Java Code Examples for org.springframework.aop.aspectj.AspectJAroundAdvice

The following examples show how to use org.springframework.aop.aspectj.AspectJAroundAdvice. These examples are extracted from open source projects. 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 Project: spring-analysis-note   Source File: ConfigBeanDefinitionParser.java    License: MIT License 6 votes vote down vote up
/**
 * Gets the advice implementation class corresponding to the supplied {@link Element}.
 */
private Class<?> getAdviceClass(Element adviceElement, ParserContext parserContext) {
	String elementName = parserContext.getDelegate().getLocalName(adviceElement);
	if (BEFORE.equals(elementName)) {
		return AspectJMethodBeforeAdvice.class;
	}
	else if (AFTER.equals(elementName)) {
		return AspectJAfterAdvice.class;
	}
	else if (AFTER_RETURNING_ELEMENT.equals(elementName)) {
		return AspectJAfterReturningAdvice.class;
	}
	else if (AFTER_THROWING_ELEMENT.equals(elementName)) {
		return AspectJAfterThrowingAdvice.class;
	}
	else if (AROUND.equals(elementName)) {
		return AspectJAroundAdvice.class;
	}
	else {
		throw new IllegalArgumentException("Unknown advice kind [" + elementName + "].");
	}
}
 
Example 2
Source Project: java-technology-stack   Source File: ConfigBeanDefinitionParser.java    License: MIT License 6 votes vote down vote up
/**
 * Gets the advice implementation class corresponding to the supplied {@link Element}.
 */
private Class<?> getAdviceClass(Element adviceElement, ParserContext parserContext) {
	String elementName = parserContext.getDelegate().getLocalName(adviceElement);
	if (BEFORE.equals(elementName)) {
		return AspectJMethodBeforeAdvice.class;
	}
	else if (AFTER.equals(elementName)) {
		return AspectJAfterAdvice.class;
	}
	else if (AFTER_RETURNING_ELEMENT.equals(elementName)) {
		return AspectJAfterReturningAdvice.class;
	}
	else if (AFTER_THROWING_ELEMENT.equals(elementName)) {
		return AspectJAfterThrowingAdvice.class;
	}
	else if (AROUND.equals(elementName)) {
		return AspectJAroundAdvice.class;
	}
	else {
		throw new IllegalArgumentException("Unknown advice kind [" + elementName + "].");
	}
}
 
Example 3
/**
 * Gets the advice implementation class corresponding to the supplied {@link Element}.
 */
private Class<?> getAdviceClass(Element adviceElement, ParserContext parserContext) {
	String elementName = parserContext.getDelegate().getLocalName(adviceElement);
	if (BEFORE.equals(elementName)) {
		return AspectJMethodBeforeAdvice.class;
	}
	else if (AFTER.equals(elementName)) {
		return AspectJAfterAdvice.class;
	}
	else if (AFTER_RETURNING_ELEMENT.equals(elementName)) {
		return AspectJAfterReturningAdvice.class;
	}
	else if (AFTER_THROWING_ELEMENT.equals(elementName)) {
		return AspectJAfterThrowingAdvice.class;
	}
	else if (AROUND.equals(elementName)) {
		return AspectJAroundAdvice.class;
	}
	else {
		throw new IllegalArgumentException("Unknown advice kind [" + elementName + "].");
	}
}
 
Example 4
Source Project: marshalsec   Source File: SpringUtil.java    License: MIT License 6 votes vote down vote up
/**
 * @param jndiUrl
 * @param bf
 * @return
 * @throws ClassNotFoundException
 * @throws NoSuchMethodException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws Exception
 */
public static Object makeBeanFactoryTriggerPCAH ( UtilFactory uf, String name, BeanFactory bf ) throws ClassNotFoundException,
        NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, Exception {
    AspectInstanceFactory aif = Reflections.createWithoutConstructor(BeanFactoryAspectInstanceFactory.class);
    Reflections.setFieldValue(aif, "beanFactory", bf);
    Reflections.setFieldValue(aif, "name", name);
    AbstractAspectJAdvice advice = Reflections.createWithoutConstructor(AspectJAroundAdvice.class);
    Reflections.setFieldValue(advice, "aspectInstanceFactory", aif);

    // make readObject happy if it is called
    Reflections.setFieldValue(advice, "declaringClass", Object.class);
    Reflections.setFieldValue(advice, "methodName", "toString");
    Reflections.setFieldValue(advice, "parameterTypes", new Class[0]);

    AspectJPointcutAdvisor advisor = Reflections.createWithoutConstructor(AspectJPointcutAdvisor.class);
    Reflections.setFieldValue(advisor, "advice", advice);

    Class<?> pcahCl = Class
            .forName("org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator$PartiallyComparableAdvisorHolder");
    Object pcah = Reflections.createWithoutConstructor(pcahCl);
    Reflections.setFieldValue(pcah, "advisor", advisor);
    return uf.makeToStringTriggerUnstable(pcah);
}
 
Example 5
/**
 * Gets the advice implementation class corresponding to the supplied {@link Element}.
 */
private Class<?> getAdviceClass(Element adviceElement, ParserContext parserContext) {
	String elementName = parserContext.getDelegate().getLocalName(adviceElement);
	if (BEFORE.equals(elementName)) {
		return AspectJMethodBeforeAdvice.class;
	}
	else if (AFTER.equals(elementName)) {
		return AspectJAfterAdvice.class;
	}
	else if (AFTER_RETURNING_ELEMENT.equals(elementName)) {
		return AspectJAfterReturningAdvice.class;
	}
	else if (AFTER_THROWING_ELEMENT.equals(elementName)) {
		return AspectJAfterThrowingAdvice.class;
	}
	else if (AROUND.equals(elementName)) {
		return AspectJAroundAdvice.class;
	}
	else {
		throw new IllegalArgumentException("Unknown advice kind [" + elementName + "].");
	}
}
 
Example 6
Source Project: learnjavabug   Source File: SpringUtil.java    License: MIT License 5 votes vote down vote up
/**
 *
 */
public static Object makeBeanFactoryTriggerPCAH(String name, BeanFactory bf)
    throws ClassNotFoundException,
    NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, Exception {
  AspectInstanceFactory aif = Reflections.createWithoutConstructor(
      BeanFactoryAspectInstanceFactory.class);
  Reflections.setFieldValue(aif, "beanFactory", bf);
  Reflections.setFieldValue(aif, "name", name);
  AbstractAspectJAdvice advice = Reflections.createWithoutConstructor(AspectJAroundAdvice.class);
  Reflections.setFieldValue(advice, "aspectInstanceFactory", aif);

  // make readObject happy if it is called
  Reflections.setFieldValue(advice, "declaringClass", Object.class);
  Reflections.setFieldValue(advice, "methodName", "toString");
  Reflections.setFieldValue(advice, "parameterTypes", new Class[0]);

  AspectJPointcutAdvisor advisor = Reflections.createWithoutConstructor(
      AspectJPointcutAdvisor.class);
  Reflections.setFieldValue(advisor, "advice", advice);

  Class<?> pcahCl = Class
      .forName(
          "org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator$PartiallyComparableAdvisorHolder");
  Object pcah = Reflections.createWithoutConstructor(pcahCl);
  Reflections.setFieldValue(pcah, "advisor", advisor);
  return ToStringUtil.makeSpringAOPToStringTrigger(pcah);
}
 
Example 7
private Advisor createAspectJAroundAdvice(int advisorOrder, int adviceDeclarationOrder, String aspectName) {
	AspectJAroundAdvice advice = new AspectJAroundAdvice(this.anyOldMethod, this.anyOldPointcut, null);
	return createAspectJAdvice(advisorOrder, adviceDeclarationOrder, aspectName, advice);
}
 
Example 8
private Advisor createAspectJAroundAdvice(int advisorOrder, int adviceDeclarationOrder, String aspectName) {
	AspectJAroundAdvice advice = new AspectJAroundAdvice(this.anyOldMethod, this.anyOldPointcut, null);
	return createAspectJAdvice(advisorOrder, adviceDeclarationOrder, aspectName, advice);
}
 
Example 9
private Advisor createAspectJAroundAdvice(int advisorOrder, int adviceDeclarationOrder, String aspectName) {
	AspectJAroundAdvice advice = new AspectJAroundAdvice(this.anyOldMethod, this.anyOldPointcut, null);
	return createAspectJAdvice(advisorOrder, adviceDeclarationOrder, aspectName, advice);
}