本文整理匯總了Java中org.springframework.aop.support.AopUtils.getTargetClass方法的典型用法代碼示例。如果您正苦於以下問題:Java AopUtils.getTargetClass方法的具體用法?Java AopUtils.getTargetClass怎麽用?Java AopUtils.getTargetClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.aop.support.AopUtils
的用法示例。
在下文中一共展示了AopUtils.getTargetClass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isMatchPackage
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
private boolean isMatchPackage(Object bean) {
if (annotationPackages == null || annotationPackages.length == 0) {
return true;
}
Class clazz = bean.getClass();
if(isProxyBean(bean)){
clazz = AopUtils.getTargetClass(bean);
}
String beanClassName = clazz.getName();
for (String pkg : annotationPackages) {
if (beanClassName.startsWith(pkg)) {
return true;
}
}
return false;
}
示例2: adaptMBeanIfPossible
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
/**
* Build an adapted MBean for the given bean instance, if possible.
* <p>The default implementation builds a JMX 1.2 StandardMBean
* for the target's MBean/MXBean interface in case of an AOP proxy,
* delegating the interface's management operations to the proxy.
* @param bean the original bean instance
* @return the adapted MBean, or {@code null} if not possible
*/
@SuppressWarnings("unchecked")
protected DynamicMBean adaptMBeanIfPossible(Object bean) throws JMException {
Class<?> targetClass = AopUtils.getTargetClass(bean);
if (targetClass != bean.getClass()) {
Class<?> ifc = JmxUtils.getMXBeanInterface(targetClass);
if (ifc != null) {
if (!ifc.isInstance(bean)) {
throw new NotCompliantMBeanException("Managed bean [" + bean +
"] has a target class with an MXBean interface but does not expose it in the proxy");
}
return new StandardMBean(bean, ((Class<Object>) ifc), true);
}
else {
ifc = JmxUtils.getMBeanInterface(targetClass);
if (ifc != null) {
if (!ifc.isInstance(bean)) {
throw new NotCompliantMBeanException("Managed bean [" + bean +
"] has a target class with an MBean interface but does not expose it in the proxy");
}
return new StandardMBean(bean, ((Class<Object>) ifc));
}
}
}
return null;
}
示例3: getObjectName
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
/**
* Reads the {@code ObjectName} from the source-level metadata associated
* with the managed resource's {@code Class}.
*/
@Override
public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
Class<?> managedClass = AopUtils.getTargetClass(managedBean);
ManagedResource mr = this.attributeSource.getManagedResource(managedClass);
// Check that an object name has been specified.
if (mr != null && StringUtils.hasText(mr.getObjectName())) {
return ObjectNameManager.getInstance(mr.getObjectName());
}
else {
try {
return ObjectNameManager.getInstance(beanKey);
}
catch (MalformedObjectNameException ex) {
String domain = this.defaultDomain;
if (domain == null) {
domain = ClassUtils.getPackageName(managedClass);
}
Hashtable<String, String> properties = new Hashtable<String, String>();
properties.put("type", ClassUtils.getShortName(managedClass));
properties.put("name", beanKey);
return ObjectNameManager.getInstance(domain, properties);
}
}
}
示例4: parseFlowTx
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
/**
* 解析流程事務
*
* @param flowTx 流程事務
* @param transactionManager 事務管理器
* @return 流程事務執行器
*/
public static FlowTxExecutor parseFlowTx(Object flowTx, PlatformTransactionManager transactionManager) {
// 獲取目標class(應對AOP代理情況)
Class<?> flowTxClass = AopUtils.getTargetClass(flowTx);
logger.debug("解析流程事務:{}", ClassUtils.getQualifiedName(flowTxClass));
FlowTx flowTxAnnotation = flowTxClass.getAnnotation(FlowTx.class);
// 創建流程事務執行器
FlowTxExecutor flowTxExecutor = new FlowTxExecutor(flowTxAnnotation.flow(), flowTx, transactionManager);
for (Method method : flowTxClass.getDeclaredMethods()) {
for (Class clazz : FlowTxExecutor.FLOW_TX_OPERATE_ANNOTATIONS) {
if (method.isAnnotationPresent(clazz)) {
// 設置流程事務操作執行器
flowTxExecutor.setOperateExecutor(clazz, parseFlowTxOperate(method));
break;
}
}
}
flowTxExecutor.validate();
return flowTxExecutor;
}
示例5: parseProcessor
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
/**
* 解析處理器
*
* @param processor 處理器
* @return 處理器執行器
*/
public static ProcessorExecutor parseProcessor(Object processor) {
// 獲取目標class(應對AOP代理情況)
Class<?> processorClass = AopUtils.getTargetClass(processor);
logger.debug("解析處理器:{}", ClassUtils.getQualifiedName(processorClass));
// 獲取處理器名稱
String processorName = processorClass.getAnnotation(Processor.class).name();
if (StringUtils.isEmpty(processorName)) {
processorName = ClassUtils.getShortNameAsProperty(processorClass);
}
// 創建處理器執行器
ProcessorExecutor processorExecutor = new ProcessorExecutor(processorName, processor);
for (Method method : processorClass.getDeclaredMethods()) {
for (Class clazz : ProcessorExecutor.PROCESSOR_METHOD_ANNOTATIONS) {
if (method.isAnnotationPresent(clazz)) {
// 設置處理器方法執行器
processorExecutor.setMethodExecutor(clazz, parseProcessorMethod(clazz, method));
break;
}
}
}
processorExecutor.validate();
return processorExecutor;
}
示例6: parseListener
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
/**
* 解析監聽器
*
* @param listener 監聽器
* @return 監聽器執行器
*/
public static ListenerExecutor parseListener(Object listener) {
// 獲取目標class(應對AOP代理情況)
Class<?> listenerClass = AopUtils.getTargetClass(listener);
logger.debug("解析監聽器:{}", ClassUtils.getQualifiedName(listenerClass));
// 此處得到的@Listener是已經經過@AliasFor屬性別名進行屬性同步後的結果
Listener listenerAnnotation = AnnotatedElementUtils.findMergedAnnotation(listenerClass, Listener.class);
// 創建監聽器執行器
ListenerExecutor listenerExecutor = new ListenerExecutor(listener, listenerAnnotation.type(), listenerAnnotation.priority(), parseEventTypeResolver(listenerAnnotation.type()));
for (Method method : listenerClass.getDeclaredMethods()) {
Listen listenAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, Listen.class);
if (listenAnnotation != null) {
ListenExecutor listenExecutor = parseListen(listenAnnotation, method);
listenerExecutor.addListenExecutor(listenExecutor);
}
}
listenerExecutor.validate();
return listenerExecutor;
}
示例7: findAnnotation
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
SchedulerLock findAnnotation(ScheduledMethodRunnable task) {
Method method = task.getMethod();
SchedulerLock annotation = findAnnotation(method);
if (annotation != null) {
return annotation;
} else {
// Try to find annotation on proxied class
Class<?> targetClass = AopUtils.getTargetClass(task.getTarget());
if (targetClass != null && !task.getTarget().getClass().equals(targetClass)) {
try {
Method methodOnTarget = targetClass
.getMethod(method.getName(), method.getParameterTypes());
return findAnnotation(methodOnTarget);
} catch (NoSuchMethodException e) {
return null;
}
} else {
return null;
}
}
}
示例8: newJob
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
@Override
public Job newJob(final TriggerFiredBundle bundle, final Scheduler scheduler) throws SchedulerException {
Preconditions.checkNotNull(applicationContext, "applicationContext cannot be null, should call setApplicationContext first.");
Job job = null;
try {
for (Job each : applicationContext.getBeansOfType(Job.class).values()) {
if (AopUtils.getTargetClass(each) == bundle.getJobDetail().getJobClass()) {
job = each;
break;
}
}
if (null == job) {
throw new NoSuchBeanDefinitionException("");
}
} catch (final BeansException ex) {
log.info("Elastic job: cannot found bean for class: '{}'. This job is not managed for spring.", bundle.getJobDetail().getJobClass().getCanonicalName());
return super.newJob(bundle, scheduler);
}
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.putAll(scheduler.getContext());
jobDataMap.putAll(bundle.getJobDetail().getJobDataMap());
jobDataMap.putAll(bundle.getTrigger().getJobDataMap());
Job target = (Job) AopTargetUtils.getTarget(job);
setBeanProps(target, jobDataMap);
return target;
}
示例9: getMainCommand
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
private Object getMainCommand(Collection<Object> candidates) {
Object mainCommand = null;
for (Object candidate : candidates) {
Class<?> clazz = AopUtils.getTargetClass(candidate);
Method method = ReflectionUtils.findMethod(Command.class, "name");
if (clazz.isAnnotationPresent(Command.class)
&& method != null
&& clazz.getAnnotation(Command.class).name().equals(method.getDefaultValue())) {
mainCommand = candidate;
break;
}
}
if (mainCommand == null) {
mainCommand = new PicocliCommand() {};
}
return mainCommand;
}
示例10: isTransactionalApplicationEventListener
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
private static boolean isTransactionalApplicationEventListener(ApplicationListener<?> listener) {
Class<?> targetClass = AopUtils.getTargetClass(listener);
if (!ApplicationListenerMethodAdapter.class.isAssignableFrom(targetClass)) {
return false;
}
Field field = ReflectionUtils.findField(ApplicationListenerMethodAdapter.class, "method");
ReflectionUtils.makeAccessible(field);
Method method = (Method) ReflectionUtils.getField(field, listener);
return AnnotatedElementUtils.hasAnnotation(method, TransactionalEventListener.class);
}
開發者ID:olivergierke,項目名稱:spring-domain-events,代碼行數:15,代碼來源:PersistentApplicationEventMulticaster.java
示例11: getServiceClass
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
@Override
protected Class getServiceClass(T ref) {
if (AopUtils.isAopProxy(ref)) {
return AopUtils.getTargetClass(ref);
}
return super.getServiceClass(ref);
}
示例12: loadSshdShellCommands
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
private void loadSshdShellCommands(Map<String, Map<String, CommandExecutableDetails>> sshdShellCommandsMap,
Object obj) throws SecurityException, NoSuchMethodException, InterruptedException {
Class<?> clazz = AopUtils.isAopProxy(obj) ? AopUtils.getTargetClass(obj) : obj.getClass();
SshdShellCommand annotation = AnnotationUtils.findAnnotation(clazz, SshdShellCommand.class);
Map<String, CommandExecutableDetails> map = getSupplierMap(annotation, sshdShellCommandsMap);
loadSshdShellCommandSuppliers(clazz, annotation, map, obj);
}
示例13: invoke
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
// Work out the target class: may be {@code null}.
// The TransactionAttributeSource should be passed the target class
// as well as the method, which may be from an interface.
Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null);
// Adapt to TransactionAspectSupport's invokeWithinTransaction...
return invokeWithinTransaction(invocation.getMethod(), targetClass, new InvocationCallback() {
@Override
public Object proceedWithInvocation() throws Throwable {
return invocation.proceed();
}
});
}
示例14: supportsEventType
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
Class<?> declaredEventType = resolveDeclaredEventType(this.delegate.getClass());
if (declaredEventType == null || declaredEventType.equals(ApplicationEvent.class)) {
Class<?> targetClass = AopUtils.getTargetClass(this.delegate);
if (targetClass != this.delegate.getClass()) {
declaredEventType = resolveDeclaredEventType(targetClass);
}
}
return (declaredEventType == null || declaredEventType.isAssignableFrom(eventType));
}
示例15: testPostProcessAfterInitialization
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
@Test
public void testPostProcessAfterInitialization() throws IOException, NoSuchMethodException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
TestSteps steps = context.getBean(TestSteps.class);
Class<?> wrapped = AopUtils.getTargetClass(steps);
Method method = wrapped.getMethod("anotherStep", String.class);
Map<String, StepImplementation> givenBeanIndex = context.getBeansOfType(StepImplementation.class);
Collection<StepImplementation> givens = givenBeanIndex.values();
List<StepImplementation> matches = Lists.newArrayList();
for (StepImplementation given : givens) {
Method givenMethod = given.getMethod();
if (givenMethod.equals(method)) {
matches.add(given);
}
}
int count = matches.size();
assertEquals(count, 1, "wrong number of GivenStep objects registered for TestSteps.anotherStep()");
StepImplementation match = matches.get(0);
Pattern pattern = match.getPattern();
Matcher matcher = pattern.matcher("another \"(.+)\" here");
assertTrue(matcher.find(), "expected Pattern to match Gherkin regular expression");
assertEquals(matcher.groupCount(), 1, "wrong number of parameters captured for TestSteps.anotherStep()");
}