List of usage examples for java.lang Class isInstance
@HotSpotIntrinsicCandidate public native boolean isInstance(Object obj);
From source file:com.navercorp.pinpoint.web.cluster.DefaultPinpointRouteResponse.java
@Override public <R extends TBase> R getResponse(Class<R> clazz) { TBase response = getResponse();/* w w w . ja v a 2s . c om*/ if (clazz.isInstance(response)) { return (R) response; } throw new ClassCastException("Not expected " + clazz + " type."); }
From source file:de.slub.fedora.jms.MessageMapperTest.java
private IndexJob findFirstByClass(List<IndexJob> jobs, Class c) { for (IndexJob job : jobs) { if (c.isInstance(job)) return job; }//from w w w . j a v a 2s . c o m return null; }
From source file:org.apache.james.container.spring.lifecycle.AbstractLifecycleBeanPostProcessor.java
/** * @see org.springframework.beans.factory.config.BeanPostProcessor * #postProcessBeforeInitialization(java.lang.Object, java.lang.String) *//*from w w w. j a v a2 s .c om*/ @SuppressWarnings("unchecked") public final Object postProcessBeforeInitialization(Object bean, String name) throws BeansException { try { Class<T> lClass = getLifeCycleInterface(); if (lClass.isInstance(bean)) { // Check if the bean is registered in the context. // If not it was created by the container and so there // is no need to execute the callback. if (factory.containsBeanDefinition(name)) { executeLifecycleMethodBeforeInit((T) bean, name); } } } catch (Exception e) { throw new FatalBeanException("Unable to execute lifecycle method on bean" + name, e); } return bean; }
From source file:org.apache.james.container.spring.lifecycle.AbstractLifecycleBeanPostProcessor.java
/** * @see org.springframework.beans.factory.config.BeanPostProcessor * #postProcessAfterInitialization(java.lang.Object, java.lang.String) *///from ww w. j ava 2 s.com @SuppressWarnings("unchecked") public final Object postProcessAfterInitialization(Object bean, String name) throws BeansException { try { Class<T> lClass = getLifeCycleInterface(); if (lClass.isInstance(bean)) { // Check if the bean is registered in the context. // If not it was created by the container and so there is no // need to execute the callback. if (factory.containsBeanDefinition(name)) { executeLifecycleMethodAfterInit((T) bean, name); } } } catch (Exception e) { throw new FatalBeanException("Unable to execute lifecycle method on bean" + name, e); } return bean; }
From source file:org.bytesoft.openjtcc.supports.spring.PropagateBeanFactoryImpl.java
@SuppressWarnings("unchecked") public <T> T getBean(Class<T> interfaceClass, String beanId) { Object beanInst = this.applicationContext.getBean(beanId); if (interfaceClass.isInstance(beanInst) // && Compensable.class.isInstance(beanInst)// ) {/* www . j a v a2 s . com*/ PropagateCompensableProxy<Serializable> proxy = new PropagateCompensableProxy<Serializable>(); proxy.setBeanName(beanId); proxy.setTarget((Compensable<Serializable>) beanInst); proxy.setProxyId(atomic.incrementAndGet()); proxy.setTransactionManager(this.transactionManager); ClassLoader classLoader = beanInst.getClass().getClassLoader(); Class<?>[] interfaces = null; if (Compensable.class.equals(interfaceClass)) { interfaces = new Class[] { interfaceClass }; } else { interfaces = new Class[] { interfaceClass, Compensable.class }; } Object proxyInst = Proxy.newProxyInstance(classLoader, interfaces, proxy); proxy.setFacade((Compensable<Serializable>) proxyInst); return interfaceClass.cast(proxyInst); } throw new RuntimeException(); }
From source file:edu.vt.middleware.ldap.handler.AbstractResultHandler.java
/** * This will enumerate through the supplied <code>NamingEnumeration</code> and * return a List of those results. The results are unaltered and the dn is * ignored. Any exceptions passed into this method will be ignored and results * will be returned as if no exception occurred. * * @param sc <code>SearchCriteria</code> used to find enumeration * @param en <code>NamingEnumeration</code> LDAP results * @param ignore <code>Class[]</code> of exception types to ignore * * @return <code>List</code> - LDAP results * * @throws NamingException if the LDAP returns an error */// w w w. java 2s . com public List<O> process(final SearchCriteria sc, final NamingEnumeration<? extends R> en, final Class<?>[] ignore) throws NamingException { final List<O> results = new ArrayList<O>(); if (en != null) { try { while (en.hasMore()) { final O o = processResult(sc, en.next()); if (o != null) { results.add(o); } } } catch (NamingException e) { boolean ignoreException = false; if (ignore != null && ignore.length > 0) { for (Class<?> ne : ignore) { if (ne.isInstance(e)) { if (this.logger.isDebugEnabled()) { this.logger.debug("Ignoring naming exception", e); } ignoreException = true; break; } } } if (!ignoreException) { throw e; } } } return results; }
From source file:eu.squadd.reflections.mapper.ServiceModelTranslator.java
private static boolean assignPropertyValue(PropertyDescriptor sourceProp, Object sourceValue, PropertyDescriptor destProp, Object destInstance) { if (sourceValue == null) { System.out.println("Null value found, assignment skipped"); return true; }/*from w w w . j av a 2 s .c om*/ boolean result = false; Class<?> sourceType = sourceProp.getPropertyType(); Method getter = sourceProp.getReadMethod(); Class<?> destType = destProp.getPropertyType(); Method setter = destProp.getWriteMethod(); try { if (destType.isInterface() || destType.isArray() || destType.isEnum()) { if (Collection.class.isAssignableFrom(sourceType) && Collection.class.isAssignableFrom(destType)) assignCollectionValue(getter, sourceValue, destType, setter, destInstance); else if (Map.class.isAssignableFrom(sourceType) && Map.class.isAssignableFrom(destType)) assignMapValue(getter, sourceValue, setter, destInstance); else assignMixedTypesValue(sourceType, getter, sourceValue, destType, setter, destInstance); } else if (destType.isInstance(sourceValue) || destType.isPrimitive()) setter.invoke(destInstance, sourceValue); else if (destType.isMemberClass()) setter.invoke(destInstance, sourceValue); else if (destType.isAssignableFrom(sourceType)) setter.invoke(destInstance, destType.cast(sourceValue)); else { //if (ClassUtils.isInnerClass(destType)) { Object member = transposeModel(sourceType, destType, sourceValue); member = destType.cast(member); setter.invoke(destInstance, member); } result = true; } catch (IllegalArgumentException ex) { System.out.println("Looks like type mismatch, source type: " + sourceType + ", dest type: " + destType); Logger.getLogger(ServiceModelTranslator.class.getName()).log(Level.SEVERE, null, ex); } catch (InvocationTargetException | IllegalAccessException ex) { Logger.getLogger(ServiceModelTranslator.class.getName()).log(Level.SEVERE, null, ex); } return result; }
From source file:org.opendaylight.ovsdb.lib.schema.DatabaseSchema.java
public <E extends TableSchema<E>> E table(String tableName, Class<E> clazz) { TableSchema<E> table = tables.get(tableName); if (clazz.isInstance(table)) { return clazz.cast(table); }//ww w.j av a 2 s. c om return createTableSchema(clazz, table); }
From source file:edu.harvard.i2b2.fhir.FhirUtil.java
public static ca.uhn.fhir.model.api.Bundle fhirBundleToHapiBundle(Bundle b) throws Exception { ca.uhn.fhir.model.api.Bundle hb = new ca.uhn.fhir.model.api.Bundle(); // IdDt idb = new IdDt(); // idb.setValue(b.getId().getValue()); // id.setValue(fhirBase + UUID.randomUUID().toString()); // hb.setId(idb); String fhirBase = "b.getBase().toString()"; for (BundleEntry be : b.getEntry()) { ResourceContainer rc = be.getResource(); Resource r = getResourceFromContainer(rc); for (Class c : getResourceClassList()) { if (c.isInstance(r)) { ca.uhn.fhir.model.api.BundleEntry entry = new ca.uhn.fhir.model.api.BundleEntry(); IdDt ide = new IdDt(); ide.setValue(r.getId().getValue()); entry.setId(ide);//from w w w . j a v a 2 s . c o m XMLGregorianCalendar lastUpdated = null; try { lastUpdated = null; } catch (Exception ex) { } if (lastUpdated != null) { Date d = lastUpdated.toGregorianCalendar().getTime(); InstantDt dt = new InstantDt(); dt.setValue(d); // entry.setUpdated(dt); } // entry.addExtension("http://www.w3.org/2005/Atom","published",null).setText(new // Date().toGMTString()); // theLinkSelf StringDt theLinkSelf = new StringDt(); theLinkSelf.setValue(fhirBase + r.getId()); entry.setLinkSelf(theLinkSelf); IResource theResource = WrapperHapi.resourceXmlToIResource(JAXBUtil.toXml(r)); entry.setResource(theResource); hb.addEntry(entry); } } } return hb; }
From source file:com.googlecode.spring.appengine.cache.memcache.MemcacheCache.java
@SuppressWarnings({ "rawtypes", "unchecked" }) protected Object toStoreValue(Object value) { // datanucleus: if value to store is StreamingQueryResult then get all objects from stream and return new list (stream cannot be stored in memcache) try {//from www .ja v a 2s.c om Class clazz = Class.forName("com.google.appengine.datanucleus.query.StreamingQueryResult"); if (clazz.isInstance(value)) { return new ArrayList((Collection) value); } } catch (Exception ignore) { } // objectify: wrap lists as objectify returns list proxies which cannot be serialized directly (https://code.google.com/p/objectify-appengine/issues/detail?id=166) try { @SuppressWarnings("unused") Class clazz = Class.forName("com.googlecode.objectify.Objectify"); if (value instanceof List) { return new ArrayList((List) value); } } catch (Exception ignore) { } return value; }