tidy up visitor pattern for ldap classes so it actually does what you'd expect
also delete unused Cardinality class


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@814035 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/AbstractExpr.java b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/AbstractExpr.java
new file mode 100644
index 0000000..fcb1084
--- /dev/null
+++ b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/AbstractExpr.java
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+package org.apache.felix.sigil.common.osgi;
+
+public abstract class AbstractExpr implements LDAPExpr
+{
+    public void visit(ExprVisitor visitor) {
+        visitor.visitExpr(this);
+        for ( LDAPExpr expr : getChildren() ) {
+            visitor.visitExpr( expr );
+        }
+    }
+}
diff --git a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/And.java b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/And.java
index 026dd8e..4f99b15 100644
--- a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/And.java
+++ b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/And.java
@@ -23,7 +23,7 @@
 import java.util.Map;
 
 
-public class And implements LDAPExpr
+public class And extends AbstractExpr
 {
 
     /**
@@ -91,12 +91,6 @@
     }
 
 
-    public void visit( ExprVisitor v )
-    {
-        v.visitAnd( this );
-    }
-
-
     public LDAPExpr[] getChildren()
     {
         return children;
diff --git a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Cardinality.java b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Cardinality.java
deleted file mode 100644
index b0ad6cb..0000000
--- a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Cardinality.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.felix.sigil.common.osgi;
-
-
-import java.io.Serializable;
-
-
-/**
- * Immutable class representing cardinality constraints between two entities.
- * 
- */
-public class Cardinality implements Serializable
-{
-
-    /**
-     * 
-     */
-    private static final long serialVersionUID = 1L;
-    public static final Cardinality ZERO_TO_MANY = new Cardinality( 0, -1 );
-    public static final Cardinality ONE_TO_MANY = new Cardinality( 1, -1 );
-    public static final Cardinality ZERO_TO_ONE = new Cardinality( 0, 1 );
-    public static final Cardinality ONE_TO_ONE = new Cardinality( 1, 1 );
-
-    private int min;
-    private int max;
-
-
-    /**
-     * @param min
-     *            >=0 (usually 0 or 1)
-     * @param max
-     *            >=min or -1 to indicate an unbounded maximum
-     */
-    public Cardinality( int min, int max )
-    {
-        if ( min < 0 )
-        {
-            throw new IllegalArgumentException( "Min cannot be less than 0" );
-        }
-
-        if ( ( max < min ) && ( max != -1 ) )
-        {
-            throw new IllegalArgumentException( "Max cannot be less than min" );
-        }
-
-        this.min = min;
-        this.max = max;
-    }
-
-
-    public int getMin()
-    {
-        return min;
-    }
-
-
-    public int getMax()
-    {
-        return max;
-    }
-
-
-    public String toString()
-    {
-        return min + ".." + ( ( max == -1 ) ? ( "n" ) : ( Integer.toString( max ) ) );
-    }
-
-
-    public boolean isDefined( Cardinality cardinality )
-    {
-        return ( min <= cardinality.min ) && ( ( max == -1 ) || ( max >= cardinality.max ) );
-    }
-
-
-    public boolean isSingleton()
-    {
-        return ( min == 1 ) && ( max == 1 );
-    }
-
-
-    public static Cardinality parse( String stringRep ) throws IllegalArgumentException
-    {
-        stringRep = stringRep.trim();
-
-        int dotdot = stringRep.indexOf( ".." );
-
-        if ( dotdot == -1 )
-        {
-            throw new IllegalArgumentException( "Invalid cardinality string representation, expected .." );
-        }
-
-        String minStr = stringRep.substring( 0, dotdot );
-        String maxStr = stringRep.substring( dotdot + 2 );
-
-        int min = Integer.parseInt( minStr );
-        int max = min;
-
-        if ( "n".equals( maxStr ) )
-        {
-            max = -1;
-        }
-        else
-        {
-            max = Integer.parseInt( maxStr );
-        }
-
-        return cardinality( min, max );
-    }
-
-
-    public static Cardinality cardinality( int min, int max )
-    {
-        Cardinality c = null;
-
-        if ( min == 0 )
-        {
-            if ( max == 1 )
-            {
-                c = ZERO_TO_ONE;
-            }
-            else if ( max == -1 )
-            {
-                c = ZERO_TO_MANY;
-            }
-        }
-        else if ( min == 1 )
-        {
-            if ( max == 1 )
-            {
-                c = ONE_TO_ONE;
-            }
-            else if ( max == -1 )
-            {
-                c = ONE_TO_MANY;
-            }
-        }
-
-        if ( c == null )
-            c = new Cardinality( min, max );
-
-        return c;
-    }
-
-
-    public int hashCode()
-    {
-        return max ^ min;
-    }
-
-
-    public boolean equals( Object o )
-    {
-        if ( o == this )
-        {
-            return true;
-        }
-
-        if ( o == null )
-        {
-            return false;
-        }
-
-        try
-        {
-            Cardinality c = ( Cardinality ) o;
-
-            return ( min == c.min ) && ( max == c.max );
-        }
-        catch ( ClassCastException cce )
-        {
-            return false;
-        }
-    }
-}
diff --git a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/ExprVisitor.java b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/ExprVisitor.java
index c208f87..88aa174 100644
--- a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/ExprVisitor.java
+++ b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/ExprVisitor.java
@@ -22,19 +22,5 @@
 
 public interface ExprVisitor
 {
-
-    void visitAnd( And a );
-
-
-    void visitOr( Or o );
-
-
-    void visitNot( Not n );
-
-
-    void visitSimple( SimpleTerm st );
-
-
-    // if none of the above matches use this
-    void visitAny( LDAPExpr ex );
+    void visitExpr(LDAPExpr expr);
 }
diff --git a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPExpr.java b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPExpr.java
index 7d911b6..d7b9bf0 100644
--- a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPExpr.java
+++ b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPExpr.java
@@ -27,8 +27,8 @@
 public interface LDAPExpr extends Serializable
 {
 
-    public static final LDAPExpr[] CHILDLESS = new LDAPExpr[]
-        {};
+    public static final LDAPExpr[] CHILDLESS = new LDAPExpr[0];
+    
     public static LDAPExpr ACCEPT_ALL = Expressions.T;
 
 
diff --git a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Not.java b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Not.java
index 661bd43..0b3480d 100644
--- a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Not.java
+++ b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Not.java
@@ -23,7 +23,7 @@
 import java.util.Map;
 
 
-public class Not implements LDAPExpr
+public class Not extends AbstractExpr
 {
 
     /**
@@ -70,12 +70,6 @@
     }
 
 
-    public void visit( ExprVisitor v )
-    {
-        v.visitNot( this );
-    }
-
-
     public LDAPExpr[] getChildren()
     {
         return children;
diff --git a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Or.java b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Or.java
index 0d2cc03..5b6e215 100644
--- a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Or.java
+++ b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Or.java
@@ -23,7 +23,7 @@
 import java.util.Map;
 
 
-public class Or implements LDAPExpr
+public class Or extends AbstractExpr
 {
 
     /**
@@ -92,12 +92,6 @@
     }
 
 
-    public void visit( ExprVisitor v )
-    {
-        v.visitOr( this );
-    }
-
-
     public LDAPExpr[] getChildren()
     {
         return children;
diff --git a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/SimpleTerm.java b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/SimpleTerm.java
index 0ebd791..ffbe7dc 100644
--- a/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/SimpleTerm.java
+++ b/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/SimpleTerm.java
@@ -26,7 +26,7 @@
 import java.util.Vector;
 
 
-public class SimpleTerm implements LDAPExpr
+public class SimpleTerm extends AbstractExpr
 {
 
     /**
@@ -297,12 +297,6 @@
     }
 
 
-    public void visit( ExprVisitor v )
-    {
-        v.visitSimple( this );
-    }
-
-
     public LDAPExpr[] getChildren()
     {
         return CHILDLESS;