List of usage examples for java.lang Class isInterface
@HotSpotIntrinsicCandidate public native boolean isInterface();
From source file:org.fornax.cartridges.sculptor.framework.accessimpl.jpa2.JpaHelper.java
/** * tries to find a property method by name * * @param clazz type//w w w. ja v a2s. co m * @param name name of the property * @return */ public static Method findProperty(Class<?> clazz, String name) { assert clazz != null; assert name != null; Class<?> entityClass = clazz; while (entityClass != null) { Method[] methods = (entityClass.isInterface() ? entityClass.getMethods() : entityClass.getDeclaredMethods()); for (Method method : methods) { if (method.getName().equals("get" + StringUtils.capitalize(name)) || method.getName().equals("is" + StringUtils.capitalize(name))) { return method; } } entityClass = entityClass.getSuperclass(); } return null; }
From source file:org.openmrs.module.openhmis.cashier.api.ReceiptNumberGeneratorFactory.java
/** * Locates and instantiates all classes that implement {@link IReceiptNumberGenerator} in the current classpath. * @return The instantiated receipt number generators. * @should Locate all classes that implement IReceiptNumberGenerator * @should Not throw an exception if the class instantiation fails * @should Use the existing instance for the currently defined generator *///ww w. ja v a 2 s. co m public static IReceiptNumberGenerator[] locateGenerators() { // Search for any modules that define classes which implement the IReceiptNumberGenerator interface Reflections reflections = new Reflections("org.openmrs.module"); List<Class<? extends IReceiptNumberGenerator>> classes = new ArrayList<Class<? extends IReceiptNumberGenerator>>(); for (Class<? extends IReceiptNumberGenerator> cls : reflections .getSubTypesOf(IReceiptNumberGenerator.class)) { // We only care about public instantiable classes so ignore others if (!cls.isInterface() && !Modifier.isAbstract(cls.getModifiers()) && Modifier.isPublic(cls.getModifiers())) { classes.add(cls); } } // Now attempt to instantiate each found class List<IReceiptNumberGenerator> instances = new ArrayList<IReceiptNumberGenerator>(); for (Class<? extends IReceiptNumberGenerator> cls : classes) { if (generator != null && cls.equals(generator.getClass())) { instances.add(generator); } else { try { instances.add(cls.newInstance()); } catch (Exception ex) { // We don't care about specific exceptions here. Just log and ignore the class LOG.warn("Could not instantiate the '" + cls.getName() + "' class. It will be ignored."); } } } // Finally, copy the instances to an array IReceiptNumberGenerator[] results = new IReceiptNumberGenerator[instances.size()]; instances.toArray(results); return results; }
From source file:com.dsj.core.beans.CollectionFactory.java
/** * Create the most approximate collection for the given collection class. * <p>Tries to create the given collection class. If that fails, * an ArrayList, TreeSet or linked Set will be used as fallback for * a List, SortedSet or Set, respectively. * @param collectionClass the original collection class * @param initialCapacity the initial capacity * @return the new collection instance/* ww w . jav a 2s . co m*/ * @see java.util.ArrayList * @see java.util.TreeSet * @see #createLinkedSetIfPossible */ public static Collection createApproximateCollection(Class collectionClass, int initialCapacity) { Assert.notNull(collectionClass, "Collection class must not be null"); if (!collectionClass.isInterface()) { try { return (Collection) collectionClass.newInstance(); } catch (Exception ex) { if (logger.isDebugEnabled()) { logger.debug("Could not instantiate collection type [" + collectionClass.getName() + "]: " + ex.getMessage()); } } } if (List.class.isAssignableFrom(collectionClass)) { return new ArrayList(initialCapacity); } else if (SortedSet.class.isAssignableFrom(collectionClass)) { return new TreeSet(); } else { return createLinkedSetIfPossible(initialCapacity); } }
From source file:net.servicefixture.util.ReflectionUtils.java
private static boolean isConcreteSubclass(Class<?> baseClass, Class<?> clazz) { return baseClass.isAssignableFrom(clazz) && !baseClass.equals(clazz) && !clazz.isInterface() && !Modifier.isAbstract(clazz.getModifiers()); }
From source file:de.perdian.commons.i18n.polyglot.PolyglotFactory.java
/** * Creates a new {@link Polyglot} implementation. A default instance of * {@code PolyglotOptions} will be created. * * @param polyglotClass/*from w w w . j a v a2s . c o m*/ * the class of the interface, that should be implemented according to * the polyglot logics. Note, that this class must be an interface, not * an actual class. * @param messageSource * the source from which messages to be localized can retrieve their * values * @return * the {@code Polyglot} implementation. Once this instance has been * created, it has no further references to the factory from which it * was created. */ public static <T> Polyglot<T> createPolyglot(Class<T> polyglotClass, MessageSource messageSource) { if (polyglotClass == null) { throw new IllegalArgumentException("Parameter 'polyglotClass' must not be null"); } else if (messageSource == null) { throw new IllegalArgumentException("Parameter 'messageSource' must not be null"); } else if (!polyglotClass.isInterface()) { StringBuilder errorMessage = new StringBuilder(); errorMessage.append("Polyglot class '").append(polyglotClass.getName()); errorMessage.append("' is not an interface. Only real interfaces can be "); errorMessage.append("used to create a Polyglot instance."); throw new IllegalArgumentException(errorMessage.toString()); } else { PolyglotImpl<T> polyglotImpl = new PolyglotImpl<>(); polyglotImpl.setInstanceClass(polyglotClass); polyglotImpl.setMessageSource(messageSource); return polyglotImpl; } }
From source file:io.github.benas.randombeans.util.ReflectionUtils.java
/** * Check if a type is an interface./*from ww w . ja va 2 s . c om*/ * * @param type the type to check * @return true if the type is an interface, false otherwise */ public static boolean isInterface(final Class<?> type) { return type.isInterface(); }
From source file:org.fuusio.api.flow.AbstractFlow.java
protected static Class<? extends View> getClass(final View view) { final Class viewClass = view.getClass(); if (viewClass.isInterface() && View.class.isAssignableFrom(viewClass)) { return viewClass; }/* w w w. j a v a 2s . co m*/ final Class[] interfaceClasses = viewClass.getInterfaces(); for (int i = 0; i < interfaceClasses.length; i++) { if (View.class.isAssignableFrom(interfaceClasses[i])) { return interfaceClasses[i]; } } return null; }
From source file:org.dozer.util.MappingUtils.java
public static boolean isProxy(Class<?> clazz) { if (clazz.isInterface()) { return false; }/* w w w. j a v a 2s.c o m*/ String className = clazz.getName(); return className.contains(DozerConstants.CGLIB_ID) || className.startsWith(DozerConstants.JAVASSIST_PACKAGE) || className.contains(DozerConstants.JAVASSIST_NAME); }
From source file:com.project.framework.util.ReflectionUtils.java
/** * ??, Class??./*w w w. j a v a 2s.co m*/ * , null Class Array. * * @param clazz * @param interfaze * @param index * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static Class getInterfaceGenricType(final Class clazz, final Class interfaze, final int index) { if (!interfaze.isInterface()) throw new IllegalArgumentException("interfaze must be a interface."); if (!interfaze.isAssignableFrom(clazz)) throw new IllegalArgumentException("clazz must be implemnet form interfaze"); Type[] genTypes = clazz.getGenericInterfaces(); for (Type genType : genTypes) { if (genType instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) genType; if (interfaze.equals(pt.getRawType())) { Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if (index >= params.length || index < 0) { logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " + params.length); return Object.class; } if (!(params[index] instanceof Class)) { logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); return Object.class; } return (Class) params[index]; } } } return null; }
From source file:com.google.gdt.eclipse.designer.util.GwtInvocationEvaluatorInterceptor.java
private static boolean isJavaScriptObject_rewrittenInterface(Class<?> clazz) { return clazz.isInterface() && ReflectionUtils.isSuccessorOf(clazz, JSO_NAME); }