01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /*
18: * Created on May 14, 2005
19: *
20: */
21: package org.apache.poi.hssf.record.formula.eval;
22:
23: /**
24: * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
25: *
26: */
27: public abstract class StringOperationEval implements OperationEval {
28:
29: /**
30: * Returns an instanceof StringValueEval or ErrorEval or BlankEval
31: *
32: * @param eval
33: * @param srcRow
34: * @param srcCol
35: */
36: protected ValueEval singleOperandEvaluate(Eval eval, int srcRow,
37: short srcCol) {
38: ValueEval retval;
39: if (eval instanceof AreaEval) {
40: AreaEval ae = (AreaEval) eval;
41: if (ae.contains(srcRow, srcCol)) { // circular ref!
42: retval = ErrorEval.CIRCULAR_REF_ERROR;
43: } else if (ae.isRow()) {
44: if (ae.containsColumn(srcCol)) {
45: ValueEval ve = ae.getValueAt(ae.getFirstRow(),
46: srcCol);
47: retval = internalResolveEval(eval);
48: } else {
49: retval = ErrorEval.NAME_INVALID;
50: }
51: } else if (ae.isColumn()) {
52: if (ae.containsRow(srcRow)) {
53: ValueEval ve = ae.getValueAt(srcRow, ae
54: .getFirstColumn());
55: retval = internalResolveEval(eval);
56: } else {
57: retval = ErrorEval.NAME_INVALID;
58: }
59: } else {
60: retval = ErrorEval.NAME_INVALID;
61: }
62: } else {
63: retval = internalResolveEval(eval);
64: }
65: return retval;
66: }
67:
68: private ValueEval internalResolveEval(Eval eval) {
69: ValueEval retval;
70: if (eval instanceof StringValueEval) {
71: retval = (StringValueEval) eval;
72: } else if (eval instanceof RefEval) {
73: RefEval re = (RefEval) eval;
74: ValueEval tve = re.getInnerValueEval();
75: if (tve instanceof StringValueEval
76: || tve instanceof BlankEval) {
77: retval = tve;
78: } else {
79: retval = ErrorEval.NAME_INVALID;
80: }
81: } else if (eval instanceof BlankEval) {
82: retval = (BlankEval) eval;
83: } else {
84: retval = ErrorEval.NAME_INVALID;
85: }
86: return retval;
87: }
88: }
|