You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2008/02/06 21:01:55 UTC

svn commit: r619130 - in /incubator/abdera/java/trunk/spring/src: main/java/org/apache/abdera/spring/ main/resources/META-INF/schemas/ test/java/org/apache/abdera/spring/ test/resources/org/apache/abdera/spring/

Author: jmsnell
Date: Wed Feb  6 12:01:54 2008
New Revision: 619130

URL: http://svn.apache.org/viewvc?rev=619130&view=rev
Log:
filter support in the spring module

see https://issues.apache.org/jira/browse/ABDERA-92

Added:
    incubator/abdera/java/trunk/spring/src/test/java/org/apache/abdera/spring/DummyFilter.java
Modified:
    incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/DefaultProviderDefinitionParser.java
    incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/ProviderFactoryBean.java
    incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/WorkspaceDefinitionParser.java
    incubator/abdera/java/trunk/spring/src/main/resources/META-INF/schemas/abdera-spring.xsd
    incubator/abdera/java/trunk/spring/src/test/java/org/apache/abdera/spring/ProviderDefinitionParserTest.java
    incubator/abdera/java/trunk/spring/src/test/resources/org/apache/abdera/spring/beans.xml

Modified: incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/DefaultProviderDefinitionParser.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/DefaultProviderDefinitionParser.java?rev=619130&r1=619129&r2=619130&view=diff
==============================================================================
--- incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/DefaultProviderDefinitionParser.java (original)
+++ incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/DefaultProviderDefinitionParser.java Wed Feb  6 12:01:54 2008
@@ -22,8 +22,11 @@
 import org.springframework.beans.factory.BeanDefinitionStoreException;
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.support.ManagedList;
 import org.springframework.beans.factory.xml.ParserContext;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 public class DefaultProviderDefinitionParser 
     extends org.apache.abdera.spring.AbstractSingleBeanDefinitionParser {
@@ -45,6 +48,18 @@
             setFirstChildAsProperty(element, ctx, bean, "targetResolver");
         } else if (name.equals("subjectResolver")) {
             setFirstChildAsProperty(element, ctx, bean, name);
+        } else if (name.equals("filter")) {
+            ManagedList filters = new ManagedList();
+            NodeList nodes = element.getChildNodes();
+            for (int i = 0; i < nodes.getLength(); i++) {
+                Node n = nodes.item(i);
+                if (n.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
+                    Element childElement = (Element)n;
+                    Object child = ctx.getDelegate().parsePropertySubElement(childElement, bean.getRawBeanDefinition());
+                    filters.add(child);
+                }
+            }
+            bean.addPropertyValue("filters", filters);
         } else if (name.equals("workspace")) {
             String id = getAndRegister(ctx, bean, element);
             

Modified: incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/ProviderFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/ProviderFactoryBean.java?rev=619130&r1=619129&r2=619130&view=diff
==============================================================================
--- incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/ProviderFactoryBean.java (original)
+++ incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/ProviderFactoryBean.java Wed Feb  6 12:01:54 2008
@@ -6,6 +6,7 @@
 import javax.security.auth.Subject;
 
 import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.Filter;
 import org.apache.abdera.protocol.server.Target;
 import org.apache.abdera.protocol.server.WorkspaceInfo;
 import org.apache.abdera.protocol.server.impl.DefaultProvider;
@@ -18,6 +19,7 @@
     private Collection<WorkspaceInfo> workspaces;
     private Resolver<Target> targetResolver;
     private Resolver<Subject> subjectResolver;
+    private Filter[] filters;
     
     public Object getObject() throws Exception {
         DefaultProvider p = null;
@@ -40,6 +42,9 @@
         if (subjectResolver != null) {
             p.setSubjectResolver(subjectResolver);
         }
+        if (filters != null && filters.length > 0) {
+            p.addFilter(filters);
+        }
         
         return p;
     }
@@ -90,6 +95,14 @@
 
     public void setSubjectResolver(Resolver<Subject> subjectResolver) {
         this.subjectResolver = subjectResolver;
+    }
+
+    public Filter[] getFilters() {
+        return filters;
+    }
+
+    public void setFilters(Filter[] filters) {
+        this.filters = filters;
     }
 
 }

