[jboss-cvs] JBossAS SVN: r68923 - in projects/aop/branches/joinpoint_graph/aop/src: main/org/jboss/aop/joinpoint/graph/tree/search/match and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Jan 12 14:16:06 EST 2008


Author: flavia.rainone at jboss.com
Date: 2008-01-12 14:16:05 -0500 (Sat, 12 Jan 2008)
New Revision: 68923

Modified:
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/element/ComparableElementFactory.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherFactory.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherSequenceProfile.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/match/package.html
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/part/ComparableKeyPartFactory.java
   projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/TreeSearchTest.java
   projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherFactoryTest.java
   projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherTest.java
Log:
[JBAOP-503] Added support to search keys that end with ".."

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/element/ComparableElementFactory.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/element/ComparableElementFactory.java	2008-01-12 16:10:16 UTC (rev 68922)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/element/ComparableElementFactory.java	2008-01-12 19:16:05 UTC (rev 68923)
@@ -75,19 +75,19 @@
       // sequence for simple part
       this.profiles[MatcherProfile.SIMPLE.getId()] = new MatcherSequenceProfile(
            MatcherProfile.SIMPLE, MatcherProfile.SIMPLE,
-           MatcherProfile.SIMPLE, MatcherProfile.SIMPLE);
+           MatcherProfile.SIMPLE, MatcherProfile.SUFFIX, MatcherProfile.SIMPLE);
       // sequence for prefix part
       this.profiles[MatcherProfile.PREFIX.getId()] = new MatcherSequenceProfile(
             MatcherProfile.SIMPLE, MatcherProfile.SIMPLE,
-            MatcherProfile.PREFIX, MatcherProfile.PREFIX);
+            MatcherProfile.PREFIX, null, MatcherProfile.PREFIX);
       // sequence for pattern part
       this.profiles[MatcherProfile.PATTERN.getId()] = new MatcherSequenceProfile(
             MatcherProfile.SUFFIX, MatcherProfile.SIMPLE,
-            MatcherProfile.PREFIX, MatcherProfile.PATTERN);
+            MatcherProfile.PREFIX, null, MatcherProfile.PATTERN);
       // sequence for suffix part
       this.profiles[MatcherProfile.SUFFIX.getId()] = new MatcherSequenceProfile(
             MatcherProfile.SUFFIX, MatcherProfile.SIMPLE,
-            MatcherProfile.SIMPLE, MatcherProfile.SUFFIX);
+            MatcherProfile.SIMPLE, MatcherProfile.SUFFIX, MatcherProfile.SUFFIX);
    }
    
    /**

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherFactory.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherFactory.java	2008-01-12 16:10:16 UTC (rev 68922)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherFactory.java	2008-01-12 19:16:05 UTC (rev 68923)
@@ -77,7 +77,21 @@
                profile.uniqueMatcherProfile);
          matchers.add(new Matcher(profile.uniqueMatcherProfile, comparable));
       }
-      else {
+      else
+      {
+         int length = matchableExpression.length();
+         MatcherProfile suffixMatcherProfile = profile.lastMatcherProfile;
+         if (length > 1 && matchableExpression.charAt(length -1) == separator &&
+               matchableExpression.charAt(length -2) == separator)
+         {
+            if (profile.doubleSeparatorMatcherProfile == null)
+            {
+               throw new RuntimeException("Double separator suffix not supported: "
+                     + matchableExpression);
+            }
+            matchableExpression = matchableExpression.substring(0, length - 1);
+            suffixMatcherProfile = profile.doubleSeparatorMatcherProfile;
+         }
          // create first matcher
          expression = matchableExpression.substring(begin, end);
          comparable = comparableFactory.create(expression,
@@ -97,9 +111,8 @@
          }
          // create last matcher
          expression = matchableExpression.substring(begin);
-         comparable = comparableFactory.create(expression,
-               profile.lastMatcherProfile);
-         matchers.add(new Matcher(profile.lastMatcherProfile, comparable));
+         comparable = comparableFactory.create(expression, suffixMatcherProfile);
+         matchers.add(new Matcher(suffixMatcherProfile, comparable));
       }
       // invoke factory notification method
       comparableFactory.stopCreation();

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherSequenceProfile.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherSequenceProfile.java	2008-01-12 16:10:16 UTC (rev 68922)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherSequenceProfile.java	2008-01-12 19:16:05 UTC (rev 68923)
@@ -48,6 +48,13 @@
    MatcherProfile lastMatcherProfile;
    
    /**
+    * The profile of the double separator matcher. This profile replaces
+    * {@code lastMatcherProfile} only if the matchable expression ends with a 
+    * double separator (two separator characters in a row).
+    */
+   MatcherProfile doubleSeparatorMatcherProfile;
+   
+   /**
     * The profile of the unique matcher in the sequence, utilized by
     * {@link MatcherFactory} when the sequence contains only one matcher.
     */
