public boolean runWithEntity(IEntity<?> entity) { super.beforeRun(); boolean result = false; /* Verifica se a entidade é compatível */ /* Verifica se a entidade passada eh um DocumentoCobranca ou pertence eh descendente */ if (ClassUtils.isAssignable(entity.getInfo().getType(), Contrato.class)) { Contrato oContrato = (Contrato) entity.getObject(); this.cpfCnpj = oContrato.getPessoa().getDocumento(); /* Alguns dados poderao ser inicializados aqui */ this.categoriaContratoId = IDAO.ENTITY_UNSAVED; /* Define as datas de vencimento e recebimento amplas */ Calendar dataInicial = CalendarUtils.getCalendar(1900, Calendar.JANUARY, 1); Calendar dataAtual = CalendarUtils.getCalendar(); this.dataVencimentoInicial = (Calendar) dataInicial.clone(); this.dataVencimentoFinal = (Calendar) dataAtual.clone(); this.dataRecebimentoInicial = (Calendar) dataInicial.clone(); this.dataRecebimentoFinal = (Calendar) dataAtual.clone(); /* Não executa nada, pois o processo gera um PDF e é importante * que o operador defina as propriedades do relatório antes de gerar o PDF */ result = true; } else if (ClassUtils.isAssignable(entity.getInfo().getType(), Pessoa.class)) { Pessoa oPessoa = (Pessoa) entity.getObject(); this.cpfCnpj = oPessoa.getDocumento(); /* Alguns dados poderao ser inicializados aqui */ this.categoriaContratoId = IDAO.ENTITY_UNSAVED; /* Define as datas de vencimento e recebimento amplas */ Calendar dataInicial = CalendarUtils.getCalendar(1900, Calendar.JANUARY, 1); Calendar dataAtual = CalendarUtils.getCalendar(); this.dataVencimentoInicial = (Calendar) dataInicial.clone(); this.dataVencimentoFinal = (Calendar) dataAtual.clone(); this.dataRecebimentoInicial = (Calendar) dataInicial.clone(); this.dataRecebimentoFinal = (Calendar) dataAtual.clone(); /* Não executa nada, pois o processo gera um PDF e é importante * que o operador defina as propriedades do relatório antes de gerar o PDF */ result = true; } else { this.getMessageList() .add( new BusinessMessage( IRunnableEntityProcess.class, "ENTITY_NOT_COMPATIBLE", PROCESS_NAME, entity.getInfo().getType().getName())); } return result; }
private static boolean shouldKeep( Class type, Object extension, @Nullable Project project, @Nullable ExtensionMatcher matcher) { boolean keep = (ClassUtils.isAssignable(extension.getClass(), type) || (org.sonar.api.batch.Sensor.class.equals(type) && ClassUtils.isAssignable(extension.getClass(), Sensor.class))) && (matcher == null || matcher.accept(extension)); if (keep && project != null && ClassUtils.isAssignable(extension.getClass(), CheckProject.class)) { keep = ((CheckProject) extension).shouldExecuteOnProject(project); } return keep; }
public static <T> T create(String pClassName, Class<T> pClass) throws IllegalAccessException, InstantiationException, ClassNotFoundException { final Object o = create(pClassName); if (ClassUtils.isAssignable(o.getClass(), pClass)) { return (T) o; } else { throw new InstantiationException("Not of type: " + pClass.getName()); } }
/** * Find an accessible method that matches the given name and has compatible parameters. Compatible * parameters mean that every method parameter is assignable from the given parameters. In other * words, it finds a method with the given name that will take the parameters given. * * <p> * * <p>This method is used by {@link #invokeMethod(Object object, String methodName, Object[] args, * Class[] parameterTypes)}. * * <p>This method can match primitive parameter by passing in wrapper classes. For example, a * <code>Boolean</code> will match a primitive <code>boolean</code> parameter. * * @param cls find method in this class * @param methodName find method with this name * @param parameterTypes find method with most compatible parameters * @return The accessible method */ public static Method getMatchingAccessibleMethod( Class cls, String methodName, Class[] parameterTypes) { try { Method method = cls.getMethod(methodName, parameterTypes); MemberUtils.setAccessibleWorkaround(method); return method; } catch (NoSuchMethodException e) { /* SWALLOW */ } // search through all methods Method bestMatch = null; Method[] methods = cls.getMethods(); for (int i = 0, size = methods.length; i < size; i++) { if (methods[i].getName().equals(methodName)) { // compare parameters if (ClassUtils.isAssignable(parameterTypes, methods[i].getParameterTypes(), true)) { // get accessible version of method Method accessibleMethod = getAccessibleMethod(methods[i]); if (accessibleMethod != null) { if (bestMatch == null || MemberUtils.compareParameterTypes( accessibleMethod.getParameterTypes(), bestMatch.getParameterTypes(), parameterTypes) < 0) { bestMatch = accessibleMethod; } } } } } if (bestMatch != null) { MemberUtils.setAccessibleWorkaround(bestMatch); } return bestMatch; }