01: /*
02: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
03: *
04: * This file is part of Resin(R) Open Source
05: *
06: * Each copy or derived work must preserve the copyright notice and this
07: * notice unmodified.
08: *
09: * Resin Open Source is free software; you can redistribute it and/or modify
10: * it under the terms of the GNU General Public License as published by
11: * the Free Software Foundation; either version 2 of the License, or
12: * (at your option) any later version.
13: *
14: * Resin Open Source is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17: * of NON-INFRINGEMENT. See the GNU General Public License for more
18: * details.
19: *
20: * You should have received a copy of the GNU General Public License
21: * along with Resin Open Source; if not, write to the
22: *
23: * Free Software Foundation, Inc.
24: * 59 Temple Place, Suite 330
25: * Boston, MA 02111-1307 USA
26: *
27: * @author Scott Ferguson
28: */
29:
30: package com.caucho.webbeans.el;
31:
32: import java.beans.*;
33: import java.util.*;
34: import javax.el.*;
35:
36: import com.caucho.webbeans.component.*;
37: import com.caucho.webbeans.manager.WebBeansContainer;
38:
39: /**
40: * Variable resolution for webbeans variables
41: */
42: public class WebBeansContextResolver extends ELResolver {
43: public WebBeansContextResolver() {
44: }
45:
46: public Class<?> getCommonPropertyType(ELContext context, Object base) {
47: return Object.class;
48: }
49:
50: public Iterator<FeatureDescriptor> getFeatureDescriptors(
51: ELContext context, Object base) {
52: ArrayList<FeatureDescriptor> list = new ArrayList<FeatureDescriptor>();
53:
54: return list.iterator();
55: }
56:
57: public Class<?> getType(ELContext context, Object base,
58: Object property) {
59: Object value = getValue(context, base, property);
60:
61: if (value == null)
62: return null;
63: else
64: return value.getClass();
65: }
66:
67: public Object getValue(ELContext context, Object base,
68: Object property) throws PropertyNotFoundException,
69: ELException {
70: if (base != null || !(property instanceof String))
71: return null;
72:
73: String name = (String) property;
74:
75: WebBeansContainer webBeans = WebBeansContainer.create();
76: ComponentImpl value = webBeans.findByName(name);
77:
78: if (value != null) {
79: context.setPropertyResolved(true);
80:
81: Object result = value.get();
82:
83: return result;
84: } else
85: return null;
86: }
87:
88: public boolean isReadOnly(ELContext context, Object base,
89: Object property) throws PropertyNotFoundException,
90: ELException {
91: return true;
92: }
93:
94: public void setValue(ELContext context, Object base,
95: Object property, Object value)
96: throws PropertyNotFoundException,
97: PropertyNotWritableException, ELException {
98: }
99: }
|