KickJava   Java API By Example, From Geeks To Geeks.

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


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, S. Chassande-Barrioz
22  */

23 package org.objectweb.medor.filter.lib;
24
25 import org.objectweb.medor.api.Field;
26 import org.objectweb.medor.expression.api.Expression;
27 import org.objectweb.medor.expression.api.Operand;
28 import org.objectweb.medor.expression.api.ParameterOperand;
29 import org.objectweb.medor.filter.api.FieldOperand;
30 import org.objectweb.medor.filter.jorm.lib.CompositePName;
31 import org.objectweb.medor.filter.jorm.lib.SinglePName;
32 import org.objectweb.medor.query.api.QueryTreeField;
33
34 /**
35  * @author S.Chassande-Barrioz
36  */

37 public class ExpressionPrinter {
38     public static String JavaDoc e2str(Expression e) {
39         if (e instanceof FieldOperand) {
40             Field f = ((FieldOperand) e).getField();
41             if (f == null)
42                 return e.getType().getJavaName() + "nullFO";
43             else
44                 return
45                         ((f instanceof QueryTreeField) ?
46                         f.getName() + " of node "
47                         + ((QueryTreeField)f).getQueryTree() :
48                         f.getName());
49         }
50         else if (e instanceof CompositePName) {
51             FieldOperand[] fields = ((CompositePName) e).getFields();
52             String JavaDoc result = "CompositePName(";
53             Field f;
54             for(int i=0; i<fields.length; i++) {
55                 f = fields[i].getField();
56                 if (f==null)
57                     result += "no field ,";
58                 else
59                     result += f.getName() + ", ";
60             }
61             result += ((CompositePName) e).getExpression(0);
62             result += ")";
63             return result;
64         }
65         else if(e instanceof SinglePName) {
66             String JavaDoc res = "SinglePName(";
67             Operand op = (Operand) ((SinglePName) e) .getExpression(1);
68             Field f = ((SinglePName) e).getField().getField();
69             res += (f == null ? null : f.getName()) + ", ";
70             if (op instanceof ParameterOperand) {
71                 res += ((ParameterOperand) op).getName();
72             } else {
73                 res += op.getObject();
74             }
75             res += ")";
76             return res;
77         }
78         else return org.objectweb.medor.expression.lib.ExpressionPrinter.e2str(e);
79     }
80 }
81
Popular Tags