cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1079392 - in /cxf/trunk/rt/core/src: main/java/org/apache/cxf/bus/extension/ main/resources/META-INF/cxf/ test/java/org/apache/cxf/bus/extension/
Date Tue, 08 Mar 2011 15:25:46 GMT
Author: cschneider
Date: Tue Mar  8 15:25:45 2011
New Revision: 1079392

URL: http://svn.apache.org/viewvc?rev=1079392&view=rev
Log:
Refactored ExtensionFragmentParser, added a test and some documentation

Added:
    cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/extension/extension2.txt   (with props)
Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionFragmentParser.java
    cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
    cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/extension/ExtensionFragmentParserTest.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionFragmentParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionFragmentParser.java?rev=1079392&r1=1079391&r2=1079392&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionFragmentParser.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionFragmentParser.java
Tue Mar  8 15:25:45 2011
@@ -52,44 +52,53 @@ public class ExtensionFragmentParser {
         
         return deserialiseExtensions(document);
     }
+    
+    /**
+     * Reads extension definitions from a Text file and instantiates them
+     * The text file has the following syntax
+     * classname:interfacename:deferred(true|false)
+     * 
+     * @param is stream to read the extension from
+     * @return list of Extensions
+     * @throws IOException
+     */
     List<Extension> getExtensionsFromText(InputStream is) throws IOException {
         List<Extension> extensions = new ArrayList<Extension>();
         BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
         String line = reader.readLine();
         while (line != null) {
-            line = line.trim();
-            if (line.length() > 0 && line.charAt(0) != '#') {
-                Extension ext = new Extension();
-                int idx = line.indexOf(':');
-                if (idx != -1) {
-                    ext.setClassname(line.substring(0, idx));
-                    line = line.substring(idx + 1);
-                } else {
-                    ext.setClassname(line);
-                    line = null;
-                }
-                if (line != null) {
-                    idx = line.indexOf(':');
-                    if (idx != -1) {
-                        ext.setInterfaceName(line.substring(0, idx));
-                        line = line.substring(idx + 1);
-                    } else {
-                        ext.setInterfaceName(line);
-                        line = null;
-                    }
-                }
-                if (line != null) {
-                    ext.setDeferred(Boolean.parseBoolean(line));
-                }
-                if (ext.getClassname() != null) {
-                    extensions.add(ext);
-                }
+            final Extension extension = getExtensionFromTextLine(line);
+            if (extension != null) {
+                extensions.add(extension);
             }
-            
             line = reader.readLine();
         }
         return extensions;
     }
+
+    private Extension getExtensionFromTextLine(String line) {
+        line = line.trim();
+        if (line.length() == 0 || line.charAt(0) == '#') {
+            return null;
+        }
+        final Extension ext = new Extension();
+        String[] parts = line.split(":");
+        ext.setClassname(parts[0]);
+        if (ext.getClassname() == null) {
+            return null;
+        }
+        if (parts.length >= 2) {
+            String interfaceName = parts[1];
+            if (interfaceName != null && interfaceName.isEmpty()) {
+                interfaceName = null;
+            }
+            ext.setInterfaceName(interfaceName);
+        }
+        if (parts.length >= 3) {
+            ext.setDeferred(Boolean.parseBoolean(parts[2]));
+        }
+        return ext;
+    }
     
     List<Extension> deserialiseExtensions(Document document) {
         List<Extension> extensions = new ArrayList<Extension>();

Modified: cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml?rev=1079392&r1=1079391&r2=1079392&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml (original)
+++ cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml Tue Mar  8 15:25:45 2011
@@ -24,7 +24,7 @@
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
 
-	<!--  For Testing using the Swing commons processor, uncomment one of:--> 
+	<!--  For Testing using the Spring commons processor, uncomment one of:--> 
 	<!-- 
 		<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>
 		<context:annotation-config/>

Modified: cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/extension/ExtensionFragmentParserTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/extension/ExtensionFragmentParserTest.java?rev=1079392&r1=1079391&r2=1079392&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/extension/ExtensionFragmentParserTest.java
(original)
+++ cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/extension/ExtensionFragmentParserTest.java
Tue Mar  8 15:25:45 2011
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.bus.extension;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collection;
 import java.util.List;
@@ -29,7 +30,7 @@ import org.junit.Test;
 public class ExtensionFragmentParserTest extends Assert {
 
     @Test
-    public void testGetExtensions() {
+    public void testGetExtensionsFromXml() {
         InputStream is = ExtensionFragmentParserTest.class.getResourceAsStream("extension1.xml");
         List<Extension> extensions = new ExtensionFragmentParser().getExtensionsFromXML(is);
         assertEquals("Unexpected number of Extension elements.", 3, extensions.size());
@@ -55,4 +56,23 @@ public class ExtensionFragmentParserTest
         }
         assertEquals("Unexpected number of namespace elements.", 1, namespaces.size());
     }
+    
+    @Test
+    public void testGetExtensionsFromText() throws IOException {
+        InputStream is = ExtensionFragmentParserTest.class.getResourceAsStream("extension2.txt");
+        List<Extension> extensions = new ExtensionFragmentParser().getExtensionsFromText(is);
+        assertEquals("Unexpected number of Extension elements.", 3, extensions.size());
+        
+        Extension e = extensions.get(0);
+        assertTrue("Extension is deferred.", !e.isDeferred());
+        assertEquals("Unexpected class name.", 
+                     "org.apache.cxf.foo.FooImpl", e.getClassname());
+        assertEquals("Unexpected number of namespace elements.", 0, e.getNamespaces().size());
+        e = extensions.get(1);
+        assertTrue("Extension is not deferred.", e.isDeferred());
+        assertEquals("Unexpected implementation class name.", 
+                     "java.lang.Boolean", e.getClassname());
+        assertNull("Interface should be null", e.getInterfaceName());
+        assertEquals("Unexpected number of namespace elements.", 0, e.getNamespaces().size());
+    }
 }

Added: cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/extension/extension2.txt
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/extension/extension2.txt?rev=1079392&view=auto
==============================================================================
--- cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/extension/extension2.txt (added)
+++ cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/extension/extension2.txt Tue Mar  8
15:25:45 2011
@@ -0,0 +1,5 @@
+# Comment
+ # Comment2
+org.apache.cxf.foo.FooImpl:org.apache.cxf.foo.Foo
+java.lang.Boolean::true
+java.lang.Long::true

Propchange: cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/extension/extension2.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message