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.config.type;
031:
032: import com.caucho.config.program.ConfigProgram;
033: import com.caucho.config.*;
034: import com.caucho.config.attribute.*;
035: import com.caucho.el.*;
036: import com.caucho.util.*;
037: import com.caucho.xml.QName;
038:
039: import javax.el.*;
040:
041: import org.w3c.dom.Node;
042:
043: /**
044: * Represents an introspected configuration type.
045: */
046: abstract public class ConfigType {
047: private static final L10N L = new L10N(ConfigType.class);
048:
049: /**
050: * Returns the Java type.
051: */
052: abstract public Class getType();
053:
054: /**
055: * Introspect the type.
056: */
057: public void introspect() {
058: }
059:
060: /**
061: * Returns a printable name of the type.
062: */
063: public String getTypeName() {
064: return getType().getName();
065: }
066:
067: /**
068: * Creates a new instance of the type.
069: */
070: public Object create(Object parent) {
071: return null;
072: }
073:
074: /**
075: * Inject and initialize the type
076: */
077: public void inject(Object bean) {
078: }
079:
080: /**
081: * Initialize the type
082: */
083: public void init(Object bean) {
084: }
085:
086: /**
087: * Replace the type with the generated object
088: */
089: public Object replaceObject(Object bean) {
090: return bean;
091: }
092:
093: /**
094: * Converts the string to a value of the type.
095: */
096: abstract public Object valueOf(String text);
097:
098: /**
099: * Converts the value to a value of the type.
100: */
101: public Object valueOf(Object value) {
102: if (value instanceof String)
103: return valueOf((String) value);
104: else
105: return value;
106: }
107:
108: /**
109: * Converts the value to a value of the type.
110: */
111: public Object valueOf(ELContext env, Expr value) {
112: return valueOf(value.getValue(env));
113: }
114:
115: /**
116: * Returns true for a bean-style type.
117: */
118: public boolean isBean() {
119: return false;
120: }
121:
122: /**
123: * Returns true for an XML node type.
124: */
125: public boolean isNode() {
126: return false;
127: }
128:
129: /**
130: * Return true for non-trim.
131: */
132: public boolean isNoTrim() {
133: return false;
134: }
135:
136: /**
137: * Return true for EL evaluation
138: */
139: public boolean isEL() {
140: return true;
141: }
142:
143: /**
144: * Returns true for a program type.
145: */
146: public boolean isProgram() {
147: return ConfigProgram.class.equals(getType());
148: }
149:
150: /**
151: * Returns the attribute with the given name.
152: */
153: public Attribute getAttribute(QName qName) {
154: throw new ConfigException(L.l(
155: "{0} does not allow attributes at '{1}'",
156: getTypeName(), qName));
157: }
158:
159: /**
160: * Returns the program attribute.
161: */
162: public Attribute getProgramAttribute() {
163: return null;
164: }
165:
166: /**
167: * Called before the children are configured.
168: */
169: public void beforeConfigureBean(ConfigContext builder, Object bean,
170: Node node) {
171: }
172:
173: /**
174: * Called before the children are configured. Also called for
175: * attribute configuration, e.g. for macros and web-app-default.
176: */
177: public void beforeConfigure(ConfigContext builder, Object bean,
178: Node node) {
179: }
180:
181: /**
182: * Called after the children are configured.
183: */
184: public void afterConfigure(ConfigContext builder, Object bean) {
185: }
186: }
|