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

项目:gemini.blueprint    文件:OsgiBundleXmlApplicationContext.java   
/**
 * Creates a special OSGi namespace handler resolver that first searches the bundle class path falling back to the
 * namespace service published by Spring-DM. This allows embedded libraries that provide namespace handlers take
 * priority over namespace provided by other bundles.
 * 
 * @param bundleContext the OSGi context of which the resolver should be aware of
 * @param filter OSGi service filter
 * @param bundleClassLoader classloader for creating the OSGi namespace resolver proxy
 * @return a OSGi aware namespace handler resolver
 */
private NamespaceHandlerResolver createNamespaceHandlerResolver(BundleContext bundleContext, String filter,
        ClassLoader bundleClassLoader) {
    Assert.notNull(bundleContext, "bundleContext is required");
    // create local namespace resolver
    // we'll use the default resolver which uses the bundle local class-loader
    NamespaceHandlerResolver localNamespaceResolver = new DefaultNamespaceHandlerResolver(bundleClassLoader);

    // hook in OSGi namespace resolver
    NamespaceHandlerResolver osgiServiceNamespaceResolver =
            lookupNamespaceHandlerResolver(bundleContext, filter, localNamespaceResolver);

    DelegatedNamespaceHandlerResolver delegate = new DelegatedNamespaceHandlerResolver();
    delegate.addNamespaceHandler(localNamespaceResolver, "LocalNamespaceResolver for bundle "
            + OsgiStringUtils.nullSafeNameAndSymName(bundleContext.getBundle()));
    delegate.addNamespaceHandler(osgiServiceNamespaceResolver, "OSGi Service resolver");

    return delegate;
}
项目:spring-osgi    文件:OsgiBundleXmlApplicationContext.java   
/**
 * Creates a special OSGi namespace handler resolver that first searches the bundle class path falling back to the
 * namespace service published by Spring-DM. This allows embedded libraries that provide namespace handlers take
 * priority over namespace provided by other bundles.
 * 
 * @param bundleContext the OSGi context of which the resolver should be aware of
 * @param filter
 * @param bundleClassLoader classloader for creating the OSGi namespace resolver proxy
 * @return a OSGi aware namespace handler resolver
 */
private NamespaceHandlerResolver createNamespaceHandlerResolver(BundleContext bundleContext, String filter,
        ClassLoader bundleClassLoader) {
    Assert.notNull(bundleContext, "bundleContext is required");
    // create local namespace resolver
    // we'll use the default resolver which uses the bundle local class-loader
    NamespaceHandlerResolver localNamespaceResolver = new DefaultNamespaceHandlerResolver(bundleClassLoader);

    // hook in OSGi namespace resolver
    NamespaceHandlerResolver osgiServiceNamespaceResolver = lookupNamespaceHandlerResolver(bundleContext, filter,
            localNamespaceResolver);

    DelegatedNamespaceHandlerResolver delegate = new DelegatedNamespaceHandlerResolver();
    delegate.addNamespaceHandler(localNamespaceResolver, "LocalNamespaceResolver for bundle "
            + OsgiStringUtils.nullSafeNameAndSymName(bundleContext.getBundle()));
    delegate.addNamespaceHandler(osgiServiceNamespaceResolver, "OSGi Service resolver");

    return delegate;
}
项目:gemini.blueprint    文件:NamespacePlugins.java   
private Plugin(Bundle bundle) {
    this.bundle = bundle;

    ClassLoader loader = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle);

    entity = new DelegatingEntityResolver(loader);
    namespace = new DefaultNamespaceHandlerResolver(loader);
}
项目:dwr    文件:DwrNamesapceHandlerTests.java   
protected void setUp() throws Exception {

    ServletConfig servletConfig = new FakeServletConfig("test", new FakeServletContext());

    webappContext = new StaticWebApplicationContext();
    webappContext.setServletConfig(servletConfig);

    NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(getClass().getClassLoader());
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(webappContext);
    reader.setNamespaceHandlerResolver(resolver);
    reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
    reader.setEntityResolver(new DummySchemaResolver());
    reader.loadBeanDefinitions(getResource());

    container = new SpringContainer();
    container.setBeanFactory(webappContext);

    container.addParameter("debug", "true");
    ContainerUtil.setupDefaultContainer(container, servletConfig);

    StartupUtil.initWebContext(servletConfig, servletConfig.getServletContext(), null, container);
    StartupUtil.initServerContext(servletConfig, servletConfig.getServletContext(), container);

    // Configure default converters etc
    ContainerUtil.configureFromSystemDwrXml(container);

    ContainerUtil.configure(container, Collections.singletonList(webappContext.getBean(DwrNamespaceHandler.DEFAULT_SPRING_CONFIGURATOR_ID)));
    ContainerUtil.publishContainer(container, servletConfig);

    ContainerUtil.debugConfig(container);
}
项目:spring4-understanding    文件:CustomNamespaceHandlerTests.java   
@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();
}
项目:spring4-understanding    文件:DefaultNamespaceHandlerResolverTests.java   
@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());
}
项目:spring4-understanding    文件:DefaultNamespaceHandlerResolverTests.java   
@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());
}
项目:spring4-understanding    文件:DefaultNamespaceHandlerResolverTests.java   
@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);
    }
}
项目:spring4-understanding    文件:DefaultNamespaceHandlerResolverTests.java   
@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) {
    }
}
项目:class-guard    文件:CustomNamespaceHandlerTests.java   
@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();
}
项目:class-guard    文件:DefaultNamespaceHandlerResolverTests.java   
@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());
}
项目:class-guard    文件:DefaultNamespaceHandlerResolverTests.java   
@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());
}
项目:class-guard    文件:DefaultNamespaceHandlerResolverTests.java   
@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);
    }
}
项目:class-guard    文件:DefaultNamespaceHandlerResolverTests.java   
@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) {
    }
}
项目:spring-osgi    文件:NamespacePlugins.java   
private Plugin(Bundle bundle) {
    this.bundle = bundle;

    ClassLoader loader = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle);

    entity = new DelegatingEntityResolver(loader);
    namespace = new DefaultNamespaceHandlerResolver(loader);
}
项目:spring4-understanding    文件:DefaultNamespaceHandlerResolverTests.java   
@Test
public void testCtorWithNullClassLoaderArgument() throws Exception {
    // simply must not bail...
    new DefaultNamespaceHandlerResolver(null);
}
项目:spring4-understanding    文件:DefaultNamespaceHandlerResolverTests.java   
@Test(expected=IllegalArgumentException.class)
public void testCtorWithNullClassLoaderArgumentAndNullMappingLocationArgument() throws Exception {
    new DefaultNamespaceHandlerResolver(null, null);
}
项目:spring4-understanding    文件:DefaultNamespaceHandlerResolverTests.java   
@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");
}
项目:class-guard    文件:DefaultNamespaceHandlerResolverTests.java   
@Test
public void testCtorWithNullClassLoaderArgument() throws Exception {
    // simply must not bail...
    new DefaultNamespaceHandlerResolver(null);
}
项目:class-guard    文件:DefaultNamespaceHandlerResolverTests.java   
@Test(expected=IllegalArgumentException.class)
public void testCtorWithNullClassLoaderArgumentAndNullMappingLocationArgument() throws Exception {
    new DefaultNamespaceHandlerResolver(null, null);
}
项目:class-guard    文件:DefaultNamespaceHandlerResolverTests.java   
@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");
}