1 /**
2  *  ServingXML
3  *
4  *  Copyright (C) 2006  Daniel Parker
5  *    daniel.parker@servingxml.com
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  **/
20 
21 package com.servingxml.expr.substitution;
22 
23 import com.servingxml.util.ServingXmlException;
24 import com.servingxml.util.record.Record;
25 import com.servingxml.util.record.Value;
26 import com.servingxml.util.QnameContext;
27 
28 public abstract class SubstitutionExpr {
29   public final static SubstitutionExpr EMPTY = new LiteralSubstitutionExpr("");
30   public static final SubstitutionExpr NULL = new NullSubstitutionExpr();
31 
parseString(QnameContext context, String s)32   public static SubstitutionExpr parseString(QnameContext context, String s) {
33     SubstitutionExpr expr = SubstitutionExprParser.parse(context,s);
34     return expr;
35   }
parseString(QnameContext context, String input, EscapeSubstitutionVariables escapeVariables)36   public static SubstitutionExpr parseString(QnameContext context, String input,
37                                              EscapeSubstitutionVariables escapeVariables) {
38     SubstitutionExpr expr = SubstitutionExprParser.parse(context,input,escapeVariables);
39     return expr;
40   }
41 
evaluateAsString(Record parameters, Record record)42   public abstract String evaluateAsString(Record parameters, Record record);
43 
evaluateAsStringArray(Record parameters, Record record)44   public abstract String[] evaluateAsStringArray(Record parameters, Record record);
45 
isNull()46   public abstract boolean isNull();
47 
isLiteral()48   public abstract boolean isLiteral();
49 
50   static class NullSubstitutionExpr extends SubstitutionExpr {
51 
evaluateAsString(Record parameters, Record record)52     public String evaluateAsString(Record parameters, Record record) {
53       //System.out.println(getClass().getName()+".intValue MAX_VALUE");
54       return "";
55     }
56 
evaluateAsStringArray(Record parameters, Record record)57     public String[] evaluateAsStringArray(Record parameters, Record record) {
58       //System.out.println(getClass().getName()+".intValue MAX_VALUE");
59       return new String[0];
60     }
61 
isNull()62     public final boolean isNull() {
63       return true;
64     }
65 
isLiteral()66     public final boolean isLiteral() {
67       return false;
68     }
69   }
70 }
71 
72 
73