List of usage examples for java.lang Class isAssignableFrom
@HotSpotIntrinsicCandidate public native boolean isAssignableFrom(Class<?> cls);
From source file:com.smhdemo.common.datasource.generate.factory.init.bean.BeanForInterfaceFactory.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override//w w w. j a v a 2 s . c om public String getBeanName(Map interfaceToBeanMappings, Class itfClass) { if (interfaceToBeanMappings == null) { return null; } try { SortedSet interfaces = new TreeSet(itfComparator); for (Iterator it = interfaceToBeanMappings.keySet().iterator(); it.hasNext();) { String itfName = (String) it.next(); Class itf = Class.forName(itfName, true, Thread.currentThread().getContextClassLoader()); if (itf.isAssignableFrom(itfClass)) { interfaces.add(itf); } } if (!interfaces.isEmpty()) { Class itf = (Class) interfaces.iterator().next(); return (String) interfaceToBeanMappings.get(itf.getName()); } return null; } catch (ClassNotFoundException e) { logger.error("ClassNotFoundException", e); throw new BaseRuntimeExceptionWrapper(e); } }
From source file:com.nesscomputing.jersey.exceptions.GuiceProvisionExceptionMapper.java
private int distance(Class<?> c, Class<?> emtc) { if (!emtc.isAssignableFrom(c)) { return Integer.MAX_VALUE; }/*w ww . j av a 2 s.c o m*/ int distance = 0; while (c != emtc) { c = c.getSuperclass(); distance++; } return distance; }
From source file:pl.bristleback.server.bristle.conf.resolver.action.interceptor.ActionInterceptorContextsResolver.java
private void checkContextObjectCompatibility(Object contextObject, ActionInterceptorInformation interceptorInformation) { Class<?> interceptorInstanceType = interceptorInformation.getInterceptorInstance().getClass(); Class<?> interceptorContextObjectType = (Class) ReflectionUtils.getParameterTypes(interceptorInstanceType, ActionInterceptor.class)[0]; if (!interceptorContextObjectType.isAssignableFrom(contextObject.getClass())) { throw new BristleInitializationException("Object returned by " + interceptorInformation.getInterceptorContextResolver().getClass().getName() + " context resolver does not match context parameter type in " + interceptorInstanceType.getName() + " interceptor class."); }//ww w . j a va 2 s . c o m }
From source file:org.codehaus.groovy.grails.plugins.searchable.compass.config.mapping.CompassAnnotationSearchableGrailsDomainClassMappingConfigurator.java
/** * Configure the Mapping in the CompassConfiguration for the given domain class * * @param compassConfiguration the CompassConfiguration instance * @param configurationContext a configuration context, for flexible parameter passing * @param searchableGrailsDomainClasses searchable domain classes to map *//*w w w. j a va 2 s .com*/ public void configureMappings(CompassConfiguration compassConfiguration, Map configurationContext, Collection searchableGrailsDomainClasses) { Assert.isTrue(annotationsAvailable, "Annotations must be available"); Assert.notNull(compassConfiguration, "compassConfiguration cannot be null"); Assert.notNull(configurationContext, "configurationContext cannot be null"); if (configurationContext.containsKey(CompassXmlConfigurationSearchableCompassConfigurator.CONFIGURED)) { return; } Class compassAnnotationsConfigurationClass = getCompassAnnotationConfigurationClass(); Assert.isTrue(compassAnnotationsConfigurationClass.isAssignableFrom(compassConfiguration.getClass()), "compassConfiguration must be an instance of CompassAnnotationsConfiguration"); for (Iterator iter = searchableGrailsDomainClasses.iterator(); iter.hasNext();) { compassConfiguration.addClass(((GrailsDomainClass) iter.next()).getClazz()); } }
From source file:bear.task.TaskResult.java
@JsonIgnore public boolean isErrorOf(Class<?> aClass) { return exception.isPresent() && (aClass.isAssignableFrom(exception.get().getClass())); }
From source file:com.ebay.erl.mobius.core.mapred.MultiInputsHelpersRepository.java
public MultiInputsHelper getHelper(Class<? extends InputFormat> inputFormat) { // get the closest helper Iterator<Class<? extends InputFormat>> it = this.mapping.keySet().iterator(); while (it.hasNext()) { Class<? extends InputFormat> anRegisteredInputFormat = it.next(); if (anRegisteredInputFormat.isAssignableFrom(inputFormat)) { // the keys in the mapping have been sorted, the most // generic classes will be put at the end of the mapping // keys set, so the first input format class from the set // which is the equals or super class of the <code>inputFormat</code> // is the best helper. return this.mapping.get(anRegisteredInputFormat); }/*from w w w .j ava 2 s .c o m*/ } throw new IllegalArgumentException("There is no " + MultiInputsHelper.class.getSimpleName() + " for handling " + inputFormat.getCanonicalName() + " please provide one using the register method in " + this.getClass().getSimpleName()); }
From source file:com.griddynamics.banshun.ContextAnalyzer.java
public boolean areImportsTypesCorrect() { boolean importsTypesAreCorrect = true; for (String exportName : exports.keySet()) { if (imports.containsKey(exportName)) { Class<?> exportIface = exports.get(exportName).getServiceInterface(); for (BeanReferenceInfo importRef : imports.get(exportName)) { Class<?> importIface = importRef.getServiceInterface(); if (!importIface.isAssignableFrom(exportIface)) { importsTypesAreCorrect = false; log.error(/* w w w . j a va2s . co m*/ "Imported bean {} from location {} must implement same interface that appropriate" + "exported bean {} or subinterface but no superclass or superinterface", new Object[] { exportName, importRef.getLocation(), exportName }); } } } } return importsTypesAreCorrect; }
From source file:org.nabucco.alfresco.enhScriptEnv.common.script.converter.general.AdapterObjectConverter.java
/** * {@inheritDoc}// w w w . jav a 2 s .com */ @Override public boolean canConvertValueForJava(final Object value, final ValueConverter globalDelegate, final Class<?> expectedClass) { final boolean canConvert = AdapterObject.class.isInstance(value) && expectedClass.isAssignableFrom(((AdapterObject) value).getBackingObject().getClass()); return canConvert; }
From source file:com.threewks.thundr.jrebel.ThundrJRebelPlugin.java
@SuppressWarnings("unchecked") private void registerListener() { // Set up the reload listener final Set<String> watchedClasses = loadWatchedClassList(); ReloaderFactory.getInstance().addClassReloadListener(new ClassEventListener() { @Override/* ww w. j a v a 2 s . c o m*/ public void onClassEvent(int eventType, Class klass) { try { Class applicationModuleClass = Class.forName(BaseModuleClassName); if (applicationModuleClass.isAssignableFrom(klass) || watchedClasses.contains(klass.getCanonicalName())) { Logger.info("%s was modified. InjectionContext will be reloaded on next request...", klass.getCanonicalName()); ThundrServletReloader.markDirty(); } } catch (Exception e) { Logger.error("Error marking ApplicationModule for reloading: %s", ExceptionUtils.getStackTrace(e)); } } @Override public int priority() { return 0; } }); }
From source file:adalid.core.XS1.java
static Class<?> getConstructorParameterType(Class<?> wrapper, Class<?> wrappable) { Class<?> parameterType = null; Constructor<?>[] constructors = wrapper.getConstructors(); for (Constructor<?> constructor : constructors) { Class<?>[] parameterTypes = constructor.getParameterTypes(); if (parameterTypes.length == 1 && parameterTypes[0].isAssignableFrom(wrappable)) { if (parameterType == null || parameterType.isAssignableFrom(parameterTypes[0])) { parameterType = parameterTypes[0]; }/*from ww w.ja va2 s. com*/ } } return parameterType; }