01: /* SimpleMapper.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Tue Sep 4 23:09:16 2007, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.xel.util;
20:
21: import java.util.Collection;
22:
23: import org.zkoss.util.DualCollection;
24: import org.zkoss.xel.Function;
25: import org.zkoss.xel.FunctionMapper;
26:
27: /**
28: * A simmple function mapper.
29: *
30: * @author tomyeh
31: * @since 3.0.0
32: */
33: public class SimpleMapper extends TaglibMapper {
34: private FunctionMapper _parent;
35:
36: public SimpleMapper() {
37: }
38:
39: public SimpleMapper(FunctionMapper parent) {
40: _parent = parent;
41: }
42:
43: /** Returns the parent mapper, or null if no parent.
44: */
45: public FunctionMapper getParent() {
46: return _parent;
47: }
48:
49: /** Sets the parent mapper.
50: *
51: * @param parent the parent mapper, or null if no parent.
52: */
53: public void setParent(FunctionMapper parent) {
54: _parent = parent;
55: }
56:
57: //-- FunctionMapper --//
58: public Function resolveFunction(String prefix, String name) {
59: Function m = super .resolveFunction(prefix, name);
60: return m != null ? m : _parent != null ? _parent
61: .resolveFunction(prefix, name) : null;
62: }
63:
64: public Collection getClassNames() {
65: return combine(super .getClassNames(), _parent != null ? _parent
66: .getClassNames() : null);
67: }
68:
69: public Class resolveClass(String name) {
70: Class m = super .resolveClass(name);
71: return m != null ? m : _parent != null ? _parent
72: .resolveClass(name) : null;
73: }
74:
75: private static Collection combine(Collection first,
76: Collection second) {
77: return DualCollection.combine(
78: first != null && !first.isEmpty() ? first : null,
79: second != null && !second.isEmpty() ? second : null);
80: }
81: }
|