blob: 2b6c5d61f2d51acab75752c5c0b8472c23cc7298 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>BeforeAdviceMethodInvocationAdapter.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">Apache Shiro :: All (aggregate jar)</a> &gt; <a href="../index.html" class="el_bundle">shiro-aspectj</a> &gt; <a href="index.source.html" class="el_package">org.apache.shiro.aspectj</a> &gt; <span class="el_source">BeforeAdviceMethodInvocationAdapter.java</span></div><h1>BeforeAdviceMethodInvocationAdapter.java</h1><pre class="source lang-java linenums">/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* &quot;License&quot;); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.shiro.aspectj;
import org.apache.shiro.aop.MethodInvocation;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.AdviceSignature;
import org.aspectj.lang.reflect.MethodSignature;
import java.lang.reflect.Method;
/**
* Helper class that adapts an AspectJ {@link JoinPoint JoinPoint}.
*
* @since 1.0
*/
public class BeforeAdviceMethodInvocationAdapter implements MethodInvocation {
private Object _object;
private Method _method;
private Object[] _arguments;
/**
* Factory method that creates a new {@link BeforeAdviceMethodInvocationAdapter} instance
* using the AspectJ {@link JoinPoint} provided. If the joint point passed in is not
* a method joint point, this method throws an {@link IllegalArgumentException}.
*
* @param aJoinPoint The AspectJ {@link JoinPoint} to use to adapt the advice.
* @return The created instance.
* @throws IllegalArgumentException If the join point passed in does not involve a method call.
*/
public static BeforeAdviceMethodInvocationAdapter createFrom(JoinPoint aJoinPoint) {
<span class="pc bpc" id="L49" title="1 of 2 branches missed."> if (aJoinPoint.getSignature() instanceof MethodSignature) {</span>
<span class="fc" id="L50"> return new BeforeAdviceMethodInvocationAdapter(aJoinPoint.getThis(),</span>
<span class="fc" id="L51"> ((MethodSignature) aJoinPoint.getSignature()).getMethod(),</span>
<span class="fc" id="L52"> aJoinPoint.getArgs());</span>
<span class="nc bnc" id="L54" title="All 2 branches missed."> } else if (aJoinPoint.getSignature() instanceof AdviceSignature) {</span>
<span class="nc" id="L55"> return new BeforeAdviceMethodInvocationAdapter(aJoinPoint.getThis(),</span>
<span class="nc" id="L56"> ((AdviceSignature) aJoinPoint.getSignature()).getAdvice(),</span>
<span class="nc" id="L57"> aJoinPoint.getArgs());</span>
} else {
<span class="nc" id="L60"> throw new IllegalArgumentException(&quot;The joint point signature is invalid: expected a MethodSignature or an AdviceSignature but was &quot; + aJoinPoint.getSignature());</span>
}
}
/**
* Creates a new {@link BeforeAdviceMethodInvocationAdapter} instance.
*
* @param aMethod The method to invoke.
* @param someArguments The arguments of the method invocation.
*/
<span class="fc" id="L70"> public BeforeAdviceMethodInvocationAdapter(Object anObject, Method aMethod, Object[] someArguments) {</span>
<span class="fc" id="L71"> _object = anObject;</span>
<span class="fc" id="L72"> _method = aMethod;</span>
<span class="fc" id="L73"> _arguments = someArguments;</span>
<span class="fc" id="L74"> }</span>
/* (non-Javadoc)
* @see org.apache.shiro.aop.MethodInvocation#getArguments()
*/
public Object[] getArguments() {
<span class="nc" id="L81"> return _arguments;</span>
}
/* (non-Javadoc)
* @see org.apache.shiro.aop.MethodInvocation#getMethod()
*/
public Method getMethod() {
<span class="fc" id="L89"> return _method;</span>
}
/* (non-Javadoc)
* @see org.apache.shiro.aop.MethodInvocation#proceed()
*/
public Object proceed() throws Throwable {
// Do nothing since this adapts a before advice
<span class="fc" id="L98"> return null;</span>
}
/**
* @since 1.0
*/
public Object getThis() {
<span class="fc" id="L105"> return _object;</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.3.201901230119</span></div></body></html>