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.attribute;
031:
032: import com.caucho.config.*;
033: import com.caucho.config.type.*;
034: import com.caucho.util.L10N;
035: import com.caucho.xml.QName;
036:
037: public abstract class Attribute {
038: private static final L10N L = new L10N(Attribute.class);
039:
040: /**
041: * Returns the config type of the attribute value.
042: */
043: abstract public ConfigType getConfigType();
044:
045: /**
046: * Returns true for a bean-style attribute.
047: */
048: public boolean isBean() {
049: return getConfigType().isBean();
050: }
051:
052: /**
053: * Returns true for an EL attribute.
054: */
055: public boolean isEL() {
056: return getConfigType().isEL();
057: }
058:
059: /**
060: * Returns true for a node attribute.
061: */
062: public boolean isNode() {
063: return getConfigType().isNode();
064: }
065:
066: /**
067: * Returns true for a program-style attribute.
068: */
069: public boolean isProgram() {
070: return getConfigType().isProgram();
071: }
072:
073: /**
074: * True if it allows text.
075: */
076: public boolean isAllowText() {
077: return true;
078: }
079:
080: /**
081: * Sets the value of the attribute as text
082: */
083: public void setText(Object bean, QName name, String value)
084: throws ConfigException {
085: throw new ConfigException(L.l(
086: "'{0}' does not allow text for attribute {1}.",
087: getConfigType().getTypeName(), name));
088: }
089:
090: /**
091: * Sets the value of the attribute
092: */
093: abstract public void setValue(Object bean, QName name, Object value)
094: throws ConfigException;
095:
096: /**
097: * Creates the child bean.
098: */
099: public Object create(Object parent) throws ConfigException {
100: return null;
101: }
102:
103: /**
104: * Replaces the given bean.
105: */
106: public Object replaceObject(Object bean) {
107: return getConfigType().replaceObject(bean);
108: }
109: }
|