[gatein-commits] gatein SVN: r5316 - portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp.

do-not-reply at jboss.org do-not-reply at jboss.org
Sat Nov 27 19:41:06 EST 2010


Author: julien_viet
Date: 2010-11-27 19:41:05 -0500 (Sat, 27 Nov 2010)
New Revision: 5316

Modified:
   portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RENode.java
   portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RegExpParser.java
Log:
update RE model to allow mutability


Modified: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RENode.java
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RENode.java	2010-11-28 00:13:53 UTC (rev 5315)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RENode.java	2010-11-28 00:41:05 UTC (rev 5316)
@@ -19,6 +19,8 @@
 
 package org.exoplatform.web.controller.regexp;
 
+import org.hibernate.criterion.Disjunction;
+
 /**
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
  * @version $Revision$
@@ -26,16 +28,19 @@
 public abstract class RENode
 {
 
+   /** The owner. */
+   private Ref<?> owner;
+
    public abstract String toString();
 
    public static final class Disjunction extends RENode
    {
 
       /** . */
-      private final Alternative alternative;
+      private final NonNullableRef<Alternative> alternative;
 
       /** . */
-      private final Disjunction next;
+      private final NullableRef<Disjunction> next;
 
       public Disjunction(Alternative alternative)
       {
@@ -44,36 +49,40 @@
 
       public Disjunction(Alternative alternative, Disjunction next)
       {
-         if (alternative == null)
-         {
-            throw new NullPointerException();
-         }
+         this.alternative = new NonNullableRef<Alternative>(alternative);
+         this.next = new NullableRef<Disjunction>(next);
+      }
 
-         //
-         this.alternative = alternative;
-         this.next = next;
+      public Alternative getAlternative()
+      {
+         return alternative.get();
       }
 
+      public void setAlternative(Alternative alternative)
+      {
+         this.alternative.set(alternative);
+      }
+
       public Disjunction getNext()
       {
-         return next;
+         return next.get();
       }
 
-      public Alternative getAlternative()
+      public void setNext(Disjunction next)
       {
-         return alternative;
+         this.next.set(next);
       }
 
       @Override
       public String toString()
       {
-         if (next != null)
+         if (next.isNotNull())
          {
-            return alternative + "|" + next;
+            return alternative.get() + "|" + next.get();
          }
          else
          {
-            return alternative.toString();
+            return alternative.get().toString();
          }
       }
    }
@@ -82,10 +91,10 @@
    {
 
       /** . */
-      private final Exp exp;
+      private final Ref<Exp> exp;
 
       /** . */
-      private final Alternative next;
+      private final Ref<Alternative> next;
 
       public Alternative(Exp exp)
       {
@@ -94,34 +103,40 @@
 
       public Alternative(Exp exp, Alternative next)
       {
-         if (exp == null)
-         {
-            throw new NullPointerException();
-         }
-         this.exp = exp;
-         this.next = next;
+         this.exp = new NonNullableRef<Exp>(exp);
+         this.next = new NullableRef<Alternative>(next);
       }
 
       public Exp getExp()
       {
-         return exp;
+         return exp.get();
       }
 
+      public void setExp(Exp exp)
+      {
+         this.exp.set(exp);
+      }
+
       public Alternative getNext()
       {
-         return next;
+         return next.get();
       }
 
+      public void setNext(Alternative next)
+      {
+         this.next.set(next);
+      }
+
       @Override
       public String toString()
       {
-         if (next != null)
+         if (next.isNotNull())
          {
-            return exp.toString() + next;
+            return exp.get().toString() + next.get();
          }
          else
          {
-            return exp.toString();
+            return exp.get().toString();
          }
       }
    }
@@ -130,17 +145,22 @@
    {
 
       /** . */
-      Quantifier quantifier;
+      private Quantifier quantifier;
 
       private Exp()
       {
       }
 
-      public Quantifier getQuantifier()
+      public final Quantifier getQuantifier()
       {
          return quantifier;
       }
 
+      public final void setQuantifier(Quantifier quantifier)
+      {
+         this.quantifier = quantifier;
+      }
+
       @Override
       public final String toString()
       {
@@ -165,28 +185,26 @@
    public static abstract class Assertion extends Exp
    {
 
-      /** . */
-      public static final Assertion BEGIN = new Assertion()
+      private Assertion()
       {
+      }
+
+      public static final class Begin extends Assertion
+      {
          @Override
          protected void writeTo(StringBuilder sb)
          {
             sb.append("<^/>");
          }
-      };
+      }
 
-      /** . */
-      public static final Assertion END = new Assertion()
+      public static final class End extends Assertion
       {
          @Override
          protected void writeTo(StringBuilder sb)
          {
             sb.append("<$/>");
          }
-      };
-
-      private Assertion()
-      {
       }
    }
 
@@ -199,14 +217,6 @@
 
    public static final class Dot extends Atom
    {
-
-      /** . */
-      public static Dot INSTANCE = new Dot();
-
-      private Dot()
-      {
-      }
-
       @Override
       protected void writeTo(StringBuilder sb)
       {
@@ -218,35 +228,41 @@
    {
 
       /** . */
-      private final Disjunction disjunction;
+      private final Ref<Disjunction> disjunction;
 
       /** . */
-      private final boolean capturing;
+      private boolean capturing;
 
       public Group(Disjunction disjunction, boolean capturing)
       {
-         if (disjunction == null)
-         {
-            throw new NullPointerException();
-         }
-         this.disjunction = disjunction;
+         this.disjunction = new NonNullableRef<Disjunction>(disjunction);
          this.capturing = capturing;
       }
 
       public Disjunction getDisjunction()
       {
-         return disjunction;
+         return disjunction.get();
       }
 
+      public void setDisjunction(Disjunction disjunction)
+      {
+         this.disjunction.set(disjunction);
+      }
+
       public boolean isCapturing()
       {
          return capturing;
       }
 
+      public void setCapturing(boolean capturing)
+      {
+         this.capturing = capturing;
+      }
+
       @Override
       protected void writeTo(StringBuilder sb)
       {
-         sb.append("<").append(capturing ? "(" : "(?:").append('>').append(disjunction).append("</").append(capturing ? ")" : ":?)").append(">");
+         sb.append("<").append(capturing ? "(" : "(?:").append('>').append(disjunction.get()).append("</").append(capturing ? ")" : ":?)").append(">");
       }
    }
 
@@ -254,14 +270,19 @@
    {
 
       /** . */
-      private final char value;
+      private char value;
 
+      public Character(char value)
+      {
+         this.value = value;
+      }
+
       public char getValue()
       {
          return value;
       }
 
-      public Character(char value)
+      public void setValue(char value)
       {
          this.value = value;
       }
@@ -277,26 +298,27 @@
    {
 
       /** . */
-      private final CharacterClassExpr expr;
+      private final Ref<CharacterClassExpr> expr;
 
       protected CharacterClass(CharacterClassExpr expr)
       {
-         if (expr == null)
-         {
-            throw new NullPointerException();
-         }
-         this.expr = expr;
+         this.expr = new NonNullableRef<CharacterClassExpr>(expr);
       }
 
       public CharacterClassExpr getExpr()
       {
-         return expr;
+         return expr.get();
       }
 
+      public void setExpr(CharacterClassExpr expr)
+      {
+         this.expr.set(expr);
+      }
+
       @Override
       protected void writeTo(StringBuilder sb)
       {
-         sb.append(expr);
+         sb.append(expr.get());
       }
    }
 
@@ -311,26 +333,27 @@
       {
 
          /** . */
-         private final CharacterClassExpr negated;
+         private final Ref<CharacterClassExpr> negated;
 
          public Not(CharacterClassExpr negated)
          {
-            if (negated == null)
-            {
-               throw new NullPointerException();
-            }
-            this.negated = negated;
+            this.negated = new NonNullableRef<CharacterClassExpr>(negated);
          }
 
          public CharacterClassExpr getNegated()
          {
-            return negated;
+            return negated.get();
          }
 
+         public void setNegated(CharacterClassExpr negated)
+         {
+            this.negated.set(negated);
+         }
+
          @Override
          public String toString()
          {
-            return "[^" + negated + "]";
+            return "[^" + negated.get() + "]";
          }
       }
 
@@ -338,39 +361,41 @@
       {
 
          /** . */
-         private final CharacterClassExpr left;
+         private final Ref<CharacterClassExpr> left;
 
          /** . */
-         private final CharacterClassExpr right;
+         private final Ref<CharacterClassExpr> right;
 
          public Or(CharacterClassExpr left, CharacterClassExpr right)
          {
-            if (left == null)
-            {
-               throw new NullPointerException();
-            }
-            if (right == null)
-            {
-               throw new NullPointerException();
-            }
-            this.left = left;
-            this.right = right;
+            this.left = new NonNullableRef<CharacterClassExpr>(left);
+            this.right = new NonNullableRef<CharacterClassExpr>(right);
          }
 
          public CharacterClassExpr getLeft()
          {
-            return left;
+            return left.get();
          }
 
+         public void setLeft(CharacterClassExpr left)
+         {
+            this.left.set(left);
+         }
+
          public CharacterClassExpr getRight()
          {
-            return right;
+            return right.get();
          }
 
+         public void setRight(CharacterClassExpr right)
+         {
+            this.right.set(right);
+         }
+
          @Override
          public String toString()
          {
-            return "[" + left + right + "]";
+            return "[" + left.get() + right.get() + "]";
          }
       }
 
@@ -378,39 +403,41 @@
       {
 
          /** . */
-         private final CharacterClassExpr left;
+         private final Ref<CharacterClassExpr> left;
 
          /** . */
-         private final CharacterClassExpr right;
+         private final Ref<CharacterClassExpr> right;
 
          public And(CharacterClassExpr left, CharacterClassExpr right)
          {
-            if (left == null)
-            {
-               throw new NullPointerException();
-            }
-            if (right == null)
-            {
-               throw new NullPointerException();
-            }
-            this.left = left;
-            this.right = right;
+            this.left = new NonNullableRef<CharacterClassExpr>(left);
+            this.right = new NonNullableRef<CharacterClassExpr>(right);
          }
 
          public CharacterClassExpr getLeft()
          {
-            return left;
+            return left.get();
          }
 
+         public void setLeft(CharacterClassExpr left)
+         {
+            this.left.set(left);
+         }
+
          public CharacterClassExpr getRight()
          {
-            return right;
+            return right.get();
          }
 
+         public void setRight(CharacterClassExpr right)
+         {
+            this.right.set(right);
+         }
+
          @Override
          public String toString()
          {
-            return "[" + left + "&&" + right + "]";
+            return "[" + left.get() + "&&" + right.get() + "]";
          }
       }
 
@@ -418,7 +445,7 @@
       {
 
          /** . */
-         private final char value;
+         private char value;
 
          public Simple(char value)
          {
@@ -430,6 +457,11 @@
             return value;
          }
 
+         public void setValue(char value)
+         {
+            this.value = value;
+         }
+
          @Override
          public String toString()
          {
@@ -441,10 +473,10 @@
       {
 
          /** From inclusive. */
-         private final char from;
+         private char from;
 
          /** To inclusive. */
-         private final char to;
+         private char to;
 
          public Range(char from, char to)
          {
@@ -457,11 +489,21 @@
             return from;
          }
 
+         public void setFrom(char from)
+         {
+            this.from = from;
+         }
+
          public char getTo()
          {
             return to;
          }
 
+         public void setTo(char to)
+         {
+            this.to = to;
+         }
+
          @Override
          public String toString()
          {
@@ -469,4 +511,112 @@
          }
       }
    }
+
+   protected abstract class Ref<N extends RENode>
+   {
+      protected abstract Ref<N> set(N node);
+      protected abstract N get();
+      protected final boolean isNull()
+      {
+         return get() == null;
+      }
+      protected final boolean isNotNull()
+      {
+         return get() != null;
+      }
+   }
+
+   protected class NullableRef<N extends RENode> extends Ref<N>
+   {
+
+      /** . */
+      private N node;
+
+      public NullableRef()
+      {
+         this(null);
+      }
+
+      public NullableRef(N node)
+      {
+         if (node != null && node.owner != null)
+         {
+            throw new IllegalArgumentException();
+         }
+         this.node = node;
+      }
+
+      @Override
+      protected Ref<N> set(N node)
+      {
+         if (node != null && node.owner != null)
+         {
+            throw new IllegalArgumentException();
+         }
+         if (this.node != null)
+         {
+            this.node.owner = null;
+         }
+         if (node != null)
+         {
+            node.owner = this;
+            this.node = node;
+         }
+         else
+         {
+            this.node = null;
+         }
+         return this;
+      }
+
+      @Override
+      protected N get()
+      {
+         return node;
+      }
+   }
+
+   protected class NonNullableRef<N extends RENode> extends Ref<N>
+   {
+
+      /** . */
+      private N node;
+
+      public NonNullableRef(N node)
+      {
+         if (node == null)
+         {
+            throw new NullPointerException();
+         }
+         if (node.owner != null)
+         {
+            throw new IllegalArgumentException();
+         }
+         node.owner = this;
+         this.node = node;
+      }
+
+      @Override
+      protected Ref<N> set(N node)
+      {
+         if (node == null)
+         {
+            throw new NullPointerException();
+         }
+         if (node.owner != null)
+         {
+            throw new IllegalArgumentException();
+         }
+         this.node.owner = null;
+         node.owner = this;
+         this.node = node;
+         return this;
+      }
+
+      @Override
+      protected N get()
+      {
+         return node;
+      }
+   }
 }

Modified: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RegExpParser.java
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RegExpParser.java	2010-11-28 00:13:53 UTC (rev 5315)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RegExpParser.java	2010-11-28 00:41:05 UTC (rev 5316)
@@ -143,11 +143,11 @@
       switch (c)
       {
          case '^':
-            exp = RENode.Exp.Assertion.BEGIN;
+            exp = new RENode.Exp.Assertion.Begin();
             index++;
             break;
          case '$':
-            exp = RENode.Exp.Assertion.END;
+            exp = new RENode.Exp.Assertion.End();
             index++;
             break;
          case '(':
@@ -223,7 +223,7 @@
                throw new SyntaxException();
             }
          case '.':
-            exp = RENode.Dot.INSTANCE;
+            exp = new RENode.Dot();
             index++;
             break;
          default:
@@ -234,7 +234,7 @@
       }
 
       //
-      exp.quantifier = parseQuantifier();
+      exp.setQuantifier(parseQuantifier());
 
       //
       return exp;



More information about the gatein-commits mailing list