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

项目:gemini.blueprint    文件:NamespaceManager.java   
/**
 * Registers the NamespacePlugins instance as an Osgi Resolver service
 */
private void registerResolverServices() {
    if (log.isDebugEnabled()) {
        log.debug("Registering Spring NamespaceHandlerResolver and EntityResolver...");
    }

    Bundle bnd = BundleUtils.getDMCoreBundle(context);
    Dictionary<String, Object> props = null;
    if (bnd != null) {
        props = new Hashtable<String, Object>();
        props.put(BundleUtils.DM_CORE_ID, bnd.getBundleId());
        props.put(BundleUtils.DM_CORE_TS, bnd.getLastModified());
    }
    nsResolverRegistration =
            context.registerService(new String[] { NamespaceHandlerResolver.class.getName() },
                    this.namespacePlugins, props);

    enResolverRegistration =
            context.registerService(new String[] { EntityResolver.class.getName() }, this.namespacePlugins, props);

}
项目: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;
}
项目:gemini.blueprint    文件:DelegatedNamespaceHandlerResolver.java   
public NamespaceHandler resolve(String namespaceUri) {
    boolean trace = log.isTraceEnabled();

    for (Iterator<Map.Entry<NamespaceHandlerResolver, String>> iterator = resolvers.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<NamespaceHandlerResolver, String> entry = iterator.next();
        NamespaceHandlerResolver handlerResolver = entry.getKey();
        if (trace)
            log.trace("Trying to resolve namespace [" + namespaceUri + "] through resolver " + entry.getValue());
        NamespaceHandler handler = handlerResolver.resolve(namespaceUri);

        String resolvedMsg = (handler != null ? "" : "not ");
        if (trace)
            log.trace("Namespace [" + namespaceUri + "] was " + resolvedMsg + "resolved through handler resolver "
                    + entry.getValue());

        if (handler != null) {
            return handler;
        }

    }
    return null;
}
项目:spring-osgi    文件:NamespaceManager.java   
/**
 * Register the NamespacePlugins instance as an Osgi Resolver service
 */
