类org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver源码实例Demo

下面列出了怎么用org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver的API类实例代码及写法,或者点击链接到github查看源代码。

@Before
public void setUp() throws Exception {
	NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(CLASS.getClassLoader(), NS_PROPS);
	this.beanFactory = new GenericApplicationContext();
	XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
	reader.setNamespaceHandlerResolver(resolver);
	reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
	reader.setEntityResolver(new DummySchemaResolver());
	reader.loadBeanDefinitions(getResource());
	this.beanFactory.refresh();
}
 
@Test
public void testResolvedMappedHandler() {
	DefaultNamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(getClass().getClassLoader());
	NamespaceHandler handler = resolver.resolve("http://www.springframework.org/schema/util");
	assertNotNull("Handler should not be null.", handler);
	assertEquals("Incorrect handler loaded", UtilNamespaceHandler.class, handler.getClass());
}
 
@Test
public void testResolvedMappedHandlerWithNoArgCtor() {
	DefaultNamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver();
	NamespaceHandler handler = resolver.resolve("http://www.springframework.org/schema/util");
	assertNotNull("Handler should not be null.", handler);
	assertEquals("Incorrect handler loaded", UtilNamespaceHandler.class, handler.getClass());
}
 
@Test
public void testNonExistentHandlerClass() throws Exception {
	String mappingPath = "org/springframework/beans/factory/xml/support/nonExistent.properties";
	try {
		new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), mappingPath);
		// pass
	}
	catch (Throwable ex) {
		fail("Non-existent handler classes must be ignored: " + ex);
	}
}
 
@Test
public void testResolveInvalidHandler() throws Exception {
	String mappingPath = "org/springframework/beans/factory/xml/support/invalid.properties";
	try {
		new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), mappingPath);
		fail("Should not be able to map a class that doesn't implement NamespaceHandler");
	}
	catch (Throwable expected) {
	}
}
 
@Before
public void setUp() throws Exception {
	NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(CLASS.getClassLoader(), NS_PROPS);
	this.beanFactory = new GenericApplicationContext();
	XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
	reader.setNamespaceHandlerResolver(resolver);
	reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
	reader.setEntityResolver(new DummySchemaResolver());
	reader.loadBeanDefinitions(getResource());
	this.beanFactory.refresh();
}
 
@Test
public void testResolvedMappedHandler() {
	DefaultNamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(getClass().getClassLoader());
	NamespaceHandler handler = resolver.resolve("http://www.springframework.org/schema/util");
	assertNotNull("Handler should not be null.", handler);
	assertEquals("Incorrect handler loaded", UtilNamespaceHandler.class, handler.getClass());
}
 
@Test
public void testResolvedMappedHandlerWithNoArgCtor() {
	DefaultNamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver();
	NamespaceHandler handler = resolver.resolve("http://www.springframework.org/schema/util");
	assertNotNull("Handler should not be null.", handler);
	assertEquals("Incorrect handler loaded", UtilNamespaceHandler.class, handler.getClass());
}
 
@Test
public void testNonExistentHandlerClass() throws Exception {
	String mappingPath = "org/springframework/beans/factory/xml/support/nonExistent.properties";
	try {
		new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), mappingPath);
		// pass
	}
	catch (Throwable ex) {
		fail("Non-existent handler classes must be ignored: " + ex);
	}
}
 
@Test
public void testResolveInvalidHandler() throws Exception {
	String mappingPath = "org/springframework/beans/factory/xml/support/invalid.properties";
	try {
		new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), mappingPath);
		fail("Should not be able to map a class that doesn't implement NamespaceHandler");
	}
	catch (Throwable expected) {
	}
}
 
@Before
public void setUp() throws Exception {
	NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(CLASS.getClassLoader(), NS_PROPS);
	this.beanFactory = new GenericApplicationContext();
	XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
	reader.setNamespaceHandlerResolver(resolver);
	reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
	reader.setEntityResolver(new DummySchemaResolver());
	reader.loadBeanDefinitions(getResource());
	this.beanFactory.refresh();
}
 
@Test
public void testResolvedMappedHandler() {
	DefaultNamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(getClass().getClassLoader());
	NamespaceHandler handler = resolver.resolve("http://www.springframework.org/schema/util");
	assertNotNull("Handler should not be null.", handler);
	assertEquals("Incorrect handler loaded", UtilNamespaceHandler.class, handler.getClass());
}
 
@Test
public void testResolvedMappedHandlerWithNoArgCtor() {
	DefaultNamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver();
	NamespaceHandler handler = resolver.resolve("http://www.springframework.org/schema/util");
	assertNotNull("Handler should not be null.", handler);
	assertEquals("Incorrect handler loaded", UtilNamespaceHandler.class, handler.getClass());
}
 
@Test
public void testNonExistentHandlerClass() throws Exception {
	String mappingPath = "org/springframework/beans/factory/xml/support/nonExistent.properties";
	try {
		new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), mappingPath);
		// pass
	}
	catch (Throwable ex) {
		fail("Non-existent handler classes must be ignored: " + ex);
	}
}
 
@Test
public void testResolveInvalidHandler() throws Exception {
	String mappingPath = "org/springframework/beans/factory/xml/support/invalid.properties";
	try {
		new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), mappingPath);
		fail("Should not be able to map a class that doesn't implement NamespaceHandler");
	}
	catch (Throwable expected) {
	}
}
 
@Test
public void testCtorWithNullClassLoaderArgument() throws Exception {
	// simply must not bail...
	new DefaultNamespaceHandlerResolver(null);
}
 
@Test(expected = IllegalArgumentException.class)
public void testCtorWithNullClassLoaderArgumentAndNullMappingLocationArgument() throws Exception {
	new DefaultNamespaceHandlerResolver(null, null);
}
 
@Test
public void testCtorWithNonExistentMappingLocationArgument() throws Exception {
	// simply must not bail; we don't want non-existent resources to result in an Exception
	new DefaultNamespaceHandlerResolver(null, "738trbc bobabloobop871");
}
 
@Test
public void testCtorWithNullClassLoaderArgument() throws Exception {
	// simply must not bail...
	new DefaultNamespaceHandlerResolver(null);
}
 
@Test(expected = IllegalArgumentException.class)
public void testCtorWithNullClassLoaderArgumentAndNullMappingLocationArgument() throws Exception {
	new DefaultNamespaceHandlerResolver(null, null);
}
 
@Test
public void testCtorWithNonExistentMappingLocationArgument() throws Exception {
	// simply must not bail; we don't want non-existent resources to result in an Exception
	new DefaultNamespaceHandlerResolver(null, "738trbc bobabloobop871");
}
 
@Test
public void testCtorWithNullClassLoaderArgument() throws Exception {
	// simply must not bail...
	new DefaultNamespaceHandlerResolver(null);
}
 
@Test(expected=IllegalArgumentException.class)
public void testCtorWithNullClassLoaderArgumentAndNullMappingLocationArgument() throws Exception {
	new DefaultNamespaceHandlerResolver(null, null);
}
 
@Test
public void testCtorWithNonExistentMappingLocationArgument() throws Exception {
	// simply must not bail; we don't want non-existent resources to result in an Exception
	new DefaultNamespaceHandlerResolver(null, "738trbc bobabloobop871");
}
 
 类方法
 同包方法