List of usage examples for java.lang.reflect Method equals
public boolean equals(Object obj)
From source file:com.impetus.kundera.proxy.cglib.CglibLazyInitializer.java
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (constructed) { String methodName = method.getName(); int params = args.length; if (params == 0) { if (isUninitialized() && method.equals(getIdentifierMethod)) { return getIdentifier(); }/* ww w. j av a 2s . c om*/ else if ("getKunderaLazyInitializer".equals(methodName)) { return this; } } Object target = getImplementation(); try { final Object returnValue; if (method.isAccessible()) { if (!method.getDeclaringClass().isInstance(target)) { throw new ClassCastException(target.getClass().getName()); } returnValue = method.invoke(target, args); } else { if (!method.isAccessible()) { method.setAccessible(true); } returnValue = method.invoke(target, args); } return returnValue == target ? proxy : returnValue; } catch (InvocationTargetException ite) { throw ite.getTargetException(); } } else { // while constructor is running throw new LazyInitializationException("unexpected case hit, method=" + method.getName()); } }
From source file:org.synyx.hades.dao.orm.GenericDaoFactory.java
/** * Returns whether the given method is considered to be a DAO base class * method./*from ww w . ja v a 2 s.c o m*/ * * @param method * @return */ private boolean isBaseClassMethod(Method method, Class<?> daoInterface) { Assert.notNull(method); if (method.getDeclaringClass().isAssignableFrom(getDaoClass())) { return true; } return !method.equals(getBaseClassMethod(method, daoInterface)); }
From source file:com.github.steveash.typedconfig.resolver.ProxyValueResolver.java
@SuppressWarnings("unchecked") private <T> T makeProxyForResolvers(final Class<?> interfaze, final ImmutableMap<Method, ValueResolver> propertyResolvers) throws NoSuchMethodException { final ImmutableMap<Method, ValueResolver> allResolvers = addInternalResolvers(interfaze, propertyResolvers); final Method equalsMethod = Object.class.getDeclaredMethod("equals", Object.class); InvocationHandler handler = new InvocationHandler() { @Override/*from www . j av a2 s . c o m*/ public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { ValueResolver valueResolver = allResolvers.get(method); if (valueResolver != null) return valueResolver.resolve(); if (equalsMethod.equals(method)) return proxyEquals(interfaze, propertyResolvers, args[0]); throw new IllegalStateException("no method is known for " + method); } }; return (T) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] { interfaze, ProxiedConfiguration.class }, handler); }
From source file:com.baidu.jprotobuf.pbrpc.spring.annotation.CommonAnnotationBeanPostProcessor.java
private InjectionMetadata findAnnotationMetadata(final Class clazz, final List<Class<? extends Annotation>> annotion) { // Quick check on the concurrent map first, with minimal locking. InjectionMetadata metadata = this.injectionMetadataCache.get(clazz); if (metadata == null) { synchronized (this.injectionMetadataCache) { metadata = this.injectionMetadataCache.get(clazz); if (metadata == null) { final InjectionMetadata newMetadata = new InjectionMetadata(clazz); ReflectionUtils.doWithFields(clazz, new ReflectionUtils.FieldCallback() { public void doWith(Field field) { for (Class<? extends Annotation> anno : annotion) { Annotation annotation = field.getAnnotation(anno); if (annotation != null) { if (Modifier.isStatic(field.getModifiers())) { throw new IllegalStateException( "Autowired annotation is not supported on static fields"); }/*from w w w. java2 s .c o m*/ newMetadata.addInjectedField(new AutowiredFieldElement(field, annotation)); } } } }); ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() { public void doWith(Method method) { for (Class<? extends Annotation> anno : annotion) { Annotation annotation = method.getAnnotation(anno); if (annotation != null && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) { if (Modifier.isStatic(method.getModifiers())) { throw new IllegalStateException( "Autowired annotation is not supported on static methods"); } if (method.getParameterTypes().length == 0) { throw new IllegalStateException( "Autowired annotation requires at least one argument: " + method); } PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method); newMetadata .addInjectedMethod(new AutowiredMethodElement(method, annotation, pd)); } } } }); metadata = newMetadata; this.injectionMetadataCache.put(clazz, metadata); } } } return metadata; }
From source file:com.eclecticlogic.pedal.dialect.postgresql.CopyCommand.java
private String extractColumnName(Method method, Class<? extends Serializable> clz) { String beanPropertyName = null; try {/*www . j a v a2s . com*/ BeanInfo info; info = Introspector.getBeanInfo(clz); for (PropertyDescriptor propDesc : info.getPropertyDescriptors()) { if (method.equals(propDesc.getReadMethod())) { beanPropertyName = propDesc.getName(); break; } } } catch (IntrospectionException e) { throw new RuntimeException(e.getMessage(), e); } String columnName = null; if (clz.isAnnotationPresent(AttributeOverrides.class)) { for (AttributeOverride annotation : clz.getAnnotation(AttributeOverrides.class).value()) { if (annotation.name().equals(beanPropertyName)) { columnName = annotation.column().name(); break; } } } else if (clz.isAnnotationPresent(AttributeOverride.class)) { AttributeOverride annotation = clz.getAnnotation(AttributeOverride.class); if (annotation.name().equals(beanPropertyName)) { columnName = annotation.column().name(); } } return columnName == null ? method.getAnnotation(Column.class).name() : columnName; }
From source file:com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.java
/** * Finds {@link InjectionMetadata.InjectedElement} Metadata from annotated {@link Reference @Reference} methods * * @param beanClass The {@link Class} of Bean * @return non-null {@link List}/* w ww.j a v a 2 s . c om*/ */ private List<InjectionMetadata.InjectedElement> findMethodReferenceMetadata(final Class<?> beanClass) { final List<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>(); ReflectionUtils.doWithMethods(beanClass, new ReflectionUtils.MethodCallback() { @Override public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { Method bridgedMethod = findBridgedMethod(method); if (!isVisibilityBridgeMethodPair(method, bridgedMethod)) { return; } Reference reference = findAnnotation(bridgedMethod, Reference.class); if (reference != null && method.equals(ClassUtils.getMostSpecificMethod(method, beanClass))) { if (Modifier.isStatic(method.getModifiers())) { if (logger.isWarnEnabled()) { logger.warn("@Reference annotation is not supported on static methods: " + method); } return; } if (method.getParameterTypes().length == 0) { if (logger.isWarnEnabled()) { logger.warn("@Reference annotation should only be used on methods with parameters: " + method); } } PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, beanClass); elements.add(new ReferenceMethodElement(method, pd, reference)); } } }); return elements; }
From source file:com.link_intersystems.lang.reflect.Class2.java
/** * * @param method/*from w w w . j a v a2 s . co m*/ * @return the {@link Method2} for the given {@link Method}. The * {@link Method} must be declared on this {@link Class2}'s * {@link Class}. * @throws NoSuchMethodException * if the method is not declared on this {@link Class2}'s * {@link Class}. * @since 1.0.0.0 */ Method2 getMethod2(Method method) throws NoSuchMethodException { Assert.notNull("method", method); List<Method2> declaredMethods = getDeclaredMethods(); for (Method2 method2 : declaredMethods) { if (method.equals(method2.getMember())) { return method2; } } throw new NoSuchMethodException(method + " must be a method of this " + clazz); }
From source file:org.alfresco.repo.lotus.ws.impl.auth.ChainingAuthProxyFactory.java
/** * Instantiates a new chaining subsystem proxy factory. *///w w w . j a va 2 s . co m public ChainingAuthProxyFactory() { addAdvisor(new DefaultPointcutAdvisor(new MethodInterceptor() { public Object invoke(MethodInvocation mi) throws Throwable { Method method = mi.getMethod(); boolean authenticated = false; try { for (String sourceBeanName : sourceBeanNames) { try { Object bean = beanFactory.getBean(sourceBeanName); // Ignore inactive beans if ((bean instanceof Authenticator) && ((Authenticator) bean).isActive()) { authenticated = (Boolean) method.invoke(bean, mi.getArguments()); if (authenticated) { return authenticated; } } } catch (BeansException e) { // Ignore and continue } } // Fall back to the default object if we have one if (!authenticated && defaultTarget != null && method.getDeclaringClass().isAssignableFrom(defaultTarget.getClass())) { return method.invoke(defaultTarget, mi.getArguments()); } // If this is the isActive() method, we can handle it ourselves! if (method.equals(Authenticator.class.getMethod("isActive"))) { return Boolean.FALSE; } // Otherwise, something has gone wrong with wiring! throw new RuntimeException("Don't know where to route call to method " + method); } catch (InvocationTargetException e) { // Unwrap invocation target exceptions throw e.getTargetException(); } } })); }
From source file:org.apereo.services.persondir.support.AttributeBasedCacheKeyGenerator.java
/** * Iterates over the {@link CachableMethod} instances to determine which instance the * passed {@link MethodInvocation} applies to. * * @param methodInvocation method invocation * @return Cachable method// w ww . j a v a 2 s .c o m */ protected CachableMethod resolveCacheableMethod(final MethodInvocation methodInvocation) { final Method targetMethod = methodInvocation.getMethod(); final Class<?> targetClass = targetMethod.getDeclaringClass(); for (final CachableMethod cachableMethod : CachableMethod.values()) { Method cacheableMethod = null; try { cacheableMethod = targetClass.getMethod(cachableMethod.getName(), cachableMethod.getArgs()); } catch (final SecurityException e) { this.logger.warn("Security exception while attempting to if the target class '" + targetClass + "' implements the cachable method '" + cachableMethod + "'", e); } catch (final NoSuchMethodException e) { final String message = "Taret class '" + targetClass + "' does not implement possible cachable method '" + cachableMethod + "'. Is the advice applied to the correct bean and methods?"; if (this.logger.isDebugEnabled()) { this.logger.debug(message, e); } else { this.logger.warn(message); } } if (targetMethod.equals(cacheableMethod)) { return cachableMethod; } } throw new IllegalArgumentException("Do not know how to generate a cache for for '" + targetMethod + "' on class '" + targetClass + "'. Is the advice applied to the correct bean and methods?"); }
From source file:com.github.wshackle.java4cpp.J4CppMain.java
private static String fixMethodName(Method m) { String mname = m.getName();//from w ww. java 2 s. c o m if (fixMultipleOverrides) { Method ma[] = m.getDeclaringClass().getMethods(); int index = 0; boolean index_incremented = false; boolean has_match = false; Arrays.sort(ma, new Comparator<Method>() { @Override public int compare(Method o1, Method o2) { return Arrays.toString(o1.getParameterTypes()) .compareTo(Arrays.toString(o2.getParameterTypes())); } }); List<Method> matchingMethods = new ArrayList<>(); for (int i = 0; i < ma.length; i++) { Method method = ma[i]; if (method.getParameterTypes().length > 0 && m.getParameterTypes().length > 0 && m.getParameterTypes()[0].isPrimitive() != method.getParameterTypes()[0].isPrimitive()) { continue; } if (!method.equals(m) && m.getName().equals(method.getName()) && m.getParameterTypes().length == method.getParameterTypes().length) { has_match = true; matchingMethods.add(method); } } for (int i = 0; i < ma.length; i++) { Method method = ma[i]; if (method.equals(m)) { break; } if (method.getParameterTypes().length != m.getParameterTypes().length) { continue; } if (method.getParameterTypes().length > 0 && m.getParameterTypes().length > 0 && m.getParameterTypes()[0].isPrimitive() != method.getParameterTypes()[0].isPrimitive()) { continue; } if (m.getParameterTypes().length >= 1) { if (String.class.isAssignableFrom(m.getParameterTypes()[0]) != String.class .isAssignableFrom(method.getParameterTypes()[0])) { continue; } } if (method.getName().equals(m.getName())) { index++; index_incremented = true; } } int start_index = 0; while (index_incremented) { index_incremented = false; for (int i = 0; i < ma.length; i++) { Method method = ma[i]; for (int j = start_index; j <= index; j++) { if (method.getName().equals(m.getName() + j) && m.getParameterTypes().length == method.getParameterTypes().length) { index++; index_incremented = true; } } } start_index = index; } if (has_match) { String paramstring = ""; Class[] paramclasses = m.getParameterTypes(); for (int i = 0; i < paramclasses.length; i++) { paramstring += classToMethodAppendage(paramclasses[i]); } mname = mname + paramstring; if (mname.contains(";")) { System.out.println("paramclasses = " + paramclasses); } } } if (badNames.contains(mname)) { return mname + "Method"; } return mname; }