Example usage for org.springframework.util Assert isNull

List of usage examples for org.springframework.util Assert isNull

Introduction

In this page you can find the example usage for org.springframework.util Assert isNull.

Prototype

public static void isNull(@Nullable Object object, Supplier<String> messageSupplier) 

Source Link

Document

Assert that an object is null .

Usage

From source file:grails.plugin.springsecurity.authentication.encoding.BCryptPasswordEncoder.java

protected void checkSalt(Object salt) {
    Assert.isNull(salt, "Salt value must be null when used with crypto module PasswordEncoder");
}

From source file:fr.mby.opa.picsimpl.dao.DbAlbumDao.java

@Override
public Album createAlbum(final Album album) {
    Assert.notNull(album, "No Album supplied !");
    Assert.isNull(album.getId(), "Id should not be set for creation !");
    Assert.hasText(album.getName(), "No Album name supplied !");

    new TxCallback(this.getEmf()) {

        @Override/*from w  w  w.  j  ava2  s .  c o m*/
        protected void executeInTransaction(final EntityManager em) {
            final Timestamp creationTime = new Timestamp(System.currentTimeMillis());

            // Persist album
            album.setCreationTime(creationTime);
            album.setLocked(false);
            em.persist(album);

            // Create initial bag
            final ProposalBag initialBag = new ProposalBag();
            initialBag.setCommited(false);
            initialBag.setCreationTime(creationTime);
            initialBag.setName(IProposalDao.INITIAL_PROPOSAL_NAME);
            initialBag.setRevision("0");
            em.persist(initialBag);

            // Create master branch
            final ProposalBranch masterBranch = new ProposalBranch();
            masterBranch.setAlbum(album);
            masterBranch.setCreationTime(creationTime);
            masterBranch.setName(IProposalDao.MASTER_BRANCH_NAME);
            masterBranch.setHead(initialBag);
            final List<ProposalBag> bagList = new ArrayList<>();
            bagList.add(initialBag);
            masterBranch.setBags(bagList);
            em.persist(masterBranch);
        }
    };

    return album;
}

From source file:fr.mby.opa.picsimpl.dao.DbPictureDao.java

@Override
public Picture createPicture(final Picture picture, final Album album) throws PictureAlreadyExistsException {
    Assert.notNull(picture, "No Picture supplied !");
    Assert.notNull(album, "No Album supplied !");
    Assert.isNull(picture.getId(), "Id should not be set for creation !");

    picture.setAlbum(album);// w  w  w  .ja  v  a2  s  .  c  o  m

    new TxCallback(this.getEmf()) {

        @Override
        protected void executeInTransaction(final EntityManager em) {
            DbPictureDao.this.testHashUniqueness(picture, em);
            em.persist(picture);
        }
    };

    return picture;
}

From source file:fr.mby.opa.picsimpl.dao.DbProposalDao.java

@Override
public ProposalBranch createBranch(final ProposalBranch branch) {
    Assert.notNull(branch, "No ProposalBag supplied !");
    Assert.isNull(branch.getId(), "Id should not be set for creation !");

    new TxCallback(this.getEmf()) {

        @Override/* w  w  w. j a  v a 2s  . c  o  m*/
        protected void executeInTransaction(final EntityManager em) {
            em.persist(branch);
        }
    };

    return branch;
}

From source file:org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBHashAndRangeKeyMethodExtractorImpl.java

/**
 * Creates a new {@link DynamoDBHashAndRangeKeyMethodExtractor} for the given domain type.
 *
 * @param idType//ww  w.  j a v a2  s  .  co m
 *            must not be {@literal null}.
 */
