You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2007/03/01 15:58:59 UTC

svn commit: r513360 - in /incubator/qpid/trunk/qpid/java: broker/src/main/java/org/apache/qpid/server/filter/ client/src/main/java/org/apache/qpid/jndi/

Author: rgreig
Date: Thu Mar  1 06:58:58 2007
New Revision: 513360

URL: http://svn.apache.org/viewvc?view=rev&rev=513360
Log:
(Patch submitted by Rupert Smith) Qpid0394.diff
Removes revision tags from source files.

Modified:
    incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ComparisonExpression.java
    incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ConstantExpression.java
    incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/PropertyExpression.java
    incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/UnaryExpression.java
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jndi/ReadOnlyContext.java

Modified: incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ComparisonExpression.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ComparisonExpression.java?view=diff&rev=513360&r1=513359&r2=513360
==============================================================================
--- incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ComparisonExpression.java (original)
+++ incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ComparisonExpression.java Thu Mar  1 06:58:58 2007
@@ -1,19 +1,22 @@
-/**
+/*
+ *
+ * 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
  *
- * 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
  *
- * 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.
  *
- * 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.qpid.server.filter;
 //
@@ -29,22 +32,26 @@
 
 /**
  * A filter performing a comparison of two objects
- * 
+ *
  * @version $Revision$
  */
