01: /*
02: * Copyright 2004,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.bsf.util;
18:
19: /**
20: * An <code>ObjInfo</code> object is used by a compiler to track the name and
21: * type of a bean.
22: *
23: * @author Matthew J. Duftler
24: */
25: public class ObjInfo {
26: static private String QUOTE_CHARS = "\'\"", EXEC_CHARS = "(=";
27: public String objName;
28: public Class objClass;
29:
30: public ObjInfo(Class objClass, String objName) {
31: this .objClass = objClass;
32: this .objName = objName;
33: }
34:
35: public boolean isExecutable() {
36: char[] chars = objName.toCharArray();
37: char openingChar = ' ';
38: boolean inString = false, inEscapeSequence = false;
39:
40: for (int i = 0; i < chars.length; i++) {
41: if (inEscapeSequence) {
42: inEscapeSequence = false;
43: } else if (QUOTE_CHARS.indexOf(chars[i]) != -1) {
44: if (!inString) {
45: openingChar = chars[i];
46: inString = true;
47: } else {
48: if (chars[i] == openingChar) {
49: inString = false;
50: }
51: }
52: } else if (EXEC_CHARS.indexOf(chars[i]) != -1) {
53: if (!inString) {
54: return true;
55: }
56: } else if (inString && chars[i] == '\\') {
57: inEscapeSequence = true;
58: }
59: }
60:
61: return false;
62: }
63:
64: public boolean isValueReturning() {
65: return (objClass != void.class && objClass != Void.class);
66: }
67:
68: public String toString() {
69: return StringUtils.getClassName(objClass) + " " + objName;
70: }
71: }
|