public DynamoDBHashAndRangeKeyMethodExtractorImpl(final Class<T> idType) {

    Assert.notNull(idType, "Id type must not be null!");
    this.idType = idType;
    ReflectionUtils.doWithMethods(idType, new MethodCallback() {
        @Override
        public void doWith(Method method) {
            if (method.getAnnotation(DynamoDBHashKey.class) != null) {
                Assert.isNull(hashKeyMethod,
                        "Multiple methods annotated by @DynamoDBHashKey within type " + idType.getName() + "!");
                ReflectionUtils.makeAccessible(method);
                hashKeyMethod = method;
            }
        }
    });
    ReflectionUtils.doWithFields(idType, new FieldCallback() {
        @Override
        public void doWith(Field field) {
            if (field.getAnnotation(DynamoDBHashKey.class) != null) {
                Assert.isNull(hashKeyField,
                        "Multiple fields annotated by @DynamoDBHashKey within type " + idType.getName() + "!");
                ReflectionUtils.makeAccessible(field);

                hashKeyField = field;
            }
        }
    });
    ReflectionUtils.doWithMethods(idType, new MethodCallback() {
        @Override
        public void doWith(Method method) {
            if (method.getAnnotation(DynamoDBRangeKey.class) != null) {
                Assert.isNull(rangeKeyMethod, "Multiple methods annotated by @DynamoDBRangeKey within type "
                        + idType.getName() + "!");
                ReflectionUtils.makeAccessible(method);
                rangeKeyMethod = method;
            }
        }
    });
    ReflectionUtils.doWithFields(idType, new FieldCallback() {
        @Override
        public void doWith(Field field) {
            if (field.getAnnotation(DynamoDBRangeKey.class) != null) {
                Assert.isNull(rangeKeyField,
                        "Multiple fields annotated by @DynamoDBRangeKey within type " + idType.getName() + "!");
                ReflectionUtils.makeAccessible(field);
                rangeKeyField = field;
            }
        }
    });
    if (hashKeyMethod == null && hashKeyField == null) {
        throw new IllegalArgumentException(
                "No method or field annotated by @DynamoDBHashKey within type " + idType.getName() + "!");
    }
    if (rangeKeyMethod == null && rangeKeyField == null) {
        throw new IllegalArgumentException(
                "No method or field annotated by @DynamoDBRangeKey within type " + idType.getName() + "!");
    }
    if (hashKeyMethod != null && hashKeyField != null) {
        throw new IllegalArgumentException(
                "Both method and field annotated by @DynamoDBHashKey within type " + idType.getName() + "!");
    }
    if (rangeKeyMethod != null && rangeKeyField != null) {
        throw new IllegalArgumentException(
                "Both method and field annotated by @DynamoDBRangeKey within type " + idType.getName() + "!");
    }
}

From source file:fr.mby.saml2.sp.impl.config.WayfConfig.java

/**
 * IdPs configuration ordered list.//from w w  w  .j a  va 2s.c  o  m
 * 
 * @param idpConfigs IdPs configuration ordered list
 */
public void setConfig(final List<IIdpConfig> idpConfigs) {
    Assert.notEmpty(idpConfigs, "IdP config ordered list is empty !");
    this.idpConfigsList = idpConfigs;
    this.idpConfigs = new HashMap<String, IIdpConfig>();
    for (IIdpConfig config : idpConfigs) {
        IIdpConfig previous = this.idpConfigs.put(config.getId(), config);
        Assert.isNull(previous, String.format("Two IdP configs owned the same unique Id: [%s] !", previous));
        config.registerWayfConfig(this);
    }
}

From source file:com.kurento.kmf.spring.KurentoApplicationContextUtils.java

/**
 * This class returns the Spring KurentoApplicationContext, which is the
 * parent context for all specific Kurento Servlet contexts. In case a
 * pre-exiting Spring root WebApplicationContext if found, the returned
 * KurentoApplicationContext will be made child of this root context. When
 * necessary, this method creates the KurentoApplicationContext, so it
 * should never return null.// w  w w.  ja  v a 2 s. c  o m
 * 
 * This method MUST NOT be called in ServletContextListeners, given that at
 * that stage there might not be information about the presence of a root
 * Spring root WebApplicationConext.
 * 
 * @param ctx
 * @return
 * 
 */
