本文整理汇总了Java中org.springframework.util.Assert.isAssignable方法的典型用法代码示例。如果您正苦于以下问题:Java Assert.isAssignable方法的具体用法?Java Assert.isAssignable怎么用?Java Assert.isAssignable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.Assert
的用法示例。
在下文中一共展示了Assert.isAssignable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createEditors
import org.springframework.util.Assert; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void createEditors(Properties configuration) {
boolean trace = log.isTraceEnabled();
// load properties using this class class loader
ClassLoader classLoader = getClass().getClassLoader();
for (Map.Entry<Object, Object> entry : configuration.entrySet()) {
// key represents type
Class<?> key;
// value represents property editor
Class<?> editorClass;
try {
key = classLoader.loadClass((String) entry.getKey());
editorClass = classLoader.loadClass((String) entry.getValue());
} catch (ClassNotFoundException ex) {
throw (RuntimeException) new IllegalArgumentException("Cannot load class").initCause(ex);
}
Assert.isAssignable(PropertyEditor.class, editorClass);
if (trace)
log.trace("Adding property editor[" + editorClass + "] for type[" + key + "]");
editors.put(key, (Class<? extends PropertyEditor>) editorClass);
}
}
示例2: getHttpEntityType
import org.springframework.util.Assert; //导入方法依赖的package包/类
private Class<?> getHttpEntityType(MethodParameter methodParam) {
Assert.isAssignable(HttpEntity.class, methodParam.getParameterType());
ParameterizedType type = (ParameterizedType) methodParam.getGenericParameterType();
if (type.getActualTypeArguments().length == 1) {
Type typeArgument = type.getActualTypeArguments()[0];
if (typeArgument instanceof Class) {
return (Class<?>) typeArgument;
}
else if (typeArgument instanceof GenericArrayType) {
Type componentType = ((GenericArrayType) typeArgument).getGenericComponentType();
if (componentType instanceof Class) {
// Surely, there should be a nicer way to do this
Object array = Array.newInstance((Class<?>) componentType, 0);
return array.getClass();
}
}
}
throw new IllegalArgumentException(
"HttpEntity parameter (" + methodParam.getParameterName() + ") is not parameterized");
}
示例3: checkClass
import org.springframework.util.Assert; //导入方法依赖的package包/类
private void checkClass(String attribute)
{
Class<?> targetClass = null;
try {
targetClass = Class.forName(attribute);
} catch (ClassNotFoundException e) {
throw new RuntimeException("not found class:" + attribute);
}
Assert.isAssignable(TemplateContainer.class, targetClass, "this current class is not implement RefreshServiceManagerService!");
}
示例4: checkClass
import org.springframework.util.Assert; //导入方法依赖的package包/类
private void checkClass(String attribute)
{
Class<?> targetClass = null;
try {
targetClass = Class.forName(attribute);
} catch (ClassNotFoundException e) {
throw new RuntimeException("not found class:" + attribute);
}
Assert.isAssignable(DispatchCenterService.class, targetClass, "this current class is not implement JFieldOpt!");
}
开发者ID:yanghao0518,项目名称:cstruct-parser,代码行数:13,代码来源:CjavaDispatchCenterManagerBeanDefinitionParser.java
示例5: checkClass
import org.springframework.util.Assert; //导入方法依赖的package包/类
private void checkClass(String attribute) throws ClassNotFoundException
{
// TODO Auto-generated method stub
Class<?> targetClass = Class.forName(attribute);
Assert.isAssignable(JFieldOpt.class, targetClass, "this current class is not implement JFieldOpt!");
}
示例6: checkClass
import org.springframework.util.Assert; //导入方法依赖的package包/类
private void checkClass(String attribute)
{
Class<?> targetClass = null;
try {
targetClass = Class.forName(attribute);
} catch (ClassNotFoundException e) {
throw new RuntimeException("not found class:" + attribute);
}
Assert.isAssignable(RefreshServiceManagerService.class, targetClass, "this current class is not implement RefreshServiceManagerService!");
}
示例7: customizeContext
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* Customize the {@link ConfigurableWebApplicationContext} created by this
* ContextLoader after config locations have been supplied to the context
* but before the context is <em>refreshed</em>.
* <p>The default implementation {@linkplain #determineContextInitializerClasses(ServletContext)
* determines} what (if any) context initializer classes have been specified through
* {@linkplain #CONTEXT_INITIALIZER_CLASSES_PARAM context init parameters} and
* {@linkplain ApplicationContextInitializer#initialize invokes each} with the
* given web application context.
* <p>Any {@code ApplicationContextInitializers} implementing
* {@link org.springframework.core.Ordered Ordered} or marked with @{@link
* org.springframework.core.annotation.Order Order} will be sorted appropriately.
* @param sc the current servlet context
* @param wac the newly created application context
* @see #createWebApplicationContext(ServletContext, ApplicationContext)
* @see #CONTEXT_INITIALIZER_CLASSES_PARAM
* @see ApplicationContextInitializer#initialize(ConfigurableApplicationContext)
*/
protected void customizeContext(ServletContext sc, ConfigurableWebApplicationContext wac) {
List<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>> initializerClasses =
determineContextInitializerClasses(sc);
if (initializerClasses.isEmpty()) {
// no ApplicationContextInitializers have been declared -> nothing to do
return;
}
ArrayList<ApplicationContextInitializer<ConfigurableApplicationContext>> initializerInstances =
new ArrayList<ApplicationContextInitializer<ConfigurableApplicationContext>>();
for (Class<ApplicationContextInitializer<ConfigurableApplicationContext>> initializerClass : initializerClasses) {
Class<?> initializerContextClass =
GenericTypeResolver.resolveTypeArgument(initializerClass, ApplicationContextInitializer.class);
if (initializerContextClass != null) {
Assert.isAssignable(initializerContextClass, wac.getClass(), String.format(
"Could not add context initializer [%s] since its generic parameter [%s] " +
"is not assignable from the type of application context used by this " +
"context loader [%s]: ", initializerClass.getName(), initializerContextClass.getName(),
wac.getClass().getName()));
}
initializerInstances.add(BeanUtils.instantiateClass(initializerClass));
}
AnnotationAwareOrderComparator.sort(initializerInstances);
for (ApplicationContextInitializer<ConfigurableApplicationContext> initializer : initializerInstances) {
initializer.initialize(wac);
}
}
示例8: loadInitializerClass
import org.springframework.util.Assert; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Class<ApplicationContextInitializer<ConfigurableApplicationContext>> loadInitializerClass(String className) {
try {
Class<?> clazz = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());
Assert.isAssignable(ApplicationContextInitializer.class, clazz);
return (Class<ApplicationContextInitializer<ConfigurableApplicationContext>>) clazz;
}
catch (ClassNotFoundException ex) {
throw new ApplicationContextException("Failed to load context initializer class [" + className + "]", ex);
}
}
示例9: afterPropertiesSet
import org.springframework.util.Assert; //导入方法依赖的package包/类
public void afterPropertiesSet() throws Exception {
Assert.notNull(bundleContext, "required property 'bundleContext' has not been set");
hasNamedBean = StringUtils.hasText(targetBeanName);
Assert.isTrue(hasNamedBean || target != null, "Either 'targetBeanName' or 'target' properties have to be set.");
// if we have a name, we need a bean factory
if (hasNamedBean) {
Assert.notNull(beanFactory, "Required property 'beanFactory' has not been set.");
}
// initialize bean only when dealing with singletons and named beans
if (hasNamedBean) {
Assert.isTrue(beanFactory.containsBean(targetBeanName), "Cannot locate bean named '" + targetBeanName
+ "' inside the running bean factory.");
if (beanFactory.isSingleton(targetBeanName)) {
if (beanFactory instanceof ConfigurableListableBeanFactory) {
ConfigurableListableBeanFactory clbf = (ConfigurableListableBeanFactory) beanFactory;
BeanDefinition definition = clbf.getBeanDefinition(targetBeanName);
if (!definition.isLazyInit()) {
target = beanFactory.getBean(targetBeanName);
targetClass = target.getClass();
}
}
}
if (targetClass == null) {
// lazily get the target class
targetClass = beanFactory.getType(targetBeanName);
}
// when running inside a container, add the dependency between this bean and the target one
addBeanFactoryDependency();
} else {
targetClass = target.getClass();
}
if (propertiesResolver == null) {
propertiesResolver = new BeanNameServicePropertiesResolver();
((BeanNameServicePropertiesResolver) propertiesResolver).setBundleContext(bundleContext);
}
// sanity check
if (interfaces == null) {
if (DefaultInterfaceDetector.DISABLED.equals(interfaceDetector))
throw new IllegalArgumentException(
"No service interface(s) specified and auto-export discovery disabled; change at least one of these properties.");
interfaces = new Class[0];
}
// check visibility type
else {
if (!ServiceFactory.class.isAssignableFrom(targetClass)) {
for (int interfaceIndex = 0; interfaceIndex < interfaces.length; interfaceIndex++) {
Class<?> intf = interfaces[interfaceIndex];
Assert.isAssignable(intf, targetClass,
"Exported service object does not implement the given interface: ");
}
}
}
// check service properties listener
if (serviceProperties instanceof ServicePropertiesListenerManager) {
propertiesListener = new PropertiesMonitor();
((ServicePropertiesListenerManager) serviceProperties).addListener(propertiesListener);
}
boolean shouldRegisterAtStartup;
synchronized (lock) {
shouldRegisterAtStartup = registerAtStartup;
}
resolver =
new LazyTargetResolver(target, beanFactory, targetBeanName, cacheTarget, getNotifier(),
getLazyListeners());
if (shouldRegisterAtStartup) {
registerService();
}
}
示例10: typeFiltersFor
import org.springframework.util.Assert; //导入方法依赖的package包/类
private List<TypeFilter> typeFiltersFor(AnnotationAttributes filterAttributes) {
List<TypeFilter> typeFilters = new ArrayList<TypeFilter>();
FilterType filterType = filterAttributes.getEnum("type");
for (Class<?> filterClass : filterAttributes.getClassArray("value")) {
switch (filterType) {
case ANNOTATION:
Assert.isAssignable(Annotation.class, filterClass,
"An error occured while processing a @ComponentScan ANNOTATION type filter: ");
@SuppressWarnings("unchecked")
Class<Annotation> annotationType = (Class<Annotation>) filterClass;
typeFilters.add(new AnnotationTypeFilter(annotationType));
break;
case ASSIGNABLE_TYPE:
typeFilters.add(new AssignableTypeFilter(filterClass));
break;
case CUSTOM:
Assert.isAssignable(TypeFilter.class, filterClass,
"An error occured while processing a @ComponentScan CUSTOM type filter: ");
typeFilters.add(BeanUtils.instantiateClass(filterClass, TypeFilter.class));
break;
default:
throw new IllegalArgumentException("Filter type not supported with Class value: " + filterType);
}
}
for (String expression : filterAttributes.getStringArray("pattern")) {
switch (filterType) {
case ASPECTJ:
typeFilters.add(new AspectJTypeFilter(expression, this.resourceLoader.getClassLoader()));
break;
case REGEX:
typeFilters.add(new RegexPatternTypeFilter(Pattern.compile(expression)));
break;
default:
throw new IllegalArgumentException("Filter type not supported with String pattern: " + filterType);
}
}
return typeFilters;
}
示例11: registerCustomEditor
import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
public void registerCustomEditor(Class<?> requiredType, Class<? extends PropertyEditor> propertyEditorClass) {
Assert.notNull(requiredType, "Required type must not be null");
Assert.isAssignable(PropertyEditor.class, propertyEditorClass);
this.customEditors.put(requiredType, propertyEditorClass);
}
示例12: setPersistenceManagerInterface
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* Specify the PersistenceManager interface to expose,
* possibly including vendor extensions.
* <p>Default is the standard {@code javax.jdo.PersistenceManager} interface.
*/
public void setPersistenceManagerInterface(Class<? extends PersistenceManager> persistenceManagerInterface) {
this.persistenceManagerInterface = persistenceManagerInterface;
Assert.notNull(persistenceManagerInterface, "persistenceManagerInterface must not be null");
Assert.isAssignable(PersistenceManager.class, persistenceManagerInterface);
}
示例13: setSchedulerFactoryClass
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* Set the Quartz SchedulerFactory implementation to use.
* <p>Default is {@link StdSchedulerFactory}, reading in the standard
* {@code quartz.properties} from {@code quartz.jar}.
* To use custom Quartz properties, specify the "configLocation"
* or "quartzProperties" bean property on this FactoryBean.
* @see org.quartz.impl.StdSchedulerFactory
* @see #setConfigLocation
* @see #setQuartzProperties
*/
public void setSchedulerFactoryClass(Class<? extends SchedulerFactory> schedulerFactoryClass) {
Assert.isAssignable(SchedulerFactory.class, schedulerFactoryClass);
this.schedulerFactoryClass = schedulerFactoryClass;
}
示例14: instantiateClass
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* Instantiate a class using its no-arg constructor and return the new instance
* as the the specified assignable type.
* <p>Useful in cases where
* the type of the class to instantiate (clazz) is not available, but the type
* desired (assignableTo) is known.
* <p>As this method doesn't try to load classes by name, it should avoid
* class-loading issues.
* <p>Note that this method tries to set the constructor accessible
* if given a non-accessible (that is, non-public) constructor.
* @param clazz class to instantiate
* @param assignableTo type that clazz must be assignableTo
* @return the new instance
* @throws BeanInstantiationException if the bean cannot be instantiated
*/
@SuppressWarnings("unchecked")
public static <T> T instantiateClass(Class<?> clazz, Class<T> assignableTo) throws BeanInstantiationException {
Assert.isAssignable(assignableTo, clazz);
return (T) instantiateClass(clazz);
}
示例15: setResourceAdapterClass
import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
* Specify the target JCA ResourceAdapter as class, to be instantiated
* with its default configuration.
* <p>Alternatively, specify a pre-configured ResourceAdapter instance
* through the "resourceAdapter" property.
* @see #setResourceAdapter
*/
public void setResourceAdapterClass(Class<?> resourceAdapterClass) {
Assert.isAssignable(ResourceAdapter.class, resourceAdapterClass);
this.resourceAdapter = (ResourceAdapter) BeanUtils.instantiateClass(resourceAdapterClass);
}