List of usage examples for org.apache.commons.lang ClassUtils getAllInterfaces
public static List<Class<?>> getAllInterfaces(Class<?> cls)
Gets a List
of all interfaces implemented by the given class and its superclasses.
The order is determined by looking through each interface in turn as declared in the source file and following its hierarchy up.
From source file:MainClass.java
public static void main(String[] args) { System.out.println(// w w w . j a v a 2 s . com "1) Interfaces implemented by java.lang.String >>> " + ClassUtils.getAllInterfaces(String.class)); }
From source file:ClassUtilsTrial.java
public static void main(String[] args) { System.out.println(//from w ww .ja v a 2 s . c o m "1) Interfaces implemented by java.lang.String >>> " + ClassUtils.getAllInterfaces(String.class)); System.out .println("2) SuperClasses of java.lang.String >>> " + ClassUtils.getAllSuperclasses(String.class)); System.out.println("3) PackageName of a string >>> " + ClassUtils.getPackageName("A String", "IfNull")); System.out.println("4) Every String is an Object = " + ClassUtils.isAssignable(String.class, Object.class)); System.out.println("5) Every Object is an String = " + ClassUtils.isAssignable(Object.class, String.class)); }
From source file:fr.inria.atlanmod.neoemf.core.impl.NeoEMFEObjectAdapterFactoryImpl.java
@SuppressWarnings("unchecked") public static <T> T getAdapter(Object adaptableObject, Class<T> adapterType) { if (adapterType.isInstance(adaptableObject)) { return (T) adaptableObject; } else if (adapterType.isAssignableFrom(NeoEMFInternalEObject.class) && adaptableObject instanceof InternalEObject) { {/*from ww w. j a v a 2 s. c o m*/ EObject adapter = adaptedObjects.get(adaptableObject); if (adapter != null) { if (adapterType.isAssignableFrom(adapter.getClass())) { return (T) adapter; } } } { // Compute the interfaces that the proxy has to implement // These are the current interfaces + NeoEMFEObject List<Class<?>> interfaces = new ArrayList<>(); interfaces.addAll(ClassUtils.getAllInterfaces(adaptableObject.getClass())); interfaces.add(NeoEMFInternalEObject.class); // Create the proxy Enhancer enhancer = new Enhancer(); enhancer.setClassLoader(NeoEMFEObjectAdapterFactoryImpl.class.getClassLoader()); enhancer.setSuperclass(adaptableObject.getClass()); enhancer.setInterfaces(interfaces.toArray(new Class[] {})); enhancer.setCallback(new NeoEMFEObjectProxyHandlerImpl((InternalEObject) adaptableObject)); T adapter = (T) enhancer.create(); adaptedObjects.put((InternalEObject) adaptableObject, (NeoEMFInternalEObject) adapter); return adapter; } } return null; }
From source file:fr.inria.atlanmod.neoemf.core.impl.NeoEObjectAdapterFactoryImpl.java
@SuppressWarnings("unchecked") public static <T> T getAdapter(Object adaptableObject, Class<T> adapterType) { if (adapterType.isInstance(adaptableObject)) { return (T) adaptableObject; } else if (adapterType.isAssignableFrom(InternalPersistentEObject.class) && adaptableObject instanceof InternalEObject) { {/*from www .j a v a 2 s . c o m*/ EObject adapter = adaptedObjects.get(adaptableObject); if (adapter != null) { if (adapterType.isAssignableFrom(adapter.getClass())) { return (T) adapter; } } } { // Compute the interfaces that the proxy has to implement // These are the current interfaces + PersistentEObject List<Class<?>> interfaces = new ArrayList<>(); interfaces.addAll(ClassUtils.getAllInterfaces(adaptableObject.getClass())); interfaces.add(InternalPersistentEObject.class); // Create the proxy Enhancer enhancer = new Enhancer(); enhancer.setClassLoader(adaptableObject.getClass().getClassLoader()); enhancer.setSuperclass(adaptableObject.getClass()); enhancer.setInterfaces(interfaces.toArray(new Class[] {})); enhancer.setCallback(new NeoEObjectProxyHandlerImpl((InternalEObject) adaptableObject)); T adapter = (T) enhancer.create(); adaptedObjects.put((InternalEObject) adaptableObject, (InternalPersistentEObject) adapter); return adapter; } } return null; }
From source file:com.eviware.soapui.plugins.PluginProxies.java
@SuppressWarnings("unchecked") static <T> T createProxyFor(T delegate) { if (delegate instanceof JComponent) { log.warn("Can't proxy JComponent derived classes"); return delegate; }//from w w w .ja v a2s.c om Collection<Class> interfaces = ClassUtils.getAllInterfaces(delegate.getClass()); if (interfaces.isEmpty()) { // this shouldn't really happen, unless reflection is being used in some odd way log.warn("Can't proxy instance of {} because the class doesn't implement any interfaces", delegate.getClass()); return delegate; } interfaces.add(PluginProxy.class); return (T) Proxy.newProxyInstance(PluginProxies.class.getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new DelegatingHandler<T>(delegate)); }
From source file:hr.fer.zemris.vhdllab.platform.listener.AutoPublishListenerBeanPostProcessor.java
@SuppressWarnings("unchecked") @Override//from w w w . ja v a 2 s .c o m public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { List<Class<?>> implementedInterfaces = ClassUtils.getAllInterfaces(bean.getClass()); for (Class<?> implementedInterface : implementedInterfaces) { AutoPublished autoPublished = implementedInterface.getAnnotation(AutoPublished.class); if (autoPublished != null) { Class<?> publisherClass = autoPublished.publisher(); Object object = context.getBean(StringUtils.uncapitalize(publisherClass.getSimpleName())); try { MethodUtils.invokeMethod(object, "addListener", bean); } catch (Exception e) { throw new IllegalStateException("Auto publishing event listener failed", e); } } } return bean; }
From source file:com.haulmont.cuba.core.sys.CubaAnnotationsLoader.java
private boolean propertyBelongsTo(Field field, MetaProperty metaProperty, List<Class> systemInterfaces) { String getterName = "get" + StringUtils.capitalize(metaProperty.getName()); Class<?> aClass = field.getDeclaringClass(); //noinspection unchecked List<Class> allInterfaces = ClassUtils.getAllInterfaces(aClass); for (Class intf : allInterfaces) { Method[] methods = intf.getDeclaredMethods(); for (Method method : methods) { if (method.getName().equals(getterName) && method.getParameterTypes().length == 0) { if (systemInterfaces.contains(intf)) return true; }/*from w ww .j ava 2 s .c o m*/ } } return false; }
From source file:com.haulmont.cuba.core.sys.remoting.RemoteServicesBeanCreator.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { log.info("Configuring remote services"); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; ApplicationContext coreContext = context.getParent(); Map<String, Object> services = coreContext.getBeansWithAnnotation(Service.class); for (Map.Entry<String, Object> entry : services.entrySet()) { String serviceName = entry.getKey(); Object service = entry.getValue(); List<Class> serviceInterfaces = new ArrayList<>(); List<Class> interfaces = ClassUtils.getAllInterfaces(service.getClass()); for (Class intf : interfaces) { if (intf.getName().endsWith("Service")) serviceInterfaces.add(intf); }/* w w w. ja v a 2s .c o m*/ String intfName = null; if (serviceInterfaces.size() == 0) { log.error("Bean " + serviceName + " has @Service annotation but no interfaces named '*Service'. Ignoring it."); } else if (serviceInterfaces.size() > 1) { intfName = findLowestSubclassName(serviceInterfaces); if (intfName == null) log.error("Bean " + serviceName + " has @Service annotation and more than one interface named '*Service', " + "but these interfaces are not from the same hierarchy. Ignoring it."); } else { intfName = serviceInterfaces.get(0).getName(); } if (intfName != null) { BeanDefinition definition = new RootBeanDefinition(HttpServiceExporter.class); MutablePropertyValues propertyValues = definition.getPropertyValues(); propertyValues.add("service", service); propertyValues.add("serviceInterface", intfName); registry.registerBeanDefinition("/" + serviceName, definition); log.debug("Bean " + serviceName + " configured for export via HTTP"); } } }
From source file:net.sf.jasperreports.export.PropertiesDefaultsConfigurationFactory.java
/** * // www. jav a 2 s . co m */ private final C getProxy(Class<?> clazz, InvocationHandler handler) { List<Class<?>> allInterfaces = new ArrayList<Class<?>>(); if (clazz.isInterface()) { allInterfaces.add(clazz); } else { @SuppressWarnings("unchecked") List<Class<?>> lcInterfaces = ClassUtils.getAllInterfaces(clazz); allInterfaces.addAll(lcInterfaces); } @SuppressWarnings("unchecked") C proxy = (C) Proxy.newProxyInstance(ExporterConfiguration.class.getClassLoader(), allInterfaces.toArray(new Class<?>[allInterfaces.size()]), handler); return proxy; }
From source file:de.Keyle.MyPet.api.util.service.ServiceManager.java
@SuppressWarnings("unchecked") private void registerService(ServiceContainer service) { boolean genericService = true; for (Object o : ClassUtils.getAllInterfaces(service.getClass())) { if (o != ServiceContainer.class && ServiceContainer.class.isAssignableFrom((Class) o)) { services.put((Class) o, service); genericService = false;//from ww w . j a v a 2 s. c om } } for (Object o : ClassUtils.getAllSuperclasses(service.getClass())) { if (o != ServiceContainer.class && ServiceContainer.class.isAssignableFrom((Class) o)) { services.put((Class) o, service); genericService = false; } } if (genericService) { services.put(ServiceContainer.class, service); } serviceByName.put(service.getServiceName(), service); services.put(service.getClass(), service); }