List of usage examples for java.lang Class isInstance
@HotSpotIntrinsicCandidate public native boolean isInstance(Object obj);
From source file:com.googlecode.psiprobe.tools.logging.slf4jlogback.TomcatSlf4jLogbackFactoryAccessor.java
/** * Attempts to initialize a TomcatSlf4jLogback logger factory via the given class loader. * //www . j av a 2 s. com * @param cl the ClassLoader to use when fetching the factory */ public TomcatSlf4jLogbackFactoryAccessor(ClassLoader cl) throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Get the singleton SLF4J binding, which may or may not be Logback, depending on the binding. Class clazz = cl.loadClass("org.apache.juli.logging.org.slf4j.impl.StaticLoggerBinder"); Method getSingleton = MethodUtils.getAccessibleMethod(clazz, "getSingleton", new Class[] {}); Object singleton = getSingleton.invoke(null, null); Method getLoggerFactory = MethodUtils.getAccessibleMethod(clazz, "getLoggerFactory", new Class[] {}); Object loggerFactory = getLoggerFactory.invoke(singleton, null); // Check if the binding is indeed Logback Class loggerFactoryClass = cl.loadClass("org.apache.juli.logging.ch.qos.logback.classic.LoggerContext"); if (!loggerFactoryClass.isInstance(loggerFactory)) { throw new RuntimeException("The singleton SLF4J binding was not Logback"); } setTarget(loggerFactory); }
From source file:hudson.model.Actionable.java
/** * Gets all actions of a specified type that contributed to this build. * * @param type The type of action to return. * @return/* w w w . j ava 2 s . c o m*/ * may be empty but never null. * @see #getAction(Class) */ public <T extends Action> List<T> getActions(Class<T> type) { List<T> result = new Vector<T>(); for (Action a : getActions()) if (type.isInstance(a)) result.add(type.cast(a)); return result; }
From source file:com.clustercontrol.view.CommonViewPart.java
/** * ????????????//from w w w .j a v a 2 s .co m * * @return ? * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) * @since 1.0.0 */ @SuppressWarnings("unchecked") @Override public Object getAdapter(@SuppressWarnings("rawtypes") Class cls) { if (cls.isInstance(this)) { return this; } else { return super.getAdapter(cls); } }
From source file:com.jivesoftware.os.routing.bird.http.client.HttpClientFactoryProvider.java
@SuppressWarnings("unchecked") private <T> T locateConfig(Collection<HttpClientConfiguration> configurations, Class<? extends T> _class, T defaultConfiguration) {/*from w w w. ja v a2s. c om*/ for (HttpClientConfiguration configuration : configurations) { if (_class.isInstance(configuration)) { return (T) configuration; } } return defaultConfiguration; }
From source file:org.apache.taverna.scufl2.rdfxml.ParserState.java
public <T extends WorkflowBean> T getCurrent(Class<T> beanType) { if (getStack().isEmpty()) throw new IllegalStateException("Parser stack is empty"); if (beanType.isInstance(getStack().peek())) return beanType.cast(getStack().peek()); T candidate = null;/*from w w w . java 2s .c o m*/ for (WorkflowBean bean : getStack()) if (beanType.isInstance(bean)) // Don't return - we want the *last* candidate candidate = beanType.cast(bean); if (candidate == null) throw new IllegalStateException("Could not find a " + beanType + " on parser stack"); return candidate; }
From source file:de.laures.cewolf.taglib.PlotDefinition.java
public void check(Dataset data, Class clazz, int plotType) throws IncompatibleDatasetException { if (!clazz.isInstance(data)) { throw new IncompatibleDatasetException("Plots of type " + PlotTypes.typeNames[plotType] + " need a dataset of type " + clazz.getName()); }//from w w w .j av a2s . com }
From source file:org.biopax.validator.rules.UnificationXrefLimitedRule.java
public void check(final Validation validation, UnificationXref x) { if (!ready)//from w ww . j ava 2 s. c om initInternalMaps(); if (x.getDb() == null || helper.getPrimaryDbName(x.getDb()) == null) { // ignore for unknown databases (another rule checks) return; } // fix case sensitivity final String xdb = helper.dbName(x.getDb()); // check constrains for each element containing this unification xref for (XReferrable bpe : x.getXrefOf()) { for (Class<? extends BioPAXElement> c : allow.keySet()) { if (c.isInstance(bpe)) { if (!allow.get(c).contains(xdb)) { error(validation, x, "not.allowed.xref", false, x.getDb(), bpe, c.getSimpleName(), allow.get(c).toString()); } } } for (Class<? extends BioPAXElement> c : deny.keySet()) { if (c.isInstance(bpe)) { if (deny.get(c).contains(xdb)) { error(validation, x, "denied.xref", false, x.getDb(), bpe, c.getSimpleName(), deny.get(c).toString()); } } } } }
From source file:moe.encode.airblock.commands.core.components.ComponentBag.java
/** * Checks if the given interface is implemented by the component holder * @param interfaceCls The interface that should be implemented. * @return {@code true} if the given interface has been implemented. */// ww w . j ava2 s. c o m public boolean isImplemented(@NonNull Class<?> interfaceCls, @NonNull HandleWrapper<?> wrapper) { return interfaceCls.isInstance(wrapper.getHandle()) || this.methods.containsKey(interfaceCls); }
From source file:grails.plugin.cache.GrailsConcurrentLinkedMapCache.java
@Override public <T> T get(Object key, Class<T> type) { Object value = getNativeCache().get(key); if (value != null && type != null && !type.isInstance(value)) { throw new IllegalStateException( "Cached value is not of required type [" + type.getName() + "]: " + value); }/*w w w . ja v a 2s .co m*/ return (T) value; }
From source file:rmblworx.tools.timey.AlarmEventsTest.java
/** * Stellt sicher, dass das Element <code>item</code> von einem der in <code>types</code> aufgefhrten Typen ist. * @param item Element// w ww .j av a2s . c o m * @param types Typen */ protected final void assertIsOfOneType(final Object item, final Class<?>... types) { for (final Class<?> klass : types) { if (klass.isInstance(item)) { return; } } fail(String.format("%s ist vom unerwarteten Typ %s.", item, item.getClass())); }