/** * Gets the caller of the given joinpoint. For a call joinpoint you have * "this" as attribute which gives you the caller. But for an execution * joinpoint "this" is not the caller but the object of execution. If you * want the caller of the excution joinpoint call this method here. * <p> * Sometime the caller of the method is an aspect. Because normally you do * not want the aspect it is filtered out. If you really want it call * {@link #getCallerOf(JoinPoint, Pattern...)} direct with an empty pattern * argument. * </p> * * @param jp * the (execution) joinpoint * @return the caller of the given joinpoint * @see #getCallerOf(JoinPoint, Pattern...) */ public static StackTraceElement getCallerOf(final JoinPoint jp) { return getCallerOf(jp, ADVICE_PATTERNS); }
private String getCallerNameOf(final JoinPoint execution) { StackTraceElement caller = JoinPointHelper.getCallerOf(execution); String classname = caller.getClassName(); for (Entry<Object, String> entry : varnames.entrySet()) { if (classname.equals(entry.getKey().getClass().getName())) { LOG.trace("Caller of {} is {}.", execution, entry); return entry.getValue(); } } LOG.trace("Caller of {} not found in {}.", execution, varnames); try { return this.addObject(Class.forName(caller.getClassName())); } catch (ClassNotFoundException ex) { LOG.info("cannot get class for {}:", caller, ex); return getActorName(); } }
/** * Logs the creation of an object in the created sequence diagram. * * @param call * the call * @param result * the created object */ public void createMessage(final JoinPoint call, final Object result) { Object creator = call.getThis(); if (creator == null) { String classname = JoinPointHelper.getCallerOf(call).getClassName(); try { creator = Class.forName(classname); } catch (ClassNotFoundException ex) { throw new NotFoundException(classname, ex); } } this.createMessage(creator, result, call.getStaticPart()); }