List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:org.apache.struts.faces.renderer.BaseRenderer.java
/** * <p>Return <code>true</code> if this is a portlet request instance. * NOTE: Implementation must not require portlet API classes to be * present.</p>/* w w w. j a va 2 s . c o m*/ * * @param context <code>FacesContext</code> for the current request */ protected boolean isPortletRequest(FacesContext context) { Object request = context.getExternalContext().getRequest(); Class clazz = request.getClass(); while (clazz != null) { // Does this class implement PortletRequest? Class interfaces[] = clazz.getInterfaces(); if (interfaces == null) { interfaces = new Class[0]; } for (int i = 0; i < interfaces.length; i++) { if ("javax.portlet.PortletRequest".equals(interfaces[i].getName())) { return (true); } } // Try our superclass (if any) clazz = clazz.getSuperclass(); } return (false); }
From source file:org.apache.openjpa.eclipse.EnhancerBuilderTest.java
public void todotestBuilder() throws Exception { project.build(IncrementalProjectBuilder.FULL_BUILD, null); // TODO INCREMENTAL and FULL_BUILD IMarker[] markers = project.findMarkers(null, true, IResource.DEPTH_INFINITE); if (markers.length != 0) { for (IMarker marker : markers) { System.err.print(marker.getAttribute(IMarker.LOCATION) + " : "); System.err.println(marker.getAttribute(IMarker.MESSAGE)); }//ww w . j a v a2s . c om fail("Project Build unexpectedly lead to Markers (printed to stderr for debugging)"); } String classFileName = "bin/" + TESTCLASS_PACKAGE.replace('.', '/') + "/TestEntity.class"; assertTrue(classFileName + " does not exist?!", project.getFile(classFileName).exists()); // assertTrue(project.getFile("bin/" + TESTCLASS_PACKAGE.replace('.', '/') + "NotToEnhance.class").exists()); ClassLoader cl = ClassLoaderFromIProjectHelper.createClassLoader(project); assertNotNull(cl); Class<?> testClass = cl.loadClass(TESTCLASS_PACKAGE + "." + "TestEntity"); Assert.assertNotNull(testClass); assertEquals("TestEntity", testClass.getSimpleName()); Assert.assertEquals(1, testClass.getInterfaces().length); Assert.assertTrue(testClass.getInterfaces()[0].equals(PersistenceCapable.class)); }
From source file:de.itsvs.cwtrpc.controller.PreparedRemoteServiceConfigBuilder.java
protected Class<?> getRemoteServiceInterface(String serviceName) throws CwtRpcException { final Class<?> serviceClass; Class<?> foundInterface = null; serviceClass = getBeanFactory().getType(serviceName); for (Class<?> c : serviceClass.getInterfaces()) { if (RemoteService.class.isAssignableFrom(c)) { if (foundInterface != null) { throw new CwtRpcException("Service class " + serviceClass.getName() + " of service '" + serviceName + "' implements multiple " + "remote service interfaces (specify service " + "interface explicitly)"); }// w w w .j a va 2s.c om foundInterface = c; } } return foundInterface; }
From source file:org.resthub.rpc.HessianEndpoint.java
private Class<?> findRemoteAPI(Class<?> implClass) { if (implClass == null) { return null; }/*from w ww .j a v a 2 s.c om*/ Class<?>[] interfaces = implClass.getInterfaces(); if (interfaces.length > 0 && !interfaces[0].equals(SpringProxy.class)) { return interfaces[0]; } return findRemoteAPI(implClass.getSuperclass()); }
From source file:SortedTableModel.java
public void addHeaderListener() { table.getTableHeader().addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { JTableHeader header = (JTableHeader) (event.getSource()); int index = header.columnAtPoint(event.getPoint()); Class dataType = table.getModel().getColumnClass(index); Class[] interfaces = dataType.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (interfaces[i].equals(java.lang.Comparable.class)) { renderer.columnSelected(index); break; }//from w ww . j a va 2s . c o m } table.setColumnSelectionInterval(index, index); } }); }
From source file:com.sun.faces.el.impl.BeanInfoManager.java
/** * If the given class is public and has a Method that declares the * same name and arguments as the given method, then that method is * returned. Otherwise the superclass and interfaces are searched * recursively.//from www . j a va 2s . c o m */ static Method getPublicMethod(Class pClass, Method pMethod) { // See if this is a public class declaring the method if (Modifier.isPublic(pClass.getModifiers())) { try { Method m; try { m = pClass.getDeclaredMethod(pMethod.getName(), pMethod.getParameterTypes()); } catch (java.security.AccessControlException ex) { // kludge to accommodate J2EE RI's default settings // TODO: see if we can simply replace // getDeclaredMethod() with getMethod() ...? m = pClass.getMethod(pMethod.getName(), pMethod.getParameterTypes()); } if (Modifier.isPublic(m.getModifiers())) { return m; } } catch (NoSuchMethodException exc) { } } // Search the interfaces { Class[] interfaces = pClass.getInterfaces(); if (interfaces != null) { for (int i = 0; i < interfaces.length; i++) { Method m = getPublicMethod(interfaces[i], pMethod); if (m != null) { return m; } } } } // Search the superclass { Class superclass = pClass.getSuperclass(); if (superclass != null) { Method m = getPublicMethod(superclass, pMethod); if (m != null) { return m; } } } return null; }
From source file:de.taimos.dvalin.interconnect.core.spring.test.InterconnectRequestMock.java
private void registerPrototype(final Class<? extends APrototypeHandlerMock> handler, final String beanName) { final Class<?>[] interfaces = handler.getInterfaces(); final String queueName = InterconnectRequestMock.getQueueName(interfaces); this.handlers.put(queueName, new RMHWrapper(handler, beanName, this.beanFactory, false)); }
From source file:de.taimos.dvalin.interconnect.core.spring.test.InterconnectRequestMock.java
private void registerSingleton(final Class<? extends ASingletonHandlerMock> handler, final String beanName) { final Class<?>[] interfaces = handler.getInterfaces(); final String queueName = InterconnectRequestMock.getQueueName(interfaces); this.handlers.put(queueName, new RMHWrapper(handler, beanName, this.beanFactory, true)); }
From source file:org.jbpm.services.task.jaxb.ComparePair.java
private Class<?> getInterface(Object obj) { Class<?> newInterface = obj.getClass(); Class<?> parent = newInterface; while (parent != null) { parent = null;//from w w w . j ava 2 s. co m if (newInterface.getInterfaces().length > 0) { Class<?> newParent = newInterface.getInterfaces()[0]; if (newParent.getPackage().getName().startsWith("org.")) { parent = newInterface = newParent; } } } return newInterface; }
From source file:objenome.util.ClassUtils.java
/** * Get an {@link Iterable} that can iterate over a class hierarchy in ascending (subclass to superclass) order. * * @param type the type to get the class hierarchy from * @param interfacesBehavior switch indicating whether to include or exclude interfaces * @return Iterable an Iterable over the class hierarchy of the given class * @since 3.2//from w ww . ja v a 2 s . c om */ public static Iterable<Class<?>> hierarchy(Class<?> type, Interfaces interfacesBehavior) { Iterable<Class<?>> classes = () -> { MutableObject<Class<?>> next = new MutableObject<>(type); return new Iterator<Class<?>>() { @Override public boolean hasNext() { return next.getValue() != null; } @Override public Class<?> next() { Class<?> result = next.getValue(); next.setValue(result.getSuperclass()); return result; } @Override public void remove() { throw new UnsupportedOperationException(); } }; }; if (interfacesBehavior != Interfaces.INCLUDE) { return classes; } return () -> { Set<Class<?>> seenInterfaces = new HashSet<>(); Iterator<Class<?>> wrapped = classes.iterator(); return new Iterator<Class<?>>() { Iterator<Class<?>> interfaces = Collections.<Class<?>>emptySet().iterator(); @Override public boolean hasNext() { return interfaces.hasNext() || wrapped.hasNext(); } @Override public Class<?> next() { if (interfaces.hasNext()) { Class<?> nextInterface = interfaces.next(); seenInterfaces.add(nextInterface); return nextInterface; } Class<?> nextSuperclass = wrapped.next(); Set<Class<?>> currentInterfaces = new LinkedHashSet<>(); walkInterfaces(currentInterfaces, nextSuperclass); interfaces = currentInterfaces.iterator(); return nextSuperclass; } private void walkInterfaces(Set<Class<?>> addTo, Class<?> c) { for (Class<?> iface : c.getInterfaces()) { if (!seenInterfaces.contains(iface)) { addTo.add(iface); } walkInterfaces(addTo, iface); } } @Override public void remove() { throw new UnsupportedOperationException(); } }; }; }