Package de.odysseus.calyxo.forms.conf.impl

Source Code of de.odysseus.calyxo.forms.conf.impl.AssertConfigImpl

/*
* Copyright 2004, 2005, 2006 Odysseus Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.odysseus.calyxo.forms.conf.impl;

import javax.servlet.jsp.el.Expression;
import javax.servlet.jsp.el.ExpressionEvaluator;

import de.odysseus.calyxo.base.ModuleContext;
import de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.conf.impl.ConfigImpl;
import de.odysseus.calyxo.forms.conf.AssertConfig;
import de.odysseus.calyxo.forms.conf.MessageConfig;


/**
* Assert configuration implementation.
*
* @author Christoph Beck
* @author Oliver Stuhr
*/
public class AssertConfigImpl extends ConfigImpl implements AssertConfig {

  private String test;
  private MessageConfigImpl message;

  private Expression expression;

  /*
   * (non-Javadoc)
   * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_getElementName()
   */
  protected String _getElementName() {
    return "assert";
  }

  /*
   * (non-Javadoc)
   * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_addChildren(de.odysseus.calyxo.base.conf.impl.ConfigImpl.Elements)
   */
  protected void _addChildren(Elements list) {
    super._addChildren(list);
    list.add(getMessageConfig());
  }

  /*
   * (non-Javadoc)
   * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_putAttributes(de.odysseus.calyxo.base.conf.impl.ConfigImpl.Attributes)
   */
  protected void _putAttributes(Attributes map) {
    super._putAttributes(map);
    map.put("test", test);
  }

  /**
   * Answer array <code>{ "test" }</code>.
   * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_getDynamicAttributes()
   */
  protected String[] _getDynamicAttributes() {
    return new String[]{ "test" };
  }

  /**
   * Validate expression.
   * @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_evaluate(de.odysseus.calyxo.base.ModuleContext)
   */
  protected void _evaluate(ModuleContext context) throws ConfigException {
    super._evaluate(context);

    ExpressionEvaluator evaluator = context.getExpressionEvaluator();

    StringBuffer s = new StringBuffer();
    s.append("${");
    s.append(test);
    s.append("}");
    try {
      expression = evaluator.parseExpression(s.toString(), Boolean.class, this);
    } catch (Exception e) {
      throw new ConfigException("Parse error in '" + test + "'", e);
    }
  }

  /*
   * (non-Javadoc)
   * @see de.odysseus.calyxo.forms.conf.AssertConfig#getTest()
   */
  public String getTest() {
    return test;
  }

  /**
   * Set test expression
   */
  public void setTest(String string) {
    test = string;
  }

  /*
   * (non-Javadoc)
   * @see de.odysseus.calyxo.forms.conf.AssertConfig#getMessageConfig()
   */
  public MessageConfig getMessageConfig() {
    return message;
  }

  /**
   * Set message element
   */
  public void setMessageConfig(MessageConfigImpl impl) {
    message = impl;
  }

  /* (non-Javadoc)
   * @see de.odysseus.calyxo.forms.conf.AssertConfig#getParsedExpression()
   */
  public Expression getParsedExpression() {
    return expression;
  }

}
TOP

Related Classes of de.odysseus.calyxo.forms.conf.impl.AssertConfigImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.