KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > expression > lib > StringLower


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

18 package org.objectweb.medor.expression.lib;
19
20 import org.objectweb.medor.expression.api.Expression;
21 import org.objectweb.medor.expression.api.Operand;
22 import org.objectweb.medor.expression.api.ParameterOperand;
23 import org.objectweb.medor.expression.api.ExpressionException;
24 import org.objectweb.medor.expression.api.MalformedExpressionException;
25 import org.objectweb.medor.expression.api.TypingException;
26 import org.objectweb.jorm.type.api.PTypeSpace;
27 import org.objectweb.jorm.type.api.PType;
28
29 /**
30  *
31  * @author S.Chassande-Barrioz
32  */

33 public class StringLower extends BasicUnaryOperator {
34
35     public StringLower() {
36         super(PTypeSpace.STRING);
37     }
38     public StringLower(Expression strOperand) {
39         super(PTypeSpace.STRING, strOperand);
40     }
41
42     public String JavaDoc getOperatorString() {
43         return STRING_UPPER;
44     }
45
46     public Operand evaluate(ParameterOperand[] pos, Object JavaDoc o)
47         throws ExpressionException {
48         if (expressions[0] == null) {
49             throw new MalformedExpressionException("Null children value");
50         }
51         if (result == null) {
52             throw new ExpressionException("Expression not compiled");
53         }
54         result.setValue(
55                 evaluate(expressions[0].evaluate(pos, o).getString()));
56         return result;
57     }
58
59     public Operand compileExpression()
60         throws ExpressionException, MalformedExpressionException {
61         if (expressions[0] == null) {
62             throw new MalformedExpressionException("Null children value");
63         }
64         expressions[0].compileExpression();
65         PType opType = expressions[0].getType();
66         if (opType == null) {
67             throw new TypingException("Argument type not defined (null)");
68         }
69         if (opType.getTypeCode() != PType.TYPECODE_STRING) {
70             throw new TypingException("Bad Argument type, expected String, found: "
71                 + expressions[0].getType().getJavaName());
72         }
73         result = new BasicVariableOperand(type);
74         verified = true;
75         return result;
76     }
77
78     public String JavaDoc evaluate(String JavaDoc str) {
79         return (str == null ? null : str.toLowerCase());
80     }
81 }
82
Popular Tags