List of usage examples for org.springframework.util Assert notNull
public static void notNull(@Nullable Object object, Supplier<String> messageSupplier)
From source file:com.athena.peacock.agent.Starter.java
/** * <pre>//from w w w. j a va 2 s. c om * * </pre> * @param args */ @SuppressWarnings("resource") public static void main(String[] args) { int rand = (int) (Math.random() * 100) % 50; System.setProperty("random.seconds", Integer.toString(rand)); String configFile = null; try { configFile = PropertyUtil.getProperty(PeacockConstant.CONFIG_FILE_KEY); } catch (Exception e) { // nothing to do. } finally { if (StringUtils.isEmpty(configFile)) { configFile = "/peacock/agent/config/agent.conf"; } } /** * ${peacock.agent.config.file.name} ?? load ? ?? ? ? ? . */ String errorMsg = "\n\"" + configFile + "\" file does not exist or cannot read.\n" + "Please check \"" + configFile + "\" file exists and can read."; Assert.isTrue(AgentConfigUtil.exception == null, errorMsg); Assert.notNull(AgentConfigUtil.getConfig(PeacockConstant.SERVER_IP), "ServerIP cannot be empty."); Assert.notNull(AgentConfigUtil.getConfig(PeacockConstant.SERVER_PORT), "ServerPort cannot be empty."); /** * Agent ID ?? ${peacock.agent.agent.file.name} ? ?, * ?? ? Agent ID ? ?? . */ String agentFile = null; String agentId = null; try { agentFile = PropertyUtil.getProperty(PeacockConstant.AGENT_ID_FILE_KEY); } catch (Exception e) { // nothing to do. } finally { if (StringUtils.isEmpty(agentFile)) { agentFile = "/peacock/agent/.agent"; } } File file = new File(agentFile); boolean isNew = false; if (file.exists()) { try { agentId = IOUtils.toString(file.toURI()); // ? ? agent ID agent ID? ? 36? ? ?. if (StringUtils.isEmpty(agentId) || agentId.length() != 36) { throw new IOException(); } } catch (IOException e) { logger.error(agentFile + " file cannot read or saved invalid agent ID.", e); agentId = PeacockAgentIDGenerator.generateId(); isNew = true; } } else { agentId = PeacockAgentIDGenerator.generateId(); isNew = true; } if (isNew) { logger.info("New Agent-ID({}) be generated.", agentId); try { file.setWritable(true); OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(file)); output.write(agentId); file.setReadOnly(); IOUtils.closeQuietly(output); } catch (UnsupportedEncodingException e) { logger.error("UnsupportedEncodingException has occurred : ", e); } catch (FileNotFoundException e) { logger.error("FileNotFoundException has occurred : ", e); } catch (IOException e) { logger.error("IOException has occurred : ", e); } } // Spring Application Context Loading logger.debug("Starting application context..."); AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext( "classpath:spring/context-*.xml"); applicationContext.registerShutdownHook(); }
From source file:Main.java
/** * Check whether the given element is contained in the given scopes. * * @param element element to checking//from w w w. ja va 2 s .c om * @param scopes scopes to checking element * @param <T> element type * @return checking result. */ public static <T> boolean contains(T element, Collection<T> scopes) { Assert.notNull(element, "Element to checking must not be null."); Assert.notNull(scopes, "Checking scopes must not be null."); return scopes.contains(element); }
From source file:org.obiba.mica.dataset.support.HarmonizedDatasetHelper.java
public static TablesMerger newTablesMerger(List<HarmonizationDataset> datasets) { Assert.notNull(datasets, "Dataset list cannot be null."); return new TablesMerger(datasets); }
From source file:grails.plugin.springevents.ProxyUtils.java
public static Object ultimateTarget(Object candidate) { Assert.notNull(candidate, "Candidate object must not be null"); Object current = candidate;//from w w w. ja va 2 s .c o m while (current instanceof TargetClassAware) { Object nested = null; if (current instanceof Advised) { TargetSource targetSource = ((Advised) current).getTargetSource(); if (targetSource instanceof SingletonTargetSource) { nested = ((SingletonTargetSource) targetSource).getTarget(); } } current = nested; } return current; }
From source file:com.foilen.smalltools.tools.SpringTools.java
public static void configure(Object object) { Assert.notNull(instance, "The SpringConfigurer is not yet inside a Spring container"); instance.beanConfigurerSupport.configureBean(object); }
From source file:com.azaptree.services.command.util.CommandUtils.java
public static <T> T get(final Context ctx, final TypeReferenceKey<T> key) { Assert.notNull(ctx, "ctx is required"); Assert.notNull(key, "key is required"); final T t = (T) ctx.get(key.getName()); return t != null ? t : key.getDefaultValue(); }
From source file:fr.mby.portal.coreimpl.acl.AclHelper.java
public static Set<IRole> buileRoleSet(final IRole... roles) { Assert.notNull(roles, "No roles supplied !"); final Set<IRole> set = new HashSet<IRole>(roles.length); for (final IRole role : roles) { if (role != null) { set.add(role);//from ww w .ja va 2 s. c o m } } return set; }
From source file:Main.java
/** * Check whether the given element is contained in the given scopes. * * @param element element to checking// w ww . j a v a 2 s.c o m * @param scopes scopes to checking element * @param <T> element type * @return checking result. */ public static <T> boolean contains(T element, T... scopes) { Assert.notNull(element, "Element to checking must not be null."); Assert.notNull(scopes, "Checking scopes must not be null."); return Stream.of(scopes).filter(t -> t.equals(element)).findFirst().isPresent(); }
From source file:com.joyveb.dbpimpl.cass.prepare.util.ParsingUtils.java
public static void setPropertyValue(BeanDefinitionBuilder builder, Element element, String attrName, String propertyName) {// w ww . ja v a 2s. c o m Assert.notNull(builder, "BeanDefinitionBuilder must not be null"); Assert.notNull(element, "Element must not be null"); Assert.hasText(attrName, "Attribute name must not be null"); Assert.hasText(propertyName, "Property name must not be null"); String attr = element.getAttribute(attrName); if (StringUtils.hasText(attr)) { builder.addPropertyValue(propertyName, attr); } }
From source file:at.porscheinformatik.common.spring.web.extended.util.ParboiledUtils.java
public static <T> List<T> buildFromResult(ParsingResult<T> result, String resourceDescription) { Assert.notNull(result, "Got null Result while parsing template " + resourceDescription); if (result.hasErrors()) { throw new IllegalArgumentException(buildErrorMessag(result, resourceDescription)); }//from w w w . j a v a 2s . c om Assert.isTrue(result.matched, "Template " + resourceDescription + " does not match the required format "); List<T> parts = new ArrayList<>(result.valueStack.size()); for (T part : result.valueStack) { parts.add(0, part); } return parts; }