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 version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jsf.cfg;
030:
031: import java.lang.reflect.*;
032: import java.util.*;
033:
034: import javax.el.*;
035:
036: import javax.faces.*;
037: import javax.faces.application.*;
038: import javax.faces.component.*;
039: import javax.faces.component.html.*;
040: import javax.faces.context.*;
041: import javax.faces.convert.*;
042: import javax.faces.el.*;
043: import javax.faces.event.*;
044: import javax.faces.validator.*;
045:
046: import javax.xml.bind.annotation.*;
047:
048: import com.caucho.config.*;
049: import com.caucho.util.*;
050:
051: public class ListEntries extends AbstractValueConfig implements
052: AbstractValue {
053: private ArrayList<AbstractValue> _list = new ArrayList<AbstractValue>();
054:
055: private Class _valueClass = String.class;
056:
057: public void setId(String id) {
058: }
059:
060: public void setValueClass(Class valueClass) {
061: _valueClass = valueClass;
062: }
063:
064: public void addValue(String value) {
065: _list.add(PropertyValue.create(value, _valueClass));
066: }
067:
068: public void setNullValue(String value) {
069: _list.add(NullPropertyValue.NULL);
070: }
071:
072: public void setMapEntries(MappedEntries value) {
073: _list.add(value);
074: }
075:
076: public void setListEntries(ListEntries value) {
077: _list.add(value);
078: }
079:
080: public ArrayList<AbstractValue> getListValues() {
081: return _list;
082: }
083:
084: AbstractValue getValue(Class type) {
085: return this ;
086: }
087:
088: public Object getValue(FacesContext context) {
089: ArrayList list = new ArrayList();
090:
091: int size = _list.size();
092: for (int i = 0; i < size; i++)
093: list.add(_list.get(i).getValue(context));
094:
095: return list;
096: }
097:
098: public Object getValue() {
099: return _list;
100: }
101:
102: public void addProgram(ArrayList<BeanProgram> program, String name,
103: Class type) {
104: String getterName = ("get"
105: + Character.toUpperCase(name.charAt(0)) + name
106: .substring(1));
107: String setterName = ("set"
108: + Character.toUpperCase(name.charAt(0)) + name
109: .substring(1));
110:
111: Method getter = findGetter(type, getterName);
112: Method setter = findSetter(type, setterName);
113:
114: if (getter != null && getter.getReturnType().isArray())
115: program.add(new ArrayPropertyBeanProgram(getter, setter,
116: _list, name));
117: else
118: program.add(new ListPropertyBeanProgram(getter, setter,
119: _list, name));
120: }
121: }
|