List of usage examples for java.lang Class isInstance
@HotSpotIntrinsicCandidate public native boolean isInstance(Object obj);
From source file:com.wabacus.config.component.other.ButtonsBean.java
public AbsButtonType getcertainTypeButton(Class buttonType) { if (mAllButtons == null || buttonType == null) return null; Iterator<String> itPositions = mAllButtons.keySet().iterator(); String position;// w w w . j a v a 2 s. c om while (itPositions.hasNext()) { position = itPositions.next(); List<AbsButtonType> lstButtons = mAllButtons.get(position); if (lstButtons == null) continue; AbsButtonType buttonObj; for (int i = 0; i < lstButtons.size(); i++) { buttonObj = lstButtons.get(i); if (buttonObj == null) continue; if (buttonType.isInstance(buttonObj)) { return buttonObj; } } } return null; }
From source file:org.rosenvold.spring.convention.ConventionBeanFactory.java
protected Map<String, Object> findAutowireCandidates(String beanName, Class requiredType, DependencyDescriptor descriptor) { // System.out.println("beanName = " + beanName + ", requiredType" + requiredType); String[] candidateNames = getCandidateNames(requiredType, descriptor); Map<String, Object> result = new LinkedHashMap<String, Object>(candidateNames.length); for (Class autowiringType : this.resolvableDependenciesLocalCache.keySet()) { if (autowiringType.isAssignableFrom(requiredType)) { Object autowiringValue = this.resolvableDependenciesLocalCache.get(autowiringType); autowiringValue = resolveAutowiringValue(autowiringValue, requiredType); if (requiredType.isInstance(autowiringValue)) { result.put(ObjectUtils.identityToString(autowiringValue), autowiringValue); break; }/* w w w . jav a 2 s . c o m*/ } } for (String candidateName : candidateNames) { if (!candidateName.equals(beanName) && isAutowireCandidate(candidateName, descriptor)) { result.put(candidateName, getBean(candidateName)); } } return result; }
From source file:org.opennms.netmgt.correlation.ncs.EventMappingRulesTest.java
private void testEventMapping(Event event, Class<? extends ComponentEvent> componentEventClass, String componentType, String componentForeignSource, String componentForeignId) { // Get engine DroolsCorrelationEngine engine = findEngineByName("eventMappingRules"); assertEquals("Expected nothing but got " + engine.getMemoryObjects(), 0, engine.getMemorySize()); engine.correlate(event);/*from ww w . j a v a2s. c o m*/ List<Object> memObjects = engine.getMemoryObjects(); assertEquals("Unexpected size of workingMemory " + memObjects, 1, memObjects.size()); Object eventObj = memObjects.get(0); assertTrue("expected " + eventObj + " to be an instance of " + componentEventClass, componentEventClass.isInstance(eventObj)); assertTrue(eventObj instanceof ComponentEvent); ComponentEvent c = (ComponentEvent) eventObj; assertSame(event, c.getEvent()); Component component = c.getComponent(); assertEquals(componentType, component.getType()); assertEquals(componentForeignSource, component.getForeignSource()); assertEquals(componentForeignId, component.getForeignId()); }
From source file:com.jaspersoft.jasperserver.war.action.ReportUnitAction.java
protected boolean checkDataSourceType(ReportDataSource ds, Set supportedTypes) { boolean valid = false; for (Iterator it = supportedTypes.iterator(); !valid && it.hasNext();) { Class type = (Class) it.next(); if (type.isInstance(ds)) { valid = true;// w w w . ja v a 2 s. c om } } return valid; }
From source file:com.cyberway.issue.crawler.settings.ComplexType.java
/** Set the value of a specific attribute of the ComplexType. * * This method is an extension to the Dynamic MBean specification so that * it is possible to set the value for a CrawlerSettings object other than * the settings object representing the order. * * @param settings the settings object for which this attributes value is valid * @param attribute The identification of the attribute to be set and the * value it is to be set to. * @throws AttributeNotFoundException is thrown if there is no attribute * with this name.// w w w .java 2 s . c om * @throws InvalidAttributeValueException is thrown if the attribute is of * wrong type and cannot be converted to the right type. * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute) */ public synchronized final void setAttribute(CrawlerSettings settings, Attribute attribute) throws InvalidAttributeValueException, AttributeNotFoundException { if (settings == null) { settings = globalSettings(); } DataContainer data = getOrCreateDataContainer(settings); Object value = attribute.getValue(); ModuleAttributeInfo attrInfo = (ModuleAttributeInfo) getAttributeInfo(settings.getParent(), attribute.getName()); ModuleAttributeInfo localAttrInfo = (ModuleAttributeInfo) data.getAttributeInfo(attribute.getName()); // Check if attribute exists if (attrInfo == null && localAttrInfo == null) { throw new AttributeNotFoundException(attribute.getName()); } // Check if we are overriding and if that is allowed for this attribute if (localAttrInfo == null) { if (!attrInfo.isOverrideable()) { throw new InvalidAttributeValueException("Attribute not overrideable: " + attribute.getName()); } localAttrInfo = new ModuleAttributeInfo(attrInfo); } // Check if value is of correct type. If not, see if it is // a string and try to turn it into right type Class typeClass = getDefinition(attribute.getName()).getLegalValueType(); if (!(typeClass.isInstance(value)) && value instanceof String) { try { value = SettingsHandler.StringToType((String) value, SettingsHandler.getTypeName(typeClass.getName())); } catch (ClassCastException e) { throw new InvalidAttributeValueException( "Unable to decode string '" + value + "' into type '" + typeClass.getName() + "'"); } } // Check if the attribute value is legal FailedCheck error = checkValue(settings, attribute.getName(), value); if (error != null) { if (error.getLevel() == Level.SEVERE) { throw new InvalidAttributeValueException(error.getMessage()); } else if (error.getLevel() == Level.WARNING) { if (!getSettingsHandler().fireValueErrorHandlers(error)) { throw new InvalidAttributeValueException(error.getMessage()); } } else { getSettingsHandler().fireValueErrorHandlers(error); } } // Everything ok, set it localAttrInfo.setType(value); Object oldValue = data.put(attribute.getName(), localAttrInfo, value); // If the attribute is a complex type other than the old value, // make sure that all sub attributes are correctly set if (value instanceof ComplexType && value != oldValue) { ComplexType complex = (ComplexType) value; replaceComplexType(settings, complex); } }
From source file:edu.umn.msi.tropix.common.logging.ExceptionUtilsTest.java
public <T extends Throwable> void logTest(final boolean message, final Class<T> exceptionClass, final Types type) throws T { final Throwable t = new Throwable(); final String messageStr = "Message"; if (message) { this.log.warn(messageStr); }/*from w w w .j a v a 2 s. co m*/ this.log.info("Exception Info : ", t); EasyMock.replay(this.log); try { if (type.equals(Types.LOG_QUIETLY)) { if (!message) { ExceptionUtils.logQuietly(this.log, t); } else { ExceptionUtils.logQuietly(this.log, t, "Message"); } } else if (type.equals(Types.LOG_AND_CONVERT)) { if (!message && exceptionClass == null) { assert RuntimeException.class.isInstance(ExceptionUtils.logAndConvert(this.log, t)); } else if (exceptionClass == null) { assert RuntimeException.class.isInstance(ExceptionUtils.logAndConvert(this.log, t, messageStr)); } else if (message) { assert exceptionClass .isInstance(ExceptionUtils.logAndConvert(this.log, t, messageStr, exceptionClass)); } else { assert exceptionClass.isInstance(ExceptionUtils.logAndConvert(this.log, t, exceptionClass)); } } else if (type.equals(Types.LOG_AND_RETHROW)) { if (!message && exceptionClass == null) { ExceptionUtils.logAndRethrowUnchecked(this.log, t); } else if (exceptionClass == null) { ExceptionUtils.logAndRethrowUnchecked(this.log, t, messageStr); } else if (message) { ExceptionUtils.logAndRethrow(this.log, t, messageStr, exceptionClass); } else { ExceptionUtils.logAndRethrow(this.log, t, exceptionClass); } } } finally { EasyMock.verify(this.log); } }
From source file:com.wabacus.config.component.other.ButtonsBean.java
public List<AbsButtonType> getAllCertainTypeButtonsList(Class buttonType) { if (mAllButtons == null || buttonType == null) return null; Iterator<String> itPositions = mAllButtons.keySet().iterator(); List<AbsButtonType> lstButtonsResult = new ArrayList<AbsButtonType>(); String position;//from ww w .ja va 2s . co m while (itPositions.hasNext()) { position = itPositions.next(); List<AbsButtonType> lstButtons = mAllButtons.get(position); if (lstButtons == null) continue; AbsButtonType buttonObj; for (int i = 0; i < lstButtons.size(); i++) { buttonObj = lstButtons.get(i); if (buttonObj == null) continue; if (buttonType.isInstance(buttonObj)) { lstButtonsResult.add(buttonObj); } } } return lstButtonsResult; }
From source file:com.evolveum.icf.dummy.resource.DummyResource.java
private <T extends DummyObject> T getObjectById(Class<T> expectedClass, String id) throws ConnectException, FileNotFoundException { if (getBreakMode == BreakMode.NONE) { DummyObject dummyObject = allObjects.get(id); if (dummyObject == null) { return null; }/*from www. jav a 2 s . c o m*/ if (!expectedClass.isInstance(dummyObject)) { throw new IllegalStateException("Arrrr! Wanted " + expectedClass + " with ID " + id + " but got " + dummyObject + " instead"); } return (T) dummyObject; } else if (schemaBreakMode == BreakMode.NETWORK) { throw new ConnectException("Network error (simulated error)"); } else if (schemaBreakMode == BreakMode.IO) { throw new FileNotFoundException("IO error (simulated error)"); } else if (schemaBreakMode == BreakMode.GENERIC) { // The connector will react with generic exception throw new IllegalArgumentException("Generic error (simulated error)"); } else if (schemaBreakMode == BreakMode.RUNTIME) { // The connector will just pass this up throw new IllegalStateException("Generic error (simulated error)"); } else if (schemaBreakMode == BreakMode.UNSUPPORTED) { throw new UnsupportedOperationException("Not supported (simulated error)"); } else { // This is a real error. Use this strange thing to make sure it passes up throw new RuntimeException("Unknown schema break mode " + schemaBreakMode); } }
From source file:com.wabacus.config.component.other.ButtonsBean.java
public void removeAllCertainTypeButtons(Class buttonType) { if (mAllButtons == null || buttonType == null) return;//from w w w . j ava 2s .com Iterator<String> itPositions = mAllButtons.keySet().iterator(); String position; while (itPositions.hasNext()) { position = itPositions.next(); List<AbsButtonType> lstButtons = mAllButtons.get(position); if (lstButtons == null) continue; AbsButtonType buttonObj; boolean flag = true; while (flag) { flag = false; for (int i = 0; i < lstButtons.size(); i++) { buttonObj = lstButtons.get(i); if (buttonObj == null) continue; if (buttonType.isInstance(buttonObj)) { lstButtons.remove(i); flag = true; break; } } } } }
From source file:engine.resources.objects.Baseline.java
public void initializeChildren(Object delta) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException { if (delta instanceof IDelta || delta instanceof SWGList || delta instanceof SWGMap || delta instanceof SWGMultiMap || delta instanceof SWGSet) { delta.getClass().getMethod("init", new Class[] { SWGObject.class }).invoke(delta, new Object[] { object }); Class<?> iDelta = null; try {/* w w w .j av a2s . c om*/ iDelta = Class.forName("engine.resources.objects.IDelta"); } catch (ClassNotFoundException e) { e.printStackTrace(); return; } for (Field field : delta.getClass().getFields()) { if (iDelta.isInstance(field.get(delta))) { initializeChildren(field.get(delta)); } } } }