aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1680054 - in /aries/trunk/blueprint/blueprint-web: pom.xml src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java
Date Mon, 18 May 2015 16:45:18 GMT
Author: sergeyb
Date: Mon May 18 16:45:17 2015
New Revision: 1680054

URL: http://svn.apache.org/r1680054
Log:
[ARIES-1323] Enhancing blueprint-web listener to optionally auto-register namespace handlers

Modified:
    aries/trunk/blueprint/blueprint-web/pom.xml
    aries/trunk/blueprint/blueprint-web/src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java

Modified: aries/trunk/blueprint/blueprint-web/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-web/pom.xml?rev=1680054&r1=1680053&r2=1680054&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-web/pom.xml (original)
+++ aries/trunk/blueprint/blueprint-web/pom.xml Mon May 18 16:45:17 2015
@@ -46,6 +46,7 @@
 
     <properties>
         <blueprint.nosgi.version>1.1.0</blueprint.nosgi.version>
+        <blueprint.parser.version>1.3.1-SNAPSHOT</blueprint.parser.version>
         <lastReleaseVersion>1.0.0</lastReleaseVersion>
     </properties>
 
@@ -65,6 +66,12 @@
             <version>${blueprint.nosgi.version}</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.aries.blueprint</groupId>
+            <artifactId>blueprint-parser</artifactId>
+            <version>${blueprint.parser.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-servlet_2.5_spec</artifactId>
             <version>1.2</version>

Modified: aries/trunk/blueprint/blueprint-web/src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-web/src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java?rev=1680054&r1=1680053&r2=1680054&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-web/src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java
(original)
+++ aries/trunk/blueprint/blueprint-web/src/main/java/org/apache/aries/blueprint/web/BlueprintContextListener.java
Mon May 18 16:45:17 2015
@@ -18,6 +18,7 @@
 package org.apache.aries.blueprint.web;
 
 import java.io.InputStream;
+import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Enumeration;
@@ -30,7 +31,10 @@ import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 
+import org.apache.aries.blueprint.NamespaceHandler;
+import org.apache.aries.blueprint.Namespaces;
 import org.apache.aries.blueprint.container.BlueprintContainerImpl;
+import org.apache.aries.blueprint.container.SimpleNamespaceHandlerSet;
 import org.apache.aries.blueprint.parser.NamespaceHandlerSet;
 
 /**
@@ -42,6 +46,8 @@ public class BlueprintContextListener im
 
     public static final String LOCATION = "blueprintLocation";
 
+    public static final String NAMESPACE_HANDLERS = "blueprintNamespaceHandlers";
+    
     public static final String PROPERTIES = "blueprintProperties";
 
     public static final String DEFAULT_LOCATION = "META-INF/blueprint.xml";
@@ -84,7 +90,7 @@ public class BlueprintContextListener im
                 }
             }
 
-            NamespaceHandlerSet nsHandlerSet = getNamespaceHandlerSet(classLoader);
+            NamespaceHandlerSet nsHandlerSet = getNamespaceHandlerSet(servletContext, classLoader);
             BlueprintContainerImpl container = new BlueprintContainerImpl(classLoader, resourcePaths,
properties, nsHandlerSet, true);
             servletContext.setAttribute(CONTAINER_ATTRIBUTE, container);
         } catch (Exception e) {
@@ -92,8 +98,35 @@ public class BlueprintContextListener im
         }
     }
     
-    protected NamespaceHandlerSet getNamespaceHandlerSet(ClassLoader tccl) {
-        return null;
+    protected NamespaceHandlerSet getNamespaceHandlerSet(ServletContext servletContext, ClassLoader
tccl) {
+        String handlersProp = servletContext.getInitParameter(NAMESPACE_HANDLERS);
+        if (handlersProp == null) {
+            return null;
+        }
+        SimpleNamespaceHandlerSet nsSet = new SimpleNamespaceHandlerSet();
+        
+        String[] handlerClassNames = handlersProp.split(",");
+        for (String name : handlerClassNames) {
+            String trimmedName = name.trim();
+            Object instance = null; 
+            try {
+                instance = tccl.loadClass(trimmedName).newInstance();
+            } catch (Exception ex) {
+                throw new RuntimeException("Failed to load NamespaceHandler: " + trimmedName,
ex);
+            }
+            if (!(instance instanceof NamespaceHandler)) {
+                throw new RuntimeException("Invalid NamespaceHandler: " + trimmedName);
+            }
+            NamespaceHandler nsHandler = (NamespaceHandler)instance;
+            Namespaces namespaces = nsHandler.getClass().getAnnotation(Namespaces.class);
+            if (namespaces != null) {
+                for (String ns : namespaces.value()) {
+                    nsSet.addNamespace(URI.create(ns), nsHandler.getSchemaLocation(ns), nsHandler);
   
+                }
+            }
+        }
+        
+        return nsSet;
     }
 
     public void contextDestroyed(ServletContextEvent event) {



Mime
View raw message