List of usage examples for java.lang Class isInterface
@HotSpotIntrinsicCandidate public native boolean isInterface();
From source file:org.resthub.rpc.AMQPProxyFactory.java
/** * Creates a new proxy from the specified interface. * @param api the interface/*from w w w. jav a2 s . com*/ * @return the proxy to the object with the specified interface */ @SuppressWarnings("unchecked") public <T> T create(Class<T> api) { if (null == api || !api.isInterface()) { throw new IllegalArgumentException("Parameter 'api' is required"); } this.serviceInterface = api; this.afterPropertiesSet(); AMQPProxy handler = new AMQPProxy(this); return (T) Proxy.newProxyInstance(api.getClassLoader(), new Class[] { api }, handler); }
From source file:org.web4thejob.orm.MetaReaderServiceImpl.java
@Override @SuppressWarnings("unchecked") public <E extends Entity> E newInstance(Class<? extends Entity> entityType) { try {/* w ww . j av a2s .c o m*/ if (entityType.isInterface()) { entityType = getEntityMetadata(entityType).getMappedClass(); } return (E) ReflectHelper.getDefaultConstructor(entityType).newInstance((Object[]) null); } catch (final Exception e) { e.printStackTrace(); return null; } }
From source file:com.github.jknack.handlebars.internal.BaseTemplate.java
@Override public <T, S extends TypeSafeTemplate<T>> S as(final Class<S> rootType) { notNull(rootType, "The rootType can't be null."); isTrue(rootType.isInterface(), "Not an interface: %s", rootType.getName()); @SuppressWarnings("unchecked") S template = (S) newTypeSafeTemplate(rootType, this); return template; }
From source file:com.netflix.paas.config.base.CglibArchaeusConfigurationFactory.java
@SuppressWarnings({ "unchecked", "static-access" }) public <T> T get(Class<T> configClass, DynamicPropertyFactory propertyFactory, AbstractConfiguration configuration) throws Exception { final Map<String, Supplier<?>> methods = ConfigurationProxyUtils.getMethodSuppliers(configClass, propertyFactory, configuration); if (configClass.isInterface()) { final Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(configClass); enhancer.setCallback(new InvocationHandler() { @Override/*from w ww . ja va 2s .c o m*/ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Supplier<?> supplier = (Supplier<?>) methods.get(method.getName()); return supplier.get(); } }); return (T) enhancer.create(); } else { final Enhancer enhancer = new Enhancer(); final Object obj = (T) enhancer.create(configClass, new net.sf.cglib.proxy.InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Supplier<?> supplier = (Supplier<?>) methods.get(method.getName()); if (supplier == null) { return method.invoke(proxy, args); } return supplier.get(); } }); ConfigurationProxyUtils.assignFieldValues(obj, configClass, propertyFactory, configuration); return (T) obj; } }
From source file:com.qmetry.qaf.automation.ui.AbstractTestPage.java
@SuppressWarnings("unchecked") protected void initParent() { try {/* www . j a v a2 s . c o m*/ Class<P> class1 = (Class<P>) ((ParameterizedType) this.getClass().getGenericSuperclass()) .getActualTypeArguments()[0]; if (!class1.isInterface()) { parent = class1.newInstance(); } } catch (Exception e) { logger.warn("Unable to init parent class" + e.getMessage()); } }
From source file:com.netflix.paas.config.base.DynamicProxyArchaeusConfigurationFactory.java
@SuppressWarnings({ "unchecked", "static-access" }) public <T> T get(Class<T> configClass, DynamicPropertyFactory propertyFactory, AbstractConfiguration configuration) throws Exception { final Map<String, Supplier<?>> methods = ConfigurationProxyUtils.getMethodSuppliers(configClass, propertyFactory, configuration); if (configClass.isInterface()) { Class<?> proxyClass = Proxy.getProxyClass(configClass.getClassLoader(), new Class[] { configClass }); return (T) proxyClass.getConstructor(new Class[] { InvocationHandler.class }) .newInstance(new Object[] { new InvocationHandler() { @Override/*from w w w . j a va 2 s. c o m*/ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Supplier<?> supplier = (Supplier<?>) methods.get(method.getName()); return supplier.get(); } } }); } else { final Enhancer enhancer = new Enhancer(); final Object obj = (T) enhancer.create(configClass, new net.sf.cglib.proxy.InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Supplier<?> supplier = (Supplier<?>) methods.get(method.getName()); if (supplier == null) { return method.invoke(proxy, args); } return supplier.get(); } }); ConfigurationProxyUtils.assignFieldValues(obj, configClass, propertyFactory, configuration); return (T) obj; } }
From source file:net.ymate.platform.commons.util.ClassUtils.java
/** * ?.class??'$'??Java"com/ymatesoft/common/A.class"~"com.ymatesoft.common.A" * /*w ww. j av a2 s .c o m*/ * @param collections * @param clazz * @param packageName * @param packageFile * @param callingClass */ @SuppressWarnings("unchecked") protected static <T> void __doFindClassByClazz(Collection<Class<T>> collections, Class<T> clazz, String packageName, File packageFile, Class<?> callingClass) { if (packageFile.isFile()) { try { if (packageFile.getName().endsWith(".class") && packageFile.getName().indexOf('$') < 0) { Class<?> _class = ResourceUtils.loadClass( packageName + "." + packageFile.getName().replace(".class", ""), callingClass); if (_class != null) { if (clazz.isAnnotation()) { if (isAnnotationOf(_class, (Class<Annotation>) clazz)) { collections.add((Class<T>) _class); } } else if (clazz.isInterface()) { if (isInterfaceOf(_class, clazz)) { collections.add((Class<T>) _class); } } else if (isSubclassOf(_class, clazz)) { collections.add((Class<T>) _class); } } } } catch (NoClassDefFoundError e) { _LOG.warn("", RuntimeUtils.unwrapThrow(e)); } catch (ClassNotFoundException e) { _LOG.warn("", RuntimeUtils.unwrapThrow(e)); } } else { File[] _tmpfiles = packageFile.listFiles(); for (File _tmpFile : _tmpfiles != null ? _tmpfiles : new File[0]) { __doFindClassByClazz(collections, clazz, packageName + "." + packageFile.getName(), _tmpFile, callingClass); } } }
From source file:com.jaliansystems.activeMQLite.impl.ObjectRepository.java
/** * Invoke a method on a local object.//from w w w. j a v a2 s. co m * * @param message * the message received. * @param client * the repository client. * @return the return value from the method invocation. * @throws Exception * the exception */ public Object invoke(JMSLiteMessage message, RepositoryClient client) throws Exception { ObjectHandle handle = (ObjectHandle) message.read(); String methodName = (String) message.read(); Object[] args = (Object[]) message.read(); Object object = getObject(handle); if (object == null) throw new IllegalArgumentException("Could not find local object: " + handle); if (client != null && args != null) for (int i = 0; i < args.length; i++) { if (args[i] != null && args[i] instanceof ObjectHandle) args[i] = lookupHandle((ObjectHandle) args[i], client); } Method method = findMethod(object, methodName, args); if (method == null) throw new NoSuchMethodError( "Could not find method: " + methodName + " on Object of type " + object.getClass().getName()); Object rval = method.invoke(object, args); Class<?> rtype = method.getReturnType(); if (rtype.isInterface() && exportedInterfaces.contains(rtype) && rval != null) { rval = createHandle(rval, rtype); } return rval; }
From source file:name.ikysil.beanpathdsl.codegen.Context.java
private boolean isExcluded(Class<?> clazz) { if (clazz.isPrimitive() || clazz.isAnonymousClass() || clazz.isLocalClass() || clazz.isInterface() || clazz.isSynthetic() || clazz.isEnum() || !Modifier.isPublic(clazz.getModifiers()) || (clazz.getPackage() == null)) { return true; }//from ww w . ja v a2s. c o m IncludedClass includedConfig = includedClasses.get(clazz); if (includedConfig != null) { return false; } ExcludedClass excludedConfig = excludedClasses.get(clazz); if (excludedConfig != null) { return true; } for (ExcludedPackage excludedPackage : excludedPackages) { if (excludedPackage.match(clazz.getPackage())) { return true; } } return false; }
From source file:net.ymate.platform.plugin.impl.DefaultPluginFactory.java
@SuppressWarnings("unchecked") private List<Class<? extends IBeanHandler>> __doLoadBeanHandles() throws Exception { List<Class<? extends IBeanHandler>> _returnValues = new ArrayList<Class<? extends IBeanHandler>>(); IBeanLoader _loader = new DefaultBeanLoader(); ////from ww w.ja va2s.c o m IBeanFilter _beanFilter = new IBeanFilter() { public boolean filter(Class<?> targetClass) { return !(targetClass.isInterface() || targetClass.isAnnotation() || targetClass.isEnum()) && (targetClass.isAnnotationPresent(Handler.class) && ClassUtils.isInterfaceOf(targetClass, IBeanHandler.class)); } }; // for (String _package : __config.getAutoscanPackages()) { for (Class<?> _targetClass : _loader.load(_package, _beanFilter)) { _returnValues.add((Class<? extends IBeanHandler>) _targetClass); } } return _returnValues; }