List of usage examples for java.lang Class isInstance
@HotSpotIntrinsicCandidate public native boolean isInstance(Object obj);
From source file:com.predic8.membrane.core.rules.SOAPProxy.java
@SuppressWarnings("unchecked") private <T extends Interceptor> T getInterceptorOfType(Class<T> class1) { for (Interceptor i : interceptors) if (class1.isInstance(i)) return (T) i; return null;// ww w .j a v a 2s . com }
From source file:org.kmnet.com.fw.web.exception.HandlerExceptionResolverLoggingInterceptor.java
/** * Determines if the exception class is in the list of classes for which log is to be output. * @param ex Exception// w ww .j a v a 2 s . co m * @return returns <code>true<code> if in the list. */ protected boolean isTargetException(Exception ex) { if (ignoreExceptions == null) { return true; } for (Class<? extends Exception> ignoreClass : ignoreExceptions) { if (ignoreClass.isInstance(ex)) { return false; } } return true; }
From source file:com.hmsinc.epicenter.model.surveillance.SurveillanceSet.java
/** * @param <T>//from w w w.ja v a2 s. c o m * @param attributeType * @return */ @Transient public <T extends Attribute> Set<T> getAttribute(final Class<T> attributeType) { final Set<T> attrs = new HashSet<T>(); for (Attribute attribute : getAttributes()) { if (attributeType.isInstance(attribute)) { attrs.add(attributeType.cast(attribute)); } } return attrs; }
From source file:de.grobmeier.jjson.convert.JSONAnnotationEncoder.java
private boolean hasInterface(Object target, Class<?> interfaceClass) { return interfaceClass.isInstance(target); }
From source file:com.kurtraschke.wmata.gtfsrealtime.services.WMATAAPIService.java
private <T> T mapUrl(URI url, boolean cache, Class<T> theClass, ObjectMapper mapper) throws IOException { Element e = _cache.get(url);/* w w w . ja v a2 s . c o m*/ if (cache && e != null) { Object value = e.getObjectValue(); if (theClass.isInstance(value)) { return theClass.cast(value); } } CloseableHttpClient client = HttpClients.custom().setConnectionManager(_connectionManager).build(); HttpGet httpget = new HttpGet(url); _limiter.acquire(); try (CloseableHttpResponse response = client.execute(httpget); InputStream responseInputStream = response.getEntity().getContent()) { T value = mapper.readValue(responseInputStream, theClass); if (cache) { _cache.put(new Element(url, value)); } return value; } }
From source file:org.ambraproject.struts2.TransactionInterceptor.java
public String intercept(final ActionInvocation actionInvocation) throws Exception { final Action action = (Action) actionInvocation.getAction(); final ActionProxy actionProxy = actionInvocation.getProxy(); final String methodName = actionProxy.getMethod(); if (getAnnotation(action.getClass(), methodName, ManualTransactionManagement.class) != null) { //Method is annotated tellling us not to manage a transaction for it log.debug(//from w ww.j av a 2 s . c o m "Not managing transaction for " + action.getClass().getSimpleName() + "." + methodName + "()"); return actionInvocation.invoke(); } if (log.isDebugEnabled()) { log.debug("Intercepted " + action.getClass().getSimpleName() + "." + methodName + "()"); } final Transactional transactionalAnnotation = getAnnotation(action.getClass(), methodName, Transactional.class); TransactionTemplate txTemplate = new TransactionTemplate(transactionManager); if (transactionalAnnotation != null) { txTemplate.setReadOnly(transactionalAnnotation.readOnly()); txTemplate.setTimeout(transactionalAnnotation.timeout()); txTemplate.setIsolationLevel(transactionalAnnotation.isolation().value()); txTemplate.setPropagationBehavior(transactionalAnnotation.propagation().value()); } CallbackResult callbackResult = (CallbackResult) txTemplate.execute(new TransactionCallback() { public CallbackResult doInTransaction(TransactionStatus transactionStatus) { CallbackResult result = new CallbackResult(); try { String actionResult = actionInvocation.invoke(); result.setResult(actionResult); //Rollback for Action responses indicating failure for (String response : new String[] { Action.ERROR, Action.INPUT, Action.LOGIN }) { if (response.equalsIgnoreCase(actionResult) && !transactionStatus.isRollbackOnly()) { log.debug("Rolling back action " + action.getClass().getSimpleName() + " due to result: " + actionResult); transactionStatus.setRollbackOnly(); break; } } } catch (Exception e) { /* * Callback does not throw exception. We need to pass Exception object in the return * parameter so we can throw it in the calling method. */ boolean noRollback = false; if (transactionalAnnotation != null && transactionalAnnotation.noRollbackFor() != null) { for (Class<? extends Throwable> exception : transactionalAnnotation.noRollbackFor()) { if (exception.isInstance(e)) { noRollback = true; break; } } } if (!noRollback && transactionalAnnotation != null && transactionalAnnotation.rollbackFor() != null) { for (Class<? extends Throwable> exception : transactionalAnnotation.rollbackFor()) { if (exception.isInstance(e)) { log.debug("Caught exception, rolling back action invocation " + action.getClass().getSimpleName()); transactionStatus.setRollbackOnly(); break; } } } result.setException(e); } return result; } }); if (callbackResult.getException() != null) throw callbackResult.getException(); return callbackResult.getResult(); }
From source file:it.unibas.spicy.persistence.object.operators.GenerateObjectInstance.java
private boolean objectHasType(TupleNode tupleNodeInSchema, Object object) { try {//from w w w . j a v a 2 s .c o m Class tupleClass = Class.forName(ClassUtility.decodeClassName(tupleNodeInSchema.getLabel())); if (tupleClass.isInstance(object)) { return true; } } catch (Exception ex) { logger.error(ex); return false; } return false; }
From source file:com.thoughtworks.go.config.materials.Materials.java
public int count(Class<? extends Material> materialClass) { int count = 0; for (Material material : this) { if (materialClass.isInstance(material)) { count++;/*w ww.j a v a 2 s. c o m*/ } } return count; }
From source file:io.cloudslang.lang.runtime.steps.ActionSteps.java
protected Object[] resolveActionArguments(Map<String, SerializableSessionObject> serializableSessionData, Method actionMethod, Map<String, Serializable> currentContext, Map<String, Object> nonSerializableExecutionData) { List<Object> args = new ArrayList<>(); int index = 0; Class[] parameterTypes = actionMethod.getParameterTypes(); for (Annotation[] annotations : actionMethod.getParameterAnnotations()) { index++;/*from w ww. j a v a 2s . c o m*/ for (Annotation annotation : annotations) { if (annotation instanceof Param) { if (parameterTypes[index - 1].equals(GlobalSessionObject.class)) { handleNonSerializableSessionContextArgument(nonSerializableExecutionData, args, (Param) annotation); } else if (parameterTypes[index - 1].equals(SerializableSessionObject.class)) { handleSerializableSessionContextArgument(serializableSessionData, args, (Param) annotation); } else { String parameterName = ((Param) annotation).value(); Serializable value = currentContext.get(parameterName); Class parameterClass = parameterTypes[index - 1]; if (parameterClass.isInstance(value) || value == null) { args.add(value); } else { StringBuilder exceptionMessageBuilder = new StringBuilder(); exceptionMessageBuilder.append("Parameter type mismatch for action "); exceptionMessageBuilder.append(actionMethod.getName()); exceptionMessageBuilder.append(" of class "); exceptionMessageBuilder.append(actionMethod.getDeclaringClass().getName()); exceptionMessageBuilder.append(". Parameter "); exceptionMessageBuilder.append(parameterName); exceptionMessageBuilder.append(" expects type "); exceptionMessageBuilder.append(parameterClass.getName()); throw new RuntimeException(exceptionMessageBuilder.toString()); } } } } if (args.size() != index) { throw new RuntimeException("All action arguments should be annotated with @Param"); } } return args.toArray(new Object[args.size()]); }
From source file:haven.Utils.java
public static <C> C hascause(Throwable t, Class<C> c) { while (t != null) { if (c.isInstance(t)) return (c.cast(t)); t = t.getCause();// w ww .ja v a2s .c om } return (null); }