Modified: incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/WorkspaceDefinitionParser.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/WorkspaceDefinitionParser.java?rev=619130&r1=619129&r2=619130&view=diff
==============================================================================
--- incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/WorkspaceDefinitionParser.java (original)
+++ incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/WorkspaceDefinitionParser.java Wed Feb  6 12:01:54 2008
@@ -38,9 +38,17 @@
         NodeList nodes = element.getChildNodes();
         for (int i = 0; i < nodes.getLength(); i++) {
             Node n = nodes.item(i);
-            if (n.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
+            if (n.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE
+//                &&
+//                n.getNodeName().equals("bean")) {
+//                Element childElement = (Element)n;
+//                BeanDefinitionHolder child = ctx.getDelegate().parseBeanDefinitionElement(childElement);
+//                collections.add(child);
+//            } else if (n.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE &&
+//                n.getNodeName().equals("ref")
+                ) {
                 Element childElement = (Element)n;
-                BeanDefinitionHolder child = ctx.getDelegate().parseBeanDefinitionElement(childElement);
+                Object child = ctx.getDelegate().parsePropertySubElement(childElement, bean.getRawBeanDefinition());
                 collections.add(child);
             }
 

Modified: incubator/abdera/java/trunk/spring/src/main/resources/META-INF/schemas/abdera-spring.xsd
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/spring/src/main/resources/META-INF/schemas/abdera-spring.xsd?rev=619130&r1=619129&r2=619130&view=diff
==============================================================================
--- incubator/abdera/java/trunk/spring/src/main/resources/META-INF/schemas/abdera-spring.xsd (original)
+++ incubator/abdera/java/trunk/spring/src/main/resources/META-INF/schemas/abdera-spring.xsd Wed Feb  6 12:01:54 2008
@@ -1,76 +1,90 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements. See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership. The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License. You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing,
-  software distributed under the License is distributed on an
-  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-  KIND, either express or implied. See the License for the
-  specific language governing permissions and limitations
-  under the License.
--->
-<xsd:schema
-  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-  xmlns:beans="http://www.springframework.org/schema/beans"
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
-  targetNamespace="http://abdera.apache.org" 
-  elementFormDefault="qualified"
-  attributeFormDefault="unqualified"  >
-
-  <xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"/>
-  <xsd:element name="provider">
-    <xsd:complexType>
-      <xsd:complexContent>
-        <xsd:extension base="beans:identifiedType">
-          <xsd:sequence>
-            <xsd:element name="workspace" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded"/>
-            <xsd:element name="workspaceManager" type="xsd:anyType" minOccurs="0"/>
-            <xsd:element name="targetResolver" type="xsd:anyType" minOccurs="0"/>
-            <xsd:element name="subjectResolver" type="xsd:anyType" minOccurs="0"/>
-          </xsd:sequence>
-          <xsd:attribute name="class" type="xsd:string" />
-          <xsd:attribute name="base" type="xsd:string"/>
-        </xsd:extension>
-      </xsd:complexContent>
-    </xsd:complexType>
-  </xsd:element>
-
-  <xsd:element name="workspace">
-    <xsd:complexType>
-      <xsd:complexContent>
-        <xsd:extension base="beans:identifiedType">
-          <xsd:sequence>
-            <xsd:element ref="beans:bean" minOccurs="0" maxOccurs="unbounded"/>
-            <xsd:element ref="beans:ref" minOccurs="0" maxOccurs="unbounded"/>
-          </xsd:sequence>
-          <xsd:attribute name="title" type="xsd:string"/>
-        </xsd:extension>
-      </xsd:complexContent>
-    </xsd:complexType>
-  </xsd:element>
-  
-  <xsd:element name="regexTargetResolver">
-    <xsd:complexType>
-      <xsd:complexContent>
-        <xsd:extension base="beans:identifiedType">
-          <xsd:choice maxOccurs="unbounded">
-            <xsd:element name="category" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded"/>
-            <xsd:element name="collection" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded"/>
-            <xsd:element name="entry" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded"/>
-            <xsd:element name="media" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded"/>
-            <xsd:element name="service" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded"/>
-          </xsd:choice>
-        </xsd:extension>
-      </xsd:complexContent>
-    </xsd:complexType>
-  </xsd:element>
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<xsd:schema
+  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+  xmlns:beans="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
+  targetNamespace="http://abdera.apache.org" 
+  elementFormDefault="qualified"
+  attributeFormDefault="unqualified"  >
+
+  <xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"/>
+  <xsd:element name="provider">
+    <xsd:complexType>
+      <xsd:complexContent>
+        <xsd:extension base="beans:identifiedType">
+          <xsd:sequence>
+            <xsd:element name="workspace" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded"/>
+            <xsd:element name="workspaceManager" type="xsd:anyType" minOccurs="0"/>
+            <xsd:element name="targetResolver" type="xsd:anyType" minOccurs="0"/>
+            <xsd:element name="subjectResolver" type="xsd:anyType" minOccurs="0"/>
+            <xsd:element name="filter" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded"/>
+          </xsd:sequence>
+          <xsd:attribute name="class" type="xsd:string" />
+          <xsd:attribute name="base" type="xsd:string"/>
+        </xsd:extension>
+      </xsd:complexContent>
+    </xsd:complexType>
+  </xsd:element>
+
+  <xsd:element name="workspace">
+    <xsd:complexType>
+      <xsd:complexContent>
+        <xsd:extension base="beans:identifiedType">
+          <xsd:sequence>
+            <xsd:element ref="beans:bean" minOccurs="0" maxOccurs="unbounded"/>
+            <xsd:element ref="beans:ref" minOccurs="0" maxOccurs="unbounded"/>
+          </xsd:sequence>
+          <xsd:attribute name="title" type="xsd:string"/>
+        </xsd:extension>
+      </xsd:complexContent>
+    </xsd:complexType>
+  </xsd:element>
+  
+  <xsd:element name="regexTargetResolver">
+    <xsd:complexType>
+      <xsd:complexContent>
+        <xsd:extension base="beans:identifiedType">
+          <xsd:choice maxOccurs="unbounded">
+            <xsd:element name="category" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded"/>
+            <xsd:element name="collection" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded"/>
+            <xsd:element name="entry" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded"/>
+            <xsd:element name="media" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded"/>
+            <xsd:element name="service" type="xsd:anyType" minOccurs="0" maxOccurs="unbounded"/>
+          </xsd:choice>
+        </xsd:extension>
+      </xsd:complexContent>
+    </xsd:complexType>
+  </xsd:element>
+
+  <xsd:element name="filter">
+    <xsd:complexType>
+      <xsd:complexContent>
+        <xsd:extension base="beans:identifiedType">
+          <xsd:sequence>
+            <xsd:element ref="beans:bean" minOccurs="0" maxOccurs="unbounded"/>
+            <xsd:element ref="beans:ref" minOccurs="0" maxOccurs="unbounded"/>
+          </xsd:sequence>
+        </xsd:extension>
+      </xsd:complexContent>
+    </xsd:complexType>
+  </xsd:element>
 </xsd:schema>

Added: incubator/abdera/java/trunk/spring/src/test/java/org/apache/abdera/spring/DummyFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/spring/src/test/java/org/apache/abdera/spring/DummyFilter.java?rev=619130&view=auto
==============================================================================
--- incubator/abdera/java/trunk/spring/src/test/java/org/apache/abdera/spring/DummyFilter.java (added)
+++ incubator/abdera/java/trunk/spring/src/test/java/org/apache/abdera/spring/DummyFilter.java Wed Feb  6 12:01:54 2008
@@ -0,0 +1,15 @@
+package org.apache.abdera.spring;
+
+import org.apache.abdera.protocol.server.Filter;
+import org.apache.abdera.protocol.server.FilterChain;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.ResponseContext;
+
+public class DummyFilter
+    implements Filter {
+
+    public ResponseContext filter(RequestContext request, FilterChain chain) {
+        return chain.next(request);
+    }
+
+}

Modified: incubator/abdera/java/trunk/spring/src/test/java/org/apache/abdera/spring/ProviderDefinitionParserTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/spring/src/test/java/org/apache/abdera/spring/ProviderDefinitionParserTest.java?rev=619130&r1=619129&r2=619130&view=diff
==============================================================================
--- incubator/abdera/java/trunk/spring/src/test/java/org/apache/abdera/spring/ProviderDefinitionParserTest.java (original)
+++ incubator/abdera/java/trunk/spring/src/test/java/org/apache/abdera/spring/ProviderDefinitionParserTest.java Wed Feb  6 12:01:54 2008
@@ -52,7 +52,9 @@
         assertEquals("Foo Workspace", w.getTitle(null));
         
         Collection<CollectionInfo> collections = w.getCollections(null);
-        assertEquals(1, collections.size());
+        assertEquals(2, collections.size());
+        
+        assertEquals(1, p.getFilters(null).length); //Parameter isn't used
         
     }
     

Modified: incubator/abdera/java/trunk/spring/src/test/resources/org/apache/abdera/spring/beans.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/spring/src/test/resources/org/apache/abdera/spring/beans.xml?rev=619130&r1=619129&r2=619130&view=diff
==============================================================================
--- incubator/abdera/java/trunk/spring/src/test/resources/org/apache/abdera/spring/beans.xml (original)
+++ incubator/abdera/java/trunk/spring/src/test/resources/org/apache/abdera/spring/beans.xml Wed Feb  6 12:01:54 2008
@@ -1,28 +1,32 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
-  xmlns:a="http://abdera.apache.org"
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="
-    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
-    http://abdera.apache.org http://abdera.apache.org/schemas/abdera-spring.xsd">
-
-  <!-- Abdera -->
-  <a:provider>
-  
-    <a:workspace title="Foo Workspace">
-      <!-- These are our collections -->
-      <bean class="org.apache.abdera.spring.TestAdapter"/>
-    </a:workspace>
-    
-    <!-- It is not necessary to specify this, but we're testing it -->
-    <a:targetResolver>
-      <a:regexTargetResolver>
-        <a:collection>/atom/feed(\?[^#]*)?</a:collection>
-        <a:entry>/atom/feed/([^/#?]+)(\?[^#]*)?</a:entry>
-        <a:service>/atom(\?[^#]*)?</a:service>
-      </a:regexTargetResolver>
-    </a:targetResolver>
-    
-  </a:provider>
-
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:a="http://abdera.apache.org"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="
+    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+    http://abdera.apache.org http://abdera.apache.org/schemas/abdera-spring.xsd">
+
+  <!-- Abdera -->
+  <a:provider>
+  
+    <a:workspace title="Foo Workspace">
+      <!-- These are our collections -->
+      <bean class="org.apache.abdera.spring.TestAdapter"/>
+      <ref bean="referencedAdapter"/>
+    </a:workspace>
+    
+    <!-- It is not necessary to specify this, but we're testing it -->
+    <a:targetResolver>
+      <a:regexTargetResolver>
+        <a:collection>/atom/feed(\?[^#]*)?</a:collection>
+        <a:entry>/atom/feed/([^/#?]+)(\?[^#]*)?</a:entry>
+        <a:service>/atom(\?[^#]*)?</a:service>
+      </a:regexTargetResolver>
+    </a:targetResolver>
+    <a:filter>
+      <bean class="org.apache.abdera.spring.DummyFilter"/>
+    </a:filter>    
+  </a:provider>
+  <bean id="referencedAdapter" class="org.apache.abdera.spring.TestAdapter"/>
+
 </beans>