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 MappedEntries extends AbstractValueConfig implements
052: AbstractValue {
053: private ArrayList<AbstractValue> _keyList = new ArrayList<AbstractValue>();
054: private ArrayList<AbstractValue> _valueList = new ArrayList<AbstractValue>();
055:
056: private Class _keyClass = String.class;
057: private Class _valueClass = String.class;
058:
059: public void setId(String id) {
060: }
061:
062: public void setKeyClass(Class keyClass) {
063: _keyClass = keyClass;
064: }
065:
066: public void setValueClass(Class valueClass) {
067: _valueClass = valueClass;
068: }
069:
070: public void addMapEntry(MapEntry entry) {
071: _keyList.add(entry.getKey(_keyClass));
072: _valueList.add(entry.getValue(_valueClass));
073: }
074:
075: public ArrayList<AbstractValue> getKeyList() {
076: return _keyList;
077: }
078:
079: public ArrayList<AbstractValue> getValueList() {
080: return _valueList;
081: }
082:
083: public Object getValue() {
084: return null;
085: }
086:
087: AbstractValue getValue(Class type) {
088: return this ;
089: }
090:
091: public Object getValue(FacesContext context) {
092: TreeMap map = new TreeMap();
093:
094: int size = _keyList.size();
095:
096: for (int i = 0; i < size; i++) {
097: map.put(_keyList.get(i).getValue(context), _valueList
098: .get(i).getValue(context));
099: }
100:
101: return map;
102: }
103:
104: public void addProgram(ArrayList<BeanProgram> program, String name,
105: Class type) {
106: String getterName = ("get"
107: + Character.toUpperCase(name.charAt(0)) + name
108: .substring(1));
109: String setterName = ("set"
110: + Character.toUpperCase(name.charAt(0)) + name
111: .substring(1));
112:
113: Method getter = findGetter(type, getterName);
114: Method setter = findSetter(type, setterName);
115:
116: program.add(new MapPropertyBeanProgram(getter, setter,
117: _keyList, _valueList, name));
118: }
119:
120: public static class MapEntry {
121: private String _key;
122:
123: private AbstractValueConfig _value = NullValue.NULL;
124:
125: public void setKey(String key) {
126: _key = key;
127: }
128:
129: public AbstractValue getKey(Class type) {
130: return PropertyValue.create(_key, type);
131: }
132:
133: public void setValue(String value) {
134: _value = new ValueConfig(value);
135: }
136:
137: public void setNullValue(String value) {
138: _value = NullValue.NULL;
139: }
140:
141: public void setMapEntries(MappedEntries entries) {
142: _value = entries;
143: }
144:
145: public void setListEntries(ListEntries entries) {
146: _value = entries;
147: }
148:
149: public Object getValue() {
150: return _value;
151: }
152:
153: public AbstractValue getValue(Class type) {
154: return _value.getValue(type);
155: }
156: }
157: }
|