KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > filter > lib > IsEmpty


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2003 France Telecom R&D
5  * Contact: alexandre.lefebvre@rd.francetelecom.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * Initial developers: M. Alia, A. Lefebvre
22  */

23
24 package org.objectweb.medor.filter.lib;
25
26 import org.objectweb.medor.expression.api.ExpressionException;
27 import org.objectweb.medor.expression.api.MalformedExpressionException;
28 import org.objectweb.medor.expression.api.ParameterOperand;
29 import org.objectweb.medor.expression.api.TypingException;
30 import org.objectweb.medor.expression.api.UnaryOperator;
31 import org.objectweb.medor.expression.api.Expression;
32 import org.objectweb.medor.expression.api.Operand;
33 import org.objectweb.medor.expression.lib.BasicUnaryOperator;
34 import org.objectweb.medor.expression.lib.BasicVariableOperand;
35 import org.objectweb.medor.type.lib.PTypeSpaceMedor;
36 import org.objectweb.medor.type.lib.QTypeTuple;
37
38 /**
39  * IsEmpty operates on an Expression which must be of a TupleCollection type,
40  * or a GenClassRef. Its evaluation returns true if the Expression is an empty
41  * TupleCollection or if the GenClassRef has no element.
42  */

43 public class IsEmpty extends BasicUnaryOperator implements UnaryOperator {
44
45     public IsEmpty() {
46         super(PTypeSpaceMedor.BOOLEAN);
47     }
48
49     public IsEmpty(Expression e) {
50         super(PTypeSpaceMedor.BOOLEAN, e);
51     }
52
53     public Operand evaluate(ParameterOperand[] pos, Object JavaDoc o)
54         throws ExpressionException {
55         try {
56             Operand subResult = expressions[0].evaluate(pos, o);
57             switch (subResult.getType().getTypeCode()) {
58             case QTypeTuple.TYPECODE_REFERENCE:
59                 //TODO: raffiner pour les genclassref
60
result.setValue(evaluate(subResult.getObject()));
61                 break;
62             case QTypeTuple.TYPECODE_TUPLE_COLLECTION:
63                 result.setValue(evaluate(subResult.getObject()));
64                 break;
65             default:
66                 throw new MalformedExpressionException(
67                     "Unauthorized expression element");
68             }
69         }
70         catch (NullPointerException JavaDoc e) {
71             throw new ExpressionException("Unevaluable Expression: Not compiled");
72         }
73         return result;
74     }
75
76     public boolean evaluate(Object JavaDoc op) {
77         //TODO
78
return true;
79     }
80
81     public Operand compileExpression()
82         throws ExpressionException, MalformedExpressionException {
83         if (expressions[0] != null) {
84             expressions[0].compileExpression();
85             //TODO raffiner pour les genclassref
86
if ((expressions[0].getType().getTypeCode()==QTypeTuple.TYPECODE_REFERENCE) ||
87                 (expressions[0].getType().getTypeCode()==QTypeTuple.TYPECODE_TUPLE_COLLECTION)) {
88                 result = new BasicVariableOperand(type);
89                 verified = true;
90             }
91             else {
92                 throw new TypingException("IsEmpty only operates on GenClassReferences and TupleCollections");
93             }
94         }
95         else
96         //Operands not yet assigned
97
throw new MalformedExpressionException("null children value");
98         return result;
99     }
100
101     public String JavaDoc getOperatorString() {
102         return "IsEmpty";
103     }
104 }
105
Popular Tags