Search in sources :

Example 6 with NamespaceHandlerSet

use of org.apache.aries.blueprint.parser.NamespaceHandlerSet in project aries by apache.

the class BlueprintContextListener method contextInitialized.

public void contextInitialized(ServletContextEvent event) {
    ServletContext servletContext = event.getServletContext();
    String location = servletContext.getInitParameter(CONTEXT_LOCATION);
    if (location == null) {
        location = DEFAULT_CONTEXT_LOCATION;
    }
    List<URL> resourcePaths = new ArrayList<URL>();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try {
        Enumeration<URL> resources = classLoader.getResources(location);
        while (resources.hasMoreElements()) {
            resourcePaths.add(resources.nextElement());
        }
        servletContext.log("Loading Blueprint contexts " + resourcePaths);
        Map<String, String> properties = new HashMap<String, String>();
        String propLocations = servletContext.getInitParameter(PROPERTIES);
        if (propLocations != null) {
            for (String propLoc : propLocations.split(",")) {
                Enumeration<URL> propUrl = classLoader.getResources(propLoc);
                while (propUrl.hasMoreElements()) {
                    URL url = propUrl.nextElement();
                    InputStream is = url.openStream();
                    try {
                        Properties props = new Properties();
                        props.load(is);
                        Enumeration names = props.propertyNames();
                        while (names.hasMoreElements()) {
                            String key = names.nextElement().toString();
                            properties.put(key, props.getProperty(key));
                        }
                    } finally {
                        is.close();
                    }
                }
            }
        }
        NamespaceHandlerSet nsHandlerSet = getNamespaceHandlerSet(servletContext, classLoader);
        BlueprintContainerImpl container = new BlueprintContainerImpl(classLoader, resourcePaths, properties, nsHandlerSet, true);
        servletContext.setAttribute(CONTAINER_ATTRIBUTE, container);
    } catch (Exception e) {
        servletContext.log("Failed to startup blueprint container. " + e, e);
    }
}
Also used : NamespaceHandlerSet(org.apache.aries.blueprint.parser.NamespaceHandlerSet) SimpleNamespaceHandlerSet(org.apache.aries.blueprint.container.SimpleNamespaceHandlerSet) Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Properties(java.util.Properties) URL(java.net.URL) IOException(java.io.IOException) BlueprintContainerImpl(org.apache.aries.blueprint.container.BlueprintContainerImpl) ServletContext(javax.servlet.ServletContext)

Aggregations

NamespaceHandlerSet (org.apache.aries.blueprint.parser.NamespaceHandlerSet)6 URI (java.net.URI)5 URL (java.net.URL)2 ComponentDefinitionRegistry (org.apache.aries.blueprint.ComponentDefinitionRegistry)2 ComponentDefinitionRegistryImpl (org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl)2 Parser (org.apache.aries.blueprint.parser.Parser)2 PassThroughMetadataImpl (org.apache.aries.blueprint.reflect.PassThroughMetadataImpl)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ServletContext (javax.servlet.ServletContext)1 BlueprintContainerImpl (org.apache.aries.blueprint.container.BlueprintContainerImpl)1 SimpleNamespaceHandlerSet (org.apache.aries.blueprint.container.SimpleNamespaceHandlerSet)1 ExtNamespaceHandler (org.apache.aries.blueprint.ext.impl.ExtNamespaceHandler)1