@@ -56,33 +63,44 @@
    /**
     * Constructor. Creates the profile of an entire sequence of matchers.
     * 
-    * @param firstMatcherProfile   the profile of the first matcher in the
-    *                              sequence
-    * @param middleMatchersProfile the profile of all matchers in the sequence
-    *                              that not the first nor the last ones
-    * @param lastMatcherProfile    the profile of the last matcher in the
-    *                              sequence
-    * @param uniqueMatcherProfile  the profile used in the unique matcher in the
-    *                              sequence, utilized by <code>MatcherFactory
-    *                              </code> when the sequence contains only one
-    *                              matcher
+    * @param firstMatcherProfile           the profile of the first matcher in the
+    *                                      sequence
+    * @param middleMatchersProfile         the profile of all matchers in the
+    *                                      sequence that not the first nor the last
+    *                                      ones
+    * @param lastMatcherProfile            the profile of the last matcher in the
+    *                                      sequence
+    * @param doubleSeparatorMatcherProfile the profile of the double separator
+    *                                      matcher. This profile replaces
+    *                                      {@code lastMatcherProfile} only if the
+    *                                      matchable expression ends with a double
+    *                                      separator (two separator characters in a
+    *                                      row). Can be {@code null} if the double
+    *                                      separator suffix feature is not supported.
+    * @param uniqueMatcherProfile          the profile used in the unique matcher in
+    *                                      the sequence, utilized by {@code
+    *                                      MatcherFactory} when the sequence contains
+    *                                      only one matcher
     * @see MatcherFactory
     */
    public MatcherSequenceProfile(MatcherProfile firstMatcherProfile,
    MatcherProfile middleMatchersProfile,
    MatcherProfile lastMatcherProfile,
+   MatcherProfile doubleSeparatorMatcherProfile,
    MatcherProfile uniqueMatcherProfile)
    {
       this.firstMatcherProfile = firstMatcherProfile;
       this.middleMatchersProfile = middleMatchersProfile;
       this.lastMatcherProfile = lastMatcherProfile;
+      this.doubleSeparatorMatcherProfile = doubleSeparatorMatcherProfile;
       this.uniqueMatcherProfile = uniqueMatcherProfile;
    }
    
    public String toString()
    {
       return "[first=" + firstMatcherProfile + ", middle=" +
-         middleMatchersProfile + ", last=" + lastMatcherProfile + ", unique=" +
+         middleMatchersProfile + ", last=" + lastMatcherProfile +
+         ", doubleSeparator=" + doubleSeparatorMatcherProfile + ", unique=" +
          uniqueMatcherProfile + "]";
    }
 }
\ No newline at end of file

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/match/package.html
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/match/package.html	2008-01-12 16:10:16 UTC (rev 68922)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/match/package.html	2008-01-12 19:16:05 UTC (rev 68923)
@@ -37,7 +37,7 @@
 expression</i>, against a <i>complete target</i>.</p>
 <p>
 In order for the matching process to take place, the matchable expression is
