List of usage examples for java.lang Class isInterface
@HotSpotIntrinsicCandidate public native boolean isInterface();
From source file:org.apache.tajo.ws.rs.resources.outputs.RestOutputFactory.java
private static Map<String, String> load() { Map<String, String> outputClasses = Maps.newHashMap(); Set<Class> restOutputClasses = ClassUtil.findClasses(AbstractStreamingOutput.class, "org.apache.tajo.ws.rs.resources.outputs"); for (Class eachClass : restOutputClasses) { if (eachClass.isInterface() || Modifier.isAbstract(eachClass.getModifiers())) { continue; }/*from w w w. j ava 2 s . co m*/ AbstractStreamingOutput streamingOutput = null; try { streamingOutput = (AbstractStreamingOutput) eachClass .getDeclaredConstructor( new Class[] { NonForwardQueryResultScanner.class, Integer.class, Integer.class }) .newInstance(null, 0, 0); } catch (Exception e) { LOG.warn(eachClass + " cannot instantiate Function class because of " + e.getMessage(), e); continue; } String className = streamingOutput.getClass().getCanonicalName(); String headerType = streamingOutput.getClass().getAnnotation(RestReturnType.class).mimeType(); if (StringUtils.isNotEmpty(headerType)) { outputClasses.put(headerType, className); } } return outputClasses; }
From source file:org.beanfuse.entity.Model.java
public static EntityType getEntityType(Class clazz) { EntityType type = null;/* w ww .ja v a2 s . c om*/ if (clazz.isInterface()) { type = context.getEntityType(clazz.getName()); } else { type = context.getEntityType(clazz); } return type; }
From source file:Main.java
@SuppressWarnings("unchecked") public static Collection<Object> newCollection(Class<?> targetClass, int length) throws InstantiationException, IllegalAccessException { if (targetClass.isInterface()) { if (Set.class.isAssignableFrom(targetClass)) { if (SortedSet.class.isAssignableFrom(targetClass)) return new TreeSet<Object>(); return new HashSet<Object>(length); }//w w w . j a v a 2 s.c om if (targetClass.isAssignableFrom(ArrayList.class)) return new ArrayList<Object>(length); throw new IllegalArgumentException("Unsupported collection interface: " + targetClass); } return (Collection<Object>) targetClass.newInstance(); }
From source file:com.ngandroid.lib.utils.JsonUtils.java
public static <T> T buildModelFromJson(JSONObject jsonObject, Class<T> clzz) throws JSONException { ModelBuilder builder = new ModelBuilder(clzz); Iterator<String> jsonkeys = jsonObject.keys(); while (jsonkeys.hasNext()) { String key = jsonkeys.next(); String keyLower = key.toLowerCase(); if (builder.hasField(keyLower)) { int type = builder.getFieldType(keyLower); switch (type) { case TypeUtils.BOOLEAN: builder.setField(keyLower, type, jsonObject.getBoolean(key)); break; case TypeUtils.INTEGER: builder.setField(keyLower, type, jsonObject.getInt(key)); break; case TypeUtils.STRING: builder.setField(keyLower, type, jsonObject.getString(key)); break; case TypeUtils.DOUBLE: builder.setField(keyLower, type, jsonObject.getDouble(key)); break; case TypeUtils.FLOAT: builder.setField(keyLower, type, (float) jsonObject.getDouble(key)); break; case TypeUtils.LONG: builder.setField(keyLower, type, jsonObject.getLong(key)); break; case TypeUtils.OBJECT: { Class clss = builder.getFieldTypeClass(keyLower); if (clss.isInterface()) { builder.setField(keyLower, type, buildModelFromJson(jsonObject.getJSONObject(key), clss)); }/*from w w w . j a v a 2 s . co m*/ break; } } } } return (T) builder.create(); }
From source file:org.cruxframework.crux.scanner.ClassScanner.java
/** * Search into the internal index for the set of classes that implements the given interface. * @param annotationClass/*from w w w .ja v a 2 s . c o m*/ * @return */ public static Set<String> searchClassesByInterface(Class<?> interfaceClass) { if (!interfaceClass.isInterface()) { throw new ClassScannerException("The class [" + interfaceClass.getName() + "] is not an interface."); } return searchClassesByInterface(interfaceClass.getName(), true); }
From source file:io.syndesis.runtime.Recordings.java
static public <T> T recorder(Object object, Class<T> as) { if (as.isInterface()) { // If it's just an interface, use standard java reflect proxying return as.cast(Proxy.newProxyInstance(as.getClassLoader(), new Class[] { as }, new RecordingInvocationHandler(object))); }// w w w. java 2s .c o m // If it's a class then use gclib to implement a subclass to implement proxying RecordingInvocationHandler ih = new RecordingInvocationHandler(object); Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(as); enhancer.setInterfaces(new Class[] { RecordingProxy.class }); enhancer.setCallback(new org.springframework.cglib.proxy.InvocationHandler() { @Override public Object invoke(Object o, Method method, Object[] objects) throws Throwable { return ih.invoke(o, method, objects); } }); return as.cast(enhancer.create()); }
From source file:ca.uhn.fhir.util.ReflectionUtil.java
public static boolean isInstantiable(Class<?> theType) { return !theType.isInterface() && !Modifier.isAbstract(theType.getModifiers()); }
From source file:com.link_intersystems.lang.reflect.ThreadLocalProxy.java
@SuppressWarnings("unchecked") public static <T, TC> T createProxy(ThreadLocal<T> threadLocal, T nullInstance, Class<TC> targetClass) { List<Class<?>> allInterfaces = new ArrayList<Class<?>>(ClassUtils.getAllInterfaces(targetClass)); if (targetClass.isInterface()) { allInterfaces.add(targetClass);/*w ww. j av a 2 s . c om*/ } Class<?>[] interfaces = (Class<?>[]) allInterfaces.toArray(new Class<?>[allInterfaces.size()]); T proxy = (T) Proxy.newProxyInstance(targetClass.getClassLoader(), interfaces, new ThreadLocalProxy(threadLocal, nullInstance)); return proxy; }
From source file:com.qmetry.qaf.automation.step.JavaStepFinder.java
private static Set<Method> getAllMethodsWithAnnotation(Collection<Class<?>> classes, Class<? extends Annotation> annotation) { Set<Method> methods = new HashSet<Method>(); for (Class<?> cls : classes) { if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers())) continue; boolean isStepProvider = cls.isAnnotationPresent(QAFTestStepProvider.class); for (Method method : cls.getMethods()) { if (isStepProvider || ClassUtil.hasAnnotation(method, annotation)) { methods.add(method);//w w w . j a v a2s . com } } } return methods; }
From source file:io.github.pellse.decorator.util.reflection.ReflectionUtils.java
public static boolean isAbstract(Class<?> clazz) { return clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers()); }