001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.webbeans.el;
031:
032: import java.beans.*;
033: import java.util.*;
034: import javax.el.*;
035:
036: import com.caucho.webbeans.component.*;
037: import com.caucho.webbeans.manager.WebBeansContainer;
038:
039: /**
040: * Variable resolution for webbeans variables
041: */
042: public class WebBeansELResolver extends ELResolver {
043: private final WebBeansContainer _webBeans;
044:
045: public WebBeansELResolver() {
046: _webBeans = WebBeansContainer.create();
047: _webBeans.update();
048: }
049:
050: public Class<?> getCommonPropertyType(ELContext context, Object base) {
051: return Object.class;
052: }
053:
054: public Iterator<FeatureDescriptor> getFeatureDescriptors(
055: ELContext context, Object base) {
056: ArrayList<FeatureDescriptor> list = new ArrayList<FeatureDescriptor>();
057:
058: return list.iterator();
059: }
060:
061: public Class<?> getType(ELContext context, Object base,
062: Object property) {
063: Object value = getValue(context, base, property);
064:
065: if (value == null)
066: return null;
067: else
068: return value.getClass();
069: }
070:
071: public Object getValue(ELContext context, Object base,
072: Object property) throws PropertyNotFoundException,
073: ELException {
074: if (base != null || !(property instanceof String))
075: return null;
076:
077: String name = (String) property;
078:
079: ComponentImpl value = _webBeans.findByName(name);
080:
081: if (value != null) {
082: context.setPropertyResolved(true);
083:
084: Object result = value.get();
085:
086: return result;
087: } else
088: return null;
089: }
090:
091: public boolean isReadOnly(ELContext context, Object base,
092: Object property) throws PropertyNotFoundException,
093: ELException {
094: return true;
095: }
096:
097: public void setValue(ELContext context, Object base,
098: Object property, Object value)
099: throws PropertyNotFoundException,
100: PropertyNotWritableException, ELException {
101: }
102: }
|