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 com.caucho.config.types.DescriptionGroupConfig;
032: import java.lang.reflect.*;
033: import java.util.*;
034:
035: import javax.el.*;
036:
037: import javax.faces.*;
038: import javax.faces.application.*;
039: import javax.faces.component.*;
040: import javax.faces.component.html.*;
041: import javax.faces.context.*;
042: import javax.faces.convert.*;
043: import javax.faces.el.*;
044: import javax.faces.event.*;
045: import javax.faces.validator.*;
046:
047: import javax.xml.bind.annotation.*;
048:
049: import com.caucho.config.*;
050: import com.caucho.config.j2ee.*;
051: import com.caucho.config.types.*;
052: import com.caucho.util.*;
053:
054: public class ManagedProperty extends DescriptionGroupConfig {
055: private static final L10N L = new L10N(ManagedProperty.class);
056:
057: private String _id;
058:
059: private String _name;
060:
061: private AbstractValueConfig _value = NullValue.NULL;
062:
063: public String getName() {
064: return _name;
065: }
066:
067: public void setId(String id) {
068: _id = id;
069: }
070:
071: public void setPropertyName(String name) {
072: _name = name;
073: }
074:
075: public void setNullValue(NullValue value) {
076: _value = NullValue.NULL;
077: }
078:
079: public void setValue(String value) {
080: _value = new ValueConfig(value);
081: }
082:
083: public void setMapEntries(MappedEntries entries) {
084: _value = entries;
085: }
086:
087: public void setListEntries(ListEntries entries) {
088: _value = entries;
089: }
090:
091: @XmlElement(name="property-class")
092: public void setPropertyClass(Class type) {
093: }
094:
095: public Class getPropertyClass() {
096: return null;
097: }
098:
099: public void addProgram(ArrayList<BeanProgram> program, Class type) {
100: if (_value instanceof MappedEntries) {
101: ((MappedEntries) _value).addProgram(program, _name, type);
102: return;
103: } else if (_value instanceof ListEntries) {
104: ((ListEntries) _value).addProgram(program, _name, type);
105: return;
106: }
107:
108: String name = ("set" + Character.toUpperCase(_name.charAt(0)) + _name
109: .substring(1));
110:
111: Method setter = findSetter(type, name);
112:
113: /*
114: if (setter == null)
115: throw new ConfigException(L.l("'{0}' is an unknown property of '{1}'.",
116: name, type.getName()));
117: */
118:
119: if (setter == null)
120: return;
121:
122: Class propType = setter.getParameterTypes()[0];
123:
124: program.add(new PropertyBeanProgram(setter, _value
125: .getValue(propType)));
126: }
127:
128: private static Method findSetter(Class type, String name) {
129: if (type == null)
130: return null;
131:
132: for (Method method : type.getDeclaredMethods()) {
133: if (!method.getName().equals(name))
134: continue;
135: else if (method.getParameterTypes().length != 1)
136: continue;
137: else if (Modifier.isStatic(method.getModifiers()))
138: continue;
139:
140: return method;
141: }
142:
143: return null;
144: }
145: }
|