db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1195305 - in /db/torque/torque4/trunk/torque-generator/src: main/java/org/apache/torque/generator/source/ test/java/org/apache/torque/generator/source/
Date Mon, 31 Oct 2011 02:00:29 GMT
Author: tfischer
Date: Mon Oct 31 02:00:29 2011
New Revision: 1195305

URL: http://svn.apache.org/viewvc?rev=1195305&view=rev
Log:
allow * wildcard in xpath-like expressions

Modified:
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourcePath.java
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProvider.java
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/SourcePathTest.java

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourcePath.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourcePath.java?rev=1195305&r1=1195304&r2=1195305&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourcePath.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourcePath.java
Mon Oct 31 02:00:29 2011
@@ -49,6 +49,11 @@ public final class SourcePath
     private static final String PARENT_TOKEN = "..";
 
     /**
+     * The token denoting the parent element.
+     */
+    private static final String ANY_ELEMENT_TOKEN = "*";
+
+    /**
      * Private constructor for utility class.
      */
     private SourcePath()
@@ -174,7 +179,8 @@ public final class SourcePath
             SourceElement sameLevelElement = sameLevelIt.previous();
             // skip first iterated element because it is input element,
             // but we want to begin before the input element.
-            if (first) {
+            if (first)
+            {
                 first = false;
                 continue;
             }
@@ -318,7 +324,14 @@ public final class SourcePath
                         nextSelection.add(parent);
                     }
                 }
-                else
+                else if (ANY_ELEMENT_TOKEN.equals(childName))
+                {
+                    for (SourceElement child
+                            : currentElement.getChildren())
+                    {
+                        nextSelection.add(child);
+                    }
+                }
                 {
                     for (SourceElement child
                             : currentElement.getChildren(childName))
@@ -338,7 +351,7 @@ public final class SourcePath
      * otherwise nothing is selected.
      *
      * @param rootElement the root element of the source tree, not null.
-     * @param path the path to use, null selects the root element..
+     * @param path the path to use, null selects the root element.
      *
      * @return the list of matching source elements, not null, may be empty.
      *
@@ -381,7 +394,8 @@ public final class SourcePath
             firstElementName = path.substring(0, firstSeparatorPos);
             path = path.substring(firstSeparatorPos + 1);
         }
-        if (!rootElement.getName().equals(firstElementName))
+        if (!ANY_ELEMENT_TOKEN.equals(firstElementName)
+                && !rootElement.getName().equals(firstElementName))
         {
             return new ArrayList<SourceElement>();
         }

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProvider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProvider.java?rev=1195305&r1=1195304&r2=1195305&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProvider.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/source/SourceProvider.java
Mon Oct 31 02:00:29 2011
@@ -124,4 +124,15 @@ public abstract class SourceProvider imp
     {
         return initialized;
     }
+
+    /**
+     * Returns a copy of this source provider in its initial state.
+     * This means the
+     * {@link #init(ConfigurationHandlers, ControllerState)}
+     * method of the new source provider must be called before it can be used.
+     *
+     * @throws ConfigurationException if the new SourceProvider cannot
+     *         be initialized.
+     */
+    public abstract SourceProvider copy() throws ConfigurationException;
 }

Modified: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/SourcePathTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/SourcePathTest.java?rev=1195305&r1=1195304&r2=1195305&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/SourcePathTest.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/source/SourcePathTest.java
Mon Oct 31 02:00:29 2011
@@ -26,8 +26,6 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.torque.generator.GeneratorException;
-import org.apache.torque.generator.source.SourceElement;
-import org.apache.torque.generator.source.SourcePath;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -75,6 +73,16 @@ public class SourcePathTest
     }
 
     @Test
+    public void testGetElementFromRootWithSlash()
+    {
+        List<SourceElement> result
+                = SourcePath.getElementsFromRoot(root, "/");
+        List<SourceElement> expected = new ArrayList<SourceElement>();
+        expected.add(root);
+        assertEquals(expected, result);
+    }
+
+    @Test
     public void testGetElementFromRootSingleRelativeElement()
     {
         List<SourceElement> result
@@ -111,6 +119,48 @@ public class SourcePathTest
     }
 
     @Test
+    public void testGetElementFromRootWildcardAtStart()
+    {
+        List<SourceElement> result
+                = SourcePath.getElementsFromRoot(root, "/*");
+        List<SourceElement> expected = new ArrayList<SourceElement>();
+        expected.add(root);
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void testGetElementFromRootWildcardInMiddle()
+    {
+        List<SourceElement> result
+                = SourcePath.getElementsFromRoot(root, "/root/*/secondLevel");
+        List<SourceElement> expected = new ArrayList<SourceElement>();
+        expected.add(secondLevel);
+        assertEquals(expected, result);
+    }
+
+// does not yet work
+//    @Test
+//    public void testGetElementFromRootBacktoRootWithParent()
+//    {
+//        List<SourceElement> result
+//                = SourcePath.getElementsFromRoot(root, "/root/../root");
+//        List<SourceElement> expected = new ArrayList<SourceElement>();
+//        expected.add(root);
+//        assertEquals(expected, result);
+//    }
+
+    @Test
+    public void testGetElementFromRootParentInMiddle()
+    {
+        List<SourceElement> result = SourcePath.getElementsFromRoot(
+                root,
+                "/root/firstLevel1/../firstLevel2");
+        List<SourceElement> expected = new ArrayList<SourceElement>();
+        expected.add(firstLevel2);
+        assertEquals(expected, result);
+    }
+
+    @Test
     public void testGetPreceding()
     {
         List<SourceElement> result



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message