001: /*
002: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package de.odysseus.calyxo.base.conf.impl;
017:
018: import javax.servlet.jsp.el.ExpressionEvaluator;
019: import javax.servlet.jsp.el.VariableResolver;
020:
021: import de.odysseus.calyxo.base.conf.ConfigException;
022: import de.odysseus.calyxo.base.conf.ObjectConfig;
023: import de.odysseus.calyxo.base.conf.MemberConfig;
024: import de.odysseus.calyxo.base.conf.ValueConfig;
025:
026: /**
027: * Value configuration implementation.
028: *
029: * @author Christoph Beck
030: */
031: public abstract class ValueConfigImpl extends ConfigImpl implements
032: ValueConfig {
033: private Object value;
034: private ObjectConfig object;
035: private MemberConfig member;
036:
037: /* (non-Javadoc)
038: * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_addChildren(de.odysseus.calyxo.base.conf.impl.ConfigImpl.Elements)
039: */
040: protected void _addChildren(Elements elements) {
041: super ._addChildren(elements);
042: elements.add(object);
043: elements.add(member);
044: }
045:
046: /*
047: * (non-Javadoc)
048: * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_putAttributes(de.odysseus.calyxo.base.conf.impl.ConfigImpl.Attributes)
049: */
050: protected void _putAttributes(Attributes map) {
051: super ._putAttributes(map);
052: map.put("value", value);
053: }
054:
055: /**
056: * Answer array <code>{ "value" }</code>.
057: * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_getDynamicAttributes()
058: */
059: protected String[] _getDynamicAttributes() {
060: return new String[] { "value" };
061: }
062:
063: /*
064: * (non-Javadoc)
065: * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_resolve(javax.servlet.jsp.el.ExpressionEvaluator, javax.servlet.jsp.el.VariableResolver)
066: */
067: protected void _resolve(ExpressionEvaluator evaluator,
068: VariableResolver variables) throws ConfigException {
069: if (value != null) {
070: if (object != null || member != null) {
071: throw new ConfigException(
072: "The value attribute requires an empty body in "
073: + toInlineString());
074: }
075: } else {
076: if (object == null && member == null) {
077: throw new ConfigException(
078: "An empty body requires the value attribute in "
079: + toInlineString());
080: }
081: }
082: super ._resolve(evaluator, variables);
083: }
084:
085: public Object eval(ClassLoader loader) throws ConfigException {
086: if (object != null) {
087: return object.create(loader);
088: }
089: if (member != null) {
090: return member.get(loader);
091: }
092: return value;
093: }
094:
095: /**
096: * Get value property
097: */
098: public Object getValue() {
099: return value;
100: }
101:
102: /**
103: * Set value property
104: */
105: public void setValue(Object value) {
106: this .value = value;
107: }
108:
109: /**
110: * Get object configuration
111: */
112: public ObjectConfig getObjectConfig() {
113: return object;
114: }
115:
116: /**
117: * Set object configuration
118: */
119: public void setObjectConfig(ObjectConfig object) {
120: this .object = object;
121: }
122:
123: /**
124: * Get member configuration
125: */
126: public MemberConfig getMemberConfig() {
127: return member;
128: }
129:
130: /**
131: * Get member configuration
132: */
133: public void setMemberConfig(MemberConfig member) {
134: this.member = member;
135: }
136: }
|