-public abstract class ComparisonExpression extends BinaryExpression implements BooleanExpression {
+public abstract class ComparisonExpression extends BinaryExpression implements BooleanExpression
+{
 
-    public static BooleanExpression createBetween(Expression value, Expression left, Expression right) {
+    public static BooleanExpression createBetween(Expression value, Expression left, Expression right)
+    {
         return LogicExpression.createAND(createGreaterThanEqual(value, left), createLessThanEqual(value, right));
     }
 
-    public static BooleanExpression createNotBetween(Expression value, Expression left, Expression right) {
+    public static BooleanExpression createNotBetween(Expression value, Expression left, Expression right)
+    {
         return LogicExpression.createOR(createLessThan(value, left), createGreaterThan(value, right));
     }
 
-    static final private HashSet REGEXP_CONTROL_CHARS = new HashSet();
+    private static final HashSet REGEXP_CONTROL_CHARS = new HashSet();
 
-    static {
+    static
+    {
         REGEXP_CONTROL_CHARS.add(new Character('.'));
         REGEXP_CONTROL_CHARS.add(new Character('\\'));
         REGEXP_CONTROL_CHARS.add(new Character('['));
@@ -67,23 +74,28 @@
         REGEXP_CONTROL_CHARS.add(new Character('!'));
     }
 
-    static class LikeExpression extends UnaryExpression implements BooleanExpression {
+    static class LikeExpression extends UnaryExpression implements BooleanExpression
+    {
 
         Pattern likePattern;
 
         /**
          * @param right
          */
-        public LikeExpression(Expression right, String like, int escape) {
+        public LikeExpression(Expression right, String like, int escape)
+        {
             super(right);
 
             StringBuffer regexp = new StringBuffer(like.length() * 2);
             regexp.append("\\A"); // The beginning of the input
-            for (int i = 0; i < like.length(); i++) {
+            for (int i = 0; i < like.length(); i++)
+            {
                 char c = like.charAt(i);
-                if (escape == (0xFFFF & c)) {
+                if (escape == (0xFFFF & c))
+                {
                     i++;
-                    if (i >= like.length()) {
+                    if (i >= like.length())
+                    {
                         // nothing left to escape...
                         break;
                     }
@@ -92,20 +104,25 @@
                     regexp.append("\\x");
                     regexp.append(Integer.toHexString(0xFFFF & t));
                 }
-                else if (c == '%') {
-                    regexp.append(".*?"); // Do a non-greedy match 
-                }
-                else if (c == '_') {
-                    regexp.append("."); // match one 
+                else if (c == '%')
+                {
+                    regexp.append(".*?"); // Do a non-greedy match
+                }
+                else if (c == '_')
+                {
+                    regexp.append("."); // match one
                 }
-                else if (REGEXP_CONTROL_CHARS.contains(new Character(c))) {
+                else if (REGEXP_CONTROL_CHARS.contains(new Character(c)))
+                {
                     regexp.append("\\x");
                     regexp.append(Integer.toHexString(0xFFFF & c));
                 }
-                else {
+                else
+                {
                     regexp.append(c);
                 }
             }
+
             regexp.append("\\z"); // The end of the input
 
             likePattern = Pattern.compile(regexp.toString(), Pattern.DOTALL);
@@ -114,351 +131,467 @@
         /**
          *  org.apache.activemq.filter.UnaryExpression#getExpressionSymbol()
          */
-        public String getExpressionSymbol() {
+        public String getExpressionSymbol()
+        {
             return "LIKE";
         }
 
         /**
          *  org.apache.activemq.filter.Expression#evaluate(MessageEvaluationContext)
          */
-        public Object evaluate(AMQMessage message) throws AMQException {
+        public Object evaluate(AMQMessage message) throws AMQException
+        {
 
             Object rv = this.getRight().evaluate(message);
 
-            if (rv == null) {
+            if (rv == null)
+            {
                 return null;
             }
 
-            if (!(rv instanceof String)) {
-            	return Boolean.FALSE;
-                //throw new RuntimeException("LIKE can only operate on String identifiers.  LIKE attemped on: '" + rv.getClass());
+            if (!(rv instanceof String))
+            {
+                return
+                    Boolean.FALSE;
+                    //throw new RuntimeException("LIKE can only operate on String identifiers.  LIKE attemped on: '" + rv.getClass());
             }
 
             return likePattern.matcher((String) rv).matches() ? Boolean.TRUE : Boolean.FALSE;
         }
-        
-        public boolean matches(AMQMessage message) throws AMQException {
+
+        public boolean matches(AMQMessage message) throws AMQException
+        {
             Object object = evaluate(message);
-            return object!=null && object==Boolean.TRUE;            
+
+            return (object != null) && (object == Boolean.TRUE);
         }
     }
 
-    public static BooleanExpression createLike(Expression left, String right, String escape) {
-        if (escape != null && escape.length() != 1) {
-            throw new RuntimeException("The ESCAPE string litteral is invalid.  It can only be one character.  Litteral used: " + escape);
+    public static BooleanExpression createLike(Expression left, String right, String escape)
+    {
+        if ((escape != null) && (escape.length() != 1))
+        {
+            throw new RuntimeException(
+                "The ESCAPE string litteral is invalid.  It can only be one character.  Litteral used: " + escape);
         }
+
         int c = -1;
-        if (escape != null) {
+        if (escape != null)
+        {
             c = 0xFFFF & escape.charAt(0);
         }
 
         return new LikeExpression(left, right, c);
     }
 
-    public static BooleanExpression createNotLike(Expression left, String right, String escape) {
+    public static BooleanExpression createNotLike(Expression left, String right, String escape)
+    {
         return UnaryExpression.createNOT(createLike(left, right, escape));
-    }    
+    }
+
+    public static BooleanExpression createInFilter(Expression left, List elements)
+    {
+
+        if (!(left instanceof PropertyExpression))
+        {
+            throw new RuntimeException("Expected a property for In expression, got: " + left);
+        }
+
+        return UnaryExpression.createInExpression((PropertyExpression) left, elements, false);
 
-    public static BooleanExpression createInFilter(Expression left, List elements) {
-    	
-    	if( !(left instanceof PropertyExpression) )
-    		throw new RuntimeException("Expected a property for In expression, got: "+left);    	
-    	return UnaryExpression.createInExpression((PropertyExpression)left, elements, false);
-    	
     }
 
-    public static BooleanExpression createNotInFilter(Expression left, List elements) {
-    	
-    	if( !(left instanceof PropertyExpression) )
-    		throw new RuntimeException("Expected a property for In expression, got: "+left);    	
-    	return UnaryExpression.createInExpression((PropertyExpression)left, elements, true);
+    public static BooleanExpression createNotInFilter(Expression left, List elements)
+    {
+
+        if (!(left instanceof PropertyExpression))
+        {
+            throw new RuntimeException("Expected a property for In expression, got: " + left);
+        }
+
+        return UnaryExpression.createInExpression((PropertyExpression) left, elements, true);
 
     }
 
-    public static BooleanExpression createIsNull(Expression left) {
+    public static BooleanExpression createIsNull(Expression left)
+    {
         return doCreateEqual(left, ConstantExpression.NULL);
     }
 
-    public static BooleanExpression createIsNotNull(Expression left) {
+    public static BooleanExpression createIsNotNull(Expression left)
+    {
         return UnaryExpression.createNOT(doCreateEqual(left, ConstantExpression.NULL));
     }
 
-    public static BooleanExpression createNotEqual(Expression left, Expression right) {
+    public static BooleanExpression createNotEqual(Expression left, Expression right)
+    {
         return UnaryExpression.createNOT(createEqual(left, right));
     }
 
-    public static BooleanExpression createEqual(Expression left, Expression right) {
-    	checkEqualOperand(left);
-    	checkEqualOperand(right);
-    	checkEqualOperandCompatability(left, right);
-    	return doCreateEqual(left, right);
-    }
-    
-	private static BooleanExpression doCreateEqual(Expression left, Expression right) {
-        return new ComparisonExpression(left, right) {
+    public static BooleanExpression createEqual(Expression left, Expression right)
+    {
+        checkEqualOperand(left);
+        checkEqualOperand(right);
+        checkEqualOperandCompatability(left, right);
+
+        return doCreateEqual(left, right);
+    }
+
+    private static BooleanExpression doCreateEqual(Expression left, Expression right)
+    {
+        return new ComparisonExpression(left, right)
+        {
 
-            public Object evaluate(AMQMessage message) throws AMQException {
+            public Object evaluate(AMQMessage message) throws AMQException
+            {
                 Object lv = left.evaluate(message);
                 Object rv = right.evaluate(message);
-                
+
                 // Iff one of the values is null
-                if (lv == null ^ rv == null) {
+                if ((lv == null) ^ (rv == null))
+                {
                     return Boolean.FALSE;
                 }
-                if (lv == rv || lv.equals(rv)) {
+
+                if ((lv == rv) || lv.equals(rv))
+                {
                     return Boolean.TRUE;
-                }                
-                if( lv instanceof Comparable && rv instanceof Comparable ) {
-                    return compare((Comparable)lv, (Comparable)rv);
                 }
+
+                if ((lv instanceof Comparable) && (rv instanceof Comparable))
+                {
+                    return compare((Comparable) lv, (Comparable) rv);
+                }
+
                 return Boolean.FALSE;
             }
 
-            protected boolean asBoolean(int answer) {
+            protected boolean asBoolean(int answer)
+            {
                 return answer == 0;
             }
 
-            public String getExpressionSymbol() {
+            public String getExpressionSymbol()
+            {
                 return "=";
             }
         };
     }
 
-    public static BooleanExpression createGreaterThan(final Expression left, final Expression right) {
-    	checkLessThanOperand(left);
-    	checkLessThanOperand(right);
-        return new ComparisonExpression(left, right) {
-            protected boolean asBoolean(int answer) {
+    public static BooleanExpression createGreaterThan(final Expression left, final Expression right)
+    {
+        checkLessThanOperand(left);
+        checkLessThanOperand(right);
+
+        return new ComparisonExpression(left, right)
+        {
+            protected boolean asBoolean(int answer)
+            {
                 return answer > 0;
             }
 
-            public String getExpressionSymbol() {
+            public String getExpressionSymbol()
+            {
                 return ">";
             }
         };
     }
 
-    public static BooleanExpression createGreaterThanEqual(final Expression left, final Expression right) {
-    	checkLessThanOperand(left);
-    	checkLessThanOperand(right);
-        return new ComparisonExpression(left, right) {
-            protected boolean asBoolean(int answer) {
+    public static BooleanExpression createGreaterThanEqual(final Expression left, final Expression right)
+    {
+        checkLessThanOperand(left);
+        checkLessThanOperand(right);
+
+        return new ComparisonExpression(left, right)
+        {
+            protected boolean asBoolean(int answer)
+            {
                 return answer >= 0;
             }
 
-            public String getExpressionSymbol() {
+            public String getExpressionSymbol()
+            {
                 return ">=";
             }
         };
     }
 
-    public static BooleanExpression createLessThan(final Expression left, final Expression right) {
-    	checkLessThanOperand(left);
-    	checkLessThanOperand(right);
-        return new ComparisonExpression(left, right) {
+    public static BooleanExpression createLessThan(final Expression left, final Expression right)
+    {
+        checkLessThanOperand(left);
+        checkLessThanOperand(right);
+
+        return new ComparisonExpression(left, right)
+        {
 
-            protected boolean asBoolean(int answer) {
+            protected boolean asBoolean(int answer)
+            {
                 return answer < 0;
             }
 
-            public String getExpressionSymbol() {
+            public String getExpressionSymbol()
+            {
                 return "<";
             }
 
         };
     }
 
-	public static BooleanExpression createLessThanEqual(final Expression left, final Expression right) {
-    	checkLessThanOperand(left);
-    	checkLessThanOperand(right);
-        return new ComparisonExpression(left, right) {
+    public static BooleanExpression createLessThanEqual(final Expression left, final Expression right)
+    {
+        checkLessThanOperand(left);
+        checkLessThanOperand(right);
+
+        return new ComparisonExpression(left, right)
+        {
 
-            protected boolean asBoolean(int answer) {
+            protected boolean asBoolean(int answer)
+            {
                 return answer <= 0;
             }
 
-            public String getExpressionSymbol() {
+            public String getExpressionSymbol()
+            {
                 return "<=";
             }
         };
     }
 
-	/**
-     * Only Numeric expressions can be used in >, >=, < or <= expressions.s 
-     * 
-	 * @param expr
-	 */
-	public static void checkLessThanOperand(Expression expr ) {
-		if( expr instanceof ConstantExpression ) {
-			Object value = ((ConstantExpression)expr).getValue();
-			if( value instanceof Number )
-				return;
-			
-			// Else it's boolean or a String..  
-			throw new RuntimeException("Value '"+expr+"' cannot be compared.");
-		}
-		if( expr instanceof BooleanExpression ) {
-			throw new RuntimeException("Value '"+expr+"' cannot be compared.");
-		}		
-	}
+    /**
+     * Only Numeric expressions can be used in >, >=, < or <= expressions.s
+     *
+     * @param expr
+     */
+    public static void checkLessThanOperand(Expression expr)
+    {
+        if (expr instanceof ConstantExpression)
+        {
+            Object value = ((ConstantExpression) expr).getValue();
+            if (value instanceof Number)
+            {
+                return;
+            }
 
-	/**
-     * Validates that the expression can be used in == or <> expression.  
+            // Else it's boolean or a String..
+            throw new RuntimeException("Value '" + expr + "' cannot be compared.");
+        }
+
+        if (expr instanceof BooleanExpression)
+        {
+            throw new RuntimeException("Value '" + expr + "' cannot be compared.");
+        }
+    }
+
+    /**
+     * Validates that the expression can be used in == or <> expression.
      * Cannot not be NULL TRUE or FALSE litterals.
-     * 
-	 * @param expr
-	 */
-	public static void checkEqualOperand(Expression expr ) {
-		if( expr instanceof ConstantExpression ) {
-			Object value = ((ConstantExpression)expr).getValue();
-			if( value == null )
-				throw new RuntimeException("'"+expr+"' cannot be compared.");
-		}
-	}
-
-	/**
-	 * 
-	 * @param left
-	 * @param right
-	 */
-	private static void checkEqualOperandCompatability(Expression left, Expression right) {
-		if( left instanceof ConstantExpression && right instanceof ConstantExpression ) {
-			if( left instanceof BooleanExpression && !(right instanceof BooleanExpression) )
-				throw new RuntimeException("'"+left+"' cannot be compared with '"+right+"'");
-		}
-	}
+     *
+     * @param expr
+     */
+    public static void checkEqualOperand(Expression expr)
+    {
+        if (expr instanceof ConstantExpression)
+        {
+            Object value = ((ConstantExpression) expr).getValue();
+            if (value == null)
+            {
+                throw new RuntimeException("'" + expr + "' cannot be compared.");
+            }
+        }
+    }
 
-	
-	
     /**
+     *
      * @param left
      * @param right
      */
-    public ComparisonExpression(Expression left, Expression right) {
+    private static void checkEqualOperandCompatability(Expression left, Expression right)
+    {
+        if ((left instanceof ConstantExpression) && (right instanceof ConstantExpression))
+        {
+            if ((left instanceof BooleanExpression) && !(right instanceof BooleanExpression))
+            {
+                throw new RuntimeException("'" + left + "' cannot be compared with '" + right + "'");
+            }
+        }
+    }
+
+    /**
+     * @param left
+     * @param right
+     */
+    public ComparisonExpression(Expression left, Expression right)
+    {
         super(left, right);
     }
 
     public Object evaluate(AMQMessage message) throws AMQException
     {
         Comparable lv = (Comparable) left.evaluate(message);
-        if (lv == null) {
+        if (lv == null)
+        {
             return null;
         }
+
         Comparable rv = (Comparable) right.evaluate(message);
-        if (rv == null) {
+        if (rv == null)
+        {
             return null;
         }
+
         return compare(lv, rv);
     }
 
-    protected Boolean compare(Comparable lv, Comparable rv) {
+    protected Boolean compare(Comparable lv, Comparable rv)
+    {
         Class lc = lv.getClass();
         Class rc = rv.getClass();
         // If the the objects are not of the same type,
         // try to convert up to allow the comparison.
-        if (lc != rc) {
-            if (lc == Byte.class) {
-                if (rc == Short.class) {
+        if (lc != rc)
+        {
+            if (lc == Byte.class)
+            {
+                if (rc == Short.class)
+                {
                     lv = new Short(((Number) lv).shortValue());
                 }
-                else if (rc == Integer.class) {
+                else if (rc == Integer.class)
+                {
                     lv = new Integer(((Number) lv).intValue());
                 }
-                else if (rc == Long.class) {
+                else if (rc == Long.class)
+                {
                     lv = new Long(((Number) lv).longValue());
                 }
-                else if (rc == Float.class) {
+                else if (rc == Float.class)
+                {
                     lv = new Float(((Number) lv).floatValue());
                 }
-                else if (rc == Double.class) {
+                else if (rc == Double.class)
+                {
                     lv = new Double(((Number) lv).doubleValue());
                 }
-                else {
+                else
+                {
                     return Boolean.FALSE;
                 }
-             } else if (lc == Short.class) {
-                if (rc == Integer.class) {
+            }
+            else if (lc == Short.class)
+            {
+                if (rc == Integer.class)
+                {
                     lv = new Integer(((Number) lv).intValue());
                 }
-                else if (rc == Long.class) {
+                else if (rc == Long.class)
+                {
                     lv = new Long(((Number) lv).longValue());
                 }
-                else if (rc == Float.class) {
+                else if (rc == Float.class)
+                {
                     lv = new Float(((Number) lv).floatValue());
                 }
-                else if (rc == Double.class) {
+                else if (rc == Double.class)
+                {
                     lv = new Double(((Number) lv).doubleValue());
                 }
-                else {
+                else
+                {
                     return Boolean.FALSE;
                 }
-            } else if (lc == Integer.class) {
-                if (rc == Long.class) {
+            }
+            else if (lc == Integer.class)
+            {
+                if (rc == Long.class)
+                {
                     lv = new Long(((Number) lv).longValue());
                 }
-                else if (rc == Float.class) {
+                else if (rc == Float.class)
+                {
                     lv = new Float(((Number) lv).floatValue());
                 }
-                else if (rc == Double.class) {
+                else if (rc == Double.class)
+                {
                     lv = new Double(((Number) lv).doubleValue());
                 }
-                else {
+                else
+                {
                     return Boolean.FALSE;
                 }
             }
-            else if (lc == Long.class) {
-                if (rc == Integer.class) {
+            else if (lc == Long.class)
+            {
+                if (rc == Integer.class)
+                {
                     rv = new Long(((Number) rv).longValue());
                 }
-                else if (rc == Float.class) {
+                else if (rc == Float.class)
+                {
                     lv = new Float(((Number) lv).floatValue());
                 }
-                else if (rc == Double.class) {
+                else if (rc == Double.class)
+                {
                     lv = new Double(((Number) lv).doubleValue());
                 }
-                else {
+                else
+                {
                     return Boolean.FALSE;
                 }
             }
-            else if (lc == Float.class) {
-                if (rc == Integer.class) {
+            else if (lc == Float.class)
+            {
+                if (rc == Integer.class)
+                {
                     rv = new Float(((Number) rv).floatValue());
                 }
-                else if (rc == Long.class) {
+                else if (rc == Long.class)
+                {
                     rv = new Float(((Number) rv).floatValue());
                 }
-                else if (rc == Double.class) {
+                else if (rc == Double.class)
+                {
                     lv = new Double(((Number) lv).doubleValue());
                 }
-                else {
+                else
+                {
                     return Boolean.FALSE;
                 }
-            } 
-            else if (lc == Double.class) {
-                if (rc == Integer.class) {
+            }
+            else if (lc == Double.class)
+            {
+                if (rc == Integer.class)
+                {
                     rv = new Double(((Number) rv).doubleValue());
                 }
-                else if (rc == Long.class) {
+                else if (rc == Long.class)
+                {
                     rv = new Double(((Number) rv).doubleValue());
                 }
-                else if (rc == Float.class) {
-                	rv = new Float(((Number) rv).doubleValue());
+                else if (rc == Float.class)
+                {
+                    rv = new Float(((Number) rv).doubleValue());
                 }
-                else {
+                else
+                {
                     return Boolean.FALSE;
                 }
-            } 
-            else 
+            }
+            else
+            {
                 return Boolean.FALSE;
+            }
         }
+
         return asBoolean(lv.compareTo(rv)) ? Boolean.TRUE : Boolean.FALSE;
     }
 
     protected abstract boolean asBoolean(int answer);
-    
-    public boolean matches(AMQMessage message) throws AMQException {
+
+    public boolean matches(AMQMessage message) throws AMQException
+    {
         Object object = evaluate(message);
-        return object!=null && object==Boolean.TRUE;            
+
+        return (object != null) && (object == Boolean.TRUE);
     }
 
 }

Modified: incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ConstantExpression.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ConstantExpression.java?view=diff&rev=513360&r1=513359&r2=513360
==============================================================================
--- incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ConstantExpression.java (original)
+++ incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ConstantExpression.java Thu Mar  1 06:58:58 2007
@@ -1,19 +1,22 @@
-/**
+/*
+ *
+ * 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
  *
- * 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
  *
- * 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.
  *
- * 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.qpid.server.filter;
 //
@@ -27,8 +30,6 @@
 
 /**
  * Represents a constant expression
- *
- * @version $Revision$
  */
 public class ConstantExpression implements Expression
 {
@@ -43,7 +44,8 @@
         public boolean matches(AMQMessage message) throws AMQException
         {
             Object object = evaluate(message);
-            return object != null && object == Boolean.TRUE;
+
+            return (object != null) && (object == Boolean.TRUE);
         }
     }
 
@@ -74,10 +76,11 @@
         }
 
         long l = value.longValue();
-        if (Integer.MIN_VALUE <= l && l <= Integer.MAX_VALUE)
+        if ((Integer.MIN_VALUE <= l) && (l <= Integer.MAX_VALUE))
         {
             value = new Integer(value.intValue());
         }
+
         return new ConstantExpression(value);
     }
 
@@ -85,10 +88,11 @@
     {
         Number value = new Long(Long.parseLong(text.substring(2), 16));
         long l = value.longValue();
-        if (Integer.MIN_VALUE <= l && l <= Integer.MAX_VALUE)
+        if ((Integer.MIN_VALUE <= l) && (l <= Integer.MAX_VALUE))
         {
             value = new Integer(value.intValue());
         }
+
         return new ConstantExpression(value);
     }
 
@@ -96,16 +100,18 @@
     {
         Number value = new Long(Long.parseLong(text, 8));
         long l = value.longValue();
-        if (Integer.MIN_VALUE <= l && l <= Integer.MAX_VALUE)
+        if ((Integer.MIN_VALUE <= l) && (l <= Integer.MAX_VALUE))
         {
             value = new Integer(value.intValue());
         }
+
         return new ConstantExpression(value);
     }
 
     public static ConstantExpression createFloat(String text)
     {
         Number value = new Double(text);
+
         return new ConstantExpression(value);
     }
 
@@ -133,14 +139,17 @@
         {
             return "NULL";
         }
+
         if (value instanceof Boolean)
         {
             return ((Boolean) value).booleanValue() ? "TRUE" : "FALSE";
         }
+
         if (value instanceof String)
         {
             return encodeString((String) value);
         }
+
         return value.toString();
     }
 
@@ -162,15 +171,15 @@
     public boolean equals(Object o)
     {
 
-        if (o == null || !this.getClass().equals(o.getClass()))
+        if ((o == null) || !this.getClass().equals(o.getClass()))
         {
             return false;
         }
+
         return toString().equals(o.toString());
 
     }
 
-
     /**
      * Encodes the value of string so that it looks like it would look like
      * when it was provided in a selector.
@@ -189,9 +198,12 @@
             {
                 b.append(c);
             }
+
             b.append(c);
         }
+
         b.append('\'');
+
         return b.toString();
     }
 

Modified: incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/PropertyExpression.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/PropertyExpression.java?view=diff&rev=513360&r1=513359&r2=513360
==============================================================================
--- incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/PropertyExpression.java (original)
+++ incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/PropertyExpression.java Thu Mar  1 06:58:58 2007
@@ -1,21 +1,23 @@
-/**
+/*
+ *
+ * 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
  *
- * 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
  *
- * 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.
  *
- * 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.qpid.server.filter;
 //
 // Based on like named file from r450141 of the Apache ActiveMQ project <http://www.activemq.org/site/home.html>
@@ -24,15 +26,14 @@
 import java.util.HashMap;
 
 import org.apache.log4j.Logger;
+
 import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.CommonContentHeaderProperties;
 import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.framing.CommonContentHeaderProperties;
 import org.apache.qpid.server.queue.AMQMessage;
 
 /**
  * Represents a property  expression
- *
- * @version $Revision$
  */
 public class PropertyExpression implements Expression
 {
@@ -41,201 +42,212 @@
     private static final int PERSISTENT = 2;
     private static final int DEFAULT_PRIORITY = 4;
 
-    private final static Logger _logger = org.apache.log4j.Logger.getLogger(PropertyExpression.class);
-
+    private static final Logger _logger = org.apache.log4j.Logger.getLogger(PropertyExpression.class);
 
-    static final private HashMap<String, Expression> JMS_PROPERTY_EXPRESSIONS = new HashMap<String, Expression>();
+    private static final HashMap<String, Expression> JMS_PROPERTY_EXPRESSIONS = new HashMap<String, Expression>();
 
     static
     {
-        JMS_PROPERTY_EXPRESSIONS.put("JMSDestination",
-                new Expression()
-                {
-                    public Object evaluate(AMQMessage message)
-                    {
-                        //TODO
-                        return null;
-                    }
-                }
-        );
+        JMS_PROPERTY_EXPRESSIONS.put("JMSDestination", new Expression()
+                                     {
+                                         public Object evaluate(AMQMessage message)
+                                         {
+                                             //TODO
+                                             return null;
+                                         }
+                                     });
         JMS_PROPERTY_EXPRESSIONS.put("JMSReplyTo", new Expression()
-        {
-                    public Object evaluate(AMQMessage message)
-                    {
-                        try
-                        {
-                            CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
-                            AMQShortString replyTo = _properties.getReplyTo();
-                            return replyTo == null ? null : replyTo.toString();
-                        }
-                        catch (AMQException e)
-                        {
-                            _logger.warn(e);
-                            return null;
-                        }
-
-                    }
-
-        });
-
-        JMS_PROPERTY_EXPRESSIONS.put("JMSType",
-                new Expression()
-                {
-                    public Object evaluate(AMQMessage message)
-                    {
-                        try
-                        {
-                            CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
-                            AMQShortString type = _properties.getType();
-                            return type == null ? null : type.toString();
-                        }
-                        catch (AMQException e)
-                        {
-                            _logger.warn(e);
-                            return null;
-                        }
-
-                    }
-                }
-        );
-
-        JMS_PROPERTY_EXPRESSIONS.put("JMSDeliveryMode",
-                new Expression()
-                {
-                    public Object evaluate(AMQMessage message)
-                    {
-                        try
-                        {
-                            int mode = message.isPersistent() ? PERSISTENT : NON_PERSISTENT;
-                            if(_logger.isDebugEnabled())
-                            {
-                                _logger.debug("JMSDeliveryMode is :" + mode);
-                            }
-                            return mode;
-                        }
-                        catch (AMQException e)
-                        {
-                            _logger.warn(e);
-                        }
-
-                        return NON_PERSISTENT;
-                    }
-                });
-
-        JMS_PROPERTY_EXPRESSIONS.put("JMSPriority",
-                new Expression()
-                {
-                    public Object evaluate(AMQMessage message)
-                    {
-                        try
-                        {
-                            CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
-                            return (int) _properties.getPriority();
-                        }
-                        catch (AMQException e)
-                        {
-                            _logger.warn(e);
-                        }
-                        return DEFAULT_PRIORITY;
-                    }
-                }
-        );
-
-
-        JMS_PROPERTY_EXPRESSIONS.put("AMQMessageID", 
-                new Expression()
-                {
-                    public Object evaluate(AMQMessage message)
-                    {
-
-                        try
-                        {
-                            CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
-                            AMQShortString messageId =  _properties.getMessageId();
-                            return messageId == null ? null : messageId;
-                        }
-                        catch (AMQException e)
-                        {
-                            _logger.warn(e);
-                            return null;
-                        }
-
-                    }
-                }
-        );
-
-        JMS_PROPERTY_EXPRESSIONS.put("JMSTimestamp",
-                new Expression()
-                {
-                    public Object evaluate(AMQMessage message)
-                    {
-
-                        try
-                        {
-                            CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
-                            return _properties.getTimestamp();
-                        }
-                        catch (AMQException e)
-                        {
-                            _logger.warn(e);
-                            return null;
-                        }
-
-                    }
-                }
-        );
-
-        JMS_PROPERTY_EXPRESSIONS.put("JMSCorrelationID",
-                new Expression()
-                {
-                    public Object evaluate(AMQMessage message)
-                    {
-
-                        try
-                        {
-                            CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
-                            AMQShortString correlationId = _properties.getCorrelationId();
-                            return correlationId == null ? null : correlationId.toString();
-                        }
-                        catch (AMQException e)
-                        {
-                            _logger.warn(e);
-                            return null;
-                        }
-
-                    }
-                }
-        );
-
-        JMS_PROPERTY_EXPRESSIONS.put("JMSExpiration",
-                new Expression()
-                {
-                    public Object evaluate(AMQMessage message)
-                    {
-
-                        try
-                        {
-                            CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
-                            return _properties.getExpiration();
-                        }
-                        catch (AMQException e)
-                        {
-                            _logger.warn(e);
-                            return null;
-                        }
-
-                    }
-                });
-
-        JMS_PROPERTY_EXPRESSIONS.put("JMSRedelivered",
-                new Expression()
-                {
-                    public Object evaluate(AMQMessage message)
-                    {
-                        return message.isRedelivered();
-                    }
-                }
-        );
+                                     {
+                                         public Object evaluate(AMQMessage message)
+                                         {
+                                             try
+                                             {
+                                                 CommonContentHeaderProperties _properties =
+                                                     (CommonContentHeaderProperties)
+                                                         message.getContentHeaderBody().properties;
+                                                 AMQShortString replyTo = _properties.getReplyTo();
+
+                                                 return (replyTo == null) ? null : replyTo.toString();
+                                             }
+                                             catch (AMQException e)
+                                             {
+                                                 _logger.warn(e);
+
+                                                 return null;
+                                             }
+
+                                         }
+
+                                     });
+
+        JMS_PROPERTY_EXPRESSIONS.put("JMSType", new Expression()
+                                     {
+                                         public Object evaluate(AMQMessage message)
+                                         {
+                                             try
+                                             {
+                                                 CommonContentHeaderProperties _properties =
+                                                     (CommonContentHeaderProperties)
+                                                         message.getContentHeaderBody().properties;
+                                                 AMQShortString type = _properties.getType();
+
+                                                 return (type == null) ? null : type.toString();
+                                             }
+                                             catch (AMQException e)
+                                             {
+                                                 _logger.warn(e);
+
+                                                 return null;
+                                             }
+
+                                         }
+                                     });
+
+        JMS_PROPERTY_EXPRESSIONS.put("JMSDeliveryMode", new Expression()
+                                     {
+                                         public Object evaluate(AMQMessage message)
+                                         {
+                                             try
+                                             {
+                                                 int mode = message.isPersistent() ? PERSISTENT : NON_PERSISTENT;
+                                                 if (_logger.isDebugEnabled())
+                                                 {
+                                                     _logger.debug("JMSDeliveryMode is :" + mode);
+                                                 }
+
+                                                 return mode;
+                                             }
+                                             catch (AMQException e)
+                                             {
+                                                 _logger.warn(e);
+                                             }
+
+                                             return NON_PERSISTENT;
+                                         }
+                                     });
+
+        JMS_PROPERTY_EXPRESSIONS.put("JMSPriority", new Expression()
+                                     {
+                                         public Object evaluate(AMQMessage message)
+                                         {
+                                             try
+                                             {
+                                                 CommonContentHeaderProperties _properties =
+                                                     (CommonContentHeaderProperties)
+                                                         message.getContentHeaderBody().properties;
+
+                                                 return (int) _properties.getPriority();
+                                             }
+                                             catch (AMQException e)
+                                             {
+                                                 _logger.warn(e);
+                                             }
+
+                                             return DEFAULT_PRIORITY;
+                                         }
+                                     });
+
+        JMS_PROPERTY_EXPRESSIONS.put("AMQMessageID", new Expression()
+                                     {
+                                         public Object evaluate(AMQMessage message)
+                                         {
+
+                                             try
+                                             {
+                                                 CommonContentHeaderProperties _properties =
+                                                     (CommonContentHeaderProperties)
+                                                         message.getContentHeaderBody().properties;
+                                                 AMQShortString messageId = _properties.getMessageId();
+
+                                                 return (messageId == null) ? null : messageId;
+                                             }
+                                             catch (AMQException e)
+                                             {
+                                                 _logger.warn(e);
+
+                                                 return null;
+                                             }
+
+                                         }
+                                     });
+
+        JMS_PROPERTY_EXPRESSIONS.put("JMSTimestamp", new Expression()
+                                     {
+                                         public Object evaluate(AMQMessage message)
+                                         {
+
+                                             try
+                                             {
+                                                 CommonContentHeaderProperties _properties =
+                                                     (CommonContentHeaderProperties)
+                                                         message.getContentHeaderBody().properties;
+
+                                                 return _properties.getTimestamp();
+                                             }
+                                             catch (AMQException e)
+                                             {
+                                                 _logger.warn(e);
+
+                                                 return null;
+                                             }
+
+                                         }
+                                     });
+
+        JMS_PROPERTY_EXPRESSIONS.put("JMSCorrelationID", new Expression()
+                                     {
+                                         public Object evaluate(AMQMessage message)
+                                         {
+
+                                             try
+                                             {
+                                                 CommonContentHeaderProperties _properties =
+                                                     (CommonContentHeaderProperties)
+                                                         message.getContentHeaderBody().properties;
+                                                 AMQShortString correlationId = _properties.getCorrelationId();
+
+                                                 return (correlationId == null) ? null : correlationId.toString();
+                                             }
+                                             catch (AMQException e)
+                                             {
+                                                 _logger.warn(e);
+
+                                                 return null;
+                                             }
+
+                                         }
+                                     });
+
+        JMS_PROPERTY_EXPRESSIONS.put("JMSExpiration", new Expression()
+                                     {
+                                         public Object evaluate(AMQMessage message)
+                                         {
+
+                                             try
+                                             {
+                                                 CommonContentHeaderProperties _properties =
+                                                     (CommonContentHeaderProperties)
+                                                         message.getContentHeaderBody().properties;
+
+                                                 return _properties.getExpiration();
+                                             }
+                                             catch (AMQException e)
+                                             {
+                                                 _logger.warn(e);
+
+                                                 return null;
+                                             }
+
+                                         }
+                                     });
+
+        JMS_PROPERTY_EXPRESSIONS.put("JMSRedelivered", new Expression()
+                                     {
+                                         public Object evaluate(AMQMessage message)
+                                         {
+                                             return message.isRedelivered();
+                                         }
+                                     });
 
     }
 
@@ -245,7 +257,7 @@
     public PropertyExpression(String name)
     {
         this.name = name;
-        jmsPropertyExpression =  JMS_PROPERTY_EXPRESSIONS.get(name);
+        jmsPropertyExpression = JMS_PROPERTY_EXPRESSIONS.get(name);
     }
 
     public Object evaluate(AMQMessage message) throws AMQException
@@ -255,13 +267,13 @@
         {
             return jmsPropertyExpression.evaluate(message);
         }
-
         else
         {
 
-            CommonContentHeaderProperties _properties = (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
+            CommonContentHeaderProperties _properties =
+                (CommonContentHeaderProperties) message.getContentHeaderBody().properties;
 
-            if(_logger.isDebugEnabled())
+            if (_logger.isDebugEnabled())
             {
                 _logger.debug("Looking up property:" + name);
                 _logger.debug("Properties are:" + _properties.getHeaders().keySet());
@@ -276,7 +288,6 @@
         return name;
     }
 
-
     /**
      * @see java.lang.Object#toString()
      */
@@ -299,10 +310,11 @@
     public boolean equals(Object o)
     {
 
-        if (o == null || !this.getClass().equals(o.getClass()))
+        if ((o == null) || !this.getClass().equals(o.getClass()))
         {
             return false;
         }
+
         return name.equals(((PropertyExpression) o).name);
 
     }

Modified: incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/UnaryExpression.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/UnaryExpression.java?view=diff&rev=513360&r1=513359&r2=513360
==============================================================================
--- incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/UnaryExpression.java (original)
+++ incubator/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/UnaryExpression.java Thu Mar  1 06:58:58 2007
@@ -1,19 +1,22 @@
-/**
+/*
+ *
+ * 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
  *
- * 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
  *
- * 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.
  *
- * 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.qpid.server.filter;
 //
@@ -31,200 +34,268 @@
 
 /**
  * An expression which performs an operation on two expression values
- * 
- * @version $Revision$
  */
-public abstract class UnaryExpression implements Expression {
+public abstract class UnaryExpression implements Expression
+{
 
     private static final BigDecimal BD_LONG_MIN_VALUE = BigDecimal.valueOf(Long.MIN_VALUE);
     protected Expression right;
 
-    public static Expression createNegate(Expression left) {
-        return new UnaryExpression(left) {
+    public static Expression createNegate(Expression left)
+    {
+        return new UnaryExpression(left)
+        {
             public Object evaluate(AMQMessage message) throws AMQException
             {
                 Object rvalue = right.evaluate(message);
-                if (rvalue == null) {
+                if (rvalue == null)
+                {
                     return null;
                 }
-                if (rvalue instanceof Number) {
+
+                if (rvalue instanceof Number)
+                {
                     return negate((Number) rvalue);
                 }
+
                 return null;
             }
 
-            public String getExpressionSymbol() {
+            public String getExpressionSymbol()
+            {
                 return "-";
             }
         };
     }
 
-    public static BooleanExpression createInExpression(PropertyExpression right, List elements, final boolean not) {
-    	
-    	// Use a HashSet if there are many elements.
-    	Collection t;
-		if( elements.size()==0 )
-    		t=null;
-    	else if( elements.size() < 5 )
-    		t = elements;
-    	else {
-    		t = new HashSet(elements);
-    	}
-    	final Collection inList = t;
-    	
-        return new BooleanUnaryExpression(right) {
-            public Object evaluate(AMQMessage message) throws AMQException {
-            	
+    public static BooleanExpression createInExpression(PropertyExpression right, List elements, final boolean not)
+    {
+
+        // Use a HashSet if there are many elements.
+        Collection t;
+        if (elements.size() == 0)
+        {
+            t = null;
+        }
+        else if (elements.size() < 5)
+        {
+            t = elements;
+        }
+        else
+        {
+            t = new HashSet(elements);
+        }
+
+        final Collection inList = t;
+
+        return new BooleanUnaryExpression(right)
+        {
+            public Object evaluate(AMQMessage message) throws AMQException
+            {
+
                 Object rvalue = right.evaluate(message);
-                if (rvalue == null) {
+                if (rvalue == null)
+                {
                     return null;
                 }
-                if( rvalue.getClass()!=String.class )
-                	return null;
-                
-                if( (inList!=null && inList.contains(rvalue)) ^ not ) {
-                	return Boolean.TRUE;
-                } else {
-                	return Boolean.FALSE;                	
-                }
-                
-            }
-
-            public String toString() {
-            	StringBuffer answer = new StringBuffer();
-            	answer.append(right);
-            	answer.append(" ");
-            	answer.append(getExpressionSymbol());
-            	answer.append(" ( ");
-
-            	int count=0;
-            	for (Iterator i = inList.iterator(); i.hasNext();) {
-					Object o = (Object) i.next();
-					if( count!=0 ) {
-		            	answer.append(", ");				
-					}
-	            	answer.append(o);				
-	            	count++;
-				}
-            	
-            	answer.append(" )");				
+
+                if (rvalue.getClass() != String.class)
+                {
+                    return null;
+                }
+
+                if (((inList != null) && inList.contains(rvalue)) ^ not)
+                {
+                    return Boolean.TRUE;
+                }
+                else
+                {
+                    return Boolean.FALSE;
+                }
+
+            }
+
+            public String toString()
+            {
+                StringBuffer answer = new StringBuffer();
+                answer.append(right);
+                answer.append(" ");
+                answer.append(getExpressionSymbol());
+                answer.append(" ( ");
+
+                int count = 0;
+                for (Iterator i = inList.iterator(); i.hasNext();)
+                {
+                    Object o = (Object) i.next();
+                    if (count != 0)
+                    {
+                        answer.append(", ");
+                    }
+
+                    answer.append(o);
+                    count++;
+                }
+
+                answer.append(" )");
+
                 return answer.toString();
-			}
-			
-            public String getExpressionSymbol() {
-            	if( not )
-            		return "NOT IN";
-            	else 
-            		return "IN";
+            }
+
+            public String getExpressionSymbol()
+            {
+                if (not)
+                {
+                    return "NOT IN";
+                }
+                else
+                {
+                    return "IN";
+                }
             }
         };
     }
 
-    abstract static class BooleanUnaryExpression extends UnaryExpression implements BooleanExpression {
-        public BooleanUnaryExpression(Expression left) {        	
+    abstract static class BooleanUnaryExpression extends UnaryExpression implements BooleanExpression
+    {
+        public BooleanUnaryExpression(Expression left)
+        {
             super(left);
         }
 
-        public boolean matches(AMQMessage message) throws AMQException {
+        public boolean matches(AMQMessage message) throws AMQException
+        {
             Object object = evaluate(message);
-            return object!=null && object==Boolean.TRUE;            
+
+            return (object != null) && (object == Boolean.TRUE);
         }
-    };
+    }
+    ;
 
-        
-    public static BooleanExpression createNOT(BooleanExpression left) {
-        return new BooleanUnaryExpression(left) {
-            public Object evaluate(AMQMessage message) throws AMQException {
+    public static BooleanExpression createNOT(BooleanExpression left)
+    {
+        return new BooleanUnaryExpression(left)
+        {
+            public Object evaluate(AMQMessage message) throws AMQException
+            {
                 Boolean lvalue = (Boolean) right.evaluate(message);
-                if (lvalue == null) {
+                if (lvalue == null)
+                {
                     return null;
                 }
+
                 return lvalue.booleanValue() ? Boolean.FALSE : Boolean.TRUE;
             }
 
-            public String getExpressionSymbol() {
+            public String getExpressionSymbol()
+            {
                 return "NOT";
             }
         };
     }
-    
-    public static BooleanExpression createXPath(final String xpath) {
+
+    public static BooleanExpression createXPath(final String xpath)
+    {
         return new XPathExpression(xpath);
     }
 
-    public static BooleanExpression createXQuery(final String xpath) {
+    public static BooleanExpression createXQuery(final String xpath)
+    {
         return new XQueryExpression(xpath);
     }
 
-    public static BooleanExpression createBooleanCast(Expression left) {
-        return new BooleanUnaryExpression(left) {
-            public Object evaluate(AMQMessage message) throws AMQException {
+    public static BooleanExpression createBooleanCast(Expression left)
+    {
+        return new BooleanUnaryExpression(left)
+        {
+            public Object evaluate(AMQMessage message) throws AMQException
+            {
                 Object rvalue = right.evaluate(message);
-                if (rvalue == null) 
+                if (rvalue == null)
+                {
                     return null;
-                if (!rvalue.getClass().equals(Boolean.class)) 
+                }
+
+                if (!rvalue.getClass().equals(Boolean.class))
+                {
                     return Boolean.FALSE;
-                return ((Boolean)rvalue).booleanValue() ? Boolean.TRUE : Boolean.FALSE;
+                }
+
+                return ((Boolean) rvalue).booleanValue() ? Boolean.TRUE : Boolean.FALSE;
             }
 
-            public String toString() {
+            public String toString()
+            {
                 return right.toString();
             }
 
-            public String getExpressionSymbol() {
+            public String getExpressionSymbol()
+            {
                 return "";
             }
         };
     }
 
-    private static Number negate(Number left) {
-    	Class clazz = left.getClass();
-        if (clazz == Integer.class) {
+    private static Number negate(Number left)
+    {
+        Class clazz = left.getClass();
+        if (clazz == Integer.class)
+        {
             return new Integer(-left.intValue());
         }
-        else if (clazz == Long.class) {
+        else if (clazz == Long.class)
+        {
             return new Long(-left.longValue());
         }
-        else if (clazz ==  Float.class) {
+        else if (clazz == Float.class)
+        {
             return new Float(-left.floatValue());
         }
-        else if (clazz == Double.class) {
+        else if (clazz == Double.class)
+        {
             return new Double(-left.doubleValue());
         }
-        else if (clazz == BigDecimal.class) {
-        	// We ussually get a big deciamal when we have Long.MIN_VALUE constant in the 
-        	// Selector.  Long.MIN_VALUE is too big to store in a Long as a positive so we store it 
-        	// as a Big decimal.  But it gets Negated right away.. to here we try to covert it back
-        	// to a Long.        	
-        	BigDecimal bd = (BigDecimal)left;
-        	bd = bd.negate();
-        	
-        	if( BD_LONG_MIN_VALUE.compareTo(bd)==0  ) {
-        		return new Long(Long.MIN_VALUE);
-        	}
+        else if (clazz == BigDecimal.class)
+        {
+            // We ussually get a big deciamal when we have Long.MIN_VALUE constant in the
+            // Selector.  Long.MIN_VALUE is too big to store in a Long as a positive so we store it
+            // as a Big decimal.  But it gets Negated right away.. to here we try to covert it back
+            // to a Long.
+            BigDecimal bd = (BigDecimal) left;
+            bd = bd.negate();
+
+            if (BD_LONG_MIN_VALUE.compareTo(bd) == 0)
+            {
+                return new Long(Long.MIN_VALUE);
+            }
+
             return bd;
         }
-        else {
-            throw new RuntimeException("Don't know how to negate: "+left);
+        else
+        {
+            throw new RuntimeException("Don't know how to negate: " + left);
         }
     }
 
-    public UnaryExpression(Expression left) {
+    public UnaryExpression(Expression left)
+    {
         this.right = left;
     }
 
-    public Expression getRight() {
+    public Expression getRight()
+    {
         return right;
     }
 
-    public void setRight(Expression expression) {
+    public void setRight(Expression expression)
+    {
         right = expression;
     }
 
     /**
      * @see java.lang.Object#toString()
      */
-    public String toString() {
+    public String toString()
+    {
         return "(" + getExpressionSymbol() + " " + right.toString() + ")";
     }
 
@@ -233,7 +304,8 @@
      *
      * @see java.lang.Object#hashCode()
      */
-    public int hashCode() {
+    public int hashCode()
+    {
         return toString().hashCode();
     }
 
@@ -242,11 +314,14 @@
      *
      * @see java.lang.Object#equals(java.lang.Object)
      */
-    public boolean equals(Object o) {
+    public boolean equals(Object o)
+    {
 
-        if (o == null || !this.getClass().equals(o.getClass())) {
+        if ((o == null) || !this.getClass().equals(o.getClass()))
+        {
             return false;
         }
+
         return toString().equals(o.toString());
 
     }
@@ -257,6 +332,6 @@
      *
      * @return
      */
-    abstract public String getExpressionSymbol();
+    public abstract String getExpressionSymbol();
 
 }

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jndi/ReadOnlyContext.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jndi/ReadOnlyContext.java?view=diff&rev=513360&r1=513359&r2=513360
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jndi/ReadOnlyContext.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jndi/ReadOnlyContext.java Thu Mar  1 06:58:58 2007
@@ -1,21 +1,23 @@
-/**
+/*
+ *
+ * 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
  *
- * 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
  *
- * 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.
  *
- * 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.qpid.jndi;
 
 import java.io.Serializable;
@@ -58,17 +60,15 @@
  * String envEntry = (String) componentContext.lookup("env/myEntry");
  * String envEntry2 = (String) componentContext.lookup("env/myEntry2");
  * </code>
- *
- * @version $Revision$ $Date$
  */
 public class ReadOnlyContext implements Context, Serializable
 {
     private static final long serialVersionUID = -5754338187296859149L;
     protected static final NameParser nameParser = new NameParserImpl();
 
-    protected final Hashtable environment;        // environment for this context
-    protected final Map bindings;         // bindings at my level
-    protected final Map treeBindings;     // all bindings under me
+    protected final Hashtable environment; // environment for this context
+    protected final Map bindings; // bindings at my level
+    protected final Map treeBindings; // all bindings under me
 
     private boolean frozen = false;
     private String nameInNamespace = "";
@@ -91,6 +91,7 @@
         {
             this.environment = new Hashtable(env);
         }
+
         this.bindings = Collections.EMPTY_MAP;
         this.treeBindings = Collections.EMPTY_MAP;
     }
@@ -105,6 +106,7 @@
         {
             this.environment = new Hashtable(environment);
         }
+
         this.bindings = bindings;
         treeBindings = new HashMap();
         frozen = true;
@@ -154,8 +156,8 @@
      */
     protected Map internalBind(String name, Object value) throws NamingException
     {
-        assert name != null && name.length() > 0;
-        assert!frozen;
+        assert (name != null) && (name.length() > 0);
+        assert !frozen;
 
         Map newBindings = new HashMap();
         int pos = name.indexOf('/');
@@ -165,6 +167,7 @@
             {
                 throw new NamingException("Something already bound at " + name);
             }
+
             bindings.put(name, value);
             newBindings.put(name, value);
         }
@@ -172,7 +175,7 @@
         {
             String segment = name.substring(0, pos);
             assert segment != null;
-            assert!segment.equals("");
+            assert !segment.equals("");
             Object o = treeBindings.get(segment);
             if (o == null)
             {
@@ -185,6 +188,7 @@
             {
                 throw new NamingException("Something already bound where a subcontext should go");
             }
+
             ReadOnlyContext readOnlyContext = (ReadOnlyContext) o;
             String remainder = name.substring(pos + 1);
             Map subBindings = readOnlyContext.internalBind(remainder, value);
@@ -197,6 +201,7 @@
                 newBindings.put(subName, bound);
             }
         }
+
         return newBindings;
     }
 
@@ -226,11 +231,13 @@
         {
             return this;
         }
+
         Object result = treeBindings.get(name);
         if (result == null)
         {
             result = bindings.get(name);
         }
+
         if (result == null)
         {
             int pos = name.indexOf(':');
@@ -242,6 +249,7 @@
                 {
                     throw new NamingException("scheme " + scheme + " not recognized");
                 }
+
                 return ctx.lookup(name);
             }
             else
@@ -262,20 +270,23 @@
                     {
                         throw new NameNotFoundException(name);
                     }
-                    else if (obj instanceof Context && path.size() > 1)
+                    else if ((obj instanceof Context) && (path.size() > 1))
                     {
                         Context subContext = (Context) obj;
                         obj = subContext.lookup(path.getSuffix(1));
                     }
+
                     return obj;
                 }
             }
         }
+
         if (result instanceof LinkRef)
         {
             LinkRef ref = (LinkRef) result;
             result = lookup(ref.getLinkName());
         }
+
         if (result instanceof Reference)
         {
             try
@@ -288,9 +299,10 @@
             }
             catch (Exception e)
             {
-                throw(NamingException) new NamingException("could not look up : " + name).initCause(e);
+                throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
             }
         }
+
         if (result instanceof ReadOnlyContext)
         {
             String prefix = getNameInNamespace();
@@ -298,8 +310,10 @@
             {
                 prefix = prefix + SEPARATOR;
             }
+
             result = new ReadOnlyContext((ReadOnlyContext) result, environment, prefix + name);
         }
+
         return result;
     }
 
@@ -317,6 +331,7 @@
     {
         Name result = (Name) prefix.clone();
         result.addAll(name);
+
         return result;
     }
 
@@ -324,6 +339,7 @@
     {
         CompositeName result = new CompositeName(prefix);
         result.addAll(new CompositeName(name));
+
         return result.toString();
     }
 
@@ -476,8 +492,7 @@
         }
 
         public void close() throws NamingException
-        {
-        }
+        { }
     }
 
     private class ListEnumeration extends LocalNamingEnumeration
@@ -490,6 +505,7 @@
         public Object nextElement()
         {
             Map.Entry entry = getNext();
+
             return new NameClassPair((String) entry.getKey(), entry.getValue().getClass().getName());
         }
     }
@@ -504,6 +520,7 @@
         public Object nextElement()
         {
             Map.Entry entry = getNext();
+
             return new Binding((String) entry.getKey(), entry.getValue());
         }
     }