public static AnnotationConfigApplicationContext createKurentoApplicationContext(ServletContext ctx) {
    Assert.notNull(ctx, "Cannot recover KurentoApplicationContext from a null ServletContext");
    Assert.isNull(kurentoApplicationContextInternalReference,
            "Pre-existing Kurento ApplicationContext found. Cannot create a new instance.");

    kurentoApplicationContextInternalReference = new AnnotationConfigApplicationContext();

    // Add or remove packages when required
    kurentoApplicationContextInternalReference.scan("com.kurento.kmf");

    // Recover root WebApplicationContext context just in case
    // application developer is using Spring
    WebApplicationContext rootContext = WebApplicationContextUtils.getWebApplicationContext(ctx);
    if (rootContext != null) {
        kurentoApplicationContextInternalReference.setParent(rootContext);
    }

    final String jbossServerConfigDir = System.getProperty("jboss.server.config.dir");
    final String kurentoPropertiesDir = System.getProperty("kurento.properties.dir");
    final String kurentoProperties = "/kurento.properties";
    InputStream inputStream = null;
    try {
        if (jbossServerConfigDir != null && new File(jbossServerConfigDir + kurentoProperties).exists()) {
            // First, look for JVM argument "jboss.server.config.dir"
            inputStream = new FileInputStream(jbossServerConfigDir + kurentoProperties);
            log.info("Found custom properties in 'jboss.server.config.dir': " + jbossServerConfigDir);
        } else if (kurentoPropertiesDir != null
                && new File(kurentoPropertiesDir + kurentoProperties).exists()) {
            // Second, look for JVM argument "kurento.properties.dir"
            log.info("Found custom properties in 'kurento.properties.dir': " + kurentoPropertiesDir);
            inputStream = new FileInputStream(kurentoPropertiesDir + kurentoProperties);
        } else {
            // Third, look for properties in Servlet Context
            ServletContextResource servletContextResource = new ServletContextResource(ctx,
                    "/WEB-INF" + kurentoProperties);
            if (servletContextResource.exists()) {
                log.info("Found custom properties in Servlet Context: /WEB-INF" + kurentoProperties);
                inputStream = servletContextResource.getInputStream();
            }
        }

        if (inputStream != null) {
            Properties properties = new Properties();
            properties.load(inputStream);
            PropertyOverrideConfigurer propertyOverrideConfigurer = new PropertyOverrideConfigurer();
            propertyOverrideConfigurer.setProperties(properties);
            kurentoApplicationContextInternalReference.addBeanFactoryPostProcessor(propertyOverrideConfigurer);
            inputStream.close();
        }

    } catch (IOException e) {
        log.error("Exception loading custom properties", e);
        throw new RuntimeException(e);
    }

    kurentoApplicationContextInternalReference.refresh();
    return kurentoApplicationContextInternalReference;
}

From source file:de.coderebell.failsafeactuator.service.CircuitBreakerRegistry.java

/**
 * Will put the {@link CircuitBreaker} into the registry. There is no check which avoids overwriting
 * of identifiers. Therefore be sure that your identifiers are unique, or you want to overwrite the
 * current {@link CircuitBreaker} which is registered with this identifier.
 *
 * @param breaker Which should be added/*from  w w w.jav  a2  s.  c om*/
 * @param name    Which is used to identify the CircuitBreaker
 */
void registerCircuitBreaker(final CircuitBreaker breaker, final String name) {
    Assert.hasText(name, "Name for circuitbreaker needs to be set");
    Assert.notNull(breaker, "Circuitbreaker to add, can't be null");

    CircuitBreaker replaced = concurrentBreakerMap.put(name, breaker);
    Assert.isNull(replaced, "There was an Circuit-Breaker registered already with name : " + name);
}

From source file:org.sakaiproject.metaobj.utils.mvc.impl.servlet.ServletRequestBeanDataBinder.java

/**
* Initialize standard JavaBean property access for this DataBinder.
* <p>This is the default; an explicit call just leads to eager initialization.
* @see #initDirectFieldAccess()//from  w w w .j  a va 2  s . c o  m
 * */
public void initBeanPropertyAccess() {
    Assert.isNull(this.bindingResult,
            "DataBinder is already initialized - call initBeanPropertyAccess before any other configuration methods");
    this.bindingResult = new CustomBeanPropertyBindingResult(getTarget(), getObjectName());
}

From source file:cz.jirutka.spring.http.client.cache.CachingHttpRequestInterceptorBuilder.java

/**
 * Use and configure the default in-memory cache.
 * This cannot be used along with {@link #cache(Cache)}.
 *//*from  w  w  w  .ja  va2 s .c o  m*/
public InMemoryCacheBuilder inMemoryCache() {
    Assert.isNull(cache, "You cannot use both custom cache and built-in inMemoryCache");

    return new InMemoryCacheBuilder();
}