private void registerResolverServices() {
    if (log.isDebugEnabled()) {
        log.debug("Registering Spring NamespaceHandlerResolver and EntityResolver...");
    }
    Bundle bnd = BundleUtils.getDMCoreBundle(context);

    Properties props = null;
    if (bnd != null) {
        props = new Properties();
        props.setProperty(BundleUtils.DM_CORE_ID, "" + bnd.getBundleId());
        props.setProperty(BundleUtils.DM_CORE_TS, "" + bnd.getLastModified());
    }

    nsResolverRegistration = context.registerService(new String[] { NamespaceHandlerResolver.class.getName() },
            this.namespacePlugins, props);

    enResolverRegistration = context.registerService(new String[] { EntityResolver.class.getName() },
            this.namespacePlugins, props);
}
项目: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;
}
项目:spring-osgi    文件:DelegatedNamespaceHandlerResolver.java   
public NamespaceHandler resolve(String namespaceUri) {
    boolean trace = log.isTraceEnabled();

    for (Iterator iterator = resolvers.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry entry = (Map.Entry) iterator.next();
        NamespaceHandlerResolver handlerResolver = (NamespaceHandlerResolver) entry.getKey();
        if (trace)
            log.trace("Trying to resolve namespace [" + namespaceUri + "] through resolver " + entry.getValue());
        NamespaceHandler handler = handlerResolver.resolve(namespaceUri);

        String resolvedMsg = (handler != null ? "" : "not ");
        if (trace)
            log.trace("Namespace [" + namespaceUri + "] was " + resolvedMsg + "resolved through handler resolver "
                    + entry.getValue());

        if (handler != null) {
            return handler;
        }

    }
    return null;
}
项目:gemini.blueprint    文件:EmbeddedNamespaceLibraryTest.java   
public void testNamespaceFilesOnTheClassPath() throws Exception {
    // simple code to trigger an import for this package
    assertNotNull(NamespaceHandlerResolver.class);

    Bundle bundle = bundleContext.getBundle();
    URL handlers = bundle.getResource("META-INF/spring.handlers");
    URL schemas = bundle.getResource("META-INF/spring.schemas");

    assertNotNull(handlers);
    assertNotNull(schemas);

}
项目:gemini.blueprint    文件:NamespacePlugins.java   
public boolean pass(Bundle bundle) {
    try {
        Class<?> type = bundle.loadClass(NS_HANDLER_RESOLVER_CLASS_NAME);
        return NamespaceHandlerResolver.class.equals(type);
    } catch (Throwable th) {
        // if the interface is not wired, ignore the bundle
        log.warn("Bundle " + OsgiStringUtils.nullSafeNameAndSymName(bundle) + " cannot see class ["
                + NS_HANDLER_RESOLVER_CLASS_NAME + "]; ignoring it as a namespace resolver");

        return false;
    }
}
项目: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();
}
项目: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();
}
项目:spring-osgi    文件:EmbeddedNamespaceLibraryTest.java   
public void testNamespaceFilesOnTheClassPath() throws Exception {
    // simple code to trigger an import for this package
    assertNotNull(NamespaceHandlerResolver.class);

    Bundle bundle = bundleContext.getBundle();
    URL handlers = bundle.getResource("META-INF/spring.handlers");
    URL schemas = bundle.getResource("META-INF/spring.schemas");

    assertNotNull(handlers);
    assertNotNull(schemas);

}
项目:spring-osgi    文件:NamespaceManager.java   
private boolean hasCompatibleNamespaceType(Bundle bundle) {
    try {
        Class type = bundle.loadClass(NS_HANDLER_RESOLVER_CLASS_NAME);
        return NamespaceHandlerResolver.class.equals(type);
    } catch (Throwable th) {
        // if the interface is not wired, ignore the bundle
        log.warn("Bundle " + OsgiStringUtils.nullSafeNameAndSymName(bundle) + " cannot see class ["
                + NS_HANDLER_RESOLVER_CLASS_NAME + "]; ignoring its namespace handlers");

        return false;
    }
}
项目:spring-osgi    文件:OsgiBundleXmlApplicationContext.java   
/**
 * {@inheritDoc}
 * 
 * <p/> Loads the bean definitions via an <code>XmlBeanDefinitionReader</code>.
 */
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException {
    // Create a new XmlBeanDefinitionReader for the given BeanFactory.
    XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);

    // Configure the bean definition reader with this context's
    // resource loading environment.
    beanDefinitionReader.setResourceLoader(this);

    final Object[] resolvers = new Object[2];

    AccessController.doPrivileged(new PrivilegedAction() {

        public Object run() {
            BundleContext ctx = getBundleContext();
            String filter = BundleUtils.createNamespaceFilter(ctx);
            resolvers[0] = createNamespaceHandlerResolver(ctx, filter, getClassLoader());
            resolvers[1] = createEntityResolver(ctx, filter, getClassLoader());
            return null;
        }
    });

    beanDefinitionReader.setNamespaceHandlerResolver((NamespaceHandlerResolver) resolvers[0]);
    beanDefinitionReader.setEntityResolver((EntityResolver) resolvers[1]);

    // Allow a subclass to provide custom initialisation of the reader,
    // then proceed with actually loading the bean definitions.
    initBeanDefinitionReader(beanDefinitionReader);
    loadBeanDefinitions(beanDefinitionReader);
}
项目:wildfly-camel    文件:SpringCamelContextBootstrap.java   
private void loadBeanDefinitions(Resource resource, ClassLoader classLoader) {
    applicationContext = new GenericApplicationContext();
    applicationContext.setClassLoader(classLoader);
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext) {
        @Override
        protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() {
            NamespaceHandlerResolver defaultResolver = super.createDefaultNamespaceHandlerResolver();
            return new SpringCamelContextBootstrap.CamelNamespaceHandlerResolver(defaultResolver);
        }
    };
    xmlReader.loadBeanDefinitions(resource);
}
项目:gemini.blueprint    文件:OsgiBundleXmlApplicationContext.java   
private NamespaceHandlerResolver lookupNamespaceHandlerResolver(final BundleContext bundleContext, String filter,
        final Object fallbackObject) {
    return (NamespaceHandlerResolver) TrackingUtil.getService(new Class<?>[] { NamespaceHandlerResolver.class },
            filter, NamespaceHandlerResolver.class.getClassLoader(), bundleContext, fallbackObject);
}
项目:gemini.blueprint    文件:DelegatedNamespaceHandlerResolver.java   
public void addNamespaceHandler(NamespaceHandlerResolver resolver, String resolverToString) {
    Assert.notNull(resolver);
    resolvers.put(resolver, resolverToString);
}
项目:spring-osgi    文件:OsgiBundleXmlApplicationContext.java   
private NamespaceHandlerResolver lookupNamespaceHandlerResolver(final BundleContext bundleContext, String filter,
        final Object fallbackObject) {
    return (NamespaceHandlerResolver) TrackingUtil.getService(new Class[] { NamespaceHandlerResolver.class },
            filter, NamespaceHandlerResolver.class.getClassLoader(), bundleContext, fallbackObject);
}
项目:spring-osgi    文件:DelegatedNamespaceHandlerResolver.java   
public void addNamespaceHandler(NamespaceHandlerResolver resolver, String resolverToString) {
    Assert.notNull(resolver);
    resolvers.put(resolver, resolverToString);
}
项目:wildfly-camel    文件:SpringCamelContextBootstrap.java   
CamelNamespaceHandlerResolver(NamespaceHandlerResolver delegate) {
    this.delegate = delegate;
    this.camelHandler = new CamelNamespaceHandler();
    this.camelHandler.init();
}