-scattered into smaller parts. Each part is associated with a {@link 
+splitten into smaller parts. Each part is associated with a {@link 
 org.jboss.aop.joinpoint.graph.tree.search.match.Matcher matcher}, responsible for matching its
 part against a complete target part, which we will call, for simplicity, just
 <i>target</i> (so, we can state that a complete target is the result of the
@@ -67,7 +67,10 @@
 The client is responsible for specifying the profile of the matchers contained
 in the sequence. It can specify the profile of: the first matcher, the last
 matcher, the middle ones, and the unique matcher (this one is generated when the
-matchers sequence contains only one element).
+matchers sequence contains only one element). Additionally, an optional fourth
+matcher type can also be specified: the double separator suffix matcher. This type
+will repalce the last matcher type when the comparable expression ends with two
+separators in a row.
 </p>
 <p>
 The extensibility in this package is on the {@link

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/part/ComparableKeyPartFactory.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/part/ComparableKeyPartFactory.java	2008-01-12 16:10:16 UTC (rev 68922)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/search/part/ComparableKeyPartFactory.java	2008-01-12 19:16:05 UTC (rev 68923)
@@ -71,7 +71,7 @@
    {
       parts = new ArrayList<ComparableKeyPart>();
       matcherSeqProfile = new MatcherSequenceProfile(MatcherProfile.PREFIX,
-            MatcherProfile.PATTERN, MatcherProfile.SUFFIX,
+            MatcherProfile.PATTERN, MatcherProfile.SUFFIX, null,
             MatcherProfile.SIMPLE);
    }
    

Modified: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/TreeSearchTest.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/TreeSearchTest.java	2008-01-12 16:10:16 UTC (rev 68922)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/TreeSearchTest.java	2008-01-12 19:16:05 UTC (rev 68923)
@@ -34,11 +34,11 @@
  */
 public class TreeSearchTest extends TestCase
 {
-   Tree tree;
+   Tree<String> tree;
    
    public void setUp()
    {
-      tree = new Tree();
+      tree = new Tree<String>();
       tree.insert("com.company.package.Class", "A1");
       tree.insert("com.company.package.Class1", "B1");
       tree.insert("com.company.package.Class2", "C1");
@@ -1664,6 +1664,13 @@
       assertEquals(1, result.size());
       assertContent(result, "U1");
    }
+   
+   public void testComCompAnyPackageDoubleDot()
+   {
+      Collection result = tree.search("com.comp.any.package..");
+      assertEquals(9, result.size());
+      assertContent(result, 'P', 1, 'X', 1);
+   }
 
    public void testComCompAnyInternalPackageInterface()
    {

Modified: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherFactoryTest.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherFactoryTest.java	2008-01-12 16:10:16 UTC (rev 68922)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherFactoryTest.java	2008-01-12 19:16:05 UTC (rev 68923)
@@ -46,13 +46,17 @@
 {
    private ComparableFactoryImpl factory;
    private MatcherSequenceProfile seqProfile;
+   private MatcherSequenceProfile doubleWildcardSeqProfile;
    
    public void setUp()
    {
       this.factory = new ComparableFactoryImpl();
       this.seqProfile = new MatcherSequenceProfile(
             MatcherProfile.PREFIX, MatcherProfile.PATTERN,
-            MatcherProfile.SUFFIX, MatcherProfile.SIMPLE);
+            MatcherProfile.SUFFIX, null, MatcherProfile.SIMPLE);
+      this.doubleWildcardSeqProfile = new MatcherSequenceProfile(
+            MatcherProfile.PREFIX, MatcherProfile.PATTERN,
+            MatcherProfile.SUFFIX, MatcherProfile.PREFIX, MatcherProfile.SIMPLE);
    }
    
    public void testSimpleMatchableExpression()
@@ -72,6 +76,23 @@
       assertEquals("slash", comparables[3].expression);
    }
    
+   public void testSimpleMatchableExpressionDoubleProfile()
+   {
+      MatcherFactory.createSequence("anything/splitten/by/slash", factory,
+            doubleWildcardSeqProfile);
+      ComparableImpl[] comparables = new ComparableImpl[4];
+      assertEquals(4, factory.created.size());
+      comparables = (ComparableImpl[]) factory.created.toArray(comparables);
+      assertEquals(MatcherProfile.PREFIX, comparables[0].profile);
+      assertEquals("anything", comparables[0].expression);
+      assertEquals(MatcherProfile.PATTERN, comparables[1].profile);
+      assertEquals("splitten", comparables[1].expression);
+      assertEquals(MatcherProfile.PATTERN, comparables[2].profile);
+      assertEquals("by", comparables[2].expression);
+      assertEquals(MatcherProfile.SUFFIX, comparables[3].profile);
+      assertEquals("slash", comparables[3].expression);
+   }
+   
    public void testEmptyPrefixMatchableExpression()
    {
       MatcherFactory.createSequence("/splitten/by/slash", factory, seqProfile);
@@ -148,12 +169,72 @@
       MatcherFactory.createSequence("uniqueComparableExpression", factory,
             seqProfile);
       assertEquals(1, factory.created.size());
-      ComparableImpl[] comparables = new ComparableImpl[0];
+      ComparableImpl[] comparables = new ComparableImpl[1];
       comparables = (ComparableImpl[]) factory.created.toArray(comparables);
       assertEquals(MatcherProfile.SIMPLE, comparables[0].profile);
       assertEquals("uniqueComparableExpression", comparables[0].expression);
    }
    
+   public void testInvalidDoubleWildcardMatchableExpresssion()
+   {
+      boolean thrown = false;
+      try
+      {
+         MatcherFactory.createSequence("doubleWildcardComparableExpression//", factory,
+            seqProfile);
+      }
+      catch (RuntimeException e)
+      {
+         thrown = true;
+      }
+      assertTrue(thrown);
+   }
+   
+   public void testDoubleWildcardMatchableExpresssion1()
+   {
+      MatcherFactory.createSequence("doubleWildcardComparableExpression//", factory,
+            doubleWildcardSeqProfile);
+      assertEquals(2, factory.created.size());
+      ComparableImpl[] comparables = new ComparableImpl[2];
+      comparables = (ComparableImpl[]) factory.created.toArray(comparables);
+      assertEquals(MatcherProfile.PREFIX, comparables[0].profile);
+      assertEquals(MatcherProfile.PREFIX, comparables[1].profile);
+      assertEquals("doubleWildcardComparableExpression", comparables[0].expression);
+      assertEquals("", comparables[1].expression);
+   }
+   
+   public void testDoubleWildcardMatchableExpresssion2()
+   {
+      MatcherFactory.createSequence("double/WildcardComparableExpression//", factory,
+            doubleWildcardSeqProfile);
+      assertEquals(3, factory.created.size());
+      ComparableImpl[] comparables = new ComparableImpl[2];
+      comparables = (ComparableImpl[]) factory.created.toArray(comparables);
+      assertEquals(MatcherProfile.PREFIX, comparables[0].profile);
+      assertEquals(MatcherProfile.PATTERN, comparables[1].profile);
+      assertEquals(MatcherProfile.PREFIX, comparables[2].profile);
+      assertEquals("double", comparables[0].expression);
+      assertEquals("WildcardComparableExpression", comparables[1].expression);
+      assertEquals("", comparables[2].expression);
+   }
+   
+   public void testDoubleWildcardMatchableExpresssion3()
+   {
+      MatcherFactory.createSequence("double/WildcardComparable/Expression//", factory,
+            doubleWildcardSeqProfile);
+      assertEquals(4, factory.created.size());
+      ComparableImpl[] comparables = new ComparableImpl[2];
+      comparables = (ComparableImpl[]) factory.created.toArray(comparables);
+      assertEquals(MatcherProfile.PREFIX, comparables[0].profile);
+      assertEquals(MatcherProfile.PATTERN, comparables[1].profile);
+      assertEquals(MatcherProfile.PATTERN, comparables[2].profile);
+      assertEquals(MatcherProfile.PREFIX, comparables[3].profile);
+      assertEquals("double", comparables[0].expression);
+      assertEquals("WildcardComparable", comparables[1].expression);
+      assertEquals("Expression", comparables[2].expression);
+      assertEquals("", comparables[3].expression);
+   }
+   
    /**
     * Implementation of <code>ComparableFactory</code>. For tests purpose.
     * 
@@ -161,7 +242,7 @@
     */
    private class ComparableFactoryImpl implements ComparableFactory
    {
-      Collection created = new ArrayList();
+      Collection<Comparable> created = new ArrayList<Comparable>();
       
       public char getSeparator()
       {

Modified: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherTest.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherTest.java	2008-01-12 16:10:16 UTC (rev 68922)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/search/match/MatcherTest.java	2008-01-12 19:16:05 UTC (rev 68923)
@@ -54,7 +54,7 @@
    {
       MatcherSequenceProfile seqProfile = new MatcherSequenceProfile(
             MatcherProfile.PREFIX, MatcherProfile.SIMPLE,
-            MatcherProfile.SUFFIX, MatcherProfile.PATTERN);
+            MatcherProfile.SUFFIX, null, MatcherProfile.PATTERN);
       ComparableElementFactory factory = ComparableElementFactory.getInstance();
       factory.performCreationForProfile(MatcherProfile.PATTERN);
       matcherSequence = MatcherFactory.createSequence(
@@ -63,7 +63,7 @@
             ComparableElementFactory.getInstance(), seqProfile);
       suffixMatcherSequence = MatcherFactory.createSequence("toCompare",
             factory, new MatcherSequenceProfile(MatcherProfile.SUFFIX,
-            MatcherProfile.SUFFIX, MatcherProfile.SUFFIX, MatcherProfile.SUFFIX));
+            MatcherProfile.SUFFIX, MatcherProfile.SUFFIX, null, MatcherProfile.SUFFIX));
       comparableIndex = new Index();
       targetIndex = new Index();
       looseState = new MatchingState();




More information about the jboss-cvs-commits mailing list