List of usage examples for org.springframework.util Assert isTrue
public static void isTrue(boolean expression, Supplier<String> messageSupplier)
From source file:cat.albirar.framework.proxy.ProxyFactory.java
/** * Create a proxy for the indicated type. * @param handler The handler// w ww. ja va 2 s . com * @param type The type, should to be a concrete class type * @return The proxy */ @SuppressWarnings("unchecked") private <T> T newProxyForConcreteClass(org.springframework.cglib.proxy.Callback handler, Class<T> type) { Enhancer enhancer; Assert.isTrue(!Modifier.isAbstract(type.getModifiers()), "The type should to be a concrete class"); enhancer = new Enhancer(); enhancer.setSuperclass(type); enhancer.setClassLoader(type.getClassLoader()); enhancer.setCallback(handler); return (T) enhancer.create(); }
From source file:org.spring.data.gemfire.AbstractGemFireIntegrationTest.java
protected static ServerLauncher startGemFireServer(final long waitTimeout, final String cacheXmlPathname, final Properties gemfireProperties) throws IOException { String gemfireMemberName = gemfireProperties.getProperty(DistributionConfig.NAME_NAME); String serverId = DATE_FORMAT.format(Calendar.getInstance().getTime()); gemfireMemberName = String.format("%1$s-%2$s", (StringUtils.hasText(gemfireMemberName) ? gemfireMemberName : ""), serverId); File serverWorkingDirectory = FileSystemUtils.createFile(gemfireMemberName.toLowerCase()); Assert.isTrue(FileSystemUtils.createDirectory(serverWorkingDirectory), String.format("Failed to create working directory (%1$s) in which the GemFire Server will run!", serverWorkingDirectory)); ServerLauncher serverLauncher = buildServerLauncher(cacheXmlPathname, gemfireProperties, serverId, DEFAULT_SERVER_PORT, serverWorkingDirectory); List<String> serverCommandLine = buildServerCommandLine(serverLauncher); System.out.printf("Starting GemFire Server in (%1$s)...%n", serverWorkingDirectory); Process serverProcess = ProcessUtils.startProcess( serverCommandLine.toArray(new String[serverCommandLine.size()]), serverWorkingDirectory); readProcessStream(serverId, "ERROR", serverProcess.getErrorStream()); readProcessStream(serverId, "OUT", serverProcess.getInputStream()); waitOnServer(waitTimeout, serverProcess, serverWorkingDirectory); return serverLauncher; }
From source file:team.curise.dao.BaseDao.java
/** * hqlselect ??union,pagedQuery./* w ww .j a v a 2 s .co m*/ * @see #pagedQuery(String,int,int,Object[]) * @param hql * @return */ public static String removeSelect(String hql) { Assert.hasText(hql); int beginPos = hql.toLowerCase().indexOf("from"); Assert.isTrue(beginPos != -1, " hql : " + hql + " must has a keyword 'from'"); return hql.substring(beginPos); }
From source file:br.com.flucianofeijao.security.JsfLoginUrlAuthenticationEntryPoint.java
public void afterPropertiesSet() throws Exception { Assert.isTrue(StringUtils.hasText(loginFormUrl) && UrlUtils.isValidRedirectUrl(loginFormUrl), "loginFormUrl must be specified and must be a valid redirect URL"); if (useForward && UrlUtils.isAbsoluteUrl(loginFormUrl)) { throw new IllegalArgumentException("useForward must be false if using an absolute loginFormURL"); }/*from www .j a v a2s .c o m*/ Assert.notNull(portMapper, "portMapper must be specified"); Assert.notNull(portResolver, "portResolver must be specified"); }
From source file:br.com.lucasisrael.regra.reflections.TratamentoReflections.java
/** * Attempt to find a {@link Field field} on the supplied {@link Class} with the * supplied {@code name} and/or {@link Class type}. Searches all superclasses * up to {@link Object}.//from w ww.j av a 2s.c o m * @param clazz the class to introspect * @param name the name of the field (may be {@code null} if type is specified) * @param type the type of the field (may be {@code null} if name is specified) * @return the corresponding Field object, or {@code null} if not found */ public static Field findField(Class<?> clazz, String name, Class<?> type) { Assert.notNull(clazz, "Class must not be null"); Assert.isTrue(name != null || type != null, "Either name or type of the field must be specified"); Class<?> searchType = clazz; while (!Object.class.equals(searchType) && searchType != null) { Field[] fields = searchType.getDeclaredFields(); for (Field field : fields) { if ((name == null || name.equals(field.getName())) && (type == null || type.equals(field.getType()))) { return field; } } searchType = searchType.getSuperclass(); } return null; }
From source file:br.com.gerenciapessoal.security.JsfLoginUrlAuthenticationEntryPoint.java
@Override public void afterPropertiesSet() throws Exception { Assert.isTrue(StringUtils.hasText(loginFormUrl) && UrlUtils.isValidRedirectUrl(loginFormUrl), "loginFormUrl must be specified and must be a valid redirect URL"); if (useForward && UrlUtils.isAbsoluteUrl(loginFormUrl)) { throw new IllegalArgumentException("useForward must be false if using an absolute loginFormURL"); }//w ww. jav a 2 s .c o m Assert.notNull(portMapper, "portMapper must be specified"); Assert.notNull(portResolver, "portResolver must be specified"); }
From source file:com.athena.peacock.common.core.action.ConfigAction.java
@Override public String perform() { Assert.notNull(fileName, "filename cannot be null."); Assert.notNull(properties, "properties cannot be null."); File file = new File(fileName); Assert.isTrue(file.exists(), fileName + " does not exist."); Assert.isTrue(file.isFile(), fileName + " is not a file."); logger.debug("[{}] file's configuration will be changed.", fileName); try {/* w w w . j a v a 2 s .com*/ String fileContents = IOUtils.toString(file.toURI()); for (Property property : properties) { logger.debug("\"${{}}\" will be changed to \"{}\".", property.getKey(), property.getValue().replaceAll("\\\\", "")); fileContents = fileContents.replaceAll("\\$\\{" + property.getKey() + "\\}", property.getValue()); } FileOutputStream fos = new FileOutputStream(file); IOUtils.write(fileContents, fos); IOUtils.closeQuietly(fos); } catch (IOException e) { logger.error("IOException has occurred.", e); } return null; }
From source file:com.nestorledon.employeedirectory.rest.Resource.java
public Resource(T content, Iterable<Link> links, Page page) { Assert.notNull(content, "Content must not be null!"); Assert.isTrue(!(content instanceof Collection), "Content must not be a collection! Use Resources instead!"); this.content = content; this.add(links); this.page = page; }
From source file:com.azaptree.services.security.commands.subjectRepository.DeleteSubjectCredential.java
public DeleteSubjectCredential() { setValidator(new CommandContextValidatorSupport() { @Override/*w w w . j a v a 2s. c o m*/ protected void checkInput(final Command command, final Context ctx) { final UUID subjectId = get(ctx, SUBJECT_ID); if (!subjectDAO.exists(subjectId)) { throw new UnknownSubjectException(subjectId.toString()); } final UUID updatedBySubjectId = get(ctx, UPDATED_BY_SUBJECT_ID); if (updatedBySubjectId != null) { Assert.isTrue(!subjectId.equals(updatedBySubjectId), String.format( "The updatedBy subject (%s) cannot be the same as the subject (%s) which we are adding the credential to", subjectId, updatedBySubjectId)); if (!subjectDAO.exists(updatedBySubjectId)) { throw new UnknownSubjectException( String.format("Subject for updatedBy does not exist: %s", updatedBySubjectId)); } } } @Override protected void checkOutput(final Command command, final Context ctx) { // none required } }); setInputKeys(SUBJECT_ID, CREDENTIAL_NAME, UPDATED_BY_SUBJECT_ID); }
From source file:org.activiti.spring.components.aop.util.MetaAnnotationMatchingPointcut.java
/** * Create a new MetaAnnotationMatchingPointcut for the given annotation type. * * @param classAnnotationType the annotation type to look for at the class level * (can be <code>null</code>) * @param methodAnnotationType the annotation type to look for at the method level * (can be <code>null</code>) *///from w w w . ja v a 2 s . c om public MetaAnnotationMatchingPointcut(Class<? extends Annotation> classAnnotationType, Class<? extends Annotation> methodAnnotationType) { Assert.isTrue((classAnnotationType != null || methodAnnotationType != null), "Either Class annotation type or Method annotation type needs to be specified (or both)"); if (classAnnotationType != null) { this.classFilter = new AnnotationClassFilter(classAnnotationType); } else { this.classFilter = ClassFilter.TRUE; } if (methodAnnotationType != null) { this.methodMatcher = new MetaAnnotationMethodMatcher(methodAnnotationType); } else { this.methodMatcher = MethodMatcher.TRUE; } }