List of usage examples for org.springframework.util Assert isAssignable
public static void isAssignable(Class<?> superType, @Nullable Class<?> subType, Supplier<String> messageSupplier)
From source file:org.socialsignin.spring.data.dynamodb.repository.support.HashKeyIsIdHashKeyExtractor.java
@Override public ID getHashKey(ID id) { Assert.isAssignable(idAndHashKeyType, id.getClass(), "Expected ID type to be the same as the return type of the hash key method ( " + idAndHashKeyType + " ) : "); return id;/*ww w . j a va2s. c om*/ }
From source file:org.brushingbits.jnap.persistence.factory.DaoFactoryPostProcessor.java
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { Assert.isAssignable(DefaultListableBeanFactory.class, registry.getClass(), "The DaoFactoryPostProcessor only works within a DefaultListableBeanFactory capable" + "BeanFactory, your BeanDefinitionRegistry is " + registry.getClass()); final DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) registry; // get already defined beans of type Dao final Set<Class<? extends PersistentModel>> alreadyDefinedDaos = new HashSet<Class<? extends PersistentModel>>(); for (String beanName : beanFactory.getBeanNamesForType(Dao.class, true, false)) { Dao<? extends PersistentModel> dao = beanFactory.getBean(beanName, Dao.class); alreadyDefinedDaos.add(dao.getEntityClass()); }/*from www . ja va 2 s .co m*/ for (String sessionFactoryName : beanFactory.getBeanNamesForType(SessionFactory.class)) { final SessionFactory sessionFactory = beanFactory.getBean(sessionFactoryName, SessionFactory.class); Map<String, ClassMetadata> entitiesMetadata = sessionFactory.getAllClassMetadata(); for (ClassMetadata entityMetadata : entitiesMetadata.values()) { Class<? extends PersistentModel> entityClass = entityMetadata.getMappedClass(EntityMode.POJO); if (entityClass != null && !alreadyDefinedDaos.contains(entityClass)) { String daoName = entityClass.getSimpleName() + "Dao"; daoName = Character.toLowerCase(daoName.charAt(0)) + daoName.substring(1); beanFactory.registerBeanDefinition(daoName, createDaoDefinition(entityClass, sessionFactory)); } } } }
From source file:org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBIdIsHashKeyEntityInformationImpl.java
@Override public Object getHashKey(final ID id) { Assert.isAssignable(getIdType(), id.getClass(), "Expected ID type to be the same as the return type of the hash key method ( " + getIdType() + " ) : "); return hashKeyExtractor.getHashKey(id); }
From source file:org.jnap.core.persistence.factory.DaoFactoryBkp.java
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { Assert.isAssignable(DefaultListableBeanFactory.class, registry.getClass(), "The DaoFactory only works within a DefaultListableBeanFactory capable" + "BeanFactory, your BeanDefinitionRegistry is " + registry.getClass()); final DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) registry; // Initialize all SessionFactory beans String[] factoryNames = beanFactory.getBeanNamesForType(EntityManagerFactory.class); Set<EntityManagerFactory> factories = new HashSet<EntityManagerFactory>(factoryNames.length); for (String factoryName : factoryNames) { factories.add(beanFactory.getBean(factoryName, EntityManagerFactory.class)); }//from w ww. java 2 s .c o m for (EntityManagerFactory factory : factories) { factory.getMetamodel().getEntities(); for (EntityType<?> entityMetadata : factory.getMetamodel().getEntities()) { Class<? extends PersistentModel> entityClass = (Class<? extends PersistentModel>) entityMetadata .getJavaType(); if (entityClass != null && !isDaoDefinedForEntity(beanFactory, entityClass)) { String daoName = buildDaoName(entityClass); beanFactory.registerBeanDefinition(daoName, createDaoDefinition(entityClass, factory)); daoNameCache.put(entityClass, daoName); } } } factories.clear(); factories = null; }
From source file:de.drv.dsrv.extra.marshaller.impl.ExtraUnmarschaller.java
@Override public <X> X unmarshal(final Source source, final Class<X> extraTransportClass, final boolean validation) throws XmlMappingException, IOException { Assert.notNull(source, "StreamSource is null"); Assert.notNull(extraTransportClass, "ExtraTransportClass is null"); final Unmarshaller unmarshaller = findUnmarschaller(validation); final Object responseObject = unmarshaller.unmarshal(source); logger.debug("ResponseObject Class: {}", responseObject.getClass()); Assert.notNull(responseObject, "Response is null"); X extraTransport = null;// w w w. j ava 2 s. co m if (ResponseTransport.class.isAssignableFrom(responseObject.getClass())) { extraTransport = extraTransportClass.cast(responseObject); } else if (JAXBElement.class.isAssignableFrom(responseObject.getClass())) { // TODO Wie funktioniert es besser? @SuppressWarnings("rawtypes") final JAXBElement jaxbElementResponse = JAXBElement.class.cast(responseObject); final Object jaxBElementValue = jaxbElementResponse.getValue(); Assert.isAssignable(extraTransportClass, jaxBElementValue.getClass(), "JaxBElement.value can not be converted to the response.ResponseTransport"); extraTransport = extraTransportClass.cast(jaxBElementValue); } else { throw new IllegalArgumentException( "Response can not be converted to the response.ResponseTransport. ResponseObjectClass: " + responseObject.getClass()); } return extraTransport; }
From source file:org.opennms.ng.dao.support.DefaultRrdDao.java
/** * <p>getPrintValues</p>/*from w w w . j a v a2 s.c o m*/ * * @param attribute a {@link org.opennms.netmgt.model.OnmsAttribute} object. * @param rraConsolidationFunction a {@link String} object. * @param startTimeInMillis a long. * @param endTimeInMillis a long. * @param printFunctions a {@link String} object. * @return an array of double. */ @Override public double[] getPrintValues(OnmsAttribute attribute, String rraConsolidationFunction, long startTimeInMillis, long endTimeInMillis, String... printFunctions) { Assert.notNull(attribute, "attribute argument must not be null"); Assert.notNull(rraConsolidationFunction, "rraConsolicationFunction argument must not be null"); Assert.isTrue(endTimeInMillis > startTimeInMillis, "end argument must be after start argument"); Assert.isAssignable(attribute.getClass(), RrdGraphAttribute.class, "attribute argument must be assignable to RrdGraphAttribute"); // if no printFunctions are given just use the rraConsolidationFunction if (printFunctions.length < 1) { printFunctions = new String[] { rraConsolidationFunction }; } RrdGraphAttribute rrdAttribute = (RrdGraphAttribute) attribute; String[] command = new String[] { m_rrdBinaryPath, "graph", "-", "--start=" + (startTimeInMillis / 1000), "--end=" + (endTimeInMillis / 1000), "DEF:ds=" + RrdFileConstants.escapeForGraphing(rrdAttribute.getRrdRelativePath()) + ":" + attribute.getName() + ":" + rraConsolidationFunction, }; String[] printDefs = new String[printFunctions.length]; for (int i = 0; i < printFunctions.length; i++) { printDefs[i] = "PRINT:ds:" + printFunctions[i] + ":\"%le\""; } String commandString = StringUtils.arrayToDelimitedString(command, " ") + ' ' + StringUtils.arrayToDelimitedString(printDefs, " "); LOG.debug("commandString: {}", commandString); RrdGraphDetails graphDetails; try { graphDetails = m_rrdStrategy.createGraphReturnDetails(commandString, m_rrdBaseDirectory); } catch (Throwable e) { throw new DataAccessResourceFailureException( "Failure when generating graph to get data with command '" + commandString + "'", e); } String[] printLines; try { printLines = graphDetails.getPrintLines(); } catch (Throwable e) { throw new DataAccessResourceFailureException( "Failure to get print lines from graph after graphing with command '" + commandString + "'", e); } if (printLines.length != printFunctions.length) { throw new DataAccessResourceFailureException("Returned number of print lines should be " + printFunctions.length + ", but was " + printLines.length + " from command: " + commandString); } double[] values = new double[printLines.length]; for (int i = 0; i < printLines.length; i++) { if (printLines[i].endsWith("nan")) { values[i] = Double.NaN; } else { try { values[i] = Double.parseDouble(printLines[i]); } catch (NumberFormatException e) { throw new DataAccessResourceFailureException("Value of line " + (i + 1) + " of output from RRD is not a valid floating point number: '" + printLines[i] + "'"); } } } return values; }
From source file:org.jnap.core.persistence.factory.DaoFactory.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { Assert.isAssignable(DefaultListableBeanFactory.class, beanFactory.getClass(), "The DaoFactory only works within a DefaultListableBeanFactory capable " + "BeanFactory. Your BeanFactory is " + beanFactory.getClass()); this.beanFactory = beanFactory; final DefaultListableBeanFactory listableBeanFactory = (DefaultListableBeanFactory) beanFactory; String[] factoryNames = beanFactory.getBeanNamesForType(EntityManagerFactory.class); Set<EntityManagerFactory> factories = new HashSet<EntityManagerFactory>(factoryNames.length); for (String factoryName : factoryNames) { factories.add(beanFactory.getBean(factoryName, EntityManagerFactory.class)); }/*from w w w.j a va 2 s . co m*/ for (EntityManagerFactory factory : factories) { factory.getMetamodel().getEntities(); for (EntityType<?> entityMetadata : factory.getMetamodel().getEntities()) { Class<? extends PersistentModel> entityClass = (Class<? extends PersistentModel>) entityMetadata .getJavaType(); if (entityClass != null && !isDaoDefinedForEntity(beanFactory, entityClass)) { String daoName = buildDaoName(entityClass); listableBeanFactory.registerBeanDefinition(daoName, createDaoDefinition(entityClass, factory)); daoNameCache.put(entityClass, daoName); } } } factories.clear(); factories = null; }
From source file:org.mybatis.spring.ext.core.annotation.AnnotationAttributes.java
@SuppressWarnings("unchecked") private <T> T doGet(String attributeName, Class<T> expectedType) { Assert.hasText(attributeName, "attributeName must not be null or empty"); Object value = this.get(attributeName); Assert.notNull(value, format("Attribute '%s' not found", attributeName)); Assert.isAssignable(expectedType, value.getClass(), format("Attribute '%s' is of type [%s], but [%s] was expected. Cause: ", attributeName, value.getClass().getSimpleName(), expectedType.getSimpleName())); return (T) value; }
From source file:com.stehno.sjdbcx.reflection.ReflectionImplementationProvider.java
private Operation buildCustomOperation(final Method method, final String sql, final OperationContext operationContext, final Implemented implAnno) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Class<? extends Operation> operationClass; if (StringUtils.hasText(implAnno.value())) { operationClass = (Class<? extends Operation>) Class.forName(implAnno.value()); } else {//from ww w .jav a 2 s . c o m operationClass = implAnno.type(); } Assert.isAssignable(AbstractOperation.class, operationClass, INVALID_EXTEND_MSG); final boolean isNamed = NamedOperation.class.isAssignableFrom(operationClass); final boolean isIndexed = IndexedOperation.class.isAssignableFrom(operationClass); Assert.isTrue(isNamed || isIndexed, MUST_IMPLEMENT_MSG); Assert.isTrue(!(isNamed && isIndexed), ONLY_ONE_MSG); return operationClass.getConstructor(Method.class, String.class, OperationContext.class).newInstance(method, sql